]> xenbits.xensource.com Git - people/aperard/linux.git/commitdiff
powerpc/smp: Remap boot CPU onto core 0 if >= nr_cpu_ids
authorMichael Ellerman <mpe@ellerman.id.au>
Wed, 14 Feb 2024 13:14:05 +0000 (00:14 +1100)
committerMichael Ellerman <mpe@ellerman.id.au>
Wed, 14 Feb 2024 13:14:05 +0000 (00:14 +1100)
If nr_cpu_ids is too low to include the boot CPU, remap the boot CPU
onto logical core 0.

This is achieved in two stages. In early_init_dt_scan_cpus() the boot
CPU is renumbered to be on logical core 0, and the original boot core's
hardware ID is recorded.

Later in smp_setup_cpu_maps(), if the original boot core ID is set, the
logical CPU numbers on the 0th core are skipped in the normal device
tree search over CPU device tree nodes. Then the search is continued
until the device tree node matching the boot core is found, and those
CPUs are assigned the CPU numbers starting at 0.

This allows kdump kernels to be booted with low values for nr_cpu_ids
to conserve memory, while also allowing the crashing/boot CPU to be
any CPU.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Tested-by: Wen Xiong <wenxiong@us.ibm.com>
Link: https://msgid.link/20231229120107.2281153-5-mpe@ellerman.id.au
arch/powerpc/include/asm/smp.h
arch/powerpc/kernel/prom.c
arch/powerpc/kernel/setup-common.c

index aaaa576d0e154edc270a4dd9ddd8bd6bb877ee4a..b77927ccb0ab00aae57cc95eac1158739dd3ce5e 100644 (file)
@@ -27,6 +27,7 @@
 
 extern int boot_cpuid;
 extern int boot_cpu_hwid; /* PPC64 only */
+extern int boot_core_hwid;
 extern int spinning_secondaries;
 extern u32 *cpu_to_phys_id;
 extern bool coregroup_enabled;
index 77364729a1b617c6040cafa6cae59e66023b19cc..f2c2f79ea4770477d723ef1d0d10583e7ed8fc19 100644 (file)
@@ -368,8 +368,6 @@ static int __init early_init_dt_scan_cpus(unsigned long node,
        if (found < 0)
                return 0;
 
-       DBG("boot cpu: logical %d physical %d\n", found,
-           be32_to_cpu(intserv[found_thread]));
        boot_cpuid = found;
 
        if (IS_ENABLED(CONFIG_PPC64))
@@ -382,11 +380,19 @@ static int __init early_init_dt_scan_cpus(unsigned long node,
        }
 
        if (boot_cpuid >= nr_cpu_ids) {
-               set_nr_cpu_ids(min(CONFIG_NR_CPUS, ALIGN(boot_cpuid + 1, nthreads)));
-               pr_warn("Boot CPU %d >= nr_cpu_ids, adjusted nr_cpu_ids to %d\n",
-                       boot_cpuid, nr_cpu_ids);
+               // Remember boot core for smp_setup_cpu_maps()
+               boot_core_hwid = be32_to_cpu(intserv[0]);
+
+               pr_warn("Boot CPU %d (core hwid %d) >= nr_cpu_ids, adjusted boot CPU to %d\n",
+                       boot_cpuid, boot_core_hwid, found_thread);
+
+               // Adjust boot CPU to appear on logical core 0
+               boot_cpuid = found_thread;
        }
 
+       DBG("boot cpu: logical %d physical %d\n", boot_cpuid,
+           be32_to_cpu(intserv[found_thread]));
+
        /*
         * PAPR defines "logical" PVR values for cpus that
         * meet various levels of the architecture:
index a5aab5a7954576433327fb68aa5511a86c9df5f1..6fe68aa932684a1371415679c005462f82e25b7c 100644 (file)
@@ -85,6 +85,7 @@ EXPORT_SYMBOL(machine_id);
 
 int boot_cpuid = -1;
 EXPORT_SYMBOL_GPL(boot_cpuid);
+int __initdata boot_core_hwid = -1;
 
 #ifdef CONFIG_PPC64
 int boot_cpu_hwid = -1;
@@ -492,12 +493,26 @@ void __init smp_setup_cpu_maps(void)
                        avail = !of_property_match_string(dn,
                                        "enable-method", "spin-table");
 
-               cpu = assign_threads(cpu, nthreads, avail, intserv);
+               if (boot_core_hwid >= 0) {
+                       if (cpu == 0) {
+                               pr_info("Skipping CPU node %pOF to allow for boot core.\n", dn);
+                               cpu = nthreads;
+                               continue;
+                       }
 
-               if (cpu >= nr_cpu_ids) {
+                       if (be32_to_cpu(intserv[0]) == boot_core_hwid) {
+                               pr_info("Renumbered boot core %pOF to logical 0\n", dn);
+                               assign_threads(0, nthreads, avail, intserv);
+                               of_node_put(dn);
+                               break;
+                       }
+               } else if (cpu >= nr_cpu_ids) {
                        of_node_put(dn);
                        break;
                }
+
+               if (cpu < nr_cpu_ids)
+                       cpu = assign_threads(cpu, nthreads, avail, intserv);
        }
 
        /* If no SMT supported, nthreads is forced to 1 */