If nr_cpu_ids is too low to include at least all the threads of a single
core adjust nr_cpu_ids upwards. This avoids triggering odd bugs in code
that assumes all threads of a core are available.

Cc: [email protected]
Signed-off-by: Michael Ellerman <[email protected]>
---
 arch/powerpc/kernel/prom.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
index 0b5878c3125b..58e80076bed5 100644
--- a/arch/powerpc/kernel/prom.c
+++ b/arch/powerpc/kernel/prom.c
@@ -375,6 +375,12 @@ static int __init early_init_dt_scan_cpus(unsigned long 
node,
        if (IS_ENABLED(CONFIG_PPC64))
                boot_cpu_hwid = be32_to_cpu(intserv[found_thread]);
 
+       if (nr_cpu_ids % nthreads != 0) {
+               set_nr_cpu_ids(ALIGN(nr_cpu_ids, nthreads));
+               pr_warn("nr_cpu_ids was not a multiple of threads_per_core, 
adjusted to %d\n",
+                       nr_cpu_ids);
+       }
+
        /*
         * PAPR defines "logical" PVR values for cpus that
         * meet various levels of the architecture:
-- 
2.43.0

Reply via email to