Skip to contentSkip to conversation

srcutree: Don't transition atomic SRCU to big in srcu_gp_end()

PATCH In review Kunwu Chan 3 participants 5 messages Sep 11 – Sep 13

Subsystems (2)
lore
Share & tools
lore

Kunwu Chan

author
#0 lore raw

PATCH v3 1/1 srcutree: Don't transition atomic SRCU to big in srcu_gp_end()

Atomic SRCU must remain in the small size state. Warn if this invariant is violated and avoid transitioning to big in that case.

---
Changes since v2:
- Also prevent the transition when the atomic SRCU size-state invariant is violated, per Paul McKenney's suggestion.
-v2: https://lore.kernel.org/rcu/[email protected]/

Changes since v1:
- Drop the !is_atomic guard from v1 and add WARN_ON_ONCE() instead, per Paul McKenney's suggestion.
- v1: https://lore.kernel.org/rcu/[email protected]/

---
 kernel/rcu/srcutree.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
kernel/rcu/srcutree.c +5 -2
index 84c022ec8e09..07db4e459b30 100644
@@ -1073,8 +1073,11 @@ static void srcu_gp_end(struct srcu_struct *ssp, bool is_atomic)
 		raw_spin_unlock_irq_rcu_node(sup);
 	}
 
-	/* Transition to big if needed. */
-	if (ss_state != SRCU_SIZE_SMALL && ss_state != SRCU_SIZE_BIG) {
+	/* Transition to big if needed, but never for atomic SRCU. */
+	if (ssp->srcu_reader_flavor == SRCU_READ_FLAVOR_ATOMIC &&
+	    ss_state != SRCU_SIZE_SMALL) {
+		WARN_ON_ONCE(1);
+	} else if (ss_state != SRCU_SIZE_SMALL && ss_state != SRCU_SIZE_BIG) {
 		if (ss_state == SRCU_SIZE_ALLOC)
 			init_srcu_struct_nodes(ssp, GFP_KERNEL);
 		else
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 4 lines · Kunwu Chan

Atomic SRCU must remain in the small size state. Warn if this invariant is violated and avoid transitioning to big in that case.

Very good, queued for further testing and review, thank you!

I folded the new "if" statement onto one line because some years back the Linux kernel liberated itself from the 80-column constraint imposed by IBM back in 1928. We can now have up to 100 characters in a line of code. ;-)

Thanx, Paul

Quoted 36 lines

---
Changes since v2:
- Also prevent the transition when the atomic SRCU size-state invariant is violated, per Paul McKenney's suggestion.
-v2: https://lore.kernel.org/rcu/[email protected]/

Changes since v1:
- Drop the !is_atomic guard from v1 and add WARN_ON_ONCE() instead, per Paul McKenney's suggestion.
- v1: https://lore.kernel.org/rcu/[email protected]/

---
 kernel/rcu/srcutree.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
kernel/rcu/srcutree.c +5 -2
index 84c022ec8e09..07db4e459b30 100644
@@ -1073,8 +1073,11 @@ static void srcu_gp_end(struct srcu_struct *ssp, bool is_atomic)
 		raw_spin_unlock_irq_rcu_node(sup);
 	}
 
-	/* Transition to big if needed. */
-	if (ss_state != SRCU_SIZE_SMALL && ss_state != SRCU_SIZE_BIG) {
+	/* Transition to big if needed, but never for atomic SRCU. */
+	if (ssp->srcu_reader_flavor == SRCU_READ_FLAVOR_ATOMIC &&
+	    ss_state != SRCU_SIZE_SMALL) {
+		WARN_ON_ONCE(1);
+	} else if (ss_state != SRCU_SIZE_SMALL && ss_state != SRCU_SIZE_BIG) {
 		if (ss_state == SRCU_SIZE_ALLOC)
 			init_srcu_struct_nodes(ssp, GFP_KERNEL);
 		else
Signature · 1 line
2.43.0
author
#2 lore raw
Quoted 5 lines · Paul E. McKenney
Quoted 3 lines · Kunwu Chan

Atomic SRCU must remain in the small size state. Warn if this invariant is violated and avoid transitioning to big in that case.

Quoted 7 lines
Quoted 1 line

Very good, queued for further testing and review, thank you!

I folded the new "if" statement onto one line because some years back the Linux kernel liberated itself from the 80-column constraint imposed by IBM back in 1928. We can now have up to 100 characters in a line of code. ;-)

Thanks, Paul. And thanks for sharing that interesting bit of kernel history! I didn't know about the IBM 80-column constraint from 1928. I had assumed that 80 columns was still the current convention, so it's good to know we can use up to 100 now. ;-)

Thanks,
Kunwu

Quoted 39 lines

Thanx, Paul

Quoted 36 lines

---
Changes since v2:
- Also prevent the transition when the atomic SRCU size-state invariant is violated, per Paul McKenney's suggestion.
-v2: https://lore.kernel.org/rcu/[email protected]/

Changes since v1:
- Drop the !is_atomic guard from v1 and add WARN_ON_ONCE() instead, per Paul McKenney's suggestion.
- v1: https://lore.kernel.org/rcu/[email protected]/

---
 kernel/rcu/srcutree.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
kernel/rcu/srcutree.c +5 -3
index 84c022ec8e09..07db4e459b30 100644
@@ -1073,8 +1073,11 @@ static void srcu_gp_end(struct srcu_struct *ssp, bool is_atomic)
              raw_spin_unlock_irq_rcu_node(sup);
      }
 
