linux-stable/arch
Paul E. McKenney 2e83b879fb srcu: Create an srcu_read_lock_nmisafe() and srcu_read_unlock_nmisafe()
On strict load-store architectures, the use of this_cpu_inc() by
srcu_read_lock() and srcu_read_unlock() is not NMI-safe in TREE SRCU.
To see this suppose that an NMI arrives in the middle of srcu_read_lock(),
just after it has read ->srcu_lock_count, but before it has written
the incremented value back to memory.  If that NMI handler also does
srcu_read_lock() and srcu_read_lock() on that same srcu_struct structure,
then upon return from that NMI handler, the interrupted srcu_read_lock()
will overwrite the NMI handler's update to ->srcu_lock_count, but
leave unchanged the NMI handler's update by srcu_read_unlock() to
->srcu_unlock_count.

This can result in a too-short SRCU grace period, which can in turn
result in arbitrary memory corruption.

If the NMI handler instead interrupts the srcu_read_unlock(), this
can result in eternal SRCU grace periods, which is not much better.

This commit therefore creates a pair of new srcu_read_lock_nmisafe()
and srcu_read_unlock_nmisafe() functions, which allow SRCU readers in
both NMI handlers and in process and IRQ context.  It is bad practice
to mix the existing and the new _nmisafe() primitives on the same
srcu_struct structure.  Use one set or the other, not both.

Just to underline that "bad practice" point, using srcu_read_lock() at
process level and srcu_read_lock_nmisafe() in your NMI handler will not,
repeat NOT, work.  If you do not immediately understand why this is the
case, please review the earlier paragraphs in this commit log.

[ paulmck: Apply kernel test robot feedback. ]
[ paulmck: Apply feedback from Randy Dunlap. ]
[ paulmck: Apply feedback from John Ogness. ]
[ paulmck: Apply feedback from Frederic Weisbecker. ]

Link: https://lore.kernel.org/all/20220910221947.171557773@linutronix.de/

Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Acked-by: Randy Dunlap <rdunlap@infradead.org> # build-tested
Reviewed-by: Frederic Weisbecker <frederic@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: John Ogness <john.ogness@linutronix.de>
Cc: Petr Mladek <pmladek@suse.com>
2022-10-20 14:39:18 -07:00
..
alpha asm-generic: arch/alpha regression fix for 6.1 2022-10-14 13:47:42 -07:00
arc - hfs and hfsplus kmap API modernization from Fabio Francesco 2022-10-12 11:00:22 -07:00
arm Random number generator fixes for Linux 6.1-rc1. 2022-10-16 15:27:07 -07:00
arm64 Random number generator fixes for Linux 6.1-rc1. 2022-10-16 15:27:07 -07:00
csky - hfs and hfsplus kmap API modernization from Fabio Francesco 2022-10-12 11:00:22 -07:00
hexagon - hfs and hfsplus kmap API modernization from Fabio Francesco 2022-10-12 11:00:22 -07:00
ia64 - hfs and hfsplus kmap API modernization from Fabio Francesco 2022-10-12 11:00:22 -07:00
loongarch Random number generator fixes for Linux 6.1-rc1. 2022-10-16 15:27:07 -07:00
m68k - hfs and hfsplus kmap API modernization from Fabio Francesco 2022-10-12 11:00:22 -07:00
microblaze - hfs and hfsplus kmap API modernization from Fabio Francesco 2022-10-12 11:00:22 -07:00
mips Random number generator fixes for Linux 6.1-rc1. 2022-10-16 15:27:07 -07:00
nios2 - hfs and hfsplus kmap API modernization from Fabio Francesco 2022-10-12 11:00:22 -07:00
openrisc OpenRISC 6.1 Updates 2022-10-15 16:47:33 -07:00
parisc Random number generator fixes for Linux 6.1-rc1. 2022-10-16 15:27:07 -07:00
powerpc Random number generator fixes for Linux 6.1-rc1. 2022-10-16 15:27:07 -07:00
riscv RISC-V Patches for the 6.1 Merge Window, Part 2 2022-10-14 11:21:11 -07:00
s390 Random number generator fixes for Linux 6.1-rc1. 2022-10-16 15:27:07 -07:00
sh - hfs and hfsplus kmap API modernization from Fabio Francesco 2022-10-12 11:00:22 -07:00
sparc Random number generator fixes for Linux 6.1-rc1. 2022-10-16 15:27:07 -07:00
um Random number generator fixes for Linux 6.1-rc1. 2022-10-16 15:27:07 -07:00
x86 Random number generator fixes for Linux 6.1-rc1. 2022-10-16 15:27:07 -07:00
xtensa - hfs and hfsplus kmap API modernization from Fabio Francesco 2022-10-12 11:00:22 -07:00
.gitignore
Kconfig srcu: Create an srcu_read_lock_nmisafe() and srcu_read_unlock_nmisafe() 2022-10-20 14:39:18 -07:00