* [PATCH v3] srcutree: Don't transition atomic SRCU to big in srcu_gp_end()
@ 2026-09-11 7:21 Kunwu Chan
2026-09-11 16:37 ` Paul E. McKenney
2026-09-13 12:47 ` Bradley Morgan
0 siblings, 2 replies; 4+ messages in thread
From: Kunwu Chan @ 2026-09-11 7:21 UTC (permalink / raw)
To: jiangshanlai, paulmck, josh
Cc: rostedt, mathieu.desnoyers, rcu, linux-kernel, 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 <kunwu.chan@gmail.com>
---
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/20260910084629.3695383-1-kunwu.chan@gmail.com/
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/20260907075829.2073224-8-kunwu.chan@linux.dev/
---
kernel/rcu/srcutree.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
index 84c022ec8e09..07db4e459b30 100644
--- a/kernel/rcu/srcutree.c
+++ b/kernel/rcu/srcutree.c
@@ -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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v3] srcutree: Don't transition atomic SRCU to big in srcu_gp_end()
2026-09-11 7:21 [PATCH v3] srcutree: Don't transition atomic SRCU to big in srcu_gp_end() Kunwu Chan
@ 2026-09-11 16:37 ` Paul E. McKenney
2026-09-12 12:41 ` KunWu Chan
2026-09-13 12:47 ` Bradley Morgan
1 sibling, 1 reply; 4+ messages in thread
From: Paul E. McKenney @ 2026-09-11 16:37 UTC (permalink / raw)
To: Kunwu Chan
Cc: jiangshanlai, josh, rostedt, mathieu.desnoyers, rcu, linux-kernel
On Fri, Sep 11, 2026 at 03:21:25PM +0800, Kunwu Chan wrote:
> 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 <kunwu.chan@gmail.com>
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
> ---
> 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/20260910084629.3695383-1-kunwu.chan@gmail.com/
>
> 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/20260907075829.2073224-8-kunwu.chan@linux.dev/
> ---
> kernel/rcu/srcutree.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
> index 84c022ec8e09..07db4e459b30 100644
> --- a/kernel/rcu/srcutree.c
> +++ b/kernel/rcu/srcutree.c
> @@ -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
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] srcutree: Don't transition atomic SRCU to big in srcu_gp_end()
2026-09-11 16:37 ` Paul E. McKenney
@ 2026-09-12 12:41 ` KunWu Chan
0 siblings, 0 replies; 4+ messages in thread
From: KunWu Chan @ 2026-09-12 12:41 UTC (permalink / raw)
To: paulmck; +Cc: jiangshanlai, josh, rostedt, mathieu.desnoyers, rcu, linux-kernel
On Sat, Sep 12, 2026 at 12:37 AM Paul E. McKenney <paulmck@kernel.org> wrote:
>
> On Fri, Sep 11, 2026 at 03:21:25PM +0800, Kunwu Chan wrote:
> > 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 <kunwu.chan@gmail.com>
>
> 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
>
> Thanx, Paul
>
> > ---
> > 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/20260910084629.3695383-1-kunwu.chan@gmail.com/
> >
> > 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/20260907075829.2073224-8-kunwu.chan@linux.dev/
> > ---
> > kernel/rcu/srcutree.c | 7 +++++--
> > 1 file changed, 5 insertions(+), 2 deletions(-)
> >
> > diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
> > index 84c022ec8e09..07db4e459b30 100644
> > --- a/kernel/rcu/srcutree.c
> > +++ b/kernel/rcu/srcutree.c
> > @@ -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
> >
> >
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] srcutree: Don't transition atomic SRCU to big in srcu_gp_end()
2026-09-11 7:21 [PATCH v3] srcutree: Don't transition atomic SRCU to big in srcu_gp_end() Kunwu Chan
2026-09-11 16:37 ` Paul E. McKenney
@ 2026-09-13 12:47 ` Bradley Morgan
1 sibling, 0 replies; 4+ messages in thread
From: Bradley Morgan @ 2026-09-13 12:47 UTC (permalink / raw)
To: kunwu.chan
Cc: jiangshanlai, josh, linux-kernel, mathieu.desnoyers, paulmck, rcu,
rostedt
On 11 September 2026 08:21:25 BST, Kunwu Chan <kunwu.chan@gmail.com> wrote:
Better late than never.
>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 <brads@mainlining.org>
>
>Signed-off-by: Kunwu Chan <kunwu.chan@gmail.com>
>---
>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/20260910084629.3695383-1-kunwu.chan@gmail.com/
>
>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/20260907075829.2073224-8-kunwu.chan@linux.dev/
>---
> kernel/rcu/srcutree.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
>diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
>index 84c022ec8e09..07db4e459b30 100644
>--- a/kernel/rcu/srcutree.c
>+++ b/kernel/rcu/srcutree.c
>@@ -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.
> if (ss_state == SRCU_SIZE_ALLOC)
> init_srcu_struct_nodes(ssp, GFP_KERNEL);
> else
>
--- Thanks!
https://lore.kernel.org/all/EE579805-42F2-4C58-B752-F28779EEB717@grrlz.net/
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-09-13 12:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-11 7:21 [PATCH v3] srcutree: Don't transition atomic SRCU to big in srcu_gp_end() Kunwu Chan
2026-09-11 16:37 ` Paul E. McKenney
2026-09-12 12:41 ` KunWu Chan
2026-09-13 12:47 ` Bradley Morgan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox