random: unify early init crng load accounting
authorJason A. Donenfeld <Jason@zx2c4.com>
Sat, 12 Feb 2022 22:54:09 +0000 (23:54 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Wed, 16 Feb 2022 23:03:52 +0000 (00:03 +0100)
commitcc538814458d90ef6225c4f84ed5165ef25b3f14
tree2b612f7189b2f37afdf8cbbaef4c57cf8fd4d89a
parent7789a5f6455d4b23f0374126073bd14a84fcef77
random: unify early init crng load accounting

crng_fast_load() and crng_slow_load() have different semantics:

- crng_fast_load() xors and accounts with crng_init_cnt.
- crng_slow_load() hashes and doesn't account.

However add_hwgenerator_randomness() can afford to hash (it's called
from a kthread), and it should account. Additionally, ones that can
afford to hash don't need to take a trylock but can take a normal lock.
So, we combine these into one function, crng_pre_init_inject(), which
allows us to control these in a uniform way. This will make it simpler
later to simplify this all down when the time comes for that.

Cc: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Dominik Brodowski <linux@dominikbrodowski.net>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
drivers/char/random.c