Skip to content

Commit 78b599a

Browse files
Andi KleenLinus Torvalds
authored andcommitted
x86_64: Don't rely on a unique IO-APIC ID
Linux 64bit only uses the IO-APIC ID as an internal cookie. In the future there could be some cases where the IO-APIC IDs are not unique because they share an 8 bit space with CPUs and if there are enough CPUs it is difficult to get them that. But Linux needs the io apic ID internally for its data structures. Assign unique IO APIC ids on table parsing. TBD do for 32bit too Signed-off-by: Andi Kleen <ak@suse.de> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 9d531cc commit 78b599a

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

arch/x86_64/kernel/mpparse.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,21 +649,35 @@ static int mp_find_ioapic(int gsi)
649649
return -1;
650650
}
651651

652+
static u8 uniq_ioapic_id(u8 id)
653+
{
654+
int i;
655+
DECLARE_BITMAP(used, 256);
656+
bitmap_zero(used, 256);
657+
for (i = 0; i < nr_ioapics; i++) {
658+
struct mpc_config_ioapic *ia = &mp_ioapics[i];
659+
__set_bit(ia->mpc_apicid, used);
660+
}
661+
if (!test_bit(id, used))
662+
return id;
663+
return find_first_zero_bit(used, 256);
664+
}
665+
652666
void __init mp_register_ioapic(u8 id, u32 address, u32 gsi_base)
653667
{
654668
int idx = 0;
655669

656670
if (bad_ioapic(address))
657671
return;
658672

659-
idx = nr_ioapics++;
673+
idx = nr_ioapics;
660674

661675
mp_ioapics[idx].mpc_type = MP_IOAPIC;
662676
mp_ioapics[idx].mpc_flags = MPC_APIC_USABLE;
663677
mp_ioapics[idx].mpc_apicaddr = address;
664678

665679
set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address);
666-
mp_ioapics[idx].mpc_apicid = id;
680+
mp_ioapics[idx].mpc_apicid = uniq_ioapic_id(id);
667681
mp_ioapics[idx].mpc_apicver = 0;
668682

669683
/*
@@ -680,6 +694,8 @@ void __init mp_register_ioapic(u8 id, u32 address, u32 gsi_base)
680694
mp_ioapics[idx].mpc_apicaddr,
681695
mp_ioapic_routing[idx].gsi_start,
682696
mp_ioapic_routing[idx].gsi_end);
697+
698+
nr_ioapics++;
683699
}
684700

685701
void __init

0 commit comments

Comments
 (0)