srcu: Make Tiny SRCU poll_state_synchronize_srcu() more precise
authorPaul E. McKenney <paulmck@kernel.org>
Tue, 2 Aug 2022 18:59:49 +0000 (11:59 -0700)
committerPaul E. McKenney <paulmck@kernel.org>
Wed, 31 Aug 2022 12:10:15 +0000 (05:10 -0700)
This commit applies the more-precise grace-period-state check used by
rcu_seq_done_exact() to poll_state_synchronize_srcu().  This is important
because Tiny SRCU uses a 16-bit counter, which can wrap quite quickly.
If counter wrap continues to be a problem, then expanding ->srcu_idx
and ->srcu_idx_max to 32 bits might be warranted.

Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
kernel/rcu/srcutiny.c

index 92c002d65482872dc536efd16ff2317518a0a34b..a2af24f2146761f4974319e93365875e9aea738e 100644 (file)
@@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(start_poll_synchronize_srcu);
  */
 bool poll_state_synchronize_srcu(struct srcu_struct *ssp, unsigned long cookie)
 {
-       bool ret = USHORT_CMP_GE(READ_ONCE(ssp->srcu_idx), cookie);
+       unsigned short cur_s = READ_ONCE(ssp->srcu_idx);
 
        barrier();
-       return ret;
+       return USHORT_CMP_GE(cur_s, cookie) || USHORT_CMP_LT(cur_s, cookie - 3);
 }
 EXPORT_SYMBOL_GPL(poll_state_synchronize_srcu);