mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Woodhouse <dwmw2@infradead.org>
To: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	"Paul E . McKenney" <paulmck@kernel.org>
Cc: linux-kernel@vger.kernel.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 0/7] srcu: NMI-safe atomic SRCU readers, and their irqsave forms
Date: Wed, 11 Nov 2026 11:02:33 -0800	[thread overview]
Message-ID: <50d177ddb1de4b84e9fd2cbd2ec5bdb7e32845d4.camel@infradead.org> (raw)
In-Reply-To: <20261111145949.70845-1-mathieu.desnoyers@efficios.com>

[-- Attachment #1: Type: text/plain, Size: 2313 bytes --]

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@amazon.co.uk> in case it actually
makes sense and you use it as anything other than a hint.

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). 

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 6179 bytes --]

  parent reply	other threads:[~2026-11-11 19:02 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11 14:59 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-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-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-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
2026-11-11 20:04     ` Paul E. McKenney
2026-11-11 20:13       ` Mathieu Desnoyers
2026-11-11 14:59 ` [PATCH v2 5/7] rcutorture: Run NMI-safe SRCU readers from NMI Mathieu Desnoyers
2026-11-11 14:59 ` [PATCH v2 6/7] rcutorture: Test the irqsave forms of atomic SRCU readers Mathieu Desnoyers
2026-11-11 14:59 ` [PATCH v2 7/7] rcutorture: Check an atomic SRCU wait within an RCU reader Mathieu Desnoyers
2026-11-11 19:02 ` David Woodhouse [this message]
2026-11-11 19:33   ` [PATCH v2 0/7] srcu: NMI-safe atomic SRCU readers, and their irqsave forms 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

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=50d177ddb1de4b84e9fd2cbd2ec5bdb7e32845d4.camel@infradead.org \
    --to=dwmw2@infradead.org \
    --cc=boqun@kernel.org \
    --cc=dave@stgolabs.net \
    --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=paulmck@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®