* [PATCH] rcu/tasks: Use static per cpu work_struct for Tasks Rude grace periods
@ 2026-10-17 12:33 Bradley Morgan
2026-10-17 17:55 ` Paul E. McKenney
0 siblings, 1 reply; 2+ messages in thread
From: Bradley Morgan @ 2026-10-17 12:33 UTC (permalink / raw)
To: qiang.zhang
Cc: paulmck, frederic, neeraj.upadhyay, joelagnelf, josh, boqun,
urezki, rostedt, mathieu.desnoyers, jiangshanlai, rcu,
linux-kernel, brads
Zqiang caught a snafu in the rude grace period, if a too small grace
period was reached, a UAF could occur. However, his patch used
a WARN_ONCE() on schedule_on_each_cpu() OOM failures, which would not
have handled the failure properly.
Instead of throwing a warning or relying on dynamic alloc_percpu(), replace
the dynamic allocation with static per cpu work_struct instances. Using
schedule_work_on() and flush_work() keeps everything in task context,
guarantees the required context switch on every online CPU, and stays
zero allocation so it cannot fail under OOM.
Suggested-by: Zqiang <qiang.zhang@linux.dev>
Signed-off-by: Bradley Morgan <brads@mainlining.org>
---
kernel/rcu/tasks.h | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/kernel/rcu/tasks.h b/kernel/rcu/tasks.h
index 627295396cd9..f81c0ea0b92a 100644
--- a/kernel/rcu/tasks.h
+++ b/kernel/rcu/tasks.h
@@ -1348,11 +1348,25 @@ static void rcu_tasks_be_rude(struct work_struct *work)
{
}
+static DEFINE_PER_CPU(struct work_struct, tasks_rude_work);
+
// Wait for one rude RCU-tasks grace period.
static void rcu_tasks_rude_wait_gp(struct rcu_tasks *rtp)
{
+ int cpu;
+
+ guard(cpus_read_lock)();
rtp->n_ipis += cpumask_weight(cpu_online_mask);
- schedule_on_each_cpu(rcu_tasks_be_rude);
+
+ for_each_online_cpu(cpu) {
+ struct work_struct *work = &per_cpu(tasks_rude_work, cpu);
+
+ INIT_WORK(work, rcu_tasks_be_rude);
+ schedule_work_on(cpu, work);
+ }
+
+ for_each_online_cpu(cpu)
+ flush_work(&per_cpu(tasks_rude_work, cpu));
}
static void call_rcu_tasks_rude(struct rcu_head *rhp, rcu_callback_t func);
--
2.53.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] rcu/tasks: Use static per cpu work_struct for Tasks Rude grace periods
2026-10-17 12:33 [PATCH] rcu/tasks: Use static per cpu work_struct for Tasks Rude grace periods Bradley Morgan
@ 2026-10-17 17:55 ` Paul E. McKenney
0 siblings, 0 replies; 2+ messages in thread
From: Paul E. McKenney @ 2026-10-17 17:55 UTC (permalink / raw)
To: Bradley Morgan
Cc: qiang.zhang, frederic, neeraj.upadhyay, joelagnelf, josh, boqun,
urezki, rostedt, mathieu.desnoyers, jiangshanlai, rcu,
linux-kernel
On Sat, Oct 17, 2026 at 12:33:13PM +0000, Bradley Morgan wrote:
> Zqiang caught a snafu in the rude grace period, if a too small grace
> period was reached, a UAF could occur. However, his patch used
> a WARN_ONCE() on schedule_on_each_cpu() OOM failures, which would not
> have handled the failure properly.
>
> Instead of throwing a warning or relying on dynamic alloc_percpu(), replace
> the dynamic allocation with static per cpu work_struct instances. Using
> schedule_work_on() and flush_work() keeps everything in task context,
> guarantees the required context switch on every online CPU, and stays
> zero allocation so it cannot fail under OOM.
>
> Suggested-by: Zqiang <qiang.zhang@linux.dev>
> Signed-off-by: Bradley Morgan <brads@mainlining.org>
Sorry, Bradley, but no, absolutely not.
Because this not taking a suggestion, but is instead *exactly* Zqiang's
patch. We do not commit plagiarism in the Linux-kernel community.
Zqiang, please submit a proper patch with appropriate credit to Bradley.
The obvious approach would be to following his example, that is, to
credit him using Suggested-by, but Reported-by or a sentence calling out
his feedback in the commit log would suffice. However, I will defer to
your best judgment.
Thanx, Paul
> ---
> kernel/rcu/tasks.h | 16 +++++++++++++++-
> 1 file changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/rcu/tasks.h b/kernel/rcu/tasks.h
> index 627295396cd9..f81c0ea0b92a 100644
> --- a/kernel/rcu/tasks.h
> +++ b/kernel/rcu/tasks.h
> @@ -1348,11 +1348,25 @@ static void rcu_tasks_be_rude(struct work_struct *work)
> {
> }
>
> +static DEFINE_PER_CPU(struct work_struct, tasks_rude_work);
> +
> // Wait for one rude RCU-tasks grace period.
> static void rcu_tasks_rude_wait_gp(struct rcu_tasks *rtp)
> {
> + int cpu;
> +
> + guard(cpus_read_lock)();
> rtp->n_ipis += cpumask_weight(cpu_online_mask);
> - schedule_on_each_cpu(rcu_tasks_be_rude);
> +
> + for_each_online_cpu(cpu) {
> + struct work_struct *work = &per_cpu(tasks_rude_work, cpu);
> +
> + INIT_WORK(work, rcu_tasks_be_rude);
> + schedule_work_on(cpu, work);
> + }
> +
> + for_each_online_cpu(cpu)
> + flush_work(&per_cpu(tasks_rude_work, cpu));
> }
>
> static void call_rcu_tasks_rude(struct rcu_head *rhp, rcu_callback_t func);
> --
> 2.53.0
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-17 17:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-17 12:33 [PATCH] rcu/tasks: Use static per cpu work_struct for Tasks Rude grace periods Bradley Morgan
2026-10-17 17:55 ` Paul E. McKenney
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®