srcu: Add SRCU_READ_FLAVOR_SLOWGP to flag need for synchronize_rcu()
authorPaul E. McKenney <paulmck@kernel.org>
Wed, 8 Jan 2025 14:48:15 +0000 (06:48 -0800)
committerBoqun Feng <boqun.feng@gmail.com>
Wed, 5 Feb 2025 15:12:05 +0000 (07:12 -0800)
This commit switches from a direct test of SRCU_READ_FLAVOR_LITE to a new
SRCU_READ_FLAVOR_SLOWGP macro to check for substituting synchronize_rcu()
for smp_mb() in SRCU grace periods.  Right now, SRCU_READ_FLAVOR_SLOWGP
is exactly SRCU_READ_FLAVOR_LITE, but the addition of the _fast() flavor
of SRCU will change that.

Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Kent Overstreet <kent.overstreet@linux.dev>
Cc: <bpf@vger.kernel.org>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
include/linux/srcu.h
kernel/rcu/srcutree.c

index ca00b9af7c2370c4c55db4abfbdb4eada2b327d6..505f5bdce4446c95ea03fe20e30e004a859e9efb 100644 (file)
@@ -49,6 +49,9 @@ int init_srcu_struct(struct srcu_struct *ssp);
 #define SRCU_READ_FLAVOR_LITE  0x4             // srcu_read_lock_lite().
 #define SRCU_READ_FLAVOR_ALL   (SRCU_READ_FLAVOR_NORMAL | SRCU_READ_FLAVOR_NMI | \
                                SRCU_READ_FLAVOR_LITE) // All of the above.
+#define SRCU_READ_FLAVOR_SLOWGP        SRCU_READ_FLAVOR_LITE
+                                               // Flavors requiring synchronize_rcu()
+                                               // instead of smp_mb().
 
 #ifdef CONFIG_TINY_SRCU
 #include <linux/srcutiny.h>
index 121dd290cae144abfffc1ecb3d9d7c5df55ebe7f..8b5c50bc98e5df9c045cedc62afe5ac318272130 100644 (file)
@@ -449,7 +449,7 @@ static bool srcu_readers_lock_idx(struct srcu_struct *ssp, int idx, bool gp, uns
        }
        WARN_ONCE(IS_ENABLED(CONFIG_PROVE_RCU) && (mask & (mask - 1)),
                  "Mixed reader flavors for srcu_struct at %ps.\n", ssp);
-       if (mask & SRCU_READ_FLAVOR_LITE && !gp)
+       if (mask & SRCU_READ_FLAVOR_SLOWGP && !gp)
                return false;
        return sum == unlocks;
 }
@@ -487,7 +487,7 @@ static bool srcu_readers_active_idx_check(struct srcu_struct *ssp, int idx)
        unsigned long unlocks;
 
        unlocks = srcu_readers_unlock_idx(ssp, idx, &rdm);
-       did_gp = !!(rdm & SRCU_READ_FLAVOR_LITE);
+       did_gp = !!(rdm & SRCU_READ_FLAVOR_SLOWGP);
 
        /*
         * Make sure that a lock is always counted if the corresponding
@@ -1205,7 +1205,7 @@ static bool srcu_should_expedite(struct srcu_struct *ssp)
 
        check_init_srcu_struct(ssp);
        /* If _lite() readers, don't do unsolicited expediting. */
-       if (this_cpu_read(ssp->sda->srcu_reader_flavor) & SRCU_READ_FLAVOR_LITE)
+       if (this_cpu_read(ssp->sda->srcu_reader_flavor) & SRCU_READ_FLAVOR_SLOWGP)
                return false;
        /* If the local srcu_data structure has callbacks, not idle.  */
        sdp = raw_cpu_ptr(ssp->sda);