From: "Paul E. McKenney" <paulmck@kernel.org>
To: rcu@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, kernel-team@fb.com,
rostedt@goodmis.org, Pingfan Liu <kernelfans@gmail.com>,
David Woodhouse <dwmw@amazon.co.uk>,
Frederic Weisbecker <frederic@kernel.org>,
Neeraj Upadhyay <quic_neeraju@quicinc.com>,
Josh Triplett <josh@joshtriplett.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Lai Jiangshan <jiangshanlai@gmail.com>,
Joel Fernandes <joel@joelfernandes.org>,
"Jason A. Donenfeld" <Jason@zx2c4.com>,
"Paul E . McKenney" <paulmck@kernel.org>
Subject: [PATCH rcu 2/8] rcu: Synchronize ->qsmaskinitnext in rcu_boost_kthread_setaffinity()
Date: Wed, 19 Oct 2022 15:46:53 -0700 [thread overview]
Message-ID: <20221019224659.2499511-2-paulmck@kernel.org> (raw)
In-Reply-To: <20221019224652.GA2499358@paulmck-ThinkPad-P17-Gen-1>
From: Pingfan Liu <kernelfans@gmail.com>
Once either rcutree_online_cpu() or rcutree_dead_cpu() is invoked
concurrently, the following rcu_boost_kthread_setaffinity() race can
occur:
CPU 1 CPU2
mask = rcu_rnp_online_cpus(rnp);
...
mask = rcu_rnp_online_cpus(rnp);
...
set_cpus_allowed_ptr(t, cm);
set_cpus_allowed_ptr(t, cm);
This results in CPU2's update being overwritten by that of CPU1, and
thus the possibility of ->boost_kthread_task continuing to run on a
to-be-offlined CPU.
This commit therefore eliminates this race by relying on the pre-existing
acquisition of ->boost_kthread_mutex to serialize the full process of
changing the affinity of ->boost_kthread_task.
Signed-off-by: Pingfan Liu <kernelfans@gmail.com>
Cc: David Woodhouse <dwmw@amazon.co.uk>
Cc: Frederic Weisbecker <frederic@kernel.org>
Cc: Neeraj Upadhyay <quic_neeraju@quicinc.com>
Cc: Josh Triplett <josh@joshtriplett.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Lai Jiangshan <jiangshanlai@gmail.com>
Cc: Joel Fernandes <joel@joelfernandes.org>
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
---
kernel/rcu/tree_plugin.h | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
index e3142ee35fc6a..7b0fe741a0886 100644
--- a/kernel/rcu/tree_plugin.h
+++ b/kernel/rcu/tree_plugin.h
@@ -1221,11 +1221,13 @@ static void rcu_spawn_one_boost_kthread(struct rcu_node *rnp)
* We don't include outgoingcpu in the affinity set, use -1 if there is
* no outgoing CPU. If there are no CPUs left in the affinity set,
* this function allows the kthread to execute on any CPU.
+ *
+ * Any future concurrent calls are serialized via ->boost_kthread_mutex.
*/
static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
{
struct task_struct *t = rnp->boost_kthread_task;
- unsigned long mask = rcu_rnp_online_cpus(rnp);
+ unsigned long mask;
cpumask_var_t cm;
int cpu;
@@ -1234,6 +1236,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
if (!zalloc_cpumask_var(&cm, GFP_KERNEL))
return;
mutex_lock(&rnp->boost_kthread_mutex);
+ mask = rcu_rnp_online_cpus(rnp);
for_each_leaf_node_possible_cpu(rnp, cpu)
if ((mask & leaf_node_cpu_bit(rnp, cpu)) &&
cpu != outgoingcpu)
--
2.31.1.189.g2e36527f23
next prev parent reply other threads:[~2022-10-19 22:47 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-19 22:46 [PATCH rcu 0/8] Miscellaneous fixes for v6.2 Paul E. McKenney
2022-10-19 22:46 ` [PATCH rcu 1/8] rcu: Remove duplicate RCU exp QS report from rcu_report_dead() Paul E. McKenney
2022-10-19 22:46 ` Paul E. McKenney [this message]
2022-10-19 22:46 ` [PATCH rcu 3/8] rcu: Remove unused 'cpu' in rcu_virt_note_context_switch() Paul E. McKenney
2022-10-19 22:46 ` [PATCH rcu 4/8] rcu: Use READ_ONCE() for lockless read of rnp->qsmask Paul E. McKenney
2022-10-19 22:46 ` [PATCH rcu 5/8] slab: Explain why SLAB_DESTROY_BY_RCU reference before locking Paul E. McKenney
2022-10-20 7:10 ` Vlastimil Babka
2022-10-20 16:31 ` Paul E. McKenney
2022-10-21 7:44 ` Christoph Lameter
2022-10-21 13:43 ` Paul E. McKenney
2022-10-21 13:50 ` Vlastimil Babka
2022-10-21 15:42 ` Paul E. McKenney
2022-10-21 15:50 ` Vlastimil Babka
2022-10-21 16:10 ` Paul E. McKenney
2022-10-19 22:46 ` [PATCH rcu 6/8] rcu: Remove rcu_is_idle_cpu() Paul E. McKenney
2022-10-19 22:46 ` [PATCH rcu 7/8] rcu-tasks: Make grace-period-age message human-readable Paul E. McKenney
2022-10-19 22:46 ` [PATCH rcu 8/8] rcu: Fix __this_cpu_read() lockdep warning in rcu_force_quiescent_state() Paul E. McKenney
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=20221019224659.2499511-2-paulmck@kernel.org \
--to=paulmck@kernel.org \
--cc=Jason@zx2c4.com \
--cc=dwmw@amazon.co.uk \
--cc=frederic@kernel.org \
--cc=jiangshanlai@gmail.com \
--cc=joel@joelfernandes.org \
--cc=josh@joshtriplett.org \
--cc=kernel-team@fb.com \
--cc=kernelfans@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=quic_neeraju@quicinc.com \
--cc=rcu@vger.kernel.org \
--cc=rostedt@goodmis.org \
/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