powerpc: wire up rng during setup_arch
Subsystems (2)
v2 cover powerpc: wire up rng during setup_arch
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.
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/rng.c | 9 ++------- arch/powerpc/platforms/microwatt/setup.c | 8 ++++++++ arch/powerpc/platforms/powernv/rng.c | 17 ++++------------- arch/powerpc/platforms/powernv/setup.c | 4 ++++ arch/powerpc/platforms/pseries/rng.c | 11 ++--------- arch/powerpc/platforms/pseries/setup.c | 3 +++ 6 files changed, 23 insertions(+), 29 deletions(-)
Signature · 1 line
2.35.1
PATCH v2 1/3 powerpc/microwatt: wire up rng during setup_arch
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.
--- arch/powerpc/platforms/microwatt/rng.c | 9 ++------- arch/powerpc/platforms/microwatt/setup.c | 8 ++++++++ 2 files changed, 10 insertions(+), 7 deletions(-)
arch/powerpc/platforms/microwatt/rng.c +2 -7
@@ -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);
arch/powerpc/platforms/microwatt/setup.c +8 -0
@@ -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, };
Signature · 1 line
2.35.1
Re: [PATCH v2 1/3] powerpc/microwatt: wire up rng during setup_arch
Le 11/06/2022 à 12:04, Jason A. Donenfeld a écrit :
Quoted 50 lines
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 fromsetup_arch(), rather than from an init call. Fortunately, each platform already has asetup_archfunction 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 Michael Ellerman <[email protected]>Cc Christophe Leroy <[email protected]>Fixes c25769fddaec ("powerpc/microwatt: Add support for hardware random number generator")Signed-off-by Jason A. Donenfeld <[email protected]>--- arch/powerpc/platforms/microwatt/rng.c | 9 ++------- arch/powerpc/platforms/microwatt/setup.c | 8 ++++++++ 2 files changed, 10 insertions(+), 7 deletions(-)arch/powerpc/platforms/microwatt/rng.c +2
-7@@ -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);arch/powerpc/platforms/microwatt/setup.c +0
-0
arch/powerpc/platforms/microwatt/setup.c static int __init microwatt_populate(void) · line 35
Quoted 4 lines
arch/powerpc/platforms/microwatt/setup.c +1
-0@@ -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'.
Quoted 14 lines
arch/powerpc/platforms/microwatt/setup.c +7
-0+ +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, };
Re: [PATCH v2 1/3] powerpc/microwatt: wire up rng during setup_arch
Hi Christophe,
Quoted 4 lines · Christophe Leroy
Quoted 2 lines
+__init void
microwatt_rng_init(void);This prototype should be declared in a header file, for instance
asm/setup.h
Alright.
Quoted 2 lines
And I think the
__initkeyword 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
Re: [PATCH v2 1/3] powerpc/microwatt: wire up rng during setup_arch
Hi again,
Quoted 10 lines · Jason A. Donenfeld
Hi Christophe,
Quoted 4 lines · Christophe Leroy
Quoted 2 lines
+__init void
microwatt_rng_init(void);This prototype should be declared in a header file, for instance
asm/setup.hAlright.
Actually, on second thought, I don't think this part is worth doing. These are per-platform functions, not powerpc-wide.
Jason
Re: [PATCH v2 1/3] powerpc/microwatt: wire up rng during setup_arch
Le 11/06/2022 à 16:46, Jason A. Donenfeld a écrit :
Quoted 8 lines
Hi again,
Quoted 5 lines · Jason A. Donenfeld
Hi Christophe,
Quoted 1 line · Christophe Leroy
Quoted 1 line
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
+__init void
microwatt_rng_init(void);This prototype should be declared in a header file, for instance
asm/setup.hAlright.
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.harch/powerpc/platforms/pseries/pseries.h
and you can add
arch/powerpc/platforms/microwatt/microwatt.h
Re: [PATCH v2 1/3] powerpc/microwatt: wire up rng during setup_arch
Hi Christophe,
Quoted 8 lines · Christophe Leroy
Then you have:
arch/powerpc/platforms/powernv/powernv.harch/powerpc/platforms/pseries/pseries.hand you can add
arch/powerpc/platforms/microwatt/microwatt.h
Oh, terrific, thanks. I'll do that.
Jason
PATCH v2 2/3 powerpc/powernv: wire up rng during setup_arch
In reply to Jason A. DonenfeldThe 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.
--- arch/powerpc/platforms/powernv/rng.c | 17 ++++------------- arch/powerpc/platforms/powernv/setup.c | 4 ++++ 2 files changed, 8 insertions(+), 13 deletions(-)
arch/powerpc/platforms/powernv/rng.c +4 -13
@@ -84,24 +84,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 +159,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 ) +__init void powernv_rng_init (void ) {struct device_node *dn;int rc;
@@ -188,7 +182,4 @@ static __init int rng_init(void) }initialise_darn (); - -return 0 ; } -machine_subsys_initcall (powernv, rng_init);
arch/powerpc/platforms/powernv/setup.c +4 -0
@@ -184,6 +184,8 @@ static void __init pnv_check_guarded_cores(void) } } +__init void powernv_rng_init (void ); +static void __init pnv_setup_arch (void ) {set_arch_panic_timeout (10 ,ARCH_PANIC_TIMEOUT );
@@ -203,6 +205,8 @@ static void __init pnv_setup_arch(void)pnv_check_guarded_cores ();/* XXX PMCS */ + +powernv_rng_init (); }static void __init pnv_init (void )
Signature · 1 line
2.35.1
Re: [PATCH v2 2/3] powerpc/powernv: wire up rng during setup_arch
Le 11/06/2022 à 12:04, Jason A. Donenfeld a écrit :
Quoted 79 lines
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 fromsetup_arch(), rather than from an init call. Fortunately, each platform already has asetup_archfunction 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 Michael Ellerman <[email protected]>Cc Christophe Leroy <[email protected]>Fixes a4da0d50b2a0 ("powerpc: Implement arch_get_random_long/int() for powernv")Signed-off-by Jason A. Donenfeld <[email protected]>--- arch/powerpc/platforms/powernv/rng.c | 17 ++++------------- arch/powerpc/platforms/powernv/setup.c | 4 ++++ 2 files changed, 8 insertions(+), 13 deletions(-)arch/powerpc/platforms/powernv/rng.c +4
-13@@ -84,24 +84,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 +159,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 ) +__init void powernv_rng_init (void ) {struct device_node *dn;int rc;@@ -188,7 +182,4 @@ static __init int rng_init(void) }initialise_darn (); - -return 0 ; } -machine_subsys_initcall (powernv, rng_init);arch/powerpc/platforms/powernv/setup.c +0
-0
arch/powerpc/platforms/powernv/setup.c static void __init pnv_check_guarded_cores(void) · line 188
Quoted 5 lines
arch/powerpc/platforms/powernv/setup.c +2
-0@@ -184,6 +184,8 @@ static void __init pnv_check_guarded_cores(void) } } +__init void powernv_rng_init (void ); +
Same here, the prototype should go in a header file., should be 'void __init' (and indeed the __init is pointless in the prototype, only matters in the function definition).
Maybe the name should be pnv_rng_init() like the setup arch below.
Quoted 12 lines
arch/powerpc/platforms/powernv/setup.c +2
-0static void __init pnv_setup_arch (void ) {set_arch_panic_timeout (10 ,ARCH_PANIC_TIMEOUT );@@ -203,6 +205,8 @@ static void __init pnv_setup_arch(void)pnv_check_guarded_cores ();/* XXX PMCS */ + +powernv_rng_init (); }static void __init pnv_init (void )
Re: [PATCH v2 2/3] powerpc/powernv: wire up rng during setup_arch
Hi Christophe,
Quoted 3 lines · Christophe Leroy
Same here, the prototype should go in a header file., should be 'void
__init' (and indeed the__initis pointless in the prototype, only matters in the function definition).
I'll change the order, but I don't see a good place for the prototype other than the .c file. It's not a big deal to keep it there.
Quoted 2 lines
Maybe the name should be
pnv_rng_init()like the setup arch below.
All the rng.c files are powernv_ prefixed, not pnv_ prefixed.
Jason
PATCH v2 3/3 powerpc/pseries: wire up rng during setup_arch
In reply to Jason A. DonenfeldThe 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.
--- arch/powerpc/platforms/pseries/rng.c | 11 ++--------- arch/powerpc/platforms/pseries/setup.c | 3 +++ 2 files changed, 5 insertions(+), 9 deletions(-)
arch/powerpc/platforms/pseries/rng.c +2 -9
@@ -24,19 +24,12 @@ static int pseries_get_random_long(unsigned long *v)return 0 ; } -static __init int rng_init (void ) +__init void 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);
arch/powerpc/platforms/pseries/setup.c +3 -0
@@ -779,6 +779,8 @@ static resource_size_t pseries_pci_iov_resource_alignment(struct pci_dev *pdev, }#endif +__init void pseries_rng_init (void ); +static void __init pSeries_setup_arch (void ) {set_arch_panic_timeout (10 ,ARCH_PANIC_TIMEOUT );
@@ -839,6 +841,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)
Signature · 1 line
2.35.1
Re: [PATCH v2 3/3] powerpc/pseries: wire up rng during setup_arch
Le 11/06/2022 à 12:04, Jason A. Donenfeld a écrit :
Quoted 23 lines
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 fromsetup_arch(), rather than from an init call. Fortunately, each platform already has asetup_archfunction 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 Michael Ellerman <[email protected]>Cc Christophe Leroy <[email protected]>Fixes a489043f4626 ("powerpc/pseries: Implement arch_get_random_long() based on H_RANDOM")Signed-off-by Jason A. Donenfeld <[email protected]>--- arch/powerpc/platforms/pseries/rng.c | 11 ++--------- arch/powerpc/platforms/pseries/setup.c | 3 +++ 2 files changed, 5 insertions(+), 9 deletions(-)arch/powerpc/platforms/pseries/rng.c +0
-0
arch/powerpc/platforms/pseries/rng.c static int pseries_get_random_long(unsigned long *v) · line 30
Quoted 8 lines
arch/powerpc/platforms/pseries/rng.c +1
-2@@ -24,19 +24,12 @@ static int pseries_get_random_long(unsigned long *v)return 0 ; } -static __init int rng_init (void ) +__init void pseries_rng_init (void ) {struct device_node *dn; -
There must be a empty line between declarations and code.
Quoted 18 lines
arch/powerpc/platforms/pseries/rng.c +1
-7dn =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);arch/powerpc/platforms/pseries/setup.c +0
-0
arch/powerpc/platforms/pseries/setup.c static resource_size_t pseries_pci_iov_resource_alignment(struct pci_dev *pdev, · line 783
Quoted 5 lines
arch/powerpc/platforms/pseries/setup.c +2
-0@@ -779,6 +779,8 @@ static resource_size_t pseries_pci_iov_resource_alignment(struct pci_dev *pdev, }#endif +__init void pseries_rng_init (void ); +
Prototype has to go in a header file, and should be pSeries maybe allthough camelCase in throw up on.
Quoted 11 lines
arch/powerpc/platforms/pseries/setup.c +1
-0static void __init pSeries_setup_arch (void ) {set_arch_panic_timeout (10 ,ARCH_PANIC_TIMEOUT );@@ -839,6 +841,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)
Re: [PATCH v2 3/3] powerpc/pseries: wire up rng during setup_arch
Hi Christophe,
Quoted 2 lines · Christophe Leroy
There must be a empty line between declarations and code.
Ack.
Quoted 1 line
Prototype has to go in a header file
Already voiced disagreement about this in the other thread.
Quoted 2 lines
and should be pSeries maybe
allthough camelCase in throw up on.
All the rng.c functions use pseries_ in lower case, so I'll stick with that, as that's where the function is defined.
Jason