powerpc/rng: wire up during setup_arch
Subsystems (2)
PATCH 1/1 powerpc/rng: wire up 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 ++++++++ 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(-)
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, };
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 )
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
Le 11/06/2022 à 10:11, Jason A. Donenfeld a écrit :
Quoted 7 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.
Can't we use one of the machine initcalls for that ? Like machine_early_initcall() or machine_arch_initcall() ?
Today it is using machine_subsys_initcall() and you didn't remove it. It means rng_init() will be called twice. Is that ok ?
Quoted 188 lines
Cc Michael Ellerman <[email protected]>Signed-off-by Jason A. Donenfeld <[email protected]>--- 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(-)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, };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 )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)
Le 11/06/2022 à 11:16, Christophe Leroy a écrit :
Quoted 11 lines
Le 11/06/2022 à 10:11, Jason A. Donenfeld a écrit :
Quoted 7 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.
Quoted 5 lines
Can't we use one of the machine initcalls for that ? Like
machine_early_initcall()ormachine_arch_initcall()?Today it is using
machine_subsys_initcall()and you didn't remove it. It meansrng_init()will be called twice. Is that ok ?
Also, you copied stable. Should you add a Fixes: tag so that we know what it fixes ?
Quoted 174 lines
Quoted 174 lines
Cc Michael Ellerman <[email protected]>Signed-off-by Jason A. Donenfeld <[email protected]>---
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(-)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, };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)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)
Hi Christophe,
Quoted 11 lines · Christophe Leroy
Le 11/06/2022 à 10:11, Jason A. Donenfeld a écrit :
Quoted 7 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.Can't we use one of the machine initcalls for that ? Like
machine_early_initcall()ormachine_arch_initcall()?
No, unfortunately. I tried this, and it's still too late. This must be done in setup_arch().
Quoted 2 lines
Today it is using
machine_subsys_initcall()and you didn't remove it. It meansrng_init()will be called twice. Is that ok ?
I did remove the calls to machine_subsys_initcall(). I just double checked:
zx2c4@thinkpad ~/Projects/random-linux/arch/powerpc $ rg machine_subsys_initcall platforms/*/rng.c zx2c4@thinkpad ~/Projects/random-linux/arch/powerpc $
Jason
Hi Christophe,
Quoted 2 lines · Christophe Leroy
Also, you copied stable. Should you add a Fixes: tag so that we know what it fixes ?
I suppose the fixes tag would be whatever introduced those files in the first place, so not all together useful. But if you want something, feel free to append these when applying the commit:
Jason
Le 11/06/2022 à 11:20, Jason A. Donenfeld a écrit :
Quoted 12 lines
Hi Christophe,
Quoted 9 lines · Christophe Leroy
Le 11/06/2022 à 10:11, Jason A. Donenfeld a écrit :
Quoted 7 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.
Quoted 5 lines
Quoted 2 lines
Can't we use one of the machine initcalls for that ? Like
machine_early_initcall()ormachine_arch_initcall()?No, unfortunately. I tried this, and it's still too late. This must be done in
setup_arch().
Ok
Quoted 9 lines
Quoted 3 lines
Today it is using
machine_subsys_initcall()and you didn't remove it. It meansrng_init()will be called twice. Is that ok ?I did remove the calls to
machine_subsys_initcall(). I just double checked:zx2c4@thinkpad ~/Projects/random-linux/arch/powerpc $ rg
machine_subsys_initcallplatforms/*/rng.czx2c4@thinkpad ~/Projects/random-linux/arch/powerpc $
Oops, I overlooked it, sorry.
Christophe
Le 11/06/2022 à 11:22, Jason A. Donenfeld a écrit :
Quoted 6 lines
Hi Christophe,
Quoted 2 lines · Christophe Leroy
Also, you copied stable. Should you add a Fixes: tag so that we know what it fixes ?
Quoted 8 lines
I suppose the fixes tag would be whatever introduced those files in the first place, so not all together useful. But if you want something, feel free to append these when applying the commit:
Fixes a4da0d50b2a0 ("powerpc: Implement arch_get_random_long/int() for powernv")Fixes a489043f4626 ("powerpc/pseries: Implement arch_get_random_long() based on H_RANDOM")Fixes c25769fddaec ("powerpc/microwatt: Add support for hardware random number generator")
Well it helps knowing on which stable version it applies.
Maybe it would be cleaner to send three patches ? After all they look like 3 independant changes with nothing in common at all.
Christophe
Hi Christophe,
Quoted 11 lines · Christophe Leroy
Le 11/06/2022 à 11:22, Jason A. Donenfeld a écrit :
Quoted 10 lines
Hi Christophe,
Quoted 2 lines · Christophe Leroy
Also, you copied stable. Should you add a Fixes: tag so that we know what it fixes ?
I suppose the fixes tag would be whatever introduced those files in the first place, so not all together useful. But if you want something, feel free to append these when applying the commit:
Quoted 8 lines
Quoted 4 lines
Fixes a4da0d50b2a0 ("powerpc: Implement arch_get_random_long/int() for powernv")Fixes a489043f4626 ("powerpc/pseries: Implement arch_get_random_long() based on H_RANDOM")Fixes c25769fddaec ("powerpc/microwatt: Add support for hardware random number generator")Well it helps knowing on which stable version it applies.
Maybe it would be cleaner to send three patches ? After all they look
Sounds like irritating paperwork to me.
Quoted 1 line
like 3 independant changes with nothing in common at all.
"Nothing in common"? I don't know about that.
Anyway, sure, I'll do that and send a v2 series.
Jason
Hey again,
Quoted 1 line · Jason A. Donenfeld
Anyway, sure, I'll do that and send a v2 series.
This is now done here:
https://lore.kernel.org/lkml/[email protected]/
Jason
Le 11/06/2022 à 11:58, Jason A. Donenfeld a écrit :
Quoted 19 lines
Hi Christophe,
Quoted 16 lines · Christophe Leroy
Le 11/06/2022 à 11:22, Jason A. Donenfeld a écrit :
Quoted 14 lines
Hi Christophe,
Quoted 2 lines · Christophe Leroy
Also, you copied stable. Should you add a Fixes: tag so that we know what it fixes ?
I suppose the fixes tag would be whatever introduced those files in the first place, so not all together useful. But if you want something, feel free to append these when applying the commit:
Fixes a4da0d50b2a0 ("powerpc: Implement arch_get_random_long/int() for powernv")Fixes a489043f4626 ("powerpc/pseries: Implement arch_get_random_long() based on H_RANDOM")Fixes c25769fddaec ("powerpc/microwatt: Add support for hardware random number generator")
Quoted 5 lines
Quoted 3 lines
Well it helps knowing on which stable version it applies.
Maybe it would be cleaner to send three patches ? After all they look
Sounds like irritating paperwork to me.
It helps with application to stable.
Two of the above commits are in v3.12, the other one appears in v5.13
So having the microwatt in a separate patch should ease.
Quoted 4 lines
Quoted 2 lines
like 3 independant changes with nothing in common at all.
"Nothing in common"? I don't know about that.
I mean no common file that needs to be changed for the three platforms, so it makes it easy.
Quoted 3 lines
Anyway, sure, I'll do that and send a v2 series.
As they are independant it doesn't need to be a series at all. But that's fine if it is a series as well.
Christophe