Skip to content

Commit

Permalink
powerpc: Use hardware RNG for arch_get_random_seed_* not arch_get_ran…
Browse files Browse the repository at this point in the history
…dom_*

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 POWER8/7+ hardware RNG only for arch_get_random_seed_{long,int}
and not for arch_get_random_{long,int}.

This won't affect any other PowerPC-based platforms because none of
them currently support a hardware RNG.  To make it clear that the
ppc_md function pointer is used for arch_get_random_seed_*, we rename
it from get_random_long to get_random_seed.

Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
  • Loading branch information
Paul Mackerras authored and Michael Ellerman committed Jul 23, 2015
1 parent 1c2cb59 commit 01c9348
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
28 changes: 14 additions & 14 deletions arch/powerpc/include/asm/archrandom.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,22 @@

static inline int arch_get_random_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)
{
return 0;
}

static inline int arch_get_random_seed_long(unsigned long *v)
{
if (ppc_md.get_random_seed)
return ppc_md.get_random_seed(v);

return 0;
}
static inline int arch_get_random_seed_int(unsigned int *v)
{
unsigned long val;
int rc;
Expand All @@ -26,23 +35,14 @@ 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_seed;
}

#endif /* CONFIG_ARCH_RANDOM */

#ifdef CONFIG_PPC_POWERNV
Expand Down
2 changes: 1 addition & 1 deletion arch/powerpc/include/asm/machdep.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ struct machdep_calls {
#endif

#ifdef CONFIG_ARCH_RANDOM
int (*get_random_long)(unsigned long *v);
int (*get_random_seed)(unsigned long *v);
#endif
};

Expand Down
2 changes: 1 addition & 1 deletion arch/powerpc/platforms/powernv/rng.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ static __init int rng_create(struct device_node *dn)

pr_info_once("Registering arch random hook.\n");

ppc_md.get_random_long = powernv_get_random_long;
ppc_md.get_random_seed = powernv_get_random_long;

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion arch/powerpc/platforms/pseries/rng.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static __init int rng_init(void)

pr_info("Registering arch random hook.\n");

ppc_md.get_random_long = pseries_get_random_long;
ppc_md.get_random_seed = pseries_get_random_long;

return 0;
}
Expand Down

0 comments on commit 01c9348

Please sign in to comment.