Skip to contentSkip to conversation

srcutiny: Add lockdep and early-boot checks to synchronize_srcu_atomic()

PATCH Applied Kunwu Chan 3 participants 5 messages Sep 11

Subsystems (2)
lore
Share & tools
lore

Kunwu Chan

author
#0 lore raw

PATCH 1/1 srcutiny: Add lockdep and early-boot checks to synchronize_srcu_atomic()

Add the RCU_LOCKDEP_WARN and early-boot check that the Tree version gained, srcu_lock_sync() was already present.

---
 kernel/rcu/srcutiny.c | 6 ++++++
 1 file changed, 6 insertions(+)
kernel/rcu/srcutiny.c +6 -0
index 99f8bfd98b04..76411562366f 100644
@@ -361,6 +361,12 @@ void synchronize_srcu_atomic(struct srcu_struct *ssp)
 
 	srcu_lock_sync(&ssp->dep_map);
 
+	RCU_LOCKDEP_WARN(lockdep_is_held(ssp),
+			 "Illegal synchronize_srcu_atomic() in same-type SRCU read-side critical section");
+
+	if (rcu_scheduler_active == RCU_SCHEDULER_INACTIVE)
+		return;
+
 	if (IS_ENABLED(CONFIG_PREEMPTION))
 		synchronize_rcu(); // Needed for RCU Tasks Trace to imply RCU grace period.
 				   // And in Tiny RCU, it is near zero cost and doesn't block.
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 5 lines · Kunwu Chan

Add the RCU_LOCKDEP_WARN and early-boot check that the Tree version gained, srcu_lock_sync() was already present.

Queued for testing and review, thank you both!

Thanx, Paul

Quoted 24 lines
---
 kernel/rcu/srcutiny.c | 6 ++++++
 1 file changed, 6 insertions(+)
kernel/rcu/srcutiny.c +6 -0
index 99f8bfd98b04..76411562366f 100644
@@ -361,6 +361,12 @@ void synchronize_srcu_atomic(struct srcu_struct *ssp)
 
 	srcu_lock_sync(&ssp->dep_map);
 
+	RCU_LOCKDEP_WARN(lockdep_is_held(ssp),
+			 "Illegal synchronize_srcu_atomic() in same-type SRCU read-side critical section");
+
+	if (rcu_scheduler_active == RCU_SCHEDULER_INACTIVE)
+		return;
+
 	if (IS_ENABLED(CONFIG_PREEMPTION))
 		synchronize_rcu(); // Needed for RCU Tasks Trace to imply RCU grace period.
 				   // And in Tiny RCU, it is near zero cost and doesn't block.
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#2 lore raw
In reply to Kunwu Chan
Quoted 4 lines · Kunwu Chan

Add the RCU_LOCKDEP_WARN and early-boot check that the Tree version gained, srcu_lock_sync() was already present.

Ok.

Quoted 10 lines

---
kernel/rcu/srcutiny.c | 6 ++++++

1 file changed, 6 insertions(+)
kernel/rcu/srcutiny.c +0 -0
index 99f8bfd98b04..76411562366f 100644

kernel/rcu/srcutiny.c void synchronize_srcu_atomic(struct srcu_struct *ssp) · line 369

Quoted 9 lines
kernel/rcu/srcutiny.c +6 -0
@@ -361,6 +361,12 @@ void synchronize_srcu_atomic(struct srcu_struct *ssp)
 
 	srcu_lock_sync(&ssp->dep_map);
 
+	RCU_LOCKDEP_WARN(lockdep_is_held(ssp),
+			 "Illegal synchronize_srcu_atomic() in same-type SRCU read-side critical section");
+
+	if (rcu_scheduler_active == RCU_SCHEDULER_INACTIVE)
+		return;
+

Wow!

kernel/rcu/srcutiny.c void synchronize_srcu_atomic(struct srcu_struct *ssp) · line 372

Quoted 4 lines
kernel/rcu/srcutiny.c +0 -0
 	if (IS_ENABLED(CONFIG_PREEMPTION))
 		synchronize_rcu(); // Needed for RCU Tasks Trace to imply RCU grace period.
 				   // And in Tiny RCU, it is near zero cost and doesn't block.

--- Thanks!
https://lore.kernel.org/all/[email protected]/

maintainer Applied
#3 lore raw
Quoted 9 lines · Bradley Morgan
Quoted 4 lines · Kunwu Chan

Add the RCU_LOCKDEP_WARN and early-boot check that the Tree version gained, srcu_lock_sync() was already present.

Ok.

Applied, thank you!

Quoted 13 lines
Quoted 13 lines

---
kernel/rcu/srcutiny.c | 6 ++++++

1 file changed, 6 insertions(+)
kernel/rcu/srcutiny.c +0 -0
index 99f8bfd98b04..76411562366f 100644
@@ -361,6 +361,12 @@ void synchronize_srcu_atomic(struct srcu_struct *ssp)
 
 	srcu_lock_sync(&ssp->dep_map);
 
Quoted 8 lines

kernel/rcu/srcutiny.c void synchronize_srcu_atomic(struct srcu_struct *ssp) · line 369

Quoted 6 lines
kernel/rcu/srcutiny.c +6 -0
+	RCU_LOCKDEP_WARN(lockdep_is_held(ssp),
+			 "Illegal synchronize_srcu_atomic() in same-type SRCU read-side critical section");
+
+	if (rcu_scheduler_active == RCU_SCHEDULER_INACTIVE)
+		return;
+

Wow!

If you think that this one is fun, take a look at the implementation of synchronize_rcu() in kernel/rcu/tiny.c. ;-)

Thanx, Paul

Quoted 7 lines

kernel/rcu/srcutiny.c void synchronize_srcu_atomic(struct srcu_struct *ssp) · line 372

Quoted 4 lines
kernel/rcu/srcutiny.c +0 -0
 	if (IS_ENABLED(CONFIG_PREEMPTION))
 		synchronize_rcu(); // Needed for RCU Tasks Trace to imply RCU grace period.
 				   // And in Tiny RCU, it is near zero cost and doesn't block.

--- Thanks!
https://lore.kernel.org/all/[email protected]/

#4 lore raw
Quoted 37 lines · Paul E. McKenney
Quoted 1 line · Bradley Morgan

On 11 September 2026 17:09:13 BST, Kunwu Chan <[email protected]>

Quoted 8 lines · wrote:
Quoted 4 lines

Add the RCU_LOCKDEP_WARN and early-boot check that the Tree version gained, srcu_lock_sync() was already present.

Ok.

Applied, thank you!

Quoted 10 lines

kernel/rcu/srcutiny.c void synchronize_srcu_atomic(struct srcu_struct

Quoted 10 lines

---
kernel/rcu/srcutiny.c | 6 ++++++

1 file changed, 6 insertions(+)
kernel/rcu/srcutiny.c +0 -0
index 99f8bfd98b04..76411562366f 100644
@@ -361,6 +361,12 @@ void synchronize_srcu_atomic(struct srcu_struct

*ssp)

Quoted 11 lines

kernel/rcu/srcutiny.c void synchronize_srcu_atomic(struct srcu_struct *ssp) · line 369

Quoted 9 lines
kernel/rcu/srcutiny.c +6 -0
 	srcu_lock_sync(&ssp->dep_map);
 
+	RCU_LOCKDEP_WARN(lockdep_is_held(ssp),
+			 "Illegal synchronize_srcu_atomic() in same-type SRCU read-side critical section");
+
+	if (rcu_scheduler_active == RCU_SCHEDULER_INACTIVE)
+		return;
+

Wow!

Quoted 2 lines

If you think that this one is fun, take a look at the implementation of synchronize_rcu() in kernel/rcu/tiny.c. ;-)

void synchronize_rcu(void)

{
    RCU_LOCKDEP_WARN(...);
    preempt_disable();
    WRITE_ONCE(rcu_ctrlblk.gp_seq, rcu_ctrlblk.gp_seq + 2);
    preempt_enable();
}

Hah!

Quoted 11 lines

Thanx, Paul

Quoted 7 lines

kernel/rcu/srcutiny.c void synchronize_srcu_atomic(struct srcu_struct *ssp)

Quoted 4 lines
kernel/rcu/srcutiny.c +0 -0
 	if (IS_ENABLED(CONFIG_PREEMPTION))
 		synchronize_rcu(); // Needed for RCU Tasks Trace to imply RCU grace period.
 				   // And in Tiny RCU, it is near zero cost and doesn't block.
 

--- Thanks!

https://lore.kernel.org/all/[email protected]/

--- Thanks!
https://lore.kernel.org/all/[email protected]/