From: "Paul E. McKenney" <paulmck@kernel.org>
To: rcu@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, kernel-team@fb.com,
rostedt@goodmis.org, Frederic Weisbecker <frederic@kernel.org>,
"Paul E . McKenney" <paulmck@kernel.org>
Subject: [PATCH v3 rcu 09/11] srcu: Warn when NMI-unsafe API is used in NMI
Date: Wed, 19 Oct 2022 15:58:44 -0700 [thread overview]
Message-ID: <20221019225846.2501109-9-paulmck@kernel.org> (raw)
In-Reply-To: <20221019225838.GA2500612@paulmck-ThinkPad-P17-Gen-1>
From: Frederic Weisbecker <frederic@kernel.org>
Using the NMI-unsafe reader API from within an NMI handler is very likely
to be buggy for three reasons:
1) NMIs aren't strictly re-entrant (a pending nested NMI will execute at
the end of the current one) so it should be fine to use a non-atomic
increment here. However, breakpoints can still interrupt NMIs and if
a breakpoint callback has a reader on that same ssp, a racy increment
can happen.
2) If the only reader site for a given srcu_struct structure is in an
NMI handler, then RCU should be used instead of SRCU.
3) Because of the previous reason (2), an srcu_struct structure having
an SRCU read side critical section in an NMI handler is likely to
have another one from a task context.
For all these reasons, warn if an NMI-unsafe reader API is used from an
NMI handler.
Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
---
kernel/rcu/srcutree.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
index 87ae6f5c1edae..18bb696cff8ca 100644
--- a/kernel/rcu/srcutree.c
+++ b/kernel/rcu/srcutree.c
@@ -642,6 +642,8 @@ static void srcu_check_nmi_safety(struct srcu_struct *ssp, bool nmi_safe)
if (!IS_ENABLED(CONFIG_PROVE_RCU))
return;
+ /* NMI-unsafe use in NMI is a bad sign */
+ WARN_ON_ONCE(!nmi_safe && in_nmi());
sdp = raw_cpu_ptr(ssp->sda);
old_nmi_safe_mask = READ_ONCE(sdp->srcu_nmi_safety);
if (!old_nmi_safe_mask) {
--
2.31.1.189.g2e36527f23
next prev parent reply other threads:[~2022-10-19 22:59 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-19 22:58 [PATCH rcu 0/11] NMI-safe SRCU readers for v6.2 Paul E. McKenney
2022-10-19 22:58 ` [PATCH v3 rcu 01/11] srcu: Convert ->srcu_lock_count and ->srcu_unlock_count to atomic Paul E. McKenney
2022-10-19 22:58 ` [PATCH v3 rcu 02/11] srcu: Create an srcu_read_lock_nmisafe() and srcu_read_unlock_nmisafe() Paul E. McKenney
2022-10-19 22:58 ` [PATCH v3 rcu 03/11] srcu: Check for consistent per-CPU per-srcu_struct NMI safety Paul E. McKenney
2022-10-19 22:58 ` [PATCH v3 rcu 04/11] srcu: Check for consistent global " Paul E. McKenney
2022-10-19 22:58 ` [PATCH v3 rcu 05/11] arch/x86: Add ARCH_HAS_NMI_SAFE_THIS_CPU_OPS Kconfig option Paul E. McKenney
2022-10-19 22:58 ` [PATCH v3 rcu 06/11] arch/arm64: " Paul E. McKenney
2022-10-19 22:58 ` [PATCH v3 rcu 07/11] arch/loongarch: " Paul E. McKenney
2022-10-19 22:58 ` [PATCH v3 rcu 08/11] arch/s390: " Paul E. McKenney
2022-10-20 5:16 ` Christian Borntraeger
2022-10-20 7:23 ` Heiko Carstens
2022-10-20 7:27 ` Heiko Carstens
2022-10-20 16:35 ` Paul E. McKenney
2022-10-19 22:58 ` Paul E. McKenney [this message]
2022-10-19 22:58 ` [PATCH v3 rcu 10/11] srcu: Explain the reason behind the read side critical section on GP start Paul E. McKenney
2022-10-19 22:58 ` [PATCH v3 rcu 11/11] srcu: Debug NMI safety even on archs that don't require it 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=20221019225846.2501109-9-paulmck@kernel.org \
--to=paulmck@kernel.org \
--cc=frederic@kernel.org \
--cc=kernel-team@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rcu@vger.kernel.org \
--cc=rostedt@goodmis.org \
/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