random: remove batched entropy locking
authorJason A. Donenfeld <Jason@zx2c4.com>
Fri, 28 Jan 2022 22:29:45 +0000 (23:29 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Sun, 13 Feb 2022 23:46:08 +0000 (00:46 +0100)
commit6a1d5317ee05839620aa6a409295a60dd904acf1
tree4cd64c63c94a0b75666db1ee2107744242e4b2ad
parent8990c225eb9f5d35fef429b65ffc64ac3c81cc50
random: remove batched entropy locking

Rather than use spinlocks to protect batched entropy, we can instead
disable interrupts locally, since we're dealing with per-cpu data, and
manage resets with a basic generation counter. At the same time, we
can't quite do this on PREEMPT_RT, where we still want spinlocks-as-
mutexes semantics. So we use a local_lock_t, which provides the right
behavior for each. Because this is a per-cpu lock, that generation
counter is still doing the necessary CPU-to-CPU communication.

This should improve performance a bit. It will also fix the linked splat
that Jonathan received with a PROVE_RAW_LOCK_NESTING=y.

Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Reviewed-by: Dominik Brodowski <linux@dominikbrodowski.net>
Suggested-by: Andy Lutomirski <luto@kernel.org>
Reported-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
Tested-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net>
Link: https://lore.kernel.org/lkml/YfMa0QgsjCVdRAvJ@latitude/
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
drivers/char/random.c