Skip to content

Commit 5e25eb2

Browse files
KAGA-KOKObp3tk0v
authored andcommitted
x86/topology: Handle the !APIC case gracefully
If there is no local APIC enumerated and registered then the topology bitmaps are empty. Therefore, topology_init_possible_cpus() will die with a division by zero exception. Prevent this by registering a fake APIC id to populate the topology bitmap. This also allows to use all topology query interfaces unconditionally. It does not affect the actual APIC code because either the local APIC address was not registered or no local APIC could be detected. Fixes: f1f758a ("x86/topology: Add a mechanism to track topology via APIC IDs") Reported-by: Guenter Roeck <[email protected]> Reported-by: Linus Torvalds <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Tested-by: Guenter Roeck <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 7af541c commit 5e25eb2

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

arch/x86/kernel/cpu/topology.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,17 @@ void __init topology_init_possible_cpus(void)
415415
unsigned int total = assigned + disabled;
416416
u32 apicid, firstid;
417417

418+
/*
419+
* If there was no APIC registered, then fake one so that the
420+
* topology bitmap is populated. That ensures that the code below
421+
* is valid and the various query interfaces can be used
422+
* unconditionally. This does not affect the actual APIC code in
423+
* any way because either the local APIC address has not been
424+
* registered or the local APIC was disabled on the command line.
425+
*/
426+
if (topo_info.boot_cpu_apic_id == BAD_APICID)
427+
topology_register_boot_apic(0);
428+
418429
if (!restrict_to_up()) {
419430
if (WARN_ON_ONCE(assigned > nr_cpu_ids)) {
420431
disabled += assigned - nr_cpu_ids;

0 commit comments

Comments
 (0)