All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hw_random: use add_hwgenerator_randomness() for early entropy
@ 2022-11-05 20:44 Jason A. Donenfeld
  2022-11-06  1:31 ` Jason A. Donenfeld
  0 siblings, 1 reply; 18+ messages in thread
From: Jason A. Donenfeld @ 2022-11-05 20:44 UTC (permalink / raw)
  To: herbert, linux-crypto; +Cc: Jason A. Donenfeld

Rather than calling add_device_randomness(), the add_early_randomness()
function should use add_hwgenerator_randomness(), so that the early
entropy can be potentially credited, which allows for the RNG to
initialize earlier without having to wait for the kthread to come up.

Cc: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 drivers/char/hw_random/core.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
index cc002b0c2f0c..8c0819ce2781 100644
--- a/drivers/char/hw_random/core.c
+++ b/drivers/char/hw_random/core.c
@@ -69,8 +69,10 @@ static void add_early_randomness(struct hwrng *rng)
 	mutex_lock(&reading_mutex);
 	bytes_read = rng_get_data(rng, rng_fillbuf, 32, 0);
 	mutex_unlock(&reading_mutex);
-	if (bytes_read > 0)
-		add_device_randomness(rng_fillbuf, bytes_read);
+	if (bytes_read > 0) {
+		size_t entropy = bytes_read * 8 * rng->quality / 1024;
+		add_hwgenerator_randomness(rng_fillbuf, bytes_read, entropy);
+	}
 }
 
 static inline void cleanup_rng(struct kref *kref)
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2022-11-13 14:11 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-05 20:44 [PATCH] hw_random: use add_hwgenerator_randomness() for early entropy Jason A. Donenfeld
2022-11-06  1:31 ` Jason A. Donenfeld
2022-11-06  1:50   ` [PATCH v2] " Jason A. Donenfeld
2022-11-06  7:02     ` Dominik Brodowski
2022-11-06 14:50       ` Jason A. Donenfeld
2022-11-06 15:02         ` [PATCH v3] " Jason A. Donenfeld
2022-11-07  2:17           ` Herbert Xu
2022-11-07 12:55             ` Jason A. Donenfeld
2022-11-08  9:58               ` Herbert Xu
2022-11-07  7:39           ` Dominik Brodowski
2022-11-08 10:53           ` AngeloGioacchino Del Regno
2022-11-08 11:00             ` Jason A. Donenfeld
2022-11-08 11:24               ` [PATCH v4] " Jason A. Donenfeld
2022-11-08 11:44                 ` AngeloGioacchino Del Regno
     [not found]                   ` <CGME20221108220529eucas1p215c0154f12de5f83b5b5072be3e51cf6@eucas1p2.samsung.com>
2022-11-08 22:05                     ` Marek Szyprowski
2022-11-13 13:48           ` [PATCH v3] " kernel test robot
2022-11-13 14:11             ` Jason A. Donenfeld
2022-11-07  7:37         ` [PATCH v2] " Dominik Brodowski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.