Message ID | 20220611100447.5066-2-Jason@zx2c4.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | powerpc: wire up rng during setup_arch | expand |
Le 11/06/2022 à 12:04, Jason A. Donenfeld a écrit : > 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 for each of the three platforms that have an > RNG. This commit also removes some noisy log messages that don't add > much. > > Cc: stable@vger.kernel.org > Cc: Michael Ellerman <mpe@ellerman.id.au> > Cc: Christophe Leroy <christophe.leroy@csgroup.eu> > Fixes: c25769fddaec ("powerpc/microwatt: Add support for hardware random number generator") > Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> > --- > arch/powerpc/platforms/microwatt/rng.c | 9 ++------- > arch/powerpc/platforms/microwatt/setup.c | 8 ++++++++ > 2 files changed, 10 insertions(+), 7 deletions(-) > > diff --git a/arch/powerpc/platforms/microwatt/rng.c b/arch/powerpc/platforms/microwatt/rng.c > index 7bc4d1cbfaf0..d13f656910ad 100644 > --- a/arch/powerpc/platforms/microwatt/rng.c > +++ b/arch/powerpc/platforms/microwatt/rng.c > @@ -29,7 +29,7 @@ static int microwatt_get_random_darn(unsigned long *v) > return 1; > } > > -static __init int rng_init(void) > +__init void microwatt_rng_init(void) > { > unsigned long val; > int i; > @@ -37,12 +37,7 @@ static __init int rng_init(void) > for (i = 0; i < 10; i++) { > if (microwatt_get_random_darn(&val)) { > ppc_md.get_random_seed = microwatt_get_random_darn; > - return 0; > + return; > } > } > - > - pr_warn("Unable to use DARN for get_random_seed()\n"); > - > - return -EIO; > } > -machine_subsys_initcall(, rng_init); > diff --git a/arch/powerpc/platforms/microwatt/setup.c b/arch/powerpc/platforms/microwatt/setup.c > index 0b02603bdb74..23c996dcc870 100644 > --- a/arch/powerpc/platforms/microwatt/setup.c > +++ b/arch/powerpc/platforms/microwatt/setup.c > @@ -32,10 +32,18 @@ static int __init microwatt_populate(void) > } > machine_arch_initcall(microwatt, microwatt_populate); > > +__init void microwatt_rng_init(void); This prototype should be declared in a header file, for instance asm/setup.h checkpatch.pl returns the following warning: WARNING:AVOID_EXTERNS: externs should be avoided in .c files #59: FILE: arch/powerpc/platforms/microwatt/setup.c:35: +__init void microwatt_rng_init(void); And I think the __init keyword usually goes after the type, so should be 'void __init'. > + > +static void __init microwatt_setup_arch(void) > +{ > + microwatt_rng_init(); > +} > + > define_machine(microwatt) { > .name = "microwatt", > .probe = microwatt_probe, > .init_IRQ = microwatt_init_IRQ, > + .setup_arch = microwatt_setup_arch, > .progress = udbg_progress, > .calibrate_decr = generic_calibrate_decr, > };
Hi Christophe, On Sat, Jun 11, 2022 at 4:40 PM Christophe Leroy <christophe.leroy@csgroup.eu> wrote: > > > > +__init void microwatt_rng_init(void); > > This prototype should be declared in a header file, for instance asm/setup.h Alright. > And I think the __init keyword usually goes after the type, so should be > 'void __init'. Indeed I thought so too. It just wasn't like this before, but that doesn't mean I shouldn't fix it. v3 coming right up. Jason
Hi again, On Sat, Jun 11, 2022 at 04:41:58PM +0200, Jason A. Donenfeld wrote: > Hi Christophe, > > On Sat, Jun 11, 2022 at 4:40 PM Christophe Leroy > <christophe.leroy@csgroup.eu> wrote: > > > > > > +__init void microwatt_rng_init(void); > > > > This prototype should be declared in a header file, for instance asm/setup.h > > Alright. Actually, on second thought, I don't think this part is worth doing. These are per-platform functions, not powerpc-wide. Jason
Le 11/06/2022 à 16:46, Jason A. Donenfeld a écrit : > Hi again, > > On Sat, Jun 11, 2022 at 04:41:58PM +0200, Jason A. Donenfeld wrote: >> Hi Christophe, >> >> On Sat, Jun 11, 2022 at 4:40 PM Christophe Leroy >> <christophe.leroy@csgroup.eu> wrote: >>>> >>>> +__init void microwatt_rng_init(void); >>> >>> This prototype should be declared in a header file, for instance asm/setup.h >> >> Alright. > > Actually, on second thought, I don't think this part is worth doing. > These are per-platform functions, not powerpc-wide. > Then you have: arch/powerpc/platforms/powernv/powernv.h arch/powerpc/platforms/pseries/pseries.h and you can add arch/powerpc/platforms/microwatt/microwatt.h
Hi Christophe, On Sat, Jun 11, 2022 at 4:49 PM Christophe Leroy <christophe.leroy@csgroup.eu> wrote: > Then you have: > > arch/powerpc/platforms/powernv/powernv.h > arch/powerpc/platforms/pseries/pseries.h > > and you can add > > arch/powerpc/platforms/microwatt/microwatt.h Oh, terrific, thanks. I'll do that. Jason
diff --git a/arch/powerpc/platforms/microwatt/rng.c b/arch/powerpc/platforms/microwatt/rng.c index 7bc4d1cbfaf0..d13f656910ad 100644 --- a/arch/powerpc/platforms/microwatt/rng.c +++ b/arch/powerpc/platforms/microwatt/rng.c @@ -29,7 +29,7 @@ static int microwatt_get_random_darn(unsigned long *v) return 1; } -static __init int rng_init(void) +__init void microwatt_rng_init(void) { unsigned long val; int i; @@ -37,12 +37,7 @@ static __init int rng_init(void) for (i = 0; i < 10; i++) { if (microwatt_get_random_darn(&val)) { ppc_md.get_random_seed = microwatt_get_random_darn; - return 0; + return; } } - - pr_warn("Unable to use DARN for get_random_seed()\n"); - - return -EIO; } -machine_subsys_initcall(, rng_init); diff --git a/arch/powerpc/platforms/microwatt/setup.c b/arch/powerpc/platforms/microwatt/setup.c index 0b02603bdb74..23c996dcc870 100644 --- a/arch/powerpc/platforms/microwatt/setup.c +++ b/arch/powerpc/platforms/microwatt/setup.c @@ -32,10 +32,18 @@ static int __init microwatt_populate(void) } machine_arch_initcall(microwatt, microwatt_populate); +__init void microwatt_rng_init(void); + +static void __init microwatt_setup_arch(void) +{ + microwatt_rng_init(); +} + define_machine(microwatt) { .name = "microwatt", .probe = microwatt_probe, .init_IRQ = microwatt_init_IRQ, + .setup_arch = microwatt_setup_arch, .progress = udbg_progress, .calibrate_decr = generic_calibrate_decr, };
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 for each of the three platforms that have an RNG. This commit also removes some noisy log messages that don't add much. Cc: stable@vger.kernel.org Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Christophe Leroy <christophe.leroy@csgroup.eu> Fixes: c25769fddaec ("powerpc/microwatt: Add support for hardware random number generator") Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- arch/powerpc/platforms/microwatt/rng.c | 9 ++------- arch/powerpc/platforms/microwatt/setup.c | 8 ++++++++ 2 files changed, 10 insertions(+), 7 deletions(-)