Re: [PATCH] lib/smp_processor_id: Don't warn if there is only one CPU
From: Peter Zijlstra
Date: Wed Nov 11 2026 - 12:11:31 EST
On Wed, Nov 11, 2026 at 05:24:21PM +0800, Huacai Chen wrote:
> 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.
The check is still valid, you don't want to have any code that uses
smp_processor_id() outside of preempt_disable(). Such code would be
invalid on SMP, even when ran on UP.
All code must be SMP ready.
Aside from that, nr_cpu_ids is the wrong number to check.