[PATCH 01/17] srcu: Move callback mutex acquisition to the GP end wrapper

From: Kunwu Chan

Date: Tue Dec 01 2026 - 11:18:52 EST


Move the srcu_cb_mutex acquisition into srcu_gp_end() so callers
that already hold both mutexes can reuse the completion body.
Keep the size-state load and mutex releases in the completion body.

Signed-off-by: Kunwu Chan <kunwu.chan@xxxxxxxxx>
---
kernel/rcu/srcutree.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
index 75ff54c9025e..1ab5a1cdc163 100644
--- a/kernel/rcu/srcutree.c
+++ b/kernel/rcu/srcutree.c
@@ -983,7 +983,7 @@ static void srcu_schedule_cbs_snp(struct srcu_struct *ssp, struct srcu_node *snp
* are initiating callback invocation. This allows the ->srcu_have_cbs[]
* array to have a finite number of elements.
*/
-static void srcu_gp_end(struct srcu_struct *ssp, bool is_atomic)
+static void __srcu_gp_end(struct srcu_struct *ssp, bool is_atomic)
{
unsigned long cbdelay = 1;
bool cbs;
@@ -999,9 +999,10 @@ static void srcu_gp_end(struct srcu_struct *ssp, bool is_atomic)
int ss_state;
struct srcu_usage *sup = ssp->srcu_sup;

- /* Prevent more than one additional grace period. */
- if (!is_atomic)
- mutex_lock(&sup->srcu_cb_mutex);
+ if (!is_atomic) {
+ lockdep_assert_held(&sup->srcu_gp_mutex);
+ lockdep_assert_held(&sup->srcu_cb_mutex);
+ }

/* End the current grace period. */
raw_spin_lock_irqsave_rcu_node(sup, flags);
@@ -1089,6 +1090,14 @@ static void srcu_gp_end(struct srcu_struct *ssp, bool is_atomic)
}
}

+static void srcu_gp_end(struct srcu_struct *ssp, bool is_atomic)
+{
+ /* Prevent more than one additional grace period. */
+ if (!is_atomic)
+ mutex_lock(&ssp->srcu_sup->srcu_cb_mutex);
+ __srcu_gp_end(ssp, is_atomic);
+}
+
/*
* Funnel-locking scheme to scalably mediate many concurrent expedited
* grace-period requests. This function is invoked for the first known
--
2.43.0