* [PATCH V2] lib/smp_processor_id: Don't warn if there is only one CPU
@ 2026-11-15 9:55 Huacai Chen
2026-11-16 9:55 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Huacai Chen @ 2026-11-15 9:55 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
Andrew Morton, Huacai Chen
Cc: linux-mm, linux-kernel, Huacai Chen, stable, Tiezhu Yang
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 (!IS_ENABLED(CONFIG_SMP)) in check_preemption_disabled(). The
effect is partially reverting 570a752b7a9bd03b50 ("lib/smp_processor_id:
Use is_percpu_thread() instead of nr_cpus_allowed"), because now in the
UP case nr_cpus_allowed is 1 but PF_NO_SETAFFINITY is unset.
Cc: stable@vger.kernel.org
Reported-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
---
V2: Keep the behaviors for CONFIG_SMP.
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..be079b908504 100644
--- a/lib/smp_processor_id.c
+++ b/lib/smp_processor_id.c
@@ -22,6 +22,9 @@ unsigned int check_preemption_disabled(const char *what1, const char *what2)
if (is_percpu_thread())
goto out;
+ if (!IS_ENABLED(CONFIG_SMP))
+ goto out;
+
if (current->migration_disabled)
goto out;
--
2.52.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH V2] lib/smp_processor_id: Don't warn if there is only one CPU
2026-11-15 9:55 [PATCH V2] lib/smp_processor_id: Don't warn if there is only one CPU Huacai Chen
@ 2026-11-16 9:55 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-16 9:55 UTC (permalink / raw)
To: Huacai Chen, Ingo Molnar, Peter Zijlstra, Juri Lelli,
Vincent Guittot, Dietmar Eggemann, Steven Rostedt, Ben Segall,
Mel Gorman, Andrew Morton, Huacai Chen
Cc: linux-mm, Tiezhu Yang
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] lib/smp_processor_id: check_preemption_disabled() skips
checks on !CONFIG_SMP
- [Low] lib/smp_processor_id: missing Fixes trailer on stable bug-fix
commit
--
commit 62cd1e08e5d017184a1415887d93a1188fd3f001
Author: Huacai Chen <chenhuacai@kernel.org>
> lib/smp_processor_id: Don't warn if there is only one CPU
>
> 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 (!IS_ENABLED(CONFIG_SMP)) in check_preemption_disabled(). The
> effect is partially reverting 570a752b7a9bd03b50 ("lib/smp_processor_id:
> Use is_percpu_thread() instead of nr_cpus_allowed"), because now in the
> UP case nr_cpus_allowed is 1 but PF_NO_SETAFFINITY is unset.
>
> Cc: stable@vger.kernel.org
> Reported-by: Tiezhu Yang <yangtiezhu@loongson.cn>
> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
[Severity: Low]
Since this commit is tagged for stable and addresses the !CONFIG_SMP
behavior changed when is_percpu_thread() stopped unconditionally returning
true on UP builds, should it include a Fixes: tag such as:
Fixes: cac5cefbade9 ("sched/smp: Make SMP unconditional")
Fixes: 06ddd17521bf ("sched/smp: Always define is_percpu_thread() and scheduler_ipi()")
> diff --git a/lib/smp_processor_id.c b/lib/smp_processor_id.c
> index 94b3f6b195388..be079b9085045 100644
> --- a/lib/smp_processor_id.c
> +++ b/lib/smp_processor_id.c
> @@ -22,6 +22,9 @@ unsigned int check_preemption_disabled(const char *what1, const char *what2)
> if (is_percpu_thread())
> goto out;
>
> + if (!IS_ENABLED(CONFIG_SMP))
> + goto out;
> +
> if (current->migration_disabled)
> goto out;
[Severity: Medium]
As reported by Peter Zijlstra on v1 [1], does returning early on
!IS_ENABLED(CONFIG_SMP) disable all CONFIG_DEBUG_PREEMPT checks in
check_preemption_disabled() on UP builds?
check_preemption_disabled() also backs __this_cpu_preempt_check(), which
guards non-atomic __this_cpu_*() read-modify-write operations that can
still race across same-CPU preemption on a preemptible UP kernel, and
suppresses warnings for smp_processor_id() callers that would be broken on
SMP. Because !IS_ENABLED(CONFIG_SMP) is a compile-time constant, this
also turns the remainder of check_preemption_disabled(), including the
current->migration_disabled check made unconditional of CONFIG_SMP by
2885daf47081 ("lib/smp_processor_id: Make migration check unconditional of
SMP"), into dead code on !CONFIG_SMP.
In the reported trace, init_cache_level(unsigned int cpu) in
arch/loongarch/kernel/cacheinfo.c already receives cpu as an argument but
reads current_cpu_data via smp_processor_id() instead of cpu_data[cpu],
while cpuhp_issue_call() invokes the callback directly in preemptible task
context on !CONFIG_SMP.
[1] https://lore.kernel.org/r/20261111170600.GS1779021@noisy.programming.kicks-ass.net
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261115095503.2922598-1-chenhuacai@loongson.cn?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-16 9:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-15 9:55 [PATCH V2] lib/smp_processor_id: Don't warn if there is only one CPU Huacai Chen
2026-11-16 9:55 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox