Skip to contentSkip to conversation

random: Use arch_get_random_long_early() for init_std_data()

PATCH In review Andre Przywara 2 participants 2 messages Nov 13, 2020 – Nov 16, 2020 Random number driver

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 random: Use arch_get_random_long_early() for init_std_data()

In commit 253d3194c2b5 ("random: add arch_get_random_*long_early()") we introduced _early versions of arch_get_random_long(), that are used on arm64 to use the CPU RNDR instruction early in the boot process, before we have established system-wide availability.
This covers the calls in crng_initialize_primary(), but missed the calls in init_std_data(), happening just before that.

Use the _early versions of the arch_get_random* calls also in init_std_data(), to help initialising the pool with proper seed values.

Fixes 253d3194c2b5 ("random: add arch_get_random_*long_early()")
Cc Mark Rutland <[email protected]>
---
 drivers/char/random.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/char/random.c +2 -2
index 2a41b21623ae..43bb331a67bd 100644
@@ -1778,8 +1778,8 @@ static void __init init_std_data(struct entropy_store *r)
 
 	mix_pool_bytes(r, &now, sizeof(now));
 	for (i = r->poolinfo->poolbytes; i > 0; i -= sizeof(rv)) {
-		if (!arch_get_random_seed_long(&rv) &&
-		    !arch_get_random_long(&rv))
+		if (!arch_get_random_seed_long_early(&rv) &&
+		    !arch_get_random_long_early(&rv))
 			rv = random_get_entropy();
 		mix_pool_bytes(r, &rv, sizeof(rv));
 	}
Signature · 1 line
2.17.1
Acked-by on v1 1/1
#1 lore raw
Quoted 22 lines · Andre Przywara

In commit 253d3194c2b5 ("random: add arch_get_random_*long_early()") we introduced _early versions of arch_get_random_long(), that are used on arm64 to use the CPU RNDR instruction early in the boot process, before we have established system-wide availability.
This covers the calls in crng_initialize_primary(), but missed the calls in init_std_data(), happening just before that.

Use the _early versions of the arch_get_random* calls also in init_std_data(), to help initialising the pool with proper seed values.

Fixes 253d3194c2b5 ("random: add arch_get_random_*long_early()")
Cc Mark Rutland <[email protected]>
---
 drivers/char/random.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/char/random.c +0 -0
index 2a41b21623ae..43bb331a67bd 100644

drivers/char/random.c static void __init init_std_data(struct entropy_store *r) · line 1784

Quoted 9 lines
drivers/char/random.c +2 -2
@@ -1778,8 +1778,8 @@ static void __init init_std_data(struct entropy_store *r)
 
 	mix_pool_bytes(r, &now, sizeof(now));
 	for (i = r->poolinfo->poolbytes; i > 0; i -= sizeof(rv)) {
-		if (!arch_get_random_seed_long(&rv) &&
-		    !arch_get_random_long(&rv))
+		if (!arch_get_random_seed_long_early(&rv) &&
+		    !arch_get_random_long_early(&rv))
 			rv = random_get_entropy();
 		mix_pool_bytes(r, &rv, sizeof(rv));

Will