* [PATCH v3 0/3] powerpc: wire up rng during setup_arch @ 2022-06-11 15:10 ` Jason A. Donenfeld 0 siblings, 0 replies; 26+ messages in thread From: Jason A. Donenfeld @ 2022-06-11 15:10 UTC (permalink / raw) To: linuxppc-dev, linux-kernel, Michael Ellerman Cc: Jason A. Donenfeld, Christophe Leroy 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. This series wires that up properly on the three platforms that currently initialize the RNG from the wrong place. Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Christophe Leroy <christophe.leroy@csgroup.eu> Jason A. Donenfeld (3): powerpc/microwatt: wire up rng during setup_arch powerpc/powernv: wire up rng during setup_arch powerpc/pseries: wire up rng during setup_arch arch/powerpc/platforms/microwatt/microwatt.h | 7 +++++++ arch/powerpc/platforms/microwatt/rng.c | 10 +++------- arch/powerpc/platforms/microwatt/setup.c | 8 ++++++++ arch/powerpc/platforms/powernv/powernv.h | 2 ++ arch/powerpc/platforms/powernv/rng.c | 18 +++++------------- arch/powerpc/platforms/powernv/setup.c | 2 ++ arch/powerpc/platforms/pseries/pseries.h | 2 ++ arch/powerpc/platforms/pseries/rng.c | 11 +++-------- arch/powerpc/platforms/pseries/setup.c | 1 + 9 files changed, 33 insertions(+), 28 deletions(-) create mode 100644 arch/powerpc/platforms/microwatt/microwatt.h -- 2.35.1 ^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v3 0/3] powerpc: wire up rng during setup_arch @ 2022-06-11 15:10 ` Jason A. Donenfeld 0 siblings, 0 replies; 26+ messages in thread From: Jason A. Donenfeld @ 2022-06-11 15:10 UTC (permalink / raw) To: linuxppc-dev, linux-kernel, Michael Ellerman; +Cc: Jason A. Donenfeld 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. This series wires that up properly on the three platforms that currently initialize the RNG from the wrong place. Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Christophe Leroy <christophe.leroy@csgroup.eu> Jason A. Donenfeld (3): powerpc/microwatt: wire up rng during setup_arch powerpc/powernv: wire up rng during setup_arch powerpc/pseries: wire up rng during setup_arch arch/powerpc/platforms/microwatt/microwatt.h | 7 +++++++ arch/powerpc/platforms/microwatt/rng.c | 10 +++------- arch/powerpc/platforms/microwatt/setup.c | 8 ++++++++ arch/powerpc/platforms/powernv/powernv.h | 2 ++ arch/powerpc/platforms/powernv/rng.c | 18 +++++------------- arch/powerpc/platforms/powernv/setup.c | 2 ++ arch/powerpc/platforms/pseries/pseries.h | 2 ++ arch/powerpc/platforms/pseries/rng.c | 11 +++-------- arch/powerpc/platforms/pseries/setup.c | 1 + 9 files changed, 33 insertions(+), 28 deletions(-) create mode 100644 arch/powerpc/platforms/microwatt/microwatt.h -- 2.35.1 ^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v3 1/3] powerpc/microwatt: wire up rng during setup_arch 2022-06-11 15:10 ` Jason A. Donenfeld @ 2022-06-11 15:10 ` Jason A. Donenfeld -1 siblings, 0 replies; 26+ messages in thread From: Jason A. Donenfeld @ 2022-06-11 15:10 UTC (permalink / raw) To: linuxppc-dev, linux-kernel, Michael Ellerman Cc: Jason A. Donenfeld, stable, Christophe Leroy 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. 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/microwatt.h | 7 +++++++ arch/powerpc/platforms/microwatt/rng.c | 10 +++------- arch/powerpc/platforms/microwatt/setup.c | 8 ++++++++ 3 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 arch/powerpc/platforms/microwatt/microwatt.h diff --git a/arch/powerpc/platforms/microwatt/microwatt.h b/arch/powerpc/platforms/microwatt/microwatt.h new file mode 100644 index 000000000000..335417e95e66 --- /dev/null +++ b/arch/powerpc/platforms/microwatt/microwatt.h @@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _MICROWATT_H +#define _MICROWATT_H + +void microwatt_rng_init(void); + +#endif /* _MICROWATT_H */ diff --git a/arch/powerpc/platforms/microwatt/rng.c b/arch/powerpc/platforms/microwatt/rng.c index 7bc4d1cbfaf0..8ece87d005c8 100644 --- a/arch/powerpc/platforms/microwatt/rng.c +++ b/arch/powerpc/platforms/microwatt/rng.c @@ -11,6 +11,7 @@ #include <asm/archrandom.h> #include <asm/cputable.h> #include <asm/machdep.h> +#include "microwatt.h" #define DARN_ERR 0xFFFFFFFFFFFFFFFFul @@ -29,7 +30,7 @@ static int microwatt_get_random_darn(unsigned long *v) return 1; } -static __init int rng_init(void) +void __init microwatt_rng_init(void) { unsigned long val; int i; @@ -37,12 +38,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..6b32539395a4 100644 --- a/arch/powerpc/platforms/microwatt/setup.c +++ b/arch/powerpc/platforms/microwatt/setup.c @@ -16,6 +16,8 @@ #include <asm/xics.h> #include <asm/udbg.h> +#include "microwatt.h" + static void __init microwatt_init_IRQ(void) { xics_init(); @@ -32,10 +34,16 @@ static int __init microwatt_populate(void) } machine_arch_initcall(microwatt, microwatt_populate); +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, }; -- 2.35.1 ^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v3 1/3] powerpc/microwatt: wire up rng during setup_arch @ 2022-06-11 15:10 ` Jason A. Donenfeld 0 siblings, 0 replies; 26+ messages in thread From: Jason A. Donenfeld @ 2022-06-11 15:10 UTC (permalink / raw) To: linuxppc-dev, linux-kernel, Michael Ellerman; +Cc: Jason A. Donenfeld, stable 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. 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/microwatt.h | 7 +++++++ arch/powerpc/platforms/microwatt/rng.c | 10 +++------- arch/powerpc/platforms/microwatt/setup.c | 8 ++++++++ 3 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 arch/powerpc/platforms/microwatt/microwatt.h diff --git a/arch/powerpc/platforms/microwatt/microwatt.h b/arch/powerpc/platforms/microwatt/microwatt.h new file mode 100644 index 000000000000..335417e95e66 --- /dev/null +++ b/arch/powerpc/platforms/microwatt/microwatt.h @@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _MICROWATT_H +#define _MICROWATT_H + +void microwatt_rng_init(void); + +#endif /* _MICROWATT_H */ diff --git a/arch/powerpc/platforms/microwatt/rng.c b/arch/powerpc/platforms/microwatt/rng.c index 7bc4d1cbfaf0..8ece87d005c8 100644 --- a/arch/powerpc/platforms/microwatt/rng.c +++ b/arch/powerpc/platforms/microwatt/rng.c @@ -11,6 +11,7 @@ #include <asm/archrandom.h> #include <asm/cputable.h> #include <asm/machdep.h> +#include "microwatt.h" #define DARN_ERR 0xFFFFFFFFFFFFFFFFul @@ -29,7 +30,7 @@ static int microwatt_get_random_darn(unsigned long *v) return 1; } -static __init int rng_init(void) +void __init microwatt_rng_init(void) { unsigned long val; int i; @@ -37,12 +38,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..6b32539395a4 100644 --- a/arch/powerpc/platforms/microwatt/setup.c +++ b/arch/powerpc/platforms/microwatt/setup.c @@ -16,6 +16,8 @@ #include <asm/xics.h> #include <asm/udbg.h> +#include "microwatt.h" + static void __init microwatt_init_IRQ(void) { xics_init(); @@ -32,10 +34,16 @@ static int __init microwatt_populate(void) } machine_arch_initcall(microwatt, microwatt_populate); +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, }; -- 2.35.1 ^ permalink raw reply related [flat|nested] 26+ messages in thread
* Re: [PATCH v3 1/3] powerpc/microwatt: wire up rng during setup_arch 2022-06-11 15:10 ` Jason A. Donenfeld (?) @ 2022-06-11 16:25 ` Christophe Leroy -1 siblings, 0 replies; 26+ messages in thread From: Christophe Leroy @ 2022-06-11 16:25 UTC (permalink / raw) To: Jason A. Donenfeld, linuxppc-dev, linux-kernel, Michael Ellerman; +Cc: stable Le 11/06/2022 à 17:10, 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. 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> Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu> > --- > arch/powerpc/platforms/microwatt/microwatt.h | 7 +++++++ > arch/powerpc/platforms/microwatt/rng.c | 10 +++------- > arch/powerpc/platforms/microwatt/setup.c | 8 ++++++++ > 3 files changed, 18 insertions(+), 7 deletions(-) > create mode 100644 arch/powerpc/platforms/microwatt/microwatt.h > > diff --git a/arch/powerpc/platforms/microwatt/microwatt.h b/arch/powerpc/platforms/microwatt/microwatt.h > new file mode 100644 > index 000000000000..335417e95e66 > --- /dev/null > +++ b/arch/powerpc/platforms/microwatt/microwatt.h > @@ -0,0 +1,7 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _MICROWATT_H > +#define _MICROWATT_H > + > +void microwatt_rng_init(void); > + > +#endif /* _MICROWATT_H */ > diff --git a/arch/powerpc/platforms/microwatt/rng.c b/arch/powerpc/platforms/microwatt/rng.c > index 7bc4d1cbfaf0..8ece87d005c8 100644 > --- a/arch/powerpc/platforms/microwatt/rng.c > +++ b/arch/powerpc/platforms/microwatt/rng.c > @@ -11,6 +11,7 @@ > #include <asm/archrandom.h> > #include <asm/cputable.h> > #include <asm/machdep.h> > +#include "microwatt.h" > > #define DARN_ERR 0xFFFFFFFFFFFFFFFFul > > @@ -29,7 +30,7 @@ static int microwatt_get_random_darn(unsigned long *v) > return 1; > } > > -static __init int rng_init(void) > +void __init microwatt_rng_init(void) > { > unsigned long val; > int i; > @@ -37,12 +38,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..6b32539395a4 100644 > --- a/arch/powerpc/platforms/microwatt/setup.c > +++ b/arch/powerpc/platforms/microwatt/setup.c > @@ -16,6 +16,8 @@ > #include <asm/xics.h> > #include <asm/udbg.h> > > +#include "microwatt.h" > + > static void __init microwatt_init_IRQ(void) > { > xics_init(); > @@ -32,10 +34,16 @@ static int __init microwatt_populate(void) > } > machine_arch_initcall(microwatt, microwatt_populate); > > +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, > }; ^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v3 2/3] powerpc/powernv: wire up rng during setup_arch 2022-06-11 15:10 ` Jason A. Donenfeld @ 2022-06-11 15:10 ` Jason A. Donenfeld -1 siblings, 0 replies; 26+ messages in thread From: Jason A. Donenfeld @ 2022-06-11 15:10 UTC (permalink / raw) To: linuxppc-dev, linux-kernel, Michael Ellerman Cc: Jason A. Donenfeld, stable, Christophe Leroy 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. Cc: stable@vger.kernel.org Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Christophe Leroy <christophe.leroy@csgroup.eu> Fixes: a4da0d50b2a0 ("powerpc: Implement arch_get_random_long/int() for powernv") Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- arch/powerpc/platforms/powernv/powernv.h | 2 ++ arch/powerpc/platforms/powernv/rng.c | 18 +++++------------- arch/powerpc/platforms/powernv/setup.c | 2 ++ 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/arch/powerpc/platforms/powernv/powernv.h b/arch/powerpc/platforms/powernv/powernv.h index e297bf4abfcb..fd3f5e1eb10b 100644 --- a/arch/powerpc/platforms/powernv/powernv.h +++ b/arch/powerpc/platforms/powernv/powernv.h @@ -42,4 +42,6 @@ ssize_t memcons_copy(struct memcons *mc, char *to, loff_t pos, size_t count); u32 __init memcons_get_size(struct memcons *mc); struct memcons *__init memcons_init(struct device_node *node, const char *mc_prop_name); +void powernv_rng_init(void); + #endif /* _POWERNV_H */ diff --git a/arch/powerpc/platforms/powernv/rng.c b/arch/powerpc/platforms/powernv/rng.c index e3d44b36ae98..c86bf097e407 100644 --- a/arch/powerpc/platforms/powernv/rng.c +++ b/arch/powerpc/platforms/powernv/rng.c @@ -17,6 +17,7 @@ #include <asm/prom.h> #include <asm/machdep.h> #include <asm/smp.h> +#include "powernv.h" #define DARN_ERR 0xFFFFFFFFFFFFFFFFul @@ -84,24 +85,20 @@ static int powernv_get_random_darn(unsigned long *v) return 1; } -static int __init initialise_darn(void) +static void __init initialise_darn(void) { unsigned long val; int i; if (!cpu_has_feature(CPU_FTR_ARCH_300)) - return -ENODEV; + return; for (i = 0; i < 10; i++) { if (powernv_get_random_darn(&val)) { ppc_md.get_random_seed = powernv_get_random_darn; - return 0; + return; } } - - pr_warn("Unable to use DARN for get_random_seed()\n"); - - return -EIO; } int powernv_get_random_long(unsigned long *v) @@ -163,14 +160,12 @@ static __init int rng_create(struct device_node *dn) rng_init_per_cpu(rng, dn); - pr_info_once("Registering arch random hook.\n"); - ppc_md.get_random_seed = powernv_get_random_long; return 0; } -static __init int rng_init(void) +void __init powernv_rng_init(void) { struct device_node *dn; int rc; @@ -188,7 +183,4 @@ static __init int rng_init(void) } initialise_darn(); - - return 0; } -machine_subsys_initcall(powernv, rng_init); diff --git a/arch/powerpc/platforms/powernv/setup.c b/arch/powerpc/platforms/powernv/setup.c index 824c3ad7a0fa..a5fcb6796b22 100644 --- a/arch/powerpc/platforms/powernv/setup.c +++ b/arch/powerpc/platforms/powernv/setup.c @@ -203,6 +203,8 @@ static void __init pnv_setup_arch(void) pnv_check_guarded_cores(); /* XXX PMCS */ + + powernv_rng_init(); } static void __init pnv_init(void) -- 2.35.1 ^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v3 2/3] powerpc/powernv: wire up rng during setup_arch @ 2022-06-11 15:10 ` Jason A. Donenfeld 0 siblings, 0 replies; 26+ messages in thread From: Jason A. Donenfeld @ 2022-06-11 15:10 UTC (permalink / raw) To: linuxppc-dev, linux-kernel, Michael Ellerman; +Cc: Jason A. Donenfeld, stable 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. Cc: stable@vger.kernel.org Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Christophe Leroy <christophe.leroy@csgroup.eu> Fixes: a4da0d50b2a0 ("powerpc: Implement arch_get_random_long/int() for powernv") Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- arch/powerpc/platforms/powernv/powernv.h | 2 ++ arch/powerpc/platforms/powernv/rng.c | 18 +++++------------- arch/powerpc/platforms/powernv/setup.c | 2 ++ 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/arch/powerpc/platforms/powernv/powernv.h b/arch/powerpc/platforms/powernv/powernv.h index e297bf4abfcb..fd3f5e1eb10b 100644 --- a/arch/powerpc/platforms/powernv/powernv.h +++ b/arch/powerpc/platforms/powernv/powernv.h @@ -42,4 +42,6 @@ ssize_t memcons_copy(struct memcons *mc, char *to, loff_t pos, size_t count); u32 __init memcons_get_size(struct memcons *mc); struct memcons *__init memcons_init(struct device_node *node, const char *mc_prop_name); +void powernv_rng_init(void); + #endif /* _POWERNV_H */ diff --git a/arch/powerpc/platforms/powernv/rng.c b/arch/powerpc/platforms/powernv/rng.c index e3d44b36ae98..c86bf097e407 100644 --- a/arch/powerpc/platforms/powernv/rng.c +++ b/arch/powerpc/platforms/powernv/rng.c @@ -17,6 +17,7 @@ #include <asm/prom.h> #include <asm/machdep.h> #include <asm/smp.h> +#include "powernv.h" #define DARN_ERR 0xFFFFFFFFFFFFFFFFul @@ -84,24 +85,20 @@ static int powernv_get_random_darn(unsigned long *v) return 1; } -static int __init initialise_darn(void) +static void __init initialise_darn(void) { unsigned long val; int i; if (!cpu_has_feature(CPU_FTR_ARCH_300)) - return -ENODEV; + return; for (i = 0; i < 10; i++) { if (powernv_get_random_darn(&val)) { ppc_md.get_random_seed = powernv_get_random_darn; - return 0; + return; } } - - pr_warn("Unable to use DARN for get_random_seed()\n"); - - return -EIO; } int powernv_get_random_long(unsigned long *v) @@ -163,14 +160,12 @@ static __init int rng_create(struct device_node *dn) rng_init_per_cpu(rng, dn); - pr_info_once("Registering arch random hook.\n"); - ppc_md.get_random_seed = powernv_get_random_long; return 0; } -static __init int rng_init(void) +void __init powernv_rng_init(void) { struct device_node *dn; int rc; @@ -188,7 +183,4 @@ static __init int rng_init(void) } initialise_darn(); - - return 0; } -machine_subsys_initcall(powernv, rng_init); diff --git a/arch/powerpc/platforms/powernv/setup.c b/arch/powerpc/platforms/powernv/setup.c index 824c3ad7a0fa..a5fcb6796b22 100644 --- a/arch/powerpc/platforms/powernv/setup.c +++ b/arch/powerpc/platforms/powernv/setup.c @@ -203,6 +203,8 @@ static void __init pnv_setup_arch(void) pnv_check_guarded_cores(); /* XXX PMCS */ + + powernv_rng_init(); } static void __init pnv_init(void) -- 2.35.1 ^ permalink raw reply related [flat|nested] 26+ messages in thread
* Re: [PATCH v3 2/3] powerpc/powernv: wire up rng during setup_arch 2022-06-11 15:10 ` Jason A. Donenfeld (?) @ 2022-06-11 16:25 ` Christophe Leroy -1 siblings, 0 replies; 26+ messages in thread From: Christophe Leroy @ 2022-06-11 16:25 UTC (permalink / raw) To: Jason A. Donenfeld, linuxppc-dev, linux-kernel, Michael Ellerman; +Cc: stable Le 11/06/2022 à 17:10, 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. 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: a4da0d50b2a0 ("powerpc: Implement arch_get_random_long/int() for powernv") > Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu> > --- > arch/powerpc/platforms/powernv/powernv.h | 2 ++ > arch/powerpc/platforms/powernv/rng.c | 18 +++++------------- > arch/powerpc/platforms/powernv/setup.c | 2 ++ > 3 files changed, 9 insertions(+), 13 deletions(-) > > diff --git a/arch/powerpc/platforms/powernv/powernv.h b/arch/powerpc/platforms/powernv/powernv.h > index e297bf4abfcb..fd3f5e1eb10b 100644 > --- a/arch/powerpc/platforms/powernv/powernv.h > +++ b/arch/powerpc/platforms/powernv/powernv.h > @@ -42,4 +42,6 @@ ssize_t memcons_copy(struct memcons *mc, char *to, loff_t pos, size_t count); > u32 __init memcons_get_size(struct memcons *mc); > struct memcons *__init memcons_init(struct device_node *node, const char *mc_prop_name); > > +void powernv_rng_init(void); > + > #endif /* _POWERNV_H */ > diff --git a/arch/powerpc/platforms/powernv/rng.c b/arch/powerpc/platforms/powernv/rng.c > index e3d44b36ae98..c86bf097e407 100644 > --- a/arch/powerpc/platforms/powernv/rng.c > +++ b/arch/powerpc/platforms/powernv/rng.c > @@ -17,6 +17,7 @@ > #include <asm/prom.h> > #include <asm/machdep.h> > #include <asm/smp.h> > +#include "powernv.h" > > #define DARN_ERR 0xFFFFFFFFFFFFFFFFul > > @@ -84,24 +85,20 @@ static int powernv_get_random_darn(unsigned long *v) > return 1; > } > > -static int __init initialise_darn(void) > +static void __init initialise_darn(void) > { > unsigned long val; > int i; > > if (!cpu_has_feature(CPU_FTR_ARCH_300)) > - return -ENODEV; > + return; > > for (i = 0; i < 10; i++) { > if (powernv_get_random_darn(&val)) { > ppc_md.get_random_seed = powernv_get_random_darn; > - return 0; > + return; > } > } > - > - pr_warn("Unable to use DARN for get_random_seed()\n"); > - > - return -EIO; > } > > int powernv_get_random_long(unsigned long *v) > @@ -163,14 +160,12 @@ static __init int rng_create(struct device_node *dn) > > rng_init_per_cpu(rng, dn); > > - pr_info_once("Registering arch random hook.\n"); > - > ppc_md.get_random_seed = powernv_get_random_long; > > return 0; > } > > -static __init int rng_init(void) > +void __init powernv_rng_init(void) > { > struct device_node *dn; > int rc; > @@ -188,7 +183,4 @@ static __init int rng_init(void) > } > > initialise_darn(); > - > - return 0; > } > -machine_subsys_initcall(powernv, rng_init); > diff --git a/arch/powerpc/platforms/powernv/setup.c b/arch/powerpc/platforms/powernv/setup.c > index 824c3ad7a0fa..a5fcb6796b22 100644 > --- a/arch/powerpc/platforms/powernv/setup.c > +++ b/arch/powerpc/platforms/powernv/setup.c > @@ -203,6 +203,8 @@ static void __init pnv_setup_arch(void) > pnv_check_guarded_cores(); > > /* XXX PMCS */ > + > + powernv_rng_init(); > } > > static void __init pnv_init(void) ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v3 2/3] powerpc/powernv: wire up rng during setup_arch 2022-06-11 15:10 ` Jason A. Donenfeld @ 2022-06-19 11:49 ` Michael Ellerman -1 siblings, 0 replies; 26+ messages in thread From: Michael Ellerman @ 2022-06-19 11:49 UTC (permalink / raw) To: Jason A. Donenfeld, linuxppc-dev, linux-kernel Cc: Jason A. Donenfeld, stable, Christophe Leroy "Jason A. Donenfeld" <Jason@zx2c4.com> writes: > 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. > > Cc: stable@vger.kernel.org > Cc: Michael Ellerman <mpe@ellerman.id.au> > Cc: Christophe Leroy <christophe.leroy@csgroup.eu> > Fixes: a4da0d50b2a0 ("powerpc: Implement arch_get_random_long/int() for powernv") > Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> > --- > arch/powerpc/platforms/powernv/powernv.h | 2 ++ > arch/powerpc/platforms/powernv/rng.c | 18 +++++------------- > arch/powerpc/platforms/powernv/setup.c | 2 ++ > 3 files changed, 9 insertions(+), 13 deletions(-) > ... > diff --git a/arch/powerpc/platforms/powernv/setup.c b/arch/powerpc/platforms/powernv/setup.c > index 824c3ad7a0fa..a5fcb6796b22 100644 > --- a/arch/powerpc/platforms/powernv/setup.c > +++ b/arch/powerpc/platforms/powernv/setup.c > @@ -203,6 +203,8 @@ static void __init pnv_setup_arch(void) > pnv_check_guarded_cores(); > > /* XXX PMCS */ > + > + powernv_rng_init(); > } This crashes on power8 because it's too early to call kzalloc() in rng_create(), and it's also too early to setup the percpu variables in there. I'll rework it and post a v4. cheers ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v3 2/3] powerpc/powernv: wire up rng during setup_arch @ 2022-06-19 11:49 ` Michael Ellerman 0 siblings, 0 replies; 26+ messages in thread From: Michael Ellerman @ 2022-06-19 11:49 UTC (permalink / raw) To: Jason A. Donenfeld, linuxppc-dev, linux-kernel; +Cc: Jason A. Donenfeld, stable "Jason A. Donenfeld" <Jason@zx2c4.com> writes: > 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. > > Cc: stable@vger.kernel.org > Cc: Michael Ellerman <mpe@ellerman.id.au> > Cc: Christophe Leroy <christophe.leroy@csgroup.eu> > Fixes: a4da0d50b2a0 ("powerpc: Implement arch_get_random_long/int() for powernv") > Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> > --- > arch/powerpc/platforms/powernv/powernv.h | 2 ++ > arch/powerpc/platforms/powernv/rng.c | 18 +++++------------- > arch/powerpc/platforms/powernv/setup.c | 2 ++ > 3 files changed, 9 insertions(+), 13 deletions(-) > ... > diff --git a/arch/powerpc/platforms/powernv/setup.c b/arch/powerpc/platforms/powernv/setup.c > index 824c3ad7a0fa..a5fcb6796b22 100644 > --- a/arch/powerpc/platforms/powernv/setup.c > +++ b/arch/powerpc/platforms/powernv/setup.c > @@ -203,6 +203,8 @@ static void __init pnv_setup_arch(void) > pnv_check_guarded_cores(); > > /* XXX PMCS */ > + > + powernv_rng_init(); > } This crashes on power8 because it's too early to call kzalloc() in rng_create(), and it's also too early to setup the percpu variables in there. I'll rework it and post a v4. cheers ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v3 2/3] powerpc/powernv: wire up rng during setup_arch 2022-06-19 11:49 ` Michael Ellerman @ 2022-06-19 20:32 ` Jason A. Donenfeld -1 siblings, 0 replies; 26+ messages in thread From: Jason A. Donenfeld @ 2022-06-19 20:32 UTC (permalink / raw) To: Michael Ellerman; +Cc: linuxppc-dev, LKML, stable, Christophe Leroy Hi Michael, On Sun, Jun 19, 2022 at 1:49 PM Michael Ellerman <mpe@ellerman.id.au> wrote: > This crashes on power8 because it's too early to call kzalloc() in > rng_create(), and it's also too early to setup the percpu variables in > there. > > I'll rework it and post a v4. Oh, darn. Sorry about that. Thanks for reworking it. Jason ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v3 2/3] powerpc/powernv: wire up rng during setup_arch @ 2022-06-19 20:32 ` Jason A. Donenfeld 0 siblings, 0 replies; 26+ messages in thread From: Jason A. Donenfeld @ 2022-06-19 20:32 UTC (permalink / raw) To: Michael Ellerman; +Cc: linuxppc-dev, LKML, stable Hi Michael, On Sun, Jun 19, 2022 at 1:49 PM Michael Ellerman <mpe@ellerman.id.au> wrote: > This crashes on power8 because it's too early to call kzalloc() in > rng_create(), and it's also too early to setup the percpu variables in > there. > > I'll rework it and post a v4. Oh, darn. Sorry about that. Thanks for reworking it. Jason ^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v4] powerpc/powernv: wire up rng during setup_arch 2022-06-19 20:32 ` Jason A. Donenfeld (?) @ 2022-06-20 12:45 ` Jason A. Donenfeld 2022-06-21 14:08 ` [PATCH v5] " Jason A. Donenfeld -1 siblings, 1 reply; 26+ messages in thread From: Jason A. Donenfeld @ 2022-06-20 12:45 UTC (permalink / raw) To: Michael Ellerman, linuxppc-dev, LKML, stable, Christophe Leroy Cc: Jason A. Donenfeld 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 we can wire it up that way. Complicating things, however, is that POWER8 systems need some per-cpu state and kmalloc, which isn't available at this stage. So we split things into an early phase and a late phase, with the early phase working well enough to seed the RNG with a spinlock, before later getting fast per-cpu allocations. 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> Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu> Fixes: a4da0d50b2a0 ("powerpc: Implement arch_get_random_long/int() for powernv") Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- arch/powerpc/platforms/powernv/powernv.h | 2 + arch/powerpc/platforms/powernv/rng.c | 68 ++++++++++++++++++------ arch/powerpc/platforms/powernv/setup.c | 2 + 3 files changed, 55 insertions(+), 17 deletions(-) diff --git a/arch/powerpc/platforms/powernv/powernv.h b/arch/powerpc/platforms/powernv/powernv.h index e297bf4abfcb..fd3f5e1eb10b 100644 --- a/arch/powerpc/platforms/powernv/powernv.h +++ b/arch/powerpc/platforms/powernv/powernv.h @@ -42,4 +42,6 @@ ssize_t memcons_copy(struct memcons *mc, char *to, loff_t pos, size_t count); u32 __init memcons_get_size(struct memcons *mc); struct memcons *__init memcons_init(struct device_node *node, const char *mc_prop_name); +void powernv_rng_init(void); + #endif /* _POWERNV_H */ diff --git a/arch/powerpc/platforms/powernv/rng.c b/arch/powerpc/platforms/powernv/rng.c index e3d44b36ae98..c1beced9c32c 100644 --- a/arch/powerpc/platforms/powernv/rng.c +++ b/arch/powerpc/platforms/powernv/rng.c @@ -17,6 +17,7 @@ #include <asm/prom.h> #include <asm/machdep.h> #include <asm/smp.h> +#include "powernv.h" #define DARN_ERR 0xFFFFFFFFFFFFFFFFul @@ -28,6 +29,12 @@ struct powernv_rng { static DEFINE_PER_CPU(struct powernv_rng *, powernv_rng); +static struct { + struct powernv_rng rng; + spinlock_t lock; +} early_state __initdata = { + .lock = __SPIN_LOCK_UNLOCKED(powernv_early_rng) +}; int powernv_hwrng_present(void) { @@ -84,7 +91,7 @@ static int powernv_get_random_darn(unsigned long *v) return 1; } -static int __init initialise_darn(void) +static int __init initialize_darn(void) { unsigned long val; int i; @@ -98,10 +105,18 @@ static int __init initialise_darn(void) return 0; } } + return -EIO; +} - pr_warn("Unable to use DARN for get_random_seed()\n"); +static int __init powernv_get_random_long_early(unsigned long *v) +{ + unsigned long flags; - return -EIO; + spin_lock_irqsave(&early_state.lock, flags); + *v = rng_whiten(&early_state.rng, in_be64(early_state.rng.regs)); + spin_unlock_irqrestore(&early_state.lock, flags); + + return 1; } int powernv_get_random_long(unsigned long *v) @@ -163,32 +178,51 @@ static __init int rng_create(struct device_node *dn) rng_init_per_cpu(rng, dn); - pr_info_once("Registering arch random hook.\n"); - ppc_md.get_random_seed = powernv_get_random_long; return 0; } -static __init int rng_init(void) +void __init powernv_rng_init(void) +{ + struct device_node *dn; + struct resource res; + + /* Prefer darn over the rest. */ + if (!initialize_darn()) + return; + + dn = of_find_compatible_node(NULL, NULL, "ibm,power-rng"); + if (!dn) + return; + if (of_address_to_resource(dn, 0, &res)) + return; + early_state.rng.regs_real = (void __iomem *)res.start; + early_state.rng.regs = of_iomap(dn, 0); + if (!early_state.rng.regs) + return; + early_state.rng.mask = in_be64(early_state.rng.regs); + ppc_md.get_random_seed = powernv_get_random_long_early; +} + +static __init int powernv_rng_late_init(void) { struct device_node *dn; - int rc; + + /* + * If this didn't get initialized early on, then we're using darn, + * or this isn't available at all, so return early. + */ + if (ppc_md.get_random_seed != powernv_get_random_long_early) + return 0; + ppc_md.get_random_seed = NULL; for_each_compatible_node(dn, NULL, "ibm,power-rng") { - rc = rng_create(dn); - if (rc) { - pr_err("Failed creating rng for %pOF (%d).\n", - dn, rc); + if (rng_create(dn)) continue; - } - /* Create devices for hwrng driver */ of_platform_device_create(dn, NULL, NULL); } - - initialise_darn(); - return 0; } -machine_subsys_initcall(powernv, rng_init); +machine_subsys_initcall(powernv, powernv_rng_late_init); diff --git a/arch/powerpc/platforms/powernv/setup.c b/arch/powerpc/platforms/powernv/setup.c index 824c3ad7a0fa..a5fcb6796b22 100644 --- a/arch/powerpc/platforms/powernv/setup.c +++ b/arch/powerpc/platforms/powernv/setup.c @@ -203,6 +203,8 @@ static void __init pnv_setup_arch(void) pnv_check_guarded_cores(); /* XXX PMCS */ + + powernv_rng_init(); } static void __init pnv_init(void) -- 2.35.1 ^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v5] powerpc/powernv: wire up rng during setup_arch 2022-06-20 12:45 ` [PATCH v4] " Jason A. Donenfeld @ 2022-06-21 14:08 ` Jason A. Donenfeld 2022-06-21 18:33 ` Christophe Leroy 2022-06-26 0:28 ` Michael Ellerman 0 siblings, 2 replies; 26+ messages in thread From: Jason A. Donenfeld @ 2022-06-21 14:08 UTC (permalink / raw) To: Michael Ellerman, linuxppc-dev, LKML, stable, Christophe Leroy Cc: Jason A. Donenfeld 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 we can wire it up that way. Complicating things, however, is that POWER8 systems need some per-cpu state and kmalloc, which isn't available at this stage. So we split things up into an early phase and a later opportunistic phase. 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> Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu> Fixes: a4da0d50b2a0 ("powerpc: Implement arch_get_random_long/int() for powernv") Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- arch/powerpc/platforms/powernv/powernv.h | 2 + arch/powerpc/platforms/powernv/rng.c | 47 ++++++++++++++++-------- arch/powerpc/platforms/powernv/setup.c | 2 + 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/arch/powerpc/platforms/powernv/powernv.h b/arch/powerpc/platforms/powernv/powernv.h index e297bf4abfcb..fd3f5e1eb10b 100644 --- a/arch/powerpc/platforms/powernv/powernv.h +++ b/arch/powerpc/platforms/powernv/powernv.h @@ -42,4 +42,6 @@ ssize_t memcons_copy(struct memcons *mc, char *to, loff_t pos, size_t count); u32 __init memcons_get_size(struct memcons *mc); struct memcons *__init memcons_init(struct device_node *node, const char *mc_prop_name); +void powernv_rng_init(void); + #endif /* _POWERNV_H */ diff --git a/arch/powerpc/platforms/powernv/rng.c b/arch/powerpc/platforms/powernv/rng.c index e3d44b36ae98..e332e72e1857 100644 --- a/arch/powerpc/platforms/powernv/rng.c +++ b/arch/powerpc/platforms/powernv/rng.c @@ -17,6 +17,7 @@ #include <asm/prom.h> #include <asm/machdep.h> #include <asm/smp.h> +#include "powernv.h" #define DARN_ERR 0xFFFFFFFFFFFFFFFFul @@ -28,7 +29,6 @@ struct powernv_rng { static DEFINE_PER_CPU(struct powernv_rng *, powernv_rng); - int powernv_hwrng_present(void) { struct powernv_rng *rng; @@ -98,9 +98,6 @@ static int __init initialise_darn(void) return 0; } } - - pr_warn("Unable to use DARN for get_random_seed()\n"); - return -EIO; } @@ -163,32 +160,50 @@ static __init int rng_create(struct device_node *dn) rng_init_per_cpu(rng, dn); - pr_info_once("Registering arch random hook.\n"); - ppc_md.get_random_seed = powernv_get_random_long; return 0; } -static __init int rng_init(void) +static int __init powernv_get_random_long_early(unsigned long *v) { struct device_node *dn; - int rc; + + if (!slab_is_available()) + return 0; + + if (cmpxchg(&ppc_md.get_random_seed, powernv_get_random_long_early, + NULL) != powernv_get_random_long_early) + return 0; for_each_compatible_node(dn, NULL, "ibm,power-rng") { - rc = rng_create(dn); - if (rc) { - pr_err("Failed creating rng for %pOF (%d).\n", - dn, rc); + if (rng_create(dn)) continue; - } - /* Create devices for hwrng driver */ of_platform_device_create(dn, NULL, NULL); } - initialise_darn(); + if (!ppc_md.get_random_seed) + return 0; + return ppc_md.get_random_seed(v); +} + +void __init powernv_rng_init(void) +{ + /* Prefer darn over the rest. */ + if (!initialise_darn()) + return; + + if (of_find_compatible_node(NULL, NULL, "ibm,power-rng")) + ppc_md.get_random_seed = powernv_get_random_long_early; +} +static int __init powernv_rng_late_init(void) +{ + unsigned long v; + /* In case it wasn't called during init for some other reason. */ + if (ppc_md.get_random_seed == powernv_get_random_long_early) + powernv_get_random_long_early(&v); return 0; } -machine_subsys_initcall(powernv, rng_init); +machine_subsys_initcall(powernv, powernv_rng_late_init); diff --git a/arch/powerpc/platforms/powernv/setup.c b/arch/powerpc/platforms/powernv/setup.c index 824c3ad7a0fa..a5fcb6796b22 100644 --- a/arch/powerpc/platforms/powernv/setup.c +++ b/arch/powerpc/platforms/powernv/setup.c @@ -203,6 +203,8 @@ static void __init pnv_setup_arch(void) pnv_check_guarded_cores(); /* XXX PMCS */ + + powernv_rng_init(); } static void __init pnv_init(void) -- 2.35.1 ^ permalink raw reply related [flat|nested] 26+ messages in thread
* Re: [PATCH v5] powerpc/powernv: wire up rng during setup_arch 2022-06-21 14:08 ` [PATCH v5] " Jason A. Donenfeld @ 2022-06-21 18:33 ` Christophe Leroy 2022-06-21 18:47 ` Jason A. Donenfeld 2022-06-26 0:28 ` Michael Ellerman 1 sibling, 1 reply; 26+ messages in thread From: Christophe Leroy @ 2022-06-21 18:33 UTC (permalink / raw) To: Jason A. Donenfeld, Michael Ellerman, linuxppc-dev, LKML, stable Le 21/06/2022 à 16:08, 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 we > can wire it up that way. Complicating things, however, is that POWER8 > systems need some per-cpu state and kmalloc, which isn't available at > this stage. So we split things up into an early phase and a later > opportunistic phase. This commit also removes some noisy log messages > that don't add much. Regarding the kmalloc(), I have not looked at it in details, but usually you can use memblock_alloc() when kmalloc is not available yet. Christophe ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v5] powerpc/powernv: wire up rng during setup_arch 2022-06-21 18:33 ` Christophe Leroy @ 2022-06-21 18:47 ` Jason A. Donenfeld 0 siblings, 0 replies; 26+ messages in thread From: Jason A. Donenfeld @ 2022-06-21 18:47 UTC (permalink / raw) To: Christophe Leroy; +Cc: Michael Ellerman, linuxppc-dev, LKML, stable Hi Christophe, On Tue, Jun 21, 2022 at 06:33:11PM +0000, Christophe Leroy wrote: > Le 21/06/2022 à 16:08, 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 we > > can wire it up that way. Complicating things, however, is that POWER8 > > systems need some per-cpu state and kmalloc, which isn't available at > > this stage. So we split things up into an early phase and a later > > opportunistic phase. This commit also removes some noisy log messages > > that don't add much. > > Regarding the kmalloc(), I have not looked at it in details, but usually > you can use memblock_alloc() when kmalloc is not available yet. That seems a bit excessive, especially as those allocations are long lived. And we don't even *need* it that early, but just before random_init(). Michael is running this v5 on the test rig overnight, so we'll learn in the Australian morning whether this finally did the trick (I hope). Jason ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v5] powerpc/powernv: wire up rng during setup_arch @ 2022-06-21 18:47 ` Jason A. Donenfeld 0 siblings, 0 replies; 26+ messages in thread From: Jason A. Donenfeld @ 2022-06-21 18:47 UTC (permalink / raw) To: Christophe Leroy; +Cc: linuxppc-dev, LKML, stable Hi Christophe, On Tue, Jun 21, 2022 at 06:33:11PM +0000, Christophe Leroy wrote: > Le 21/06/2022 à 16:08, 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 we > > can wire it up that way. Complicating things, however, is that POWER8 > > systems need some per-cpu state and kmalloc, which isn't available at > > this stage. So we split things up into an early phase and a later > > opportunistic phase. This commit also removes some noisy log messages > > that don't add much. > > Regarding the kmalloc(), I have not looked at it in details, but usually > you can use memblock_alloc() when kmalloc is not available yet. That seems a bit excessive, especially as those allocations are long lived. And we don't even *need* it that early, but just before random_init(). Michael is running this v5 on the test rig overnight, so we'll learn in the Australian morning whether this finally did the trick (I hope). Jason ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v5] powerpc/powernv: wire up rng during setup_arch 2022-06-21 18:47 ` Jason A. Donenfeld @ 2022-06-21 19:22 ` Christophe Leroy -1 siblings, 0 replies; 26+ messages in thread From: Christophe Leroy @ 2022-06-21 19:22 UTC (permalink / raw) To: Jason A. Donenfeld; +Cc: Michael Ellerman, linuxppc-dev, LKML, stable Le 21/06/2022 à 20:47, Jason A. Donenfeld a écrit : > Hi Christophe, > > On Tue, Jun 21, 2022 at 06:33:11PM +0000, Christophe Leroy wrote: >> Le 21/06/2022 à 16:08, 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 we >>> can wire it up that way. Complicating things, however, is that POWER8 >>> systems need some per-cpu state and kmalloc, which isn't available at >>> this stage. So we split things up into an early phase and a later >>> opportunistic phase. This commit also removes some noisy log messages >>> that don't add much. >> >> Regarding the kmalloc(), I have not looked at it in details, but usually >> you can use memblock_alloc() when kmalloc is not available yet. > > That seems a bit excessive, especially as those allocations are long > lived. And we don't even *need* it that early, but just before > random_init(). Michael is running this v5 on the test rig overnight, so > we'll learn in the Australian morning whether this finally did the trick > (I hope). > The fact that they are long lived make them a good candidate for memblock_alloc(). But fair enough, if they are not required that early then just do it later. Christophe ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v5] powerpc/powernv: wire up rng during setup_arch @ 2022-06-21 19:22 ` Christophe Leroy 0 siblings, 0 replies; 26+ messages in thread From: Christophe Leroy @ 2022-06-21 19:22 UTC (permalink / raw) To: Jason A. Donenfeld; +Cc: linuxppc-dev, LKML, stable Le 21/06/2022 à 20:47, Jason A. Donenfeld a écrit : > Hi Christophe, > > On Tue, Jun 21, 2022 at 06:33:11PM +0000, Christophe Leroy wrote: >> Le 21/06/2022 à 16:08, 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 we >>> can wire it up that way. Complicating things, however, is that POWER8 >>> systems need some per-cpu state and kmalloc, which isn't available at >>> this stage. So we split things up into an early phase and a later >>> opportunistic phase. This commit also removes some noisy log messages >>> that don't add much. >> >> Regarding the kmalloc(), I have not looked at it in details, but usually >> you can use memblock_alloc() when kmalloc is not available yet. > > That seems a bit excessive, especially as those allocations are long > lived. And we don't even *need* it that early, but just before > random_init(). Michael is running this v5 on the test rig overnight, so > we'll learn in the Australian morning whether this finally did the trick > (I hope). > The fact that they are long lived make them a good candidate for memblock_alloc(). But fair enough, if they are not required that early then just do it later. Christophe ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v5] powerpc/powernv: wire up rng during setup_arch 2022-06-21 19:22 ` Christophe Leroy (?) @ 2022-06-22 2:27 ` Michael Ellerman -1 siblings, 0 replies; 26+ messages in thread From: Michael Ellerman @ 2022-06-22 2:27 UTC (permalink / raw) To: Christophe Leroy, Jason A. Donenfeld; +Cc: linuxppc-dev, LKML, stable Christophe Leroy <christophe.leroy@csgroup.eu> writes: > Le 21/06/2022 à 20:47, Jason A. Donenfeld a écrit : >> On Tue, Jun 21, 2022 at 06:33:11PM +0000, Christophe Leroy wrote: >>> Le 21/06/2022 à 16:08, 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 we >>>> can wire it up that way. Complicating things, however, is that POWER8 >>>> systems need some per-cpu state and kmalloc, which isn't available at >>>> this stage. So we split things up into an early phase and a later >>>> opportunistic phase. This commit also removes some noisy log messages >>>> that don't add much. >>> >>> Regarding the kmalloc(), I have not looked at it in details, but usually >>> you can use memblock_alloc() when kmalloc is not available yet. >> >> That seems a bit excessive, especially as those allocations are long >> lived. And we don't even *need* it that early, but just before >> random_init(). Michael is running this v5 on the test rig overnight, so >> we'll learn in the Australian morning whether this finally did the trick >> (I hope). > > The fact that they are long lived make them a good candidate for > memblock_alloc(). > > But fair enough, if they are not required that early then just do it later. memblock works but then we trip on ioremap vs early_ioremap. Fixing that is a bit of a pain as we'd have to stop using of_iomap() and we'd also need to switch the mappings to ioremap() later in boot. We'd also have to defer the percpu initialisation. So it's all just a bit of a pain when we actually only need to get the hook ready before random_init() which is called much later in boot when slab/ioremap/percpu are all ready. cheers ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v5] powerpc/powernv: wire up rng during setup_arch 2022-06-21 14:08 ` [PATCH v5] " Jason A. Donenfeld 2022-06-21 18:33 ` Christophe Leroy @ 2022-06-26 0:28 ` Michael Ellerman 1 sibling, 0 replies; 26+ messages in thread From: Michael Ellerman @ 2022-06-26 0:28 UTC (permalink / raw) To: Christophe Leroy, stable, Jason A. Donenfeld, linuxppc-dev, Michael Ellerman, LKML On Tue, 21 Jun 2022 16:08:49 +0200, Jason A. Donenfeld wrote: > 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 we > can wire it up that way. Complicating things, however, is that POWER8 > systems need some per-cpu state and kmalloc, which isn't available at > this stage. So we split things up into an early phase and a later > opportunistic phase. This commit also removes some noisy log messages > that don't add much. > > [...] Applied to powerpc/fixes. [1/1] powerpc/powernv: wire up rng during setup_arch https://git.kernel.org/powerpc/c/f3eac426657d985b97c92fa5f7ae1d43f04721f3 cheers ^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v3 3/3] powerpc/pseries: wire up rng during setup_arch 2022-06-11 15:10 ` Jason A. Donenfeld @ 2022-06-11 15:10 ` Jason A. Donenfeld -1 siblings, 0 replies; 26+ messages in thread From: Jason A. Donenfeld @ 2022-06-11 15:10 UTC (permalink / raw) To: linuxppc-dev, linux-kernel, Michael Ellerman Cc: Jason A. Donenfeld, stable, Christophe Leroy 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. Cc: stable@vger.kernel.org Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Christophe Leroy <christophe.leroy@csgroup.eu> Fixes: a489043f4626 ("powerpc/pseries: Implement arch_get_random_long() based on H_RANDOM") Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- arch/powerpc/platforms/pseries/pseries.h | 2 ++ arch/powerpc/platforms/pseries/rng.c | 11 +++-------- arch/powerpc/platforms/pseries/setup.c | 1 + 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/arch/powerpc/platforms/pseries/pseries.h b/arch/powerpc/platforms/pseries/pseries.h index f5c916c839c9..1d75b7742ef0 100644 --- a/arch/powerpc/platforms/pseries/pseries.h +++ b/arch/powerpc/platforms/pseries/pseries.h @@ -122,4 +122,6 @@ void pseries_lpar_read_hblkrm_characteristics(void); static inline void pseries_lpar_read_hblkrm_characteristics(void) { } #endif +void pseries_rng_init(void); + #endif /* _PSERIES_PSERIES_H */ diff --git a/arch/powerpc/platforms/pseries/rng.c b/arch/powerpc/platforms/pseries/rng.c index 6268545947b8..6ddfdeaace9e 100644 --- a/arch/powerpc/platforms/pseries/rng.c +++ b/arch/powerpc/platforms/pseries/rng.c @@ -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) @@ -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); diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c index afb074269b42..ee4f1db49515 100644 --- a/arch/powerpc/platforms/pseries/setup.c +++ b/arch/powerpc/platforms/pseries/setup.c @@ -839,6 +839,7 @@ static void __init pSeries_setup_arch(void) } ppc_md.pcibios_root_bridge_prepare = pseries_root_bridge_prepare; + pseries_rng_init(); } static void pseries_panic(char *str) -- 2.35.1 ^ permalink raw reply related [flat|nested] 26+ messages in thread
* [PATCH v3 3/3] powerpc/pseries: wire up rng during setup_arch @ 2022-06-11 15:10 ` Jason A. Donenfeld 0 siblings, 0 replies; 26+ messages in thread From: Jason A. Donenfeld @ 2022-06-11 15:10 UTC (permalink / raw) To: linuxppc-dev, linux-kernel, Michael Ellerman; +Cc: Jason A. Donenfeld, stable 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. Cc: stable@vger.kernel.org Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Christophe Leroy <christophe.leroy@csgroup.eu> Fixes: a489043f4626 ("powerpc/pseries: Implement arch_get_random_long() based on H_RANDOM") Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> --- arch/powerpc/platforms/pseries/pseries.h | 2 ++ arch/powerpc/platforms/pseries/rng.c | 11 +++-------- arch/powerpc/platforms/pseries/setup.c | 1 + 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/arch/powerpc/platforms/pseries/pseries.h b/arch/powerpc/platforms/pseries/pseries.h index f5c916c839c9..1d75b7742ef0 100644 --- a/arch/powerpc/platforms/pseries/pseries.h +++ b/arch/powerpc/platforms/pseries/pseries.h @@ -122,4 +122,6 @@ void pseries_lpar_read_hblkrm_characteristics(void); static inline void pseries_lpar_read_hblkrm_characteristics(void) { } #endif +void pseries_rng_init(void); + #endif /* _PSERIES_PSERIES_H */ diff --git a/arch/powerpc/platforms/pseries/rng.c b/arch/powerpc/platforms/pseries/rng.c index 6268545947b8..6ddfdeaace9e 100644 --- a/arch/powerpc/platforms/pseries/rng.c +++ b/arch/powerpc/platforms/pseries/rng.c @@ -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) @@ -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); diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c index afb074269b42..ee4f1db49515 100644 --- a/arch/powerpc/platforms/pseries/setup.c +++ b/arch/powerpc/platforms/pseries/setup.c @@ -839,6 +839,7 @@ static void __init pSeries_setup_arch(void) } ppc_md.pcibios_root_bridge_prepare = pseries_root_bridge_prepare; + pseries_rng_init(); } static void pseries_panic(char *str) -- 2.35.1 ^ permalink raw reply related [flat|nested] 26+ messages in thread
* Re: [PATCH v3 3/3] powerpc/pseries: wire up rng during setup_arch 2022-06-11 15:10 ` Jason A. Donenfeld (?) @ 2022-06-11 16:25 ` Christophe Leroy -1 siblings, 0 replies; 26+ messages in thread From: Christophe Leroy @ 2022-06-11 16:25 UTC (permalink / raw) To: Jason A. Donenfeld, linuxppc-dev, linux-kernel, Michael Ellerman; +Cc: stable Le 11/06/2022 à 17:10, 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. 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: a489043f4626 ("powerpc/pseries: Implement arch_get_random_long() based on H_RANDOM") > Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu> > --- > arch/powerpc/platforms/pseries/pseries.h | 2 ++ > arch/powerpc/platforms/pseries/rng.c | 11 +++-------- > arch/powerpc/platforms/pseries/setup.c | 1 + > 3 files changed, 6 insertions(+), 8 deletions(-) > > diff --git a/arch/powerpc/platforms/pseries/pseries.h b/arch/powerpc/platforms/pseries/pseries.h > index f5c916c839c9..1d75b7742ef0 100644 > --- a/arch/powerpc/platforms/pseries/pseries.h > +++ b/arch/powerpc/platforms/pseries/pseries.h > @@ -122,4 +122,6 @@ void pseries_lpar_read_hblkrm_characteristics(void); > static inline void pseries_lpar_read_hblkrm_characteristics(void) { } > #endif > > +void pseries_rng_init(void); > + > #endif /* _PSERIES_PSERIES_H */ > diff --git a/arch/powerpc/platforms/pseries/rng.c b/arch/powerpc/platforms/pseries/rng.c > index 6268545947b8..6ddfdeaace9e 100644 > --- a/arch/powerpc/platforms/pseries/rng.c > +++ b/arch/powerpc/platforms/pseries/rng.c > @@ -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) > @@ -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); > diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c > index afb074269b42..ee4f1db49515 100644 > --- a/arch/powerpc/platforms/pseries/setup.c > +++ b/arch/powerpc/platforms/pseries/setup.c > @@ -839,6 +839,7 @@ static void __init pSeries_setup_arch(void) > } > > ppc_md.pcibios_root_bridge_prepare = pseries_root_bridge_prepare; > + pseries_rng_init(); > } > > static void pseries_panic(char *str) ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v3 0/3] powerpc: wire up rng during setup_arch 2022-06-11 15:10 ` Jason A. Donenfeld @ 2022-06-19 11:55 ` Michael Ellerman -1 siblings, 0 replies; 26+ messages in thread From: Michael Ellerman @ 2022-06-19 11:55 UTC (permalink / raw) To: linux-kernel, Michael Ellerman, Jason A. Donenfeld, linuxppc-dev Cc: Christophe Leroy On Sat, 11 Jun 2022 17:10:12 +0200, Jason A. Donenfeld wrote: > 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. This series > wires that up properly on the three platforms that currently initialize > the RNG from the wrong place. > > Cc: Michael Ellerman <mpe@ellerman.id.au> > Cc: Christophe Leroy <christophe.leroy@csgroup.eu> > > [...] Patches 1 & 3 applied to powerpc/fixes. [1/3] powerpc/microwatt: wire up rng during setup_arch https://git.kernel.org/powerpc/c/20a9689b3607456d92c6fb764501f6a95950b098 [3/3] powerpc/pseries: wire up rng during setup_arch https://git.kernel.org/powerpc/c/e561e472a3d441753bd012333b057f48fef1045b cheers ^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v3 0/3] powerpc: wire up rng during setup_arch @ 2022-06-19 11:55 ` Michael Ellerman 0 siblings, 0 replies; 26+ messages in thread From: Michael Ellerman @ 2022-06-19 11:55 UTC (permalink / raw) To: linux-kernel, Michael Ellerman, Jason A. Donenfeld, linuxppc-dev On Sat, 11 Jun 2022 17:10:12 +0200, Jason A. Donenfeld wrote: > 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. This series > wires that up properly on the three platforms that currently initialize > the RNG from the wrong place. > > Cc: Michael Ellerman <mpe@ellerman.id.au> > Cc: Christophe Leroy <christophe.leroy@csgroup.eu> > > [...] Patches 1 & 3 applied to powerpc/fixes. [1/3] powerpc/microwatt: wire up rng during setup_arch https://git.kernel.org/powerpc/c/20a9689b3607456d92c6fb764501f6a95950b098 [3/3] powerpc/pseries: wire up rng during setup_arch https://git.kernel.org/powerpc/c/e561e472a3d441753bd012333b057f48fef1045b cheers ^ permalink raw reply [flat|nested] 26+ messages in thread
end of thread, other threads:[~2022-06-26 0:29 UTC | newest] Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-06-11 15:10 [PATCH v3 0/3] powerpc: wire up rng during setup_arch Jason A. Donenfeld 2022-06-11 15:10 ` Jason A. Donenfeld 2022-06-11 15:10 ` [PATCH v3 1/3] powerpc/microwatt: " Jason A. Donenfeld 2022-06-11 15:10 ` Jason A. Donenfeld 2022-06-11 16:25 ` Christophe Leroy 2022-06-11 15:10 ` [PATCH v3 2/3] powerpc/powernv: " Jason A. Donenfeld 2022-06-11 15:10 ` Jason A. Donenfeld 2022-06-11 16:25 ` Christophe Leroy 2022-06-19 11:49 ` Michael Ellerman 2022-06-19 11:49 ` Michael Ellerman 2022-06-19 20:32 ` Jason A. Donenfeld 2022-06-19 20:32 ` Jason A. Donenfeld 2022-06-20 12:45 ` [PATCH v4] " Jason A. Donenfeld 2022-06-21 14:08 ` [PATCH v5] " Jason A. Donenfeld 2022-06-21 18:33 ` Christophe Leroy 2022-06-21 18:47 ` Jason A. Donenfeld 2022-06-21 18:47 ` Jason A. Donenfeld 2022-06-21 19:22 ` Christophe Leroy 2022-06-21 19:22 ` Christophe Leroy 2022-06-22 2:27 ` Michael Ellerman 2022-06-26 0:28 ` Michael Ellerman 2022-06-11 15:10 ` [PATCH v3 3/3] powerpc/pseries: " Jason A. Donenfeld 2022-06-11 15:10 ` Jason A. Donenfeld 2022-06-11 16:25 ` Christophe Leroy 2022-06-19 11:55 ` [PATCH v3 0/3] powerpc: " Michael Ellerman 2022-06-19 11:55 ` Michael Ellerman
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.