[PATCH] arm64: smp: Limit nr_cpu_ids under nosmp
Pengjie Zhang
zhangpengjie2 at huawei.com
Wed Apr 22 02:58:31 PDT 2026
Under nosmp (maxcpus=0), arm64 never brings up secondary CPUs.
However, arm64 still enumerates firmware-described CPUs during SMP
initialization, so secondary CPUs can remain visible to
for_each_possible_cpu() users even though they never reach the
bringup path in this configuration.
This is not just a cosmetic mask mismatch: code iterating over
possible CPUs may observe secondary CPU per-CPU state that is never
fully initialized under nosmp.
Limit nr_cpu_ids to 1 in arch_disable_smp_support() so that
secondary CPUs are not set up on arm64 when nosmp/maxcpus=0 is in
effect.
Signed-off-by: Pengjie Zhang <zhangpengjie2 at huawei.com>
---
arch/arm64/kernel/smp.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c
index 1aa324104afb..cc34c68871e9 100644
--- a/arch/arm64/kernel/smp.c
+++ b/arch/arm64/kernel/smp.c
@@ -435,6 +435,15 @@ static void __init hyp_mode_check(void)
}
}
+void __init arch_disable_smp_support(void)
+{
+ /*
+ * Under nosmp/maxcpus=0, only the boot CPU can ever be brought up.
+ * Limit nr_cpu_ids so that secondary CPUs are never set up.
+ */
+ set_nr_cpu_ids(1);
+}
+
void __init smp_cpus_done(unsigned int max_cpus)
{
pr_info("SMP: Total of %d processors activated.\n", num_online_cpus());
--
2.33.0
More information about the linux-arm-kernel
mailing list