From: Joel Fernandes <joelagnelf@nvidia.com>
To: linux-kernel@vger.kernel.org
Cc: "Paul E . McKenney" <paulmck@kernel.org>,
Frederic Weisbecker <frederic@kernel.org>,
Neeraj Upadhyay <neeraj.upadhyay@kernel.org>,
Joel Fernandes <joelagnelf@nvidia.com>,
Josh Triplett <josh@joshtriplett.org>,
Boqun Feng <boqun.feng@gmail.com>,
Steven Rostedt <rostedt@goodmis.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Lai Jiangshan <jiangshanlai@gmail.com>,
Zqiang <qiang.zhang@linux.dev>,
Uladzislau Rezki <urezki@gmail.com>,
joel@joelfernandes.org, rcu@vger.kernel.org
Subject: [PATCH RFC 04/14] rcu: Promote blocked tasks from per-CPU to rnp lists
Date: Fri, 2 Jan 2026 19:23:33 -0500 [thread overview]
Message-ID: <20260103002343.6599-5-joelagnelf@nvidia.com> (raw)
In-Reply-To: <20260103002343.6599-1-joelagnelf@nvidia.com>
Add rcu_promote_blocked_tasks() helper that moves blocked tasks from
per-CPU rdp->blkd_list to the rcu_node's blkd_tasks list during grace
period initialization. This is a prerequisite for deferring rnp list
addition until gp_init.
Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com>
---
kernel/rcu/tree.c | 2 +
kernel/rcu/tree_plugin.h | 80 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 82 insertions(+)
diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index e2b6a4579086..5837e9923642 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -1899,6 +1899,7 @@ static noinline_for_stack bool rcu_gp_init(void)
*/
arch_spin_lock(&rcu_state.ofl_lock);
raw_spin_lock_rcu_node(rnp);
+ rcu_promote_blocked_tasks(rnp);
#ifdef CONFIG_RCU_PER_CPU_BLOCKED_LISTS
/*
* Verify rdp lists consistent with rnp list. Since the unlock
@@ -1982,6 +1983,7 @@ static noinline_for_stack bool rcu_gp_init(void)
rcu_gp_slow(gp_init_delay);
raw_spin_lock_irqsave_rcu_node(rnp, flags);
rdp = this_cpu_ptr(&rcu_data);
+ rcu_promote_blocked_tasks(rnp);
rcu_preempt_check_blocked_tasks(rnp);
rnp->qsmask = rnp->qsmaskinit;
WRITE_ONCE(rnp->gp_seq, rcu_state.gp_seq);
diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
index ee26e87c72f8..6810f1b72d2a 100644
--- a/kernel/rcu/tree_plugin.h
+++ b/kernel/rcu/tree_plugin.h
@@ -806,6 +806,84 @@ static void rcu_read_unlock_special(struct task_struct *t)
rcu_preempt_deferred_qs_irqrestore(t, flags);
}
+#ifdef CONFIG_RCU_PER_CPU_BLOCKED_LISTS
+/*
+ * Promote blocked tasks from a single CPU's per-CPU list to the rnp list.
+ *
+ * If there are no tracked blockers (gp_tasks NULL) and this CPU
+ * is still blocking the corresponding GP (bit set in qsmask), set
+ * the pointer to ensure the GP machinery knows about the blocking task.
+ * This handles late promotion during QS reporting, where tasks may have
+ * blocked after rcu_gp_init() or sync_exp_reset_tree() ran their scans.
+ */
+static void rcu_promote_blocked_tasks_rdp(struct rcu_data *rdp,
+ struct rcu_node *rnp)
+{
+ struct task_struct *t, *tmp;
+
+ raw_lockdep_assert_held_rcu_node(rnp);
+
+ raw_spin_lock(&rdp->blkd_lock);
+ list_for_each_entry_safe(t, tmp, &rdp->blkd_list, rcu_rdp_entry) {
+ /*
+ * Skip tasks already on rnp list. A non-NULL
+ * rcu_blocked_node indicates the task was already
+ * promoted or added directly during blocking.
+ * TODO: Should be WARN_ON_ONCE() after the last patch?
+ */
+ if (t->rcu_blocked_node != NULL)
+ continue;
+
+ /*
+ * Add to rnp list and remove from per-CPU list. We must add to
+ * TAIL so that the task blocks any ongoing GPs.
+ */
+ list_add_tail(&t->rcu_node_entry, &rnp->blkd_tasks);
+ t->rcu_blocked_node = rnp;
+ list_del_init(&t->rcu_rdp_entry);
+ t->rcu_blocked_cpu = -1;
+
+ /*
+ * Set gp_tasks if this is the first blocker and
+ * this CPU is still blocking the corresponding GP.
+ */
+ if (!rnp->gp_tasks && (rnp->qsmask & rdp->grpmask))
+ WRITE_ONCE(rnp->gp_tasks, &t->rcu_node_entry);
+ }
+ raw_spin_unlock(&rdp->blkd_lock);
+}
+
+/*
+ * Promote blocked tasks from per-CPU lists to the rcu_node's blkd_tasks list.
+ * This is called during grace period initialization to move tasks that were
+ * blocked on per-CPU lists to the rnp list where they will block the new GP.
+ * rnp->lock must be held by the caller.
+ */
+static void rcu_promote_blocked_tasks(struct rcu_node *rnp)
+{
+ int cpu;
+ struct rcu_data *rdp_cpu;
+
+ raw_lockdep_assert_held_rcu_node(rnp);
+
+ /*
+ * Only leaf nodes have per-CPU blocked task lists.
+ * TODO: Should be WARN_ON_ONCE()?
+ */
+ if (!rcu_is_leaf_node(rnp))
+ return;
+
+ for (cpu = rnp->grplo; cpu <= rnp->grphi; cpu++) {
+ rdp_cpu = per_cpu_ptr(&rcu_data, cpu);
+ rcu_promote_blocked_tasks_rdp(rdp_cpu, rnp);
+ }
+}
+#else /* #ifdef CONFIG_RCU_PER_CPU_BLOCKED_LISTS */
+static inline void rcu_promote_blocked_tasks_rdp(struct rcu_data *rdp,
+ struct rcu_node *rnp) { }
+static void rcu_promote_blocked_tasks(struct rcu_node *rnp) { }
+#endif /* #else #ifdef CONFIG_RCU_PER_CPU_BLOCKED_LISTS */
+
/*
* Check that the list of blocked tasks for the newly completed grace
* period is in fact empty. It is a serious bug to complete a grace
@@ -1139,6 +1217,8 @@ dump_blkd_tasks(struct rcu_node *rnp, int ncheck)
static void rcu_preempt_deferred_qs_init(struct rcu_data *rdp) { }
+static void rcu_promote_blocked_tasks(struct rcu_node *rnp) { }
+
#endif /* #else #ifdef CONFIG_PREEMPT_RCU */
/*
--
2.34.1
next prev parent reply other threads:[~2026-01-03 0:24 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-03 0:23 [PATCH RFC 00/14] rcu: Reduce rnp->lock contention with per-CPU blocked task lists Joel Fernandes
2026-01-03 0:23 ` [PATCH RFC 01/14] rcu: Add WARN_ON_ONCE for blocked flag invariant in exit_rcu() Joel Fernandes
2026-01-05 15:31 ` Steven Rostedt
2026-01-05 15:44 ` Joel Fernandes
2026-01-03 0:23 ` [PATCH RFC 02/14] rcu: Add per-CPU blocked task lists for PREEMPT_RCU Joel Fernandes
2026-01-05 15:48 ` Steven Rostedt
2026-01-03 0:23 ` [PATCH RFC 03/14] rcu: Early return during unlock for tasks only on per-CPU blocked list Joel Fernandes
2026-01-03 0:23 ` Joel Fernandes [this message]
2026-01-05 15:59 ` [PATCH RFC 04/14] rcu: Promote blocked tasks from per-CPU to rnp lists Steven Rostedt
2026-01-09 3:52 ` Joel Fernandes
2026-01-03 0:23 ` [PATCH RFC 05/14] rcu: Promote blocked tasks for expedited GPs Joel Fernandes
2026-01-03 0:23 ` [PATCH RFC 06/14] rcu: Promote per-CPU blocked tasks before checking for blocked readers Joel Fernandes
2026-01-03 0:23 ` [PATCH RFC 07/14] rcu: Promote late-arriving blocked tasks before reporting QS Joel Fernandes
2026-01-03 0:23 ` [PATCH RFC 08/14] rcu: Promote blocked tasks before QS report in force_qs_rnp() Joel Fernandes
2026-01-03 0:23 ` [PATCH RFC 09/14] rcu: Promote blocked tasks before QS report in rcutree_report_cpu_dead() Joel Fernandes
2026-01-03 0:23 ` [PATCH RFC 10/14] rcu: Promote blocked tasks before QS report in rcu_gp_init() Joel Fernandes
2026-01-03 0:23 ` [PATCH RFC 11/14] rcu: Add per-CPU blocked list check in exit_rcu() Joel Fernandes
2026-01-03 0:23 ` [PATCH RFC 12/14] rcu: Skip per-CPU list addition when GP already started Joel Fernandes
2026-01-03 0:23 ` [PATCH RFC 13/14] rcu: Skip rnp addition when no grace period waiting Joel Fernandes
2026-01-03 0:23 ` [PATCH RFC 14/14] rcu: Remove checking of per-cpu blocked list against the node list Joel Fernandes
2026-01-05 16:46 ` [PATCH RFC 00/14] rcu: Reduce rnp->lock contention with per-CPU blocked task lists Paul E. McKenney
2026-01-06 0:55 ` Joel Fernandes
2026-01-06 15:08 ` Joel Fernandes
2026-01-06 19:24 ` Paul E. McKenney
2026-01-06 21:24 ` Joel Fernandes
2026-01-09 2:00 ` Paul E. McKenney
2026-01-06 19:17 ` Paul E. McKenney
2026-01-06 20:19 ` Steven Rostedt
2026-01-06 20:35 ` Paul E. McKenney
2026-01-06 20:49 ` Joel Fernandes
2026-01-09 1:55 ` Paul E. McKenney
2026-01-06 20:40 ` Joel Fernandes
2026-01-09 1:52 ` 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=20260103002343.6599-5-joelagnelf@nvidia.com \
--to=joelagnelf@nvidia.com \
--cc=boqun.feng@gmail.com \
--cc=frederic@kernel.org \
--cc=jiangshanlai@gmail.com \
--cc=joel@joelfernandes.org \
--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®