From: "Paul E. McKenney" <paulmck@kernel.org>
To: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: linux-kernel@vger.kernel.org,
David Woodhouse <dwmw2@infradead.org>,
Frederic Weisbecker <frederic@kernel.org>,
Neeraj Upadhyay <neeraj.upadhyay@kernel.org>,
Joel Fernandes <joelagnelf@nvidia.com>,
Josh Triplett <josh@joshtriplett.org>,
Boqun Feng <boqun@kernel.org>,
Uladzislau Rezki <urezki@gmail.com>,
Steven Rostedt <rostedt@goodmis.org>,
Lai Jiangshan <jiangshanlai@gmail.com>,
Zqiang <qiang.zhang@linux.dev>,
Davidlohr Bueso <dave@stgolabs.net>,
Kunwu Chan <kunwu.chan@gmail.com>,
Puranjay Mohan <puranjay@kernel.org>,
rcu@vger.kernel.org
Subject: Re: [PATCH v2 4/7] srcu: Add irqsave variants of the atomic SRCU readers
Date: Wed, 11 Nov 2026 11:58:21 -0800 [thread overview]
Message-ID: <0f5b9d22-353a-4e30-91e1-aeea47461583@paulmck-laptop> (raw)
In-Reply-To: <20261111145949.70845-5-mathieu.desnoyers@efficios.com>
On Wed, Nov 11, 2026 at 09:59:46AM -0500, Mathieu Desnoyers wrote:
> synchronize_srcu_atomic() may be invoked with interrupts disabled, for
> example under a raw spinlock. Its kerneldoc then requires every reader
> of that srcu_struct to disable interrupts too. srcu_read_lock_atomic()
> only disables preemption, so such a reader has to disable interrupts
> itself around it.
>
> Add srcu_read_lock_atomic_irqsave() and
> srcu_read_unlock_atomic_irqrestore(). They disable interrupts instead
> of preemption, and keep the interrupt state in a flags argument, so
> they are macros. Both forms share the rest of the reader through
> __srcu_read_lock_atomic() and __srcu_read_unlock_atomic().
>
> Suggested-by: Paul E. McKenney <paulmck@kernel.org>
> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Reviewed-by: Paul E. McKenney <paulmck@kernel.org>
(Smoke tests passed as well.)
> ---
> include/linux/srcu.h | 100 ++++++++++++++++++++++++++++++++-----------
> 1 file changed, 75 insertions(+), 25 deletions(-)
>
> diff --git a/include/linux/srcu.h b/include/linux/srcu.h
> index e3b541ceb8dd..11e9ad914a71 100644
> --- a/include/linux/srcu.h
> +++ b/include/linux/srcu.h
> @@ -357,31 +357,15 @@ static inline int srcu_read_lock(struct srcu_struct *ssp)
> return retval;
> }
>
> -/**
> - * srcu_read_lock_atomic - register a new reader promising an atomic section
> - * @ssp: srcu_struct in which to register the new reader.
> - *
> - * As srcu_read_lock(), but the caller promises that the read-side
> - * critical section never sleeps and never blocks on anything which
> - * may itself depend on memory allocation to make progress. Preemption
> - * is disabled for the duration, which both enforces that promise (any
> - * sleepable call in the section will splat on every configuration)
> - * and bounds the section so that the update side may spin rather
> - * than sleep when waiting for readers: see synchronize_srcu_atomic().
> - *
> - * The lock and matching srcu_read_unlock_atomic() must be invoked on
> - * the same CPU, from the same context; passing the return value to
> - * another task is not permitted for this flavor.
> - *
> - * This function is NMI-safe, in a manner similar to
> - * srcu_read_lock_nmisafe().
> +/*
> + * Register an atomic-section reader. The caller has disabled preemption,
> + * or interrupts.
> */
> -static inline int srcu_read_lock_atomic(struct srcu_struct *ssp)
> +static inline int __srcu_read_lock_atomic(struct srcu_struct *ssp)
> __acquires_shared(ssp)
> {
> int retval;
>
> - preempt_disable();
> /*
> * Arm might_sleep() to catch even a *potentially* sleeping call
> * in the section, not just an actual schedule: the atomic-domain
> @@ -406,6 +390,50 @@ static inline int srcu_read_lock_atomic(struct srcu_struct *ssp)
> return retval;
> }
>
> +/**
> + * srcu_read_lock_atomic - register a new reader promising an atomic section
> + * @ssp: srcu_struct in which to register the new reader.
> + *
> + * As srcu_read_lock(), but the caller promises that the read-side
> + * critical section never sleeps and never blocks on anything which
> + * may itself depend on memory allocation to make progress. Preemption
> + * is disabled for the duration, which both enforces that promise (any
> + * sleepable call in the section will splat on every configuration)
> + * and bounds the section so that the update side may spin rather
> + * than sleep when waiting for readers: see synchronize_srcu_atomic().
> + *
> + * The lock and matching srcu_read_unlock_atomic() must be invoked on
> + * the same CPU, from the same context; passing the return value to
> + * another task is not permitted for this flavor.
> + *
> + * This function is NMI-safe, in a manner similar to
> + * srcu_read_lock_nmisafe().
> + */
> +static inline int srcu_read_lock_atomic(struct srcu_struct *ssp)
> + __acquires_shared(ssp)
> +{
> + preempt_disable();
> + return __srcu_read_lock_atomic(ssp);
> +}
> +
> +/**
> + * srcu_read_lock_atomic_irqsave - register an atomic reader, interrupts off
> + * @ssp: srcu_struct in which to register the new reader.
> + * @flags: interrupt state to restore at srcu_read_unlock_atomic_irqrestore().
> + *
> + * As srcu_read_lock_atomic(), but with interrupts disabled for the
> + * duration instead of preemption. Use it when synchronize_srcu_atomic()
> + * may be invoked with interrupts disabled for this srcu_struct: its
> + * readers must then disable interrupts too.
> + *
> + * Returns the index to pass to srcu_read_unlock_atomic_irqrestore().
> + */
> +#define srcu_read_lock_atomic_irqsave(ssp, flags) \
> +({ \
> + local_irq_save(flags); \
> + __srcu_read_lock_atomic((ssp)); \
> +})
> +
> /**
> * srcu_read_lock_fast - register a new reader for an SRCU-protected structure.
> * @ssp: srcu_struct in which to register the new reader.
> @@ -598,12 +626,11 @@ static inline void srcu_read_unlock(struct srcu_struct *ssp, int idx)
> __srcu_read_unlock(ssp, idx);
> }
>
> -/**
> - * srcu_read_unlock_atomic - unregister an atomic-section reader
> - * @ssp: srcu_struct from which to unregister the old reader.
> - * @idx: return value from corresponding srcu_read_lock_atomic().
> +/*
> + * Unregister an atomic-section reader. The caller then enables preemption,
> + * or interrupts, again.
> */
> -static inline void srcu_read_unlock_atomic(struct srcu_struct *ssp, int idx)
> +static inline void __srcu_read_unlock_atomic(struct srcu_struct *ssp, int idx)
> __releases_shared(ssp)
> {
> WARN_ON_ONCE(idx & ~0x1);
> @@ -612,9 +639,32 @@ static inline void srcu_read_unlock_atomic(struct srcu_struct *ssp, int idx)
> __srcu_read_unlock_nmisafe(ssp, idx);
> if (in_task())
> non_block_end();
> +}
> +
> +/**
> + * srcu_read_unlock_atomic - unregister an atomic-section reader
> + * @ssp: srcu_struct from which to unregister the old reader.
> + * @idx: return value from corresponding srcu_read_lock_atomic().
> + */
> +static inline void srcu_read_unlock_atomic(struct srcu_struct *ssp, int idx)
> + __releases_shared(ssp)
> +{
> + __srcu_read_unlock_atomic(ssp, idx);
> preempt_enable();
> }
>
> +/**
> + * srcu_read_unlock_atomic_irqrestore - unregister an irqsave atomic reader
> + * @ssp: srcu_struct from which to unregister the old reader.
> + * @idx: return value from corresponding srcu_read_lock_atomic_irqsave().
> + * @flags: interrupt state saved by srcu_read_lock_atomic_irqsave().
> + */
> +#define srcu_read_unlock_atomic_irqrestore(ssp, idx, flags) \
> +do { \
> + __srcu_read_unlock_atomic((ssp), (idx)); \
> + local_irq_restore(flags); \
> +} while (0)
> +
> /**
> * srcu_read_unlock_fast - unregister a old reader from an SRCU-protected structure.
> * @ssp: srcu_struct in which to unregister the old reader.
> --
> 2.47.3
>
next prev parent reply other threads:[~2026-11-11 19:58 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 14:59 [PATCH v2 0/7] srcu: NMI-safe atomic SRCU readers, and their irqsave forms Mathieu Desnoyers
2026-11-11 14:59 ` [PATCH v2 1/7] srcutiny: Do not call synchronize_rcu() from synchronize_srcu_atomic() Mathieu Desnoyers
2026-11-11 18:35 ` Paul E. McKenney
2026-11-12 3:03 ` KunWu Chan
2026-11-11 14:59 ` [PATCH v2 2/7] srcu: Rule for using synchronize_srcu_atomic() from interrupt handlers Mathieu Desnoyers
2026-11-11 18:54 ` Paul E. McKenney
2026-11-12 3:18 ` KunWu Chan
2026-11-11 14:59 ` [PATCH v2 3/7] srcu: Make atomic SRCU readers NMI-safe Mathieu Desnoyers
2026-11-11 19:55 ` Paul E. McKenney
2026-11-12 9:14 ` KunWu Chan
2026-11-11 14:59 ` [PATCH v2 4/7] srcu: Add irqsave variants of the atomic SRCU readers Mathieu Desnoyers
2026-11-11 19:58 ` Paul E. McKenney [this message]
2026-11-11 20:04 ` Paul E. McKenney
2026-11-11 20:13 ` Mathieu Desnoyers
2026-11-12 0:07 ` Paul E. McKenney
2026-11-12 1:32 ` Mathieu Desnoyers
2026-11-12 2:13 ` Paul E. McKenney
2026-11-12 2:50 ` Mathieu Desnoyers
2026-11-12 4:25 ` Paul E. McKenney
2026-11-12 20:08 ` Paul E. McKenney
2026-11-11 14:59 ` [PATCH v2 5/7] rcutorture: Run NMI-safe SRCU readers from NMI Mathieu Desnoyers
2026-11-12 0:39 ` Paul E. McKenney
2026-11-11 14:59 ` [PATCH v2 6/7] rcutorture: Test the irqsave forms of atomic SRCU readers Mathieu Desnoyers
2026-11-12 0:45 ` Paul E. McKenney
2026-11-11 14:59 ` [PATCH v2 7/7] rcutorture: Check an atomic SRCU wait within an RCU reader Mathieu Desnoyers
2026-11-12 0:46 ` Paul E. McKenney
2026-11-11 19:02 ` [PATCH v2 0/7] srcu: NMI-safe atomic SRCU readers, and their irqsave forms David Woodhouse
2026-11-11 19:33 ` Mathieu Desnoyers
2026-11-11 19:35 ` Paul E. McKenney
2026-11-11 19:37 ` David Woodhouse
2026-11-11 19:40 ` Mathieu Desnoyers
2026-11-11 19:50 ` Paul E. McKenney
2026-11-11 19:34 ` Paul E. McKenney
2026-11-12 1:53 ` David Woodhouse
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0f5b9d22-353a-4e30-91e1-aeea47461583@paulmck-laptop \
--to=paulmck@kernel.org \
--cc=boqun@kernel.org \
--cc=dave@stgolabs.net \
--cc=dwmw2@infradead.org \
--cc=frederic@kernel.org \
--cc=jiangshanlai@gmail.com \
--cc=joelagnelf@nvidia.com \
--cc=josh@joshtriplett.org \
--cc=kunwu.chan@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=neeraj.upadhyay@kernel.org \
--cc=puranjay@kernel.org \
--cc=qiang.zhang@linux.dev \
--cc=rcu@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=urezki@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®