Skip to content

Commit

Permalink
powerpc/pseries: wire up rng during setup_arch()
Browse files Browse the repository at this point in the history
commit e561e47 upstream.

The platform's RNG must be available before random_init() in order to be
useful for initial seeding, which in turn means that it needs to be
called from setup_arch(), rather than from an init call. Fortunately,
each platform already has a setup_arch function pointer, which means
it's easy to wire this up. This commit also removes some noisy log
messages that don't add much.

Fixes: a489043 ("powerpc/pseries: Implement arch_get_random_long() based on H_RANDOM")
Cc: stable@vger.kernel.org # v3.13+
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20220611151015.548325-4-Jason@zx2c4.com
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
zx2c4 authored and gregkh committed Jun 29, 2022
1 parent 95d73d5 commit 1cca46c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
2 changes: 2 additions & 0 deletions arch/powerpc/platforms/pseries/pseries.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,6 @@ int dlpar_workqueue_init(void);
void pseries_setup_security_mitigations(void);
void pseries_lpar_read_hblkrm_characteristics(void);

void pseries_rng_init(void);

#endif /* _PSERIES_PSERIES_H */
11 changes: 3 additions & 8 deletions arch/powerpc/platforms/pseries/rng.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <asm/archrandom.h>
#include <asm/machdep.h>
#include <asm/plpar_wrappers.h>
#include "pseries.h"


static int pseries_get_random_long(unsigned long *v)
Expand All @@ -24,19 +25,13 @@ static int pseries_get_random_long(unsigned long *v)
return 0;
}

static __init int rng_init(void)
void __init pseries_rng_init(void)
{
struct device_node *dn;

dn = of_find_compatible_node(NULL, NULL, "ibm,random");
if (!dn)
return -ENODEV;

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

return;
ppc_md.get_random_seed = pseries_get_random_long;

of_node_put(dn);
return 0;
}
machine_subsys_initcall(pseries, rng_init);
2 changes: 2 additions & 0 deletions arch/powerpc/platforms/pseries/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,8 @@ static void __init pSeries_setup_arch(void)

if (swiotlb_force == SWIOTLB_FORCE)
ppc_swiotlb_enable = 1;

pseries_rng_init();
}

static void pseries_panic(char *str)
Expand Down

0 comments on commit 1cca46c

Please sign in to comment.