stop_machine: Make stop_one_cpu_nowait() return void
PATCH v2 1/1 stop_machine: Make stop_one_cpu_nowait() return void
No caller checks the return value from stop_one_cpu_nowait(). All callers require the callback to run and arrange for the target CPU's stopper to remain enabled while queuing the work. In particular, commit f0498d2a54e7 ("sched: Fix stop_one_cpu_nowait() vs hotplug") added preemption protection to the scheduler callers so that queuing must succeed once the target CPU has been observed online.
Therefore, a failure is an unrecoverable violation rather than a condition individual callers can recover from. Diagnose it with WARN_ON_ONCE() in stop_one_cpu_nowait(). A check in the common helper covers current and future callers consistently, while individual checks would duplicate the same non-recoverable handling at every call site.
Make the function return void because there is no longer a meaningful result for callers to consume.
On UP, warn if the supplied CPU is not the current CPU because the work cannot be scheduled in that case.
---
v1: https://lore.kernel.org/all/[email protected]/
v2:
- carefully include linux/bug.h (Bradley);
- update the CONTEXT section (Bradley).
include/linux/stop_machine.h | 21 ++++++++++----------- kernel/stop_machine.c | 14 ++++++-------- 2 files changed, 16 insertions(+), 19 deletions(-)
include/linux/stop_machine.h +10 -11
@@ -2,6 +2,7 @@#ifndef _LINUX_STOP_MACHINE#define _LINUX_STOP_MACHINE +#include <linux/bug.h> #include <linux/cpu.h> #include <linux/cpumask_types.h> #include <linux/smp.h>
@@ -31,7 +32,7 @@ struct cpu_stop_work {int stop_one_cpu (unsigned int cpu,cpu_stop_fn_t fn,void *arg);int stop_two_cpus (unsigned int cpu1,unsigned int cpu2,cpu_stop_fn_t fn,void *arg); -bool stop_one_cpu_nowait (unsigned int cpu,cpu_stop_fn_t fn,void *arg, +void stop_one_cpu_nowait (unsigned int cpu,cpu_stop_fn_t fn,void *arg,struct cpu_stop_work *work_buf);void stop_machine_park (int cpu);void stop_machine_unpark (int cpu);
@@ -68,19 +69,17 @@ static void stop_one_cpu_nowait_workfn(struct work_struct *work)preempt_enable (); } -static inline bool stop_one_cpu_nowait (unsigned int cpu, +static inline void stop_one_cpu_nowait (unsigned int cpu,cpu_stop_fn_t fn,void *arg,struct cpu_stop_work *work_buf) { -if (cpu ==smp_processor_id ()) { -INIT_WORK (&work_buf->work, stop_one_cpu_nowait_workfn); - work_buf->fn = fn; - work_buf->arg = arg; -schedule_work (&work_buf->work); -return true; - } - -return false; +if (WARN_ON_ONCE (cpu !=smp_processor_id ())) +return ; + +INIT_WORK (&work_buf->work, stop_one_cpu_nowait_workfn); + work_buf->fn = fn; + work_buf->arg = arg; +schedule_work (&work_buf->work); }static inline void print_stop_info (const char *log_lvl,struct task_struct *task) { }
kernel/stop_machine.c +6 -8
@@ -7,6 +7,7 @@* Copyright (C) 2010 SUSE Linux Products GmbH * Copyright (C) 2010 Tejun Heo <[email protected]> */ +#include <linux/bug.h> #include <linux/compiler.h> #include <linux/completion.h> #include <linux/cpu.h>
@@ -376,17 +377,14 @@ int stop_two_cpus(unsigned int cpu1, unsigned int cpu2, cpu_stop_fn_t fn, void ** and will remain untouched until stopper starts executing @fn. * * CONTEXT: -* Don't care. -* -* RETURNS: -* true if cpu_stop_work was queued successfully and @fn will be called, -* false otherwise. +* Don't care, but the caller must ensure @cpu's stopper stays enabled +* until the work is queued, e.g. by preempt_disable(). */ -bool stop_one_cpu_nowait (unsigned int cpu,cpu_stop_fn_t fn,void *arg, -struct cpu_stop_work *work_buf) +void stop_one_cpu_nowait (unsigned int cpu,cpu_stop_fn_t fn,void *arg, +struct cpu_stop_work *work_buf) { *work_buf = (struct cpu_stop_work ){ .fn = fn, .arg = arg, .caller = _RET_IP_, }; -return cpu_stop_queue_work (cpu, work_buf); +WARN_ON_ONCE (!cpu_stop_queue_work (cpu, work_buf)); } static bool queue_stop_cpus_work(const struct cpumask *cpumask,
Signature · 1 line
2.53.0
Quoted 13 lines · Yury Norov
No caller checks the return value from
stop_one_cpu_nowait(). All callers require the callback to run and arrange for the target CPU's stopper to remain enabled while queuing the work. In particular, commitf0498d2a54e7("sched: Fixstop_one_cpu_nowait()vs hotplug") added preemption protection to the scheduler callers so that queuing must succeed once the target CPU has been observed online.Therefore, a failure is an unrecoverable violation rather than a condition individual callers can recover from. Diagnose it with
WARN_ON_ONCE()instop_one_cpu_nowait(). A check in the common helper covers current and future callers consistently, while individual checks would duplicate the same non-recoverable handling at every call site.
Quoted 7 lines
Make the function return void because there is no longer a meaningful result for callers to consume.
On UP, warn if the supplied CPU is not the current CPU because the work cannot be scheduled in that case.
CC Bradley Morgan <[email protected]>
Quoted 88 lines
Signed-off-by Yury Norov <[email protected]>---
v1: https://lore.kernel.org/all/[email protected]/
v2:
- carefully includelinux/bug.h(Bradley);
- update the CONTEXT section (Bradley).
include/linux/stop_machine.h| 21 ++++++++++-----------kernel/stop_machine.c| 14 ++++++--------2 files changed, 16 insertions(+), 19 deletions(-)include/linux/stop_machine.h +2
-1@@ -2,6 +2,7 @@#ifndef _LINUX_STOP_MACHINE#define _LINUX_STOP_MACHINE +#include <linux/bug.h> #include <linux/cpu.h> #include <linux/cpumask_types.h> #include <linux/smp.h> @@ -31,7 +32,7 @@ struct cpu_stop_work {int stop_one_cpu (unsigned int cpu,cpu_stop_fn_t fn,void *arg);int stop_two_cpus (unsigned int cpu1,unsigned int cpu2,cpu_stop_fn_t fn,void *arg); -bool stop_one_cpu_nowait (unsigned int cpu,cpu_stop_fn_t fn,void *arg, +void stop_one_cpu_nowait (unsigned int cpu,cpu_stop_fn_t fn,void *arg,struct cpu_stop_work *work_buf);void stop_machine_park (int cpu);void
stop_machine_unpark(int cpu);include/linux/stop_machine.h +8
-10@@ -68,19 +69,17 @@ static void stop_one_cpu_nowait_workfn(struct work_struct *work)preempt_enable (); } -static inline bool stop_one_cpu_nowait (unsigned int cpu, +static inline void stop_one_cpu_nowait (unsigned int cpu,cpu_stop_fn_t fn,void *arg,struct cpu_stop_work *work_buf) { -if (cpu ==smp_processor_id ()) { -INIT_WORK (&work_buf->work, stop_one_cpu_nowait_workfn); - work_buf->fn = fn; - work_buf->arg = arg; -schedule_work (&work_buf->work); -return true; - } - -return false; +if (WARN_ON_ONCE (cpu !=smp_processor_id ())) +return ; + +INIT_WORK (&work_buf->work, stop_one_cpu_nowait_workfn); + work_buf->fn = fn; + work_buf->arg = arg; +schedule_work (&work_buf->work); }static inline void
print_stop_info(const char *log_lvl, struct task_struct *task){ }kernel/stop_machine.c +3
-6@@ -7,6 +7,7 @@* Copyright (C) 2010 SUSE Linux Products GmbH * Copyright (C) 2010 Tejun Heo <[email protected]> */ +#include <linux/bug.h> #include <linux/compiler.h> #include <linux/completion.h> #include <linux/cpu.h> @@ -376,17 +377,14 @@ int stop_two_cpus(unsigned int cpu1, unsigned int cpu2, cpu_stop_fn_t fn, void ** and will remain untouched until stopper starts executing @fn. * * CONTEXT: -* Don't care. -* -* RETURNS: -* true if cpu_stop_work was queued successfully and @fn will be called, -* false otherwise. +* Don't care, but the caller must ensure @cpu's stopper stays enabled +* until the work is queued, e.g. by preempt_disable(). */ -bool stop_one_cpu_nowait(unsigned int cpu, cpu_stop_fn_t fn, void *arg,
kernel/stop_machine.c int stop_two_cpus(unsigned int cpu1, unsigned int cpu2, cpu_stop_fn_t fn, void * · line 390
Quoted 10 lines
kernel/stop_machine.c +3
-2- struct cpu_stop_work *work_buf) +void stop_one_cpu_nowait (unsigned int cpu,cpu_stop_fn_t fn,void *arg, +struct cpu_stop_work *work_buf) { *work_buf = (struct cpu_stop_work ){ .fn = fn, .arg = arg, .caller = _RET_IP_, }; -return cpu_stop_queue_work (cpu, work_buf); +WARN_ON_ONCE (!cpu_stop_queue_work (cpu, work_buf)); } static bool queue_stop_cpus_work(const struct cpumask *cpumask,
Thanks!
Quoted 13 lines · Yury Norov
No caller checks the return value from
stop_one_cpu_nowait(). All callers require the callback to run and arrange for the target CPU's stopper to remain enabled while queuing the work. In particular, commitf0498d2a54e7("sched: Fixstop_one_cpu_nowait()vs hotplug") added preemption protection to the scheduler callers so that queuing must succeed once the target CPU has been observed online.Therefore, a failure is an unrecoverable violation rather than a condition individual callers can recover from. Diagnose it with
WARN_ON_ONCE()instop_one_cpu_nowait(). A check in the common helper covers current and future callers consistently, while individual checks would duplicate the same non-recoverable handling at every call site.
Quoted 8 lines
Make the function return void because there is no longer a meaningful result for callers to consume.
On UP, warn if the supplied CPU is not the current CPU because the work cannot be scheduled in that case.
CC Bradley Morgan <[email protected]>Signed-off-by Yury Norov <[email protected]>
I suppose; you want me to take this through the scheduler tree?
Quoted 17 lines · Peter Zijlstra
Quoted 16 lines · Yury Norov
No caller checks the return value from
stop_one_cpu_nowait(). All callers require the callback to run and arrange for the target CPU's stopper to remain enabled while queuing the work. In particular, commitf0498d2a54e7("sched: Fixstop_one_cpu_nowait()vs hotplug") added preemption protection to the scheduler callers so that queuing must succeed once the target CPU has been observed online.Therefore, a failure is an unrecoverable violation rather than a condition individual callers can recover from. Diagnose it with
WARN_ON_ONCE()instop_one_cpu_nowait(). A check in the common helper covers current and future callers consistently, while individual checks would duplicate the same non-recoverable handling at every call site.Make the function return void because there is no longer a meaningful result for callers to consume.
Quoted 7 lines
Quoted 5 lines
On UP, warn if the supplied CPU is not the current CPU because the work cannot be scheduled in that case.
CC Bradley Morgan <[email protected]>Signed-off-by Yury Norov <[email protected]>I suppose; you want me to take this through the scheduler tree?
Sure, thanks!
Hi Yury.
Quoted 93 lines · Yury Norov
No caller checks the return value from
stop_one_cpu_nowait(). All callers require the callback to run and arrange for the target CPU's stopper to remain enabled while queuing the work. In particular, commitf0498d2a54e7("sched: Fixstop_one_cpu_nowait()vs hotplug") added preemption protection to the scheduler callers so that queuing must succeed once the target CPU has been observed online.Therefore, a failure is an unrecoverable violation rather than a condition individual callers can recover from. Diagnose it with
WARN_ON_ONCE()instop_one_cpu_nowait(). A check in the common helper covers current and future callers consistently, while individual checks would duplicate the same non-recoverable handling at every call site.Make the function return void because there is no longer a meaningful result for callers to consume.
On UP, warn if the supplied CPU is not the current CPU because the work cannot be scheduled in that case.
CC Bradley Morgan <[email protected]>Signed-off-by Yury Norov <[email protected]>---
v1: https://lore.kernel.org/all/[email protected]/
v2:
- carefully includelinux/bug.h(Bradley);
- update the CONTEXT section (Bradley).include/linux/stop_machine.h | 21 ++++++++++----------- kernel/stop_machine.c | 14 ++++++-------- 2 files changed, 16 insertions(+), 19 deletions(-)include/linux/stop_machine.h +10
-11@@ -2,6 +2,7 @@#ifndef _LINUX_STOP_MACHINE#define _LINUX_STOP_MACHINE +#include <linux/bug.h> #include <linux/cpu.h> #include <linux/cpumask_types.h> #include <linux/smp.h> @@ -31,7 +32,7 @@ struct cpu_stop_work {int stop_one_cpu (unsigned int cpu,cpu_stop_fn_t fn,void *arg);int stop_two_cpus (unsigned int cpu1,unsigned int cpu2,cpu_stop_fn_t fn,void *arg); -bool stop_one_cpu_nowait (unsigned int cpu,cpu_stop_fn_t fn,void *arg, +void stop_one_cpu_nowait (unsigned int cpu,cpu_stop_fn_t fn,void *arg,struct cpu_stop_work *work_buf);void stop_machine_park (int cpu);void stop_machine_unpark (int cpu);@@ -68,19 +69,17 @@ static void stop_one_cpu_nowait_workfn(struct work_struct *work)preempt_enable (); } -static inline bool stop_one_cpu_nowait (unsigned int cpu, +static inline void stop_one_cpu_nowait (unsigned int cpu,cpu_stop_fn_t fn,void *arg,struct cpu_stop_work *work_buf) { -if (cpu ==smp_processor_id ()) { -INIT_WORK (&work_buf->work, stop_one_cpu_nowait_workfn); - work_buf->fn = fn; - work_buf->arg = arg; -schedule_work (&work_buf->work); -return true; - } - -return false; +if (WARN_ON_ONCE (cpu !=smp_processor_id ())) +return ; + +INIT_WORK (&work_buf->work, stop_one_cpu_nowait_workfn); + work_buf->fn = fn; + work_buf->arg = arg; +schedule_work (&work_buf->work); }static inline void print_stop_info (const char *log_lvl,struct task_struct *task) { }kernel/stop_machine.c +1
-0@@ -7,6 +7,7 @@* Copyright (C) 2010 SUSE Linux Products GmbH * Copyright (C) 2010 Tejun Heo <[email protected]> */ +#include <linux/bug.h> #include <linux/compiler.h> #include <linux/completion.h> #include <linux/cpu.h>
kernel/stop_machine.c int stop_two_cpus(unsigned int cpu1, unsigned int cpu2, cpu_stop_fn_t fn, void * · line 381
Quoted 10 lines
kernel/stop_machine.c +2
-5@@ -376,17 +377,14 @@ int stop_two_cpus(unsigned int cpu1, unsigned int cpu2, cpu_stop_fn_t fn, void ** and will remain untouched until stopper starts executing @fn. * * CONTEXT: -* Don't care. -* -* RETURNS: -* true if cpu_stop_work was queued successfully and @fn will be called, -* false otherwise. +* Don't care, but the caller must ensure @cpu's stopper stays enabled +* until the work is queued, e.g. by preempt_disable().
nit:
* until the work is queued, i.e. ensuring preemption/irq disabled. ?
Because, if irq are disabled it is equally good enough.
#define preemptible() (preempt_count() == 0 && !irqs_disabled())
kernel/stop_machine.c int stop_two_cpus(unsigned int cpu1, unsigned int cpu2, cpu_stop_fn_t fn, void * · line 390
Quoted 12 lines
kernel/stop_machine.c +3
-3*/ -bool stop_one_cpu_nowait (unsigned int cpu,cpu_stop_fn_t fn,void *arg, -struct cpu_stop_work *work_buf) +void stop_one_cpu_nowait (unsigned int cpu,cpu_stop_fn_t fn,void *arg, +struct cpu_stop_work *work_buf) { *work_buf = (struct cpu_stop_work ){ .fn = fn, .arg = arg, .caller = _RET_IP_, }; -return cpu_stop_queue_work (cpu, work_buf); +WARN_ON_ONCE (!cpu_stop_queue_work (cpu, work_buf)); } static bool queue_stop_cpus_work(const struct cpumask *cpumask,
Other than that,
The following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 5186ef36909c792591fda7a1ae2afc168f60bc90 Gitweb: https://git.kernel.org/tip/5186ef36909c792591fda7a1ae2afc168f60bc90 Author: Yury Norov <[email protected]> AuthorDate: Tue, 28 Jul 2026 22:23:54 -04:00 Committer: Peter Zijlstra <[email protected]> CommitterDate: Fri, 31 Jul 2026 12:35:26 +02:00
stop_machine: Make stop_one_cpu_nowait() return void
No caller checks the return value from stop_one_cpu_nowait(). All callers require the callback to run and arrange for the target CPU's stopper to remain enabled while queuing the work. In particular, commit f0498d2a54e7 ("sched: Fix stop_one_cpu_nowait() vs hotplug") added preemption protection to the scheduler callers so that queuing must succeed once the target CPU has been observed online.
Therefore, a failure is an unrecoverable violation rather than a condition individual callers can recover from. Diagnose it with WARN_ON_ONCE() in stop_one_cpu_nowait(). A check in the common helper covers current and future callers consistently, while individual checks would duplicate the same non-recoverable handling at every call site.
Make the function return void because there is no longer a meaningful result for callers to consume.
On UP, warn if the supplied CPU is not the current CPU because the work cannot be scheduled in that case.
--- include/linux/stop_machine.h | 21 ++++++++++----------- kernel/stop_machine.c | 14 ++++++-------- 2 files changed, 16 insertions(+), 19 deletions(-)
include/linux/stop_machine.h +10 -11
@@ -2,6 +2,7 @@#ifndef _LINUX_STOP_MACHINE#define _LINUX_STOP_MACHINE +#include <linux/bug.h> #include <linux/cpu.h> #include <linux/cpumask_types.h> #include <linux/smp.h>
@@ -31,7 +32,7 @@ struct cpu_stop_work {int stop_one_cpu (unsigned int cpu,cpu_stop_fn_t fn,void *arg);int stop_two_cpus (unsigned int cpu1,unsigned int cpu2,cpu_stop_fn_t fn,void *arg); -bool stop_one_cpu_nowait (unsigned int cpu,cpu_stop_fn_t fn,void *arg, +void stop_one_cpu_nowait (unsigned int cpu,cpu_stop_fn_t fn,void *arg,struct cpu_stop_work *work_buf);void stop_machine_park (int cpu);void stop_machine_unpark (int cpu);
@@ -68,19 +69,17 @@ static void stop_one_cpu_nowait_workfn(struct work_struct *work)preempt_enable (); } -static inline bool stop_one_cpu_nowait (unsigned int cpu, +static inline void stop_one_cpu_nowait (unsigned int cpu,cpu_stop_fn_t fn,void *arg,struct cpu_stop_work *work_buf) { -if (cpu ==smp_processor_id ()) { -INIT_WORK (&work_buf->work, stop_one_cpu_nowait_workfn); - work_buf->fn = fn; - work_buf->arg = arg; -schedule_work (&work_buf->work); -return true; - } - -return false; +if (WARN_ON_ONCE (cpu !=smp_processor_id ())) +return ; + +INIT_WORK (&work_buf->work, stop_one_cpu_nowait_workfn); + work_buf->fn = fn; + work_buf->arg = arg; +schedule_work (&work_buf->work); }static inline void print_stop_info (const char *log_lvl,struct task_struct *task) { }
kernel/stop_machine.c +6 -8
@@ -7,6 +7,7 @@* Copyright (C) 2010 SUSE Linux Products GmbH * Copyright (C) 2010 Tejun Heo <[email protected]> */ +#include <linux/bug.h> #include <linux/compiler.h> #include <linux/completion.h> #include <linux/cpu.h>
@@ -376,17 +377,14 @@ int stop_two_cpus(unsigned int cpu1, unsigned int cpu2, cpu_stop_fn_t fn, void ** and will remain untouched until stopper starts executing @fn. * * CONTEXT: -* Don't care. -* -* RETURNS: -* true if cpu_stop_work was queued successfully and @fn will be called, -* false otherwise. +* Don't care, but the caller must ensure @cpu's stopper stays enabled +* until the work is queued, e.g. by preempt_disable(). */ -bool stop_one_cpu_nowait (unsigned int cpu,cpu_stop_fn_t fn,void *arg, -struct cpu_stop_work *work_buf) +void stop_one_cpu_nowait (unsigned int cpu,cpu_stop_fn_t fn,void *arg, +struct cpu_stop_work *work_buf) { *work_buf = (struct cpu_stop_work ){ .fn = fn, .arg = arg, .caller = _RET_IP_, }; -return cpu_stop_queue_work (cpu, work_buf); +WARN_ON_ONCE (!cpu_stop_queue_work (cpu, work_buf)); } static bool queue_stop_cpus_work(const struct cpumask *cpumask,