[PATCH] lib/smp_processor_id: Don't warn if there is only one CPU

From: Huacai Chen

Date: Wed Nov 11 2026 - 04:35:51 EST


When CONFIG_DEBUG_PREEMPT is enabled on a Non-SMP (single-core) kernel,
calls to smp_processor_id() in preemptible contexts trigger some false
positive "BUG: using smp_processor_id() in preemptible" warnings, which
are harmless noise because the process always executes on CPU 0 and CPU
migration is impossible.

Here are some of the trimmed log messages:

Call Trace:
[<9000000000d33e28>] show_stack+0xf8/0x1c0
[<9000000000d2fdac>] dump_stack_lvl+0x4c/0x78
[<9000000002456fc0>] check_preemption_disabled.isra.0+0x100/0x110
[<9000000002456ff8>] debug_smp_processor_id+0x18/0x40
[<9000000000d31118>] init_cache_level+0x18/0x90
[<9000000001adbe2c>] detect_cache_attributes+0x4c/0x640
[<9000000001adc44c>] cacheinfo_cpu_online+0x1c/0x310
[<9000000000d5ae04>] cpuhp_issue_call.constprop.0+0x94/0xd0
[<9000000000d5b278>] __cpuhp_setup_state_cpuslocked+0x208/0x320
[<9000000000d30148>] do_one_initcall+0x68/0x200
[<90000000024711b8>] kernel_init_freeable+0x1fc/0x294
[<900000000245824c>] kernel_init+0x20/0x134
[<9000000002455b54>] ret_from_kernel_thread+0x24/0x1d0
[<9000000000d31650>] ret_from_kernel_thread_asm+0xc/0x9c

This warning only exists for the !CONFIG_SMP build. This is because for
CONFIG_SMP cpuhp_issue_call() invokes callbacks in cpuhp_thread_fun()
which is a percpu thread, but for !CONFIG_SMP build it invoke callbacks
in the init process which is not a percpu thread. And there is such a
skip condition in check_preemption_disabled():

if (is_percpu_thread())
goto out;

Since there is only one CPU for the !CONFIG_SMP, we can simply skip the
warning if (nr_cpu_ids == 1) in check_preemption_disabled().

Cc: stable@xxxxxxxxxxxxxxx
Reported-by: Tiezhu Yang <yangtiezhu@xxxxxxxxxxx>
Signed-off-by: Huacai Chen <chenhuacai@xxxxxxxxxxx>
---
lib/smp_processor_id.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/lib/smp_processor_id.c b/lib/smp_processor_id.c
index 94b3f6b19538..64901d33c0ee 100644
--- a/lib/smp_processor_id.c
+++ b/lib/smp_processor_id.c
@@ -19,6 +19,9 @@ unsigned int check_preemption_disabled(const char *what1, const char *what2)
if (irqs_disabled())
goto out;

+ if (nr_cpu_ids == 1)
+ goto out;
+
if (is_percpu_thread())
goto out;

--
2.52.0