random: do not take pool spinlock at boot
authorJason A. Donenfeld <Jason@zx2c4.com>
Sat, 12 Feb 2022 00:26:17 +0000 (01:26 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Mon, 21 Feb 2022 20:14:17 +0000 (21:14 +0100)
Since rand_initialize() is run while interrupts are still off and
nothing else is running, we don't need to repeatedly take and release
the pool spinlock, especially in the RDSEED loop.

Reviewed-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Dominik Brodowski <linux@dominikbrodowski.net>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
drivers/char/random.c

index 26cbfcaa3b783931c9da92c56117278db799247d..0541066e2e5c13e28b43a7bba5ae49ec01b4dd01 100644 (file)
@@ -978,10 +978,10 @@ int __init rand_initialize(void)
                        rv = random_get_entropy();
                        arch_init = false;
                }
-               mix_pool_bytes(&rv, sizeof(rv));
+               _mix_pool_bytes(&rv, sizeof(rv));
        }
-       mix_pool_bytes(&now, sizeof(now));
-       mix_pool_bytes(utsname(), sizeof(*(utsname())));
+       _mix_pool_bytes(&now, sizeof(now));
+       _mix_pool_bytes(utsname(), sizeof(*(utsname())));
 
        extract_entropy(base_crng.key, sizeof(base_crng.key));
        ++base_crng.generation;