On Tue, Oct 22, 2024 at 09:07:17AM +0200, Peter Zijlstra wrote: > On Mon, Oct 21, 2024 at 08:30:43PM -0700, Paul E. McKenney wrote: > > Thoughts? > > Thanks Paul! > > Acked-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx> Thank you, Peter! I will apply this on my next rebase. Thanx, Paul > > ------------------------------------------------------------------------ > > > > commit 4433b7d3785d8d2a700f5ed5ca234c64bc63180e > > Author: Paul E. McKenney <paulmck@xxxxxxxxxx> > > Date: Mon Oct 21 15:09:39 2024 -0700 > > > > srcu: Guarantee non-negative return value from srcu_read_lock() > > > > For almost 20 years, the int return value from srcu_read_lock() has > > been always either zero or one. This commit therefore documents the > > fact that it will be non-negative, and does the same for the underlying > > __srcu_read_lock(). > > > > [ paulmck: Apply Andrii Nakryiko feedback. ] > > > > Signed-off-by: Paul E. McKenney <paulmck@xxxxxxxxxx> > > Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx> > > Acked-by: Andrii Nakryiko <andrii@xxxxxxxxxx> > > > > diff --git a/include/linux/srcu.h b/include/linux/srcu.h > > index bab1dae3f69e6..512a8c54ba5ba 100644 > > --- a/include/linux/srcu.h > > +++ b/include/linux/srcu.h > > @@ -238,13 +238,14 @@ void srcu_check_read_flavor(struct srcu_struct *ssp, int read_flavor); > > * a mutex that is held elsewhere while calling synchronize_srcu() or > > * synchronize_srcu_expedited(). > > * > > - * The return value from srcu_read_lock() must be passed unaltered > > - * to the matching srcu_read_unlock(). Note that srcu_read_lock() and > > - * the matching srcu_read_unlock() must occur in the same context, for > > - * example, it is illegal to invoke srcu_read_unlock() in an irq handler > > - * if the matching srcu_read_lock() was invoked in process context. Or, > > - * for that matter to invoke srcu_read_unlock() from one task and the > > - * matching srcu_read_lock() from another. > > + * The return value from srcu_read_lock() is guaranteed to be > > + * non-negative. This value must be passed unaltered to the matching > > + * srcu_read_unlock(). Note that srcu_read_lock() and the matching > > + * srcu_read_unlock() must occur in the same context, for example, it is > > + * illegal to invoke srcu_read_unlock() in an irq handler if the matching > > + * srcu_read_lock() was invoked in process context. Or, for that matter to > > + * invoke srcu_read_unlock() from one task and the matching srcu_read_lock() > > + * from another. > > */ > > static inline int srcu_read_lock(struct srcu_struct *ssp) __acquires(ssp) > > { > > diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c > > index 07147efcb64d3..ae17c214e0de5 100644 > > --- a/kernel/rcu/srcutree.c > > +++ b/kernel/rcu/srcutree.c > > @@ -738,7 +738,8 @@ EXPORT_SYMBOL_GPL(srcu_check_read_flavor); > > /* > > * Counts the new reader in the appropriate per-CPU element of the > > * srcu_struct. > > - * Returns an index that must be passed to the matching srcu_read_unlock(). > > + * Returns a guaranteed non-negative index that must be passed to the > > + * matching __srcu_read_unlock(). > > */ > > int __srcu_read_lock(struct srcu_struct *ssp) > > {