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, Neeraj Upadhyay <quic_neeraju@quicinc.com>,
David Woodhouse <dwmw@amazon.co.uk>,
"Paul E . McKenney" <paulmck@kernel.org>
Subject: [PATCH rcu 02/10] rcu/nocb: Handle concurrent nocb kthreads creation
Date: Fri, 4 Feb 2022 15:23:58 -0800 [thread overview]
Message-ID: <20220204232406.814-2-paulmck@kernel.org> (raw)
In-Reply-To: <20220204232355.GA728@paulmck-ThinkPad-P17-Gen-1>
From: Neeraj Upadhyay <quic_neeraju@quicinc.com>
When multiple CPUs in the same nocb gp/cb group concurrently
come online, they might try to concurrently create the same
rcuog kthread. Fix this by using nocb gp CPU's spawn mutex to
provide mutual exclusion for the rcuog kthread creation code.
[ paulmck: Whitespace fixes per kernel test robot feedback. ]
Acked-by: David Woodhouse <dwmw@amazon.co.uk>
Signed-off-by: Neeraj Upadhyay <quic_neeraju@quicinc.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
---
kernel/rcu/tree.h | 2 ++
kernel/rcu/tree_nocb.h | 7 ++++++-
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
index 486fc901bd085..24dd4b0d805f1 100644
--- a/kernel/rcu/tree.h
+++ b/kernel/rcu/tree.h
@@ -203,6 +203,8 @@ struct rcu_data {
int nocb_defer_wakeup; /* Defer wakeup of nocb_kthread. */
struct timer_list nocb_timer; /* Enforce finite deferral. */
unsigned long nocb_gp_adv_time; /* Last call_rcu() CB adv (jiffies). */
+ struct mutex nocb_gp_kthread_mutex; /* Exclusion for nocb gp kthread */
+ /* spawning */
/* The following fields are used by call_rcu, hence own cacheline. */
raw_spinlock_t nocb_bypass_lock ____cacheline_internodealigned_in_smp;
diff --git a/kernel/rcu/tree_nocb.h b/kernel/rcu/tree_nocb.h
index eeafb546a7a09..1e40519d1a05a 100644
--- a/kernel/rcu/tree_nocb.h
+++ b/kernel/rcu/tree_nocb.h
@@ -1226,6 +1226,7 @@ static void __init rcu_boot_init_nocb_percpu_data(struct rcu_data *rdp)
raw_spin_lock_init(&rdp->nocb_gp_lock);
timer_setup(&rdp->nocb_timer, do_nocb_deferred_wakeup_timer, 0);
rcu_cblist_init(&rdp->nocb_bypass);
+ mutex_init(&rdp->nocb_gp_kthread_mutex);
}
/*
@@ -1248,13 +1249,17 @@ static void rcu_spawn_cpu_nocb_kthread(int cpu)
/* If we didn't spawn the GP kthread first, reorganize! */
rdp_gp = rdp->nocb_gp_rdp;
+ mutex_lock(&rdp_gp->nocb_gp_kthread_mutex);
if (!rdp_gp->nocb_gp_kthread) {
t = kthread_run(rcu_nocb_gp_kthread, rdp_gp,
"rcuog/%d", rdp_gp->cpu);
- if (WARN_ONCE(IS_ERR(t), "%s: Could not start rcuo GP kthread, OOM is now expected behavior\n", __func__))
+ if (WARN_ONCE(IS_ERR(t), "%s: Could not start rcuo GP kthread, OOM is now expected behavior\n", __func__)) {
+ mutex_unlock(&rdp_gp->nocb_gp_kthread_mutex);
return;
+ }
WRITE_ONCE(rdp_gp->nocb_gp_kthread, t);
}
+ mutex_unlock(&rdp_gp->nocb_gp_kthread_mutex);
/* Spawn the kthread for this CPU. */
t = kthread_run(rcu_nocb_cb_kthread, rdp,
--
2.31.1.189.g2e36527f23
next prev parent reply other threads:[~2022-02-04 23:24 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-04 23:23 [PATCH rcu 0/10] Real-time-related updates for v5.18 Paul E. McKenney
2022-02-04 23:23 ` [PATCH rcu 01/10] rcu: Mark accesses to boost_starttime Paul E. McKenney
2022-02-04 23:23 ` Paul E. McKenney [this message]
2022-02-04 23:23 ` [PATCH rcu 03/10] rcu: Remove unused rcu_state.boost Paul E. McKenney
2022-02-04 23:24 ` [PATCH rcu 04/10] rcu: Create per-cpu rcuc kthreads only when rcutree.use_softirq=0 Paul E. McKenney
2022-02-04 23:24 ` [PATCH rcu 05/10] rcu: Move kthread_prio bounds-check to a separate function Paul E. McKenney
2022-02-04 23:24 ` [PATCH rcu 06/10] rcu: Make priority of grace-period thread consistent Paul E. McKenney
2022-02-04 23:24 ` [PATCH rcu 07/10] rcu: Elevate priority of offloaded callback threads Paul E. McKenney
2022-02-04 23:24 ` [PATCH rcu 08/10] rcu: Update documentation regarding kthread_prio cmdline parameter Paul E. McKenney
2022-02-04 23:24 ` [PATCH rcu 09/10] rcu: Don't deboost before reporting expedited quiescent state Paul E. McKenney
2022-02-04 23:24 ` [PATCH rcu 10/10] rcu: Add per-CPU rcuc task dumps to RCU CPU stall warnings 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=20220204232406.814-2-paulmck@kernel.org \
--to=paulmck@kernel.org \
--cc=dwmw@amazon.co.uk \
--cc=kernel-team@fb.com \
--cc=linux-kernel@vger.kernel.org \
--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