Atomic SRCU remain in the small size state, so add a
WARN_ON_ONCE() before the transition check to catch any future
code path that might violate this invariant.

Signed-off-by: Kunwu Chan <[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 | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
index 84c022ec8e09..68441c32cebf 100644
--- a/kernel/rcu/srcutree.c
+++ b/kernel/rcu/srcutree.c
@@ -1074,6 +1074,8 @@ static void srcu_gp_end(struct srcu_struct *ssp, bool 
is_atomic)
        }
 
        /* Transition to big if needed. */
+       WARN_ON_ONCE(ssp->srcu_reader_flavor == SRCU_READ_FLAVOR_ATOMIC &&
+                       ss_state != SRCU_SIZE_SMALL);
        if (ss_state != SRCU_SIZE_SMALL && ss_state != SRCU_SIZE_BIG) {
                if (ss_state == SRCU_SIZE_ALLOC)
                        init_srcu_struct_nodes(ssp, GFP_KERNEL);
-- 
2.43.0


Reply via email to