Skip to contentSkip to conversation

powerpc: Use hardware RNG for arch_get_random_seed_* not arch_get_random_*

PATCH In review Paul Mackerras 2 participants 2 messages Jul 16, 2015 – Jul 17, 2015 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc: Use hardware RNG for arch_get_random_seed_* not arch_get_random_*

The hardware RNG on POWER8 and POWER7+ can be relatively slow, since it can only supply one 64-bit value per microsecond. Currently we read it in arch_get_random_long(), but that slows down reading from /dev/urandom since the code in random.c calls arch_get_random_long() for every longword read from /dev/urandom.

Since the hardware RNG supplies high-quality entropy on every read, it matches the semantics of arch_get_random_seed_long() better than those of arch_get_random_long(). Therefore this commit makes the code use the hardware RNG only for arch_get_random_seed_{long,int} and not for arch_get_random_{long,int}.

---
 arch/powerpc/include/asm/archrandom.h | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)
arch/powerpc/include/asm/archrandom.h +13 -13
index 0cc6eed..a4c3f54 100644
@@ -7,13 +7,22 @@
 
 static inline int arch_get_random_long(unsigned long *v)
 {
+	return 0;
+}
+
+static inline int arch_get_random_int(unsigned int *v)
+{
+	return 0;
+}
+
+static inline int arch_get_random_seed_long(unsigned long *v)
+{
 	if (ppc_md.get_random_long)
 		return ppc_md.get_random_long(v);
 
 	return 0;
 }
-
-static inline int arch_get_random_int(unsigned int *v)
+static inline int arch_get_random_seed_int(unsigned int *v)
 {
 	unsigned long val;
 	int rc;
@@ -27,22 +36,13 @@ static inline int arch_get_random_int(unsigned int *v)
 
 static inline int arch_has_random(void)
 {
-	return !!ppc_md.get_random_long;
-}
-
-static inline int arch_get_random_seed_long(unsigned long *v)
-{
-	return 0;
-}
-static inline int arch_get_random_seed_int(unsigned int *v)
-{
 	return 0;
 }
+
 static inline int arch_has_random_seed(void)
 {
-	return 0;
+	return !!ppc_md.get_random_long;
 }
-
 #endif /* CONFIG_ARCH_RANDOM */
 
 #ifdef CONFIG_PPC_POWERNV
Signature · 1 line
2.1.4
#1 lore raw
Quoted 6 lines · Paul Mackerras

The hardware RNG on POWER8 and POWER7+ can be relatively slow, since it can only supply one 64-bit value per microsecond. Currently we read it in arch_get_random_long(), but that slows down reading from /dev/urandom since the code in random.c calls arch_get_random_long() for every longword read from /dev/urandom.

Quoted 7 lines

Since the hardware RNG supplies high-quality entropy on every read, it matches the semantics of arch_get_random_seed_long() better than those of arch_get_random_long(). Therefore this commit makes the code use the hardware RNG only for arch_get_random_seed_{long,int} and not for arch_get_random_{long,int}.

Yep seems sensible.

Can you resend and CC some of the random folks, just in case they care.

eg: [email protected], [email protected], [email protected].

cheers