Skip to content

Commit 6558b91

Browse files
Frederic Weisbeckerpaulmckrcu
authored andcommitted
srcu: Warn when NMI-unsafe API is used in NMI
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 <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
1 parent 2eac2f7 commit 6558b91

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

kernel/rcu/srcutree.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,8 @@ static void srcu_check_nmi_safety(struct srcu_struct *ssp, bool nmi_safe)
642642

643643
if (!IS_ENABLED(CONFIG_PROVE_RCU))
644644
return;
645+
/* NMI-unsafe use in NMI is a bad sign */
646+
WARN_ON_ONCE(!nmi_safe && in_nmi());
645647
sdp = raw_cpu_ptr(ssp->sda);
646648
old_nmi_safe_mask = READ_ONCE(sdp->srcu_nmi_safety);
647649
if (!old_nmi_safe_mask) {

0 commit comments

Comments
 (0)