Re: [PATCH v3 1/2] random: remove batched entropy locking

From: Eric Biggers
Date: Tue Feb 08 2022 - 18:44:32 EST


On Mon, Feb 07, 2022 at 04:39:13PM +0100, Jason A. Donenfeld wrote:
> 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.
>
> Suggested-by: Andy Lutomirski <luto@xxxxxxxxxx>
> Reported-by: Jonathan Neuschäfer <j.neuschaefer@xxxxxxx>
> Tested-by: Jonathan Neuschäfer <j.neuschaefer@xxxxxxx>
> Link: https://lore.kernel.org/lkml/YfMa0QgsjCVdRAvJ@latitude/
> Cc: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx>
> Cc: Sultan Alsawaf <sultan@xxxxxxxxxxxxxxx>
> Signed-off-by: Jason A. Donenfeld <Jason@xxxxxxxxx>
> ---
> drivers/char/random.c | 51 ++++++++++++++++++++++---------------------
> 1 file changed, 26 insertions(+), 25 deletions(-)

Looks good. The comment above invalidate_batched_entropy() needs to be updated,
though.

Also, please Cc patches for random.c to linux-crypto.

- Eric