Commit 7b878d4b48c4e04b936918bb83836a107ba453b3

Authored by H. Peter Anvin
Committed by Theodore Ts'o
1 parent 331c6490c7

random: Add arch_has_random[_seed]()

Add predicate functions for having arch_get_random[_seed]*().  The
only current use is to avoid the loop in arch_random_refill() when
arch_get_random_seed_long() is unavailable.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>

Showing 4 changed files with 23 additions and 0 deletions Side-by-side Diff

arch/powerpc/include/asm/archrandom.h
... ... @@ -25,6 +25,11 @@
25 25 return rc;
26 26 }
27 27  
  28 +static inline int arch_has_random(void)
  29 +{
  30 + return !!ppc_md.get_random_long;
  31 +}
  32 +
28 33 int powernv_get_random_long(unsigned long *v);
29 34  
30 35 static inline int arch_get_random_seed_long(unsigned long *v)
... ... @@ -32,6 +37,10 @@
32 37 return 0;
33 38 }
34 39 static inline int arch_get_random_seed_int(unsigned int *v)
  40 +{
  41 + return 0;
  42 +}
  43 +static inline int arch_has_random_seed(void)
35 44 {
36 45 return 0;
37 46 }
arch/x86/include/asm/archrandom.h
... ... @@ -114,6 +114,9 @@
114 114  
115 115 #endif /* CONFIG_X86_64 */
116 116  
  117 +#define arch_has_random() static_cpu_has(X86_FEATURE_RDRAND)
  118 +#define arch_has_random_seed() static_cpu_has(X86_FEATURE_RDSEED)
  119 +
117 120 #else
118 121  
119 122 static inline int rdrand_long(unsigned long *v)
drivers/char/random.c
... ... @@ -1307,6 +1307,9 @@
1307 1307 unsigned int i;
1308 1308 unsigned long buf[nlongs];
1309 1309  
  1310 + if (!arch_has_random_seed())
  1311 + return 0;
  1312 +
1310 1313 for (i = 0; i < nlongs; i++) {
1311 1314 if (arch_get_random_seed_long(&buf[n]))
1312 1315 n++;
include/linux/random.h
... ... @@ -88,11 +88,19 @@
88 88 {
89 89 return 0;
90 90 }
  91 +static inline int arch_has_random(void)
  92 +{
  93 + return 0;
  94 +}
91 95 static inline int arch_get_random_seed_long(unsigned long *v)
92 96 {
93 97 return 0;
94 98 }
95 99 static inline int arch_get_random_seed_int(unsigned int *v)
  100 +{
  101 + return 0;
  102 +}
  103 +static inline int arch_has_random_seed(void)
96 104 {
97 105 return 0;
98 106 }