s390/archrandom: Reconsider s390 arch random implementation
authorHarald Freudenberger <freude@linux.vnet.ibm.com>
Fri, 27 Oct 2017 13:53:49 +0000 (15:53 +0200)
committerHeiko Carstens <heiko.carstens@de.ibm.com>
Wed, 8 Nov 2017 08:47:51 +0000 (09:47 +0100)
The reworked version of the random device driver now calls
the arch_get_random_* functions on a very high frequency.
It does about 100.000 calls to arch_get_random_long for
providing 10 MB via /dev/urandom. Each invocation was
fetching entropy from the hardware random generator which
has a rate limit of about 4 MB/s. As the trng invocation
waits until enough entropy is gathered, the random device
driver is slowed down dramatically.

The s390 true random generator is not designed for such
a high rate. The TRNG is more designed to be used together
with the arch_get_random_seed_* functions. This is similar
to the way how powerpc has implemented their arch random
functionality.

This patch removes the invocations of the s390 TRNG for
arch_get_random_long() and arch_get_random_int() but leaving
the invocations for arch_get_random_seed_long() and
arch_get_random_seed_int(). So the s390 arch random
implementation now contributes high quality entropy to
the kernel random device for reseeding.

Signed-off-by: Harald Freudenberger <freude@linux.vnet.ibm.com>
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
arch/s390/include/asm/archrandom.h

index 6033901a40b2366da9b7b05bea41f118506dd4e5..9695f8d09edf33fa1320d4b982753a811d790627 100644 (file)
@@ -27,42 +27,42 @@ static void s390_arch_random_generate(u8 *buf, unsigned int nbytes)
 
 static inline bool arch_has_random(void)
 {
-       if (static_branch_likely(&s390_arch_random_available))
-               return true;
        return false;
 }
 
 static inline bool arch_has_random_seed(void)
 {
-       return arch_has_random();
+       if (static_branch_likely(&s390_arch_random_available))
+               return true;
+       return false;
 }
 
 static inline bool arch_get_random_long(unsigned long *v)
 {
-       if (static_branch_likely(&s390_arch_random_available)) {
-               s390_arch_random_generate((u8 *)v, sizeof(*v));
-               return true;
-       }
        return false;
 }
 
 static inline bool arch_get_random_int(unsigned int *v)
 {
-       if (static_branch_likely(&s390_arch_random_available)) {
-               s390_arch_random_generate((u8 *)v, sizeof(*v));
-               return true;
-       }
        return false;
 }
 
 static inline bool arch_get_random_seed_long(unsigned long *v)
 {
-       return arch_get_random_long(v);
+       if (static_branch_likely(&s390_arch_random_available)) {
+               s390_arch_random_generate((u8 *)v, sizeof(*v));
+               return true;
+       }
+       return false;
 }
 
 static inline bool arch_get_random_seed_int(unsigned int *v)
 {
-       return arch_get_random_int(v);
+       if (static_branch_likely(&s390_arch_random_available)) {
+               s390_arch_random_generate((u8 *)v, sizeof(*v));
+               return true;
+       }
+       return false;
 }
 
 #endif /* CONFIG_ARCH_RANDOM */