srcu: Warn when NMI-unsafe API is used in NMI
authorFrederic Weisbecker <frederic@kernel.org>
Thu, 13 Oct 2022 17:22:42 +0000 (19:22 +0200)
committerPaul E. McKenney <paulmck@kernel.org>
Fri, 21 Oct 2022 17:15:53 +0000 (10:15 -0700)
commit6b77bb9b99c66c6596c58e7a25169bc2ea6b82dd
treec8e0c6a1fa368ea90142e40a7698f2e76fc86d3e
parent85bf37855ce287fe045a539441c0a3cd9c8b16fc
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 <frederic@kernel.org>
Reviewed-by: Joel Fernandes (Google) <joel@joelfernandes.org>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
kernel/rcu/srcutree.c