srcutree: Don't transition atomic SRCU to big in srcu_gp_end()
Subsystems (2)
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
@@ -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
Paul E. McKenney
maintainerQuoted 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.
Signed-off-by Kunwu Chan <[email protected]>
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 addWARN_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@@ -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
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
Signed-off-by Kunwu Chan <[email protected]>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 addWARN_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@@ -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
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
Signed-off-by Kunwu Chan <[email protected]>---
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 addWARN_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
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
-0if (ss_state ==SRCU_SIZE_ALLOC )init_srcu_struct_nodes (ssp,GFP_KERNEL );else
Paul E. McKenney
maintainerQuoted 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.
Reviewed-by Bradley Morgan <[email protected]>
Thank you! I will apply this on my next rebase.
Thanx, Paul
Quoted 40 lines
Quoted 20 lines
Signed-off-by Kunwu Chan <[email protected]>---
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 addWARN_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
-0kernel/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
-0if (ss_state ==SRCU_SIZE_ALLOC )init_srcu_struct_nodes (ssp,GFP_KERNEL );else