Skip to content

Commit b4c0a73

Browse files
praritKAGA-KOKO
authored andcommitted
x86/smpboot: Fix __max_logical_packages estimate
A system booted with a small number of cores enabled per package panics because the estimate of __max_logical_packages is too low. This occurs when the total number of active cores across all packages is less than the maximum core count for a single package. e.g.: On a 4 package system with 20 cores/package where only 4 cores are enabled on each package, the value of __max_logical_packages is calculated as DIV_ROUND_UP(16 / 20) = 1 and not 4. Calculate __max_logical_packages after the cpu enumeration has completed. Use the boot cpu's data to extrapolate the number of packages. Signed-off-by: Prarit Bhargava <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Cc: Tom Lendacky <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Christian Borntraeger <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Kan Liang <[email protected]> Cc: He Chen <[email protected]> Cc: Stephane Eranian <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Piotr Luc <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Arvind Yadav <[email protected]> Cc: Vitaly Kuznetsov <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Tim Chen <[email protected]> Cc: Mathias Krause <[email protected]> Cc: "Kirill A. Shutemov" <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 30bb981 commit b4c0a73

File tree

1 file changed

+10
-45
lines changed

1 file changed

+10
-45
lines changed

arch/x86/kernel/smpboot.c

Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,6 @@ int topology_update_package_map(unsigned int pkg, unsigned int cpu)
310310
if (new >= 0)
311311
goto found;
312312

313-
if (logical_packages >= __max_logical_packages) {
314-
pr_warn("Package %u of CPU %u exceeds BIOS package data %u.\n",
315-
logical_packages, cpu, __max_logical_packages);
316-
return -ENOSPC;
317-
}
318-
319313
new = logical_packages++;
320314
if (new != pkg) {
321315
pr_info("CPU %u Converting physical %u to logical package %u\n",
@@ -326,52 +320,14 @@ int topology_update_package_map(unsigned int pkg, unsigned int cpu)
326320
return 0;
327321
}
328322

329-
static void __init smp_init_package_map(struct cpuinfo_x86 *c, unsigned int cpu)
330-
{
331-
unsigned int ncpus;
332-
333-
/*
334-
* Today neither Intel nor AMD support heterogenous systems. That
335-
* might change in the future....
336-
*
337-
* While ideally we'd want '* smp_num_siblings' in the below @ncpus
338-
* computation, this won't actually work since some Intel BIOSes
339-
* report inconsistent HT data when they disable HT.
340-
*
341-
* In particular, they reduce the APIC-IDs to only include the cores,
342-
* but leave the CPUID topology to say there are (2) siblings.
343-
* This means we don't know how many threads there will be until
344-
* after the APIC enumeration.
345-
*
346-
* By not including this we'll sometimes over-estimate the number of
347-
* logical packages by the amount of !present siblings, but this is
348-
* still better than MAX_LOCAL_APIC.
349-
*
350-
* We use total_cpus not nr_cpu_ids because nr_cpu_ids can be limited
351-
* on the command line leading to a similar issue as the HT disable
352-
* problem because the hyperthreads are usually enumerated after the
353-
* primary cores.
354-
*/
355-
ncpus = boot_cpu_data.x86_max_cores;
356-
if (!ncpus) {
357-
pr_warn("x86_max_cores == zero !?!?");
358-
ncpus = 1;
359-
}
360-
361-
__max_logical_packages = DIV_ROUND_UP(total_cpus, ncpus);
362-
pr_info("Max logical packages: %u\n", __max_logical_packages);
363-
364-
topology_update_package_map(c->phys_proc_id, cpu);
365-
}
366-
367323
void __init smp_store_boot_cpu_info(void)
368324
{
369325
int id = 0; /* CPU 0 */
370326
struct cpuinfo_x86 *c = &cpu_data(id);
371327

372328
*c = boot_cpu_data;
373329
c->cpu_index = id;
374-
smp_init_package_map(c, id);
330+
topology_update_package_map(c->phys_proc_id, id);
375331
c->initialized = true;
376332
}
377333

@@ -1341,7 +1297,16 @@ void __init native_smp_prepare_boot_cpu(void)
13411297

13421298
void __init native_smp_cpus_done(unsigned int max_cpus)
13431299
{
1300+
int ncpus;
1301+
13441302
pr_debug("Boot done\n");
1303+
/*
1304+
* Today neither Intel nor AMD support heterogenous systems so
1305+
* extrapolate the boot cpu's data to all packages.
1306+
*/
1307+
ncpus = cpu_data(0).booted_cores * smp_num_siblings;
1308+
__max_logical_packages = DIV_ROUND_UP(nr_cpu_ids, ncpus);
1309+
pr_info("Max logical packages: %u\n", __max_logical_packages);
13451310

13461311
if (x86_has_numa_in_package)
13471312
set_sched_topology(x86_numa_in_package_topology);

0 commit comments

Comments
 (0)