* [PATCH] smp: Suppress false DEBUG_PREEMPT warning in smp_call_on_cpu()
@ 2025-10-24 7:07 Nam Cao
2025-10-24 14:08 ` Sebastian Andrzej Siewior
0 siblings, 1 reply; 4+ messages in thread
From: Nam Cao @ 2025-10-24 7:07 UTC (permalink / raw)
To: Ingo Molnar
Cc: Peter Zijlstra, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
Mel Gorman, Sebastian Andrzej Siewior, Shrikanth Hegde,
Steven Rostedt, Valentin Schneider, linux-kernel, Nam Cao
While booting UP (uniprocessor) kernel with CONFIG_DEBUG_PREEMPT=y, the
following warning is observed:
BUG: using smp_processor_id() in preemptible [00000000] code: swapper/0/1
caller is debug_smp_processor_id+0x1c/0x28
CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.18.0-rc2-00012-g002733e953a7 #111 PREEMPT_RT
Hardware name: MangoPi MQ Pro (DT)
Call Trace:
dump_backtrace
show_stack
dump_stack_lvl
dump_stack
check_preemption_disabled.isra.0
debug_smp_processor_id
check_unaligned_access
smp_call_on_cpu
check_unaligned_access_all_cpus
do_one_initcall
kernel_init_freeable
kernel_init
ret_from_fork_kernel
ret_from_fork_kernel_asm
This is a false warning. The UP-variant of smp_call_on_cpu() simply calls
the callback, and thus debug_smp_processor_id() thinks the context is
unsafe for smp_processor_id(), which is obviously false because this is UP
kernel.
This appears after commit 06ddd17521bf ("sched/smp: Always define
is_percpu_thread() and scheduler_ipi()"). Before this commit,
is_percpu_thread() always returns true on UP kernel and thus
debug_smp_processor_id() always sees a per-cpu thread and never warns. But
now is_percpu_thread() returns false for this case.
Suppress this warning with a migrate_disable()+migrate_enable() pair.
Fixes: 06ddd17521bf ("sched/smp: Always define is_percpu_thread() and scheduler_ipi()")
Signed-off-by: Nam Cao <namcao@linutronix.de>
---
grep shows me that the followings also have the same false warning:
arch/arm64/kernel/watchdog_hld.c
drivers/hwmon/dell-smm-hwmon.c
drivers/platform/x86/dell/dcdbas.c
kernel/watchdog.c
---
kernel/up.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/kernel/up.c b/kernel/up.c
index df50828cc2f0..37c9f0d39b36 100644
--- a/kernel/up.c
+++ b/kernel/up.c
@@ -64,7 +64,14 @@ int smp_call_on_cpu(unsigned int cpu, int (*func)(void *), void *par, bool phys)
if (phys)
hypervisor_pin_vcpu(0);
+
+ /* suppress warnings from debug_smp_processor_id() */
+ migrate_disable();
+
ret = func(par);
+
+ migrate_enable();
+
if (phys)
hypervisor_pin_vcpu(-1);
--
2.39.5
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] smp: Suppress false DEBUG_PREEMPT warning in smp_call_on_cpu()
2025-10-24 7:07 [PATCH] smp: Suppress false DEBUG_PREEMPT warning in smp_call_on_cpu() Nam Cao
@ 2025-10-24 14:08 ` Sebastian Andrzej Siewior
2025-11-05 8:42 ` Nam Cao
0 siblings, 1 reply; 4+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-10-24 14:08 UTC (permalink / raw)
To: Nam Cao
Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Mel Gorman, Shrikanth Hegde, Steven Rostedt,
Valentin Schneider, linux-kernel
On 2025-10-24 09:07:14 [+0200], Nam Cao wrote:
> While booting UP (uniprocessor) kernel with CONFIG_DEBUG_PREEMPT=y, the
> following warning is observed:
>
> BUG: using smp_processor_id() in preemptible [00000000] code: swapper/0/1
> caller is debug_smp_processor_id+0x1c/0x28
> CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.18.0-rc2-00012-g002733e953a7 #111 PREEMPT_RT
> Hardware name: MangoPi MQ Pro (DT)
> Call Trace:
> dump_backtrace
> show_stack
> dump_stack_lvl
> dump_stack
> check_preemption_disabled.isra.0
> debug_smp_processor_id
> check_unaligned_access
> smp_call_on_cpu
> check_unaligned_access_all_cpus
> do_one_initcall
> kernel_init_freeable
> kernel_init
> ret_from_fork_kernel
> ret_from_fork_kernel_asm
Can be compressed to:
Using smp_processor_id() in a smp_call_on_cpu() callback triggers a
"using ... in preemptible" warning in UP builds.
> This is a false warning. The UP-variant of smp_call_on_cpu() simply calls
> the callback, and thus debug_smp_processor_id() thinks the context is
> unsafe for smp_processor_id(), which is obviously false because this is UP
> kernel.
"Only the UP implementation is affected by this"
> This appears after commit 06ddd17521bf ("sched/smp: Always define
> is_percpu_thread() and scheduler_ipi()"). Before this commit,
> is_percpu_thread() always returns true on UP kernel and thus
> debug_smp_processor_id() always sees a per-cpu thread and never warns. But
> now is_percpu_thread() returns false for this case.
>
> Suppress this warning with a migrate_disable()+migrate_enable() pair.
Right. This is one of the possibilities. The other one would be to also
workqueue on UP and preserve the same semantic.
I don't mind this.
> Fixes: 06ddd17521bf ("sched/smp: Always define is_percpu_thread() and scheduler_ipi()")
> Signed-off-by: Nam Cao <namcao@linutronix.de>
> ---
> grep shows me that the followings also have the same false warning:
>
> arch/arm64/kernel/watchdog_hld.c
> drivers/hwmon/dell-smm-hwmon.c
> drivers/platform/x86/dell/dcdbas.c
> kernel/watchdog.c
> ---
> kernel/up.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/kernel/up.c b/kernel/up.c
> index df50828cc2f0..37c9f0d39b36 100644
> --- a/kernel/up.c
> +++ b/kernel/up.c
> @@ -64,7 +64,14 @@ int smp_call_on_cpu(unsigned int cpu, int (*func)(void *), void *par, bool phys)
>
> if (phys)
> hypervisor_pin_vcpu(0);
> +
> + /* suppress warnings from debug_smp_processor_id() */
If you want to add a comment, what about something like
/* Preserve not being migratable such as SMP variant does */
> + migrate_disable();
> +
> ret = func(par);
> +
> + migrate_enable();
> +
> if (phys)
> hypervisor_pin_vcpu(-1);
>
Sebastian
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] smp: Suppress false DEBUG_PREEMPT warning in smp_call_on_cpu()
2025-10-24 14:08 ` Sebastian Andrzej Siewior
@ 2025-11-05 8:42 ` Nam Cao
2025-11-05 8:48 ` Sebastian Andrzej Siewior
0 siblings, 1 reply; 4+ messages in thread
From: Nam Cao @ 2025-11-05 8:42 UTC (permalink / raw)
To: Sebastian Andrzej Siewior
Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Mel Gorman, Shrikanth Hegde, Steven Rostedt,
Valentin Schneider, linux-kernel
Sebastian Andrzej Siewior <bigeasy@linutronix.de> writes:
>> This appears after commit 06ddd17521bf ("sched/smp: Always define
>> is_percpu_thread() and scheduler_ipi()"). Before this commit,
>> is_percpu_thread() always returns true on UP kernel and thus
>> debug_smp_processor_id() always sees a per-cpu thread and never warns. But
>> now is_percpu_thread() returns false for this case.
>>
>> Suppress this warning with a migrate_disable()+migrate_enable() pair.
>
> Right. This is one of the possibilities. The other one would be to also
> workqueue on UP and preserve the same semantic.
> I don't mind this.
Yeah it's a tradeoff. I'm not sure if someone will be bothered by the
overhead that workqueue introduces, so I use this cheap solution.
>> +
>> + /* suppress warnings from debug_smp_processor_id() */
>
> If you want to add a comment, what about something like
>
> /* Preserve not being migratable such as SMP variant does */
Wouldn't it be a bit misleading? It's true that technically SMP variant
is not migratable, but that's because it is a per-cpu thread, not
because of migrate_disable(). To me, the comment sounds like that there
is also a migrate_disable() in SMP variant.
Nam
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] smp: Suppress false DEBUG_PREEMPT warning in smp_call_on_cpu()
2025-11-05 8:42 ` Nam Cao
@ 2025-11-05 8:48 ` Sebastian Andrzej Siewior
0 siblings, 0 replies; 4+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-11-05 8:48 UTC (permalink / raw)
To: Nam Cao
Cc: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot,
Dietmar Eggemann, Mel Gorman, Shrikanth Hegde, Steven Rostedt,
Valentin Schneider, linux-kernel
On 2025-11-05 09:42:42 [+0100], Nam Cao wrote:
> >> +
> >> + /* suppress warnings from debug_smp_processor_id() */
> >
> > If you want to add a comment, what about something like
> >
> > /* Preserve not being migratable such as SMP variant does */
>
> Wouldn't it be a bit misleading? It's true that technically SMP variant
> is not migratable, but that's because it is a per-cpu thread, not
> because of migrate_disable(). To me, the comment sounds like that there
> is also a migrate_disable() in SMP variant.
A per-cpu thread ensures that the control flow can not migrate to
another CPU. This is also what stops debug_smp_processor_id() warnings
from work invoked from queue_work_on() vs queue_work().
> Nam
Sebastian
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-11-05 8:48 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-24 7:07 [PATCH] smp: Suppress false DEBUG_PREEMPT warning in smp_call_on_cpu() Nam Cao
2025-10-24 14:08 ` Sebastian Andrzej Siewior
2025-11-05 8:42 ` Nam Cao
2025-11-05 8:48 ` Sebastian Andrzej Siewior
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.