From: Bradley Morgan <brads@mainlining.org>
To: qiang.zhang@linux.dev
Cc: paulmck@kernel.org, frederic@kernel.org,
neeraj.upadhyay@kernel.org, joelagnelf@nvidia.com,
josh@joshtriplett.org, boqun@kernel.org, urezki@gmail.com,
rostedt@goodmis.org, mathieu.desnoyers@efficios.com,
jiangshanlai@gmail.com, rcu@vger.kernel.org,
linux-kernel@vger.kernel.org, brads@mainlining.org
Subject: [PATCH] rcu/tasks: Use static per cpu work_struct for Tasks Rude grace periods
Date: Sat, 17 Oct 2026 12:33:13 +0000 [thread overview]
Message-ID: <20261017123313.1441679-1-brads@mainlining.org> (raw)
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
next reply other threads:[~2026-10-17 12:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-17 12:33 Bradley Morgan [this message]
2026-10-17 17:55 ` Paul E. McKenney
2026-10-17 18:00 ` Bradley Morgan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261017123313.1441679-1-brads@mainlining.org \
--to=brads@mainlining.org \
--cc=boqun@kernel.org \
--cc=frederic@kernel.org \
--cc=jiangshanlai@gmail.com \
--cc=joelagnelf@nvidia.com \
--cc=josh@joshtriplett.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=neeraj.upadhyay@kernel.org \
--cc=paulmck@kernel.org \
--cc=qiang.zhang@linux.dev \
--cc=rcu@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=urezki@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®