-     /* Transition to big if needed. */
-     if (ss_state != SRCU_SIZE_SMALL && ss_state != SRCU_SIZE_BIG) {
+     /* Transition to big if needed, but never for atomic SRCU. */
+     if (ssp->srcu_reader_flavor == SRCU_READ_FLAVOR_ATOMIC &&
+         ss_state != SRCU_SIZE_SMALL) {
+             WARN_ON_ONCE(1);
+     } else if (ss_state != SRCU_SIZE_SMALL && ss_state != SRCU_SIZE_BIG) {
              if (ss_state == SRCU_SIZE_ALLOC)
                      init_srcu_struct_nodes(ssp, GFP_KERNEL);
              else
--

2.43.0

Reviewed-by on v3 1/1
#3 lore raw
In reply to Kunwu Chan

On 11 September 2026 08:21:25 BST, Kunwu Chan <[email protected]> wrote:

Better late than never.

Quoted 2 lines

Atomic SRCU must remain in the small size state. Warn if this invariant is violated and avoid transitioning to big in that case.

Fair enough.

Quoted 21 lines

---
Changes since v2:
- Also prevent the transition when the atomic SRCU size-state invariant is violated, per Paul McKenney's suggestion.
-v2: https://lore.kernel.org/rcu/[email protected]/

Changes since v1:
- Drop the !is_atomic guard from v1 and add WARN_ON_ONCE() instead, per Paul McKenney's suggestion.
- v1: https://lore.kernel.org/rcu/[email protected]/
---
kernel/rcu/srcutree.c | 7 +++++--

1 file changed, 5 insertions(+), 2 deletions(-)
kernel/rcu/srcutree.c +0 -0
index 84c022ec8e09..07db4e459b30 100644

kernel/rcu/srcutree.c static void srcu_gp_end(struct srcu_struct *ssp, bool is_atomic) · line 1080

Quoted 10 lines
kernel/rcu/srcutree.c +5 -2
@@ -1073,8 +1073,11 @@ static void srcu_gp_end(struct srcu_struct *ssp, bool is_atomic)
 		raw_spin_unlock_irq_rcu_node(sup);
 	}
 
-	/* Transition to big if needed. */
-	if (ss_state != SRCU_SIZE_SMALL && ss_state != SRCU_SIZE_BIG) {
+	/* Transition to big if needed, but never for atomic SRCU. */
+	if (ssp->srcu_reader_flavor == SRCU_READ_FLAVOR_ATOMIC &&
+	    ss_state != SRCU_SIZE_SMALL) {
+		WARN_ON_ONCE(1);
+	} else if (ss_state != SRCU_SIZE_SMALL && ss_state != SRCU_SIZE_BIG) {

I like this fix.

kernel/rcu/srcutree.c static void srcu_gp_end(struct srcu_struct *ssp, bool is_atomic) · line 1083

Quoted 4 lines
kernel/rcu/srcutree.c +0 -0
 		if (ss_state == SRCU_SIZE_ALLOC)
 			init_srcu_struct_nodes(ssp, GFP_KERNEL);
 		else

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

maintainer
#4 lore raw
Quoted 10 lines · Bradley Morgan

On 11 September 2026 08:21:25 BST, Kunwu Chan <[email protected]> wrote:

Better late than never.

Quoted 2 lines

Atomic SRCU must remain in the small size state. Warn if this invariant is violated and avoid transitioning to big in that case.

Fair enough.

Thank you! I will apply this on my next rebase.

Thanx, Paul

Quoted 40 lines
Quoted 20 lines

---
Changes since v2:
- Also prevent the transition when the atomic SRCU size-state invariant is violated, per Paul McKenney's suggestion.
-v2: https://lore.kernel.org/rcu/[email protected]/

Changes since v1:
- Drop the !is_atomic guard from v1 and add WARN_ON_ONCE() instead, per Paul McKenney's suggestion.
- v1: https://lore.kernel.org/rcu/[email protected]/
---
kernel/rcu/srcutree.c | 7 +++++--

1 file changed, 5 insertions(+), 2 deletions(-)
kernel/rcu/srcutree.c +0 -0
index 84c022ec8e09..07db4e459b30 100644

kernel/rcu/srcutree.c static void srcu_gp_end(struct srcu_struct *ssp, bool is_atomic) · line 1080

Quoted 10 lines
kernel/rcu/srcutree.c +5 -2
@@ -1073,8 +1073,11 @@ static void srcu_gp_end(struct srcu_struct *ssp, bool is_atomic)
 		raw_spin_unlock_irq_rcu_node(sup);
 	}
 
-	/* Transition to big if needed. */
-	if (ss_state != SRCU_SIZE_SMALL && ss_state != SRCU_SIZE_BIG) {
+	/* Transition to big if needed, but never for atomic SRCU. */
+	if (ssp->srcu_reader_flavor == SRCU_READ_FLAVOR_ATOMIC &&
+	    ss_state != SRCU_SIZE_SMALL) {
+		WARN_ON_ONCE(1);
+	} else if (ss_state != SRCU_SIZE_SMALL && ss_state != SRCU_SIZE_BIG) {

I like this fix.

kernel/rcu/srcutree.c static void srcu_gp_end(struct srcu_struct *ssp, bool is_atomic) · line 1083

Quoted 4 lines
kernel/rcu/srcutree.c +0 -0
 		if (ss_state == SRCU_SIZE_ALLOC)
 			init_srcu_struct_nodes(ssp, GFP_KERNEL);
 		else

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