Re: [PATCH v2 0/7] srcu: NMI-safe atomic SRCU readers, and their irqsave forms

From: Paul E. McKenney

Date: Wed Nov 11 2026 - 14:42:52 EST


On Wed, Nov 11, 2026 at 11:02:33AM -0800, David Woodhouse wrote:
> On Wed, 2026-11-11 at 09:59 -0500, Mathieu Desnoyers wrote:
> >
> > On architectures without NMI-safe this_cpu_inc(), every atomic reader
> > now pays an atomic increment at lock and at unlock.  The update side is
> > unchanged.  On architectures with NMI-safe this_cpu_inc(), such as x86,
> > the readers use the same counter increments as before.  
>
> The latter claim is only true in __srcu_read_lock_fast()/_fast_updown()
> isn't it? Not in the atomic-SRCU. Unless we do something like this on
> top?
>
> Signed-off-by: David Woodhouse <dwmw@xxxxxxxxxxxx> in case it actually
> makes sense and you use it as anything other than a hint.

Could we call __srcu_read_lock_fast() and __srcu_read_unlock_fast(),
respectively, instead of replicating their logic here? (There might
well be a reason. I am not immediately seeing one, but that would be
RCU for you!)

Thanx, Paul

> diff --git a/include/linux/srcu.h b/include/linux/srcu.h
> index b6e6171b4cd4..a6db7bf55cde 100644
> --- a/include/linux/srcu.h
> +++ b/include/linux/srcu.h
> @@ -342,7 +342,18 @@ static inline int __srcu_read_lock_atomic(struct srcu_struct *ssp)
> if (in_task())
> non_block_start();
> srcu_check_read_flavor(ssp, SRCU_READ_FLAVOR_ATOMIC);
> - retval = __srcu_read_lock_nmisafe(ssp);
> + /*
> + * Where this_cpu_inc() is NMI-safe, the this_cpu_inc() + smp_mb()
> + * of __srcu_read_lock() is NMI-safe too, and is exactly what this
> + * flavor's readers always paid. Only the architectures which
> + * genuinely need the atomic increments take them; the pairing
> + * with synchronize_srcu_atomic()'s counter scan is unchanged
> + * either way (full barrier after the increment in both forms).
> + */
> + if (!IS_ENABLED(CONFIG_NEED_SRCU_NMI_SAFE))
> + retval = __srcu_read_lock(ssp);
> + else
> + retval = __srcu_read_lock_nmisafe(ssp);
> /*
> * An NMI may interrupt lockdep itself. Annotate it as a trylock
> * there, as srcu_read_lock_nmisafe() does.
> @@ -600,7 +611,10 @@ static inline void __srcu_read_unlock_atomic(struct srcu_struct *ssp, int idx)
> WARN_ON_ONCE(idx & ~0x1);
> srcu_check_read_flavor(ssp, SRCU_READ_FLAVOR_ATOMIC);
> srcu_lock_release(&ssp->dep_map);
> - __srcu_read_unlock_nmisafe(ssp, idx);
> + if (!IS_ENABLED(CONFIG_NEED_SRCU_NMI_SAFE))
> + __srcu_read_unlock(ssp, idx);
> + else
> + __srcu_read_unlock_nmisafe(ssp, idx);
> if (in_task())
> non_block_end();
> }
>
>
>
> > David agreed to
> > the change, as long as synchronize_srcu_atomic() stays within the 4-16us
> > it was designed for [3].
>
> I set a test running (*without* the above).