diff mbox series

powerpc/rng: wire up during setup_arch

Message ID 20220611081114.449165-1-Jason@zx2c4.com (mailing list archive)
State Superseded
Headers show
Series powerpc/rng: wire up during setup_arch | expand

Checks

Context Check Description
snowpatch_ozlabs/github-powerpc_ppctests success Successfully ran 10 jobs.
snowpatch_ozlabs/github-powerpc_selftests success Successfully ran 10 jobs.
snowpatch_ozlabs/github-powerpc_clang success Successfully ran 7 jobs.
snowpatch_ozlabs/github-powerpc_sparse success Successfully ran 4 jobs.
snowpatch_ozlabs/github-powerpc_kernel_qemu success Successfully ran 23 jobs.

Commit Message

Jason A. Donenfeld June 11, 2022, 8:11 a.m. UTC
The platform's RNG must be available before random_init() in order to be
useful for initial seeding, which in turn means that it needs to be
called from setup_arch(), rather than from an init call. Fortunately,
each platform already has a setup_arch function pointer, which means
it's easy to wire this up for each of the three platforms that have an
RNG. This commit also removes some noisy log messages that don't add
much.

Cc: stable@vger.kernel.org
Cc: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 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(-)

Comments

Christophe Leroy June 11, 2022, 9:16 a.m. UTC | #1
Le 11/06/2022 à 10:11, Jason A. Donenfeld a écrit :
> The platform's RNG must be available before random_init() in order to be
> useful for initial seeding, which in turn means that it needs to be
> called from setup_arch(), rather than from an init call. Fortunately,
> each platform already has a setup_arch function pointer, which means
> it's easy to wire this up for each of the three platforms that have an
> RNG. This commit also removes some noisy log messages that don't add
> much.

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 ?



> 
> Cc: stable@vger.kernel.org
> Cc: Michael Ellerman <mpe@ellerman.id.au>
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> ---
>   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(-)
> 
> diff --git a/arch/powerpc/platforms/microwatt/rng.c b/arch/powerpc/platforms/microwatt/rng.c
> index 7bc4d1cbfaf0..d13f656910ad 100644
> --- a/arch/powerpc/platforms/microwatt/rng.c
> +++ b/arch/powerpc/platforms/microwatt/rng.c
> @@ -29,7 +29,7 @@ static int microwatt_get_random_darn(unsigned long *v)
>   	return 1;
>   }
>   
> -static __init int rng_init(void)
> +__init void microwatt_rng_init(void)
>   {
>   	unsigned long val;
>   	int i;
> @@ -37,12 +37,7 @@ static __init int rng_init(void)
>   	for (i = 0; i < 10; i++) {
>   		if (microwatt_get_random_darn(&val)) {
>   			ppc_md.get_random_seed = microwatt_get_random_darn;
> -			return 0;
> +			return;
>   		}
>   	}
> -
> -	pr_warn("Unable to use DARN for get_random_seed()\n");
> -
> -	return -EIO;
>   }
> -machine_subsys_initcall(, rng_init);
> diff --git a/arch/powerpc/platforms/microwatt/setup.c b/arch/powerpc/platforms/microwatt/setup.c
> index 0b02603bdb74..23c996dcc870 100644
> --- a/arch/powerpc/platforms/microwatt/setup.c
> +++ b/arch/powerpc/platforms/microwatt/setup.c
> @@ -32,10 +32,18 @@ static int __init microwatt_populate(void)
>   }
>   machine_arch_initcall(microwatt, microwatt_populate);
>   
> +__init void microwatt_rng_init(void);
> +
> +static void __init microwatt_setup_arch(void)
> +{
> +	microwatt_rng_init();
> +}
> +
>   define_machine(microwatt) {
>   	.name			= "microwatt",
>   	.probe			= microwatt_probe,
>   	.init_IRQ		= microwatt_init_IRQ,
> +	.setup_arch		= microwatt_setup_arch,
>   	.progress		= udbg_progress,
>   	.calibrate_decr		= generic_calibrate_decr,
>   };
> diff --git a/arch/powerpc/platforms/powernv/rng.c b/arch/powerpc/platforms/powernv/rng.c
> index e3d44b36ae98..ef24e72a1b69 100644
> --- a/arch/powerpc/platforms/powernv/rng.c
> +++ b/arch/powerpc/platforms/powernv/rng.c
> @@ -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);
> diff --git a/arch/powerpc/platforms/powernv/setup.c b/arch/powerpc/platforms/powernv/setup.c
> index 824c3ad7a0fa..a0c5217bc5c0 100644
> --- a/arch/powerpc/platforms/powernv/setup.c
> +++ b/arch/powerpc/platforms/powernv/setup.c
> @@ -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)
> diff --git a/arch/powerpc/platforms/pseries/rng.c b/arch/powerpc/platforms/pseries/rng.c
> index 6268545947b8..d39bfce39aa1 100644
> --- a/arch/powerpc/platforms/pseries/rng.c
> +++ b/arch/powerpc/platforms/pseries/rng.c
> @@ -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);
> diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
> index afb074269b42..7f3ee2658163 100644
> --- a/arch/powerpc/platforms/pseries/setup.c
> +++ b/arch/powerpc/platforms/pseries/setup.c
> @@ -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)
Christophe Leroy June 11, 2022, 9:17 a.m. UTC | #2
Le 11/06/2022 à 11:16, Christophe Leroy a écrit :
> 
> 
> Le 11/06/2022 à 10:11, Jason A. Donenfeld a écrit :
>> The platform's RNG must be available before random_init() in order to be
>> useful for initial seeding, which in turn means that it needs to be
>> called from setup_arch(), rather than from an init call. Fortunately,
>> each platform already has a setup_arch function pointer, which means
>> it's easy to wire this up for each of the three platforms that have an
>> RNG. This commit also removes some noisy log messages that don't add
>> much.
> 
> 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 ?
> 

Also, you copied stable. Should you add a Fixes: tag so that we know 
what it fixes ?

> 
> 
>>
>> Cc: stable@vger.kernel.org
>> Cc: Michael Ellerman <mpe@ellerman.id.au>
>> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
>> ---
>>   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(-)
>>
>> diff --git a/arch/powerpc/platforms/microwatt/rng.c 
>> b/arch/powerpc/platforms/microwatt/rng.c
>> index 7bc4d1cbfaf0..d13f656910ad 100644
>> --- a/arch/powerpc/platforms/microwatt/rng.c
>> +++ b/arch/powerpc/platforms/microwatt/rng.c
>> @@ -29,7 +29,7 @@ static int microwatt_get_random_darn(unsigned long *v)
>>       return 1;
>>   }
>> -static __init int rng_init(void)
>> +__init void microwatt_rng_init(void)
>>   {
>>       unsigned long val;
>>       int i;
>> @@ -37,12 +37,7 @@ static __init int rng_init(void)
>>       for (i = 0; i < 10; i++) {
>>           if (microwatt_get_random_darn(&val)) {
>>               ppc_md.get_random_seed = microwatt_get_random_darn;
>> -            return 0;
>> +            return;
>>           }
>>       }
>> -
>> -    pr_warn("Unable to use DARN for get_random_seed()\n");
>> -
>> -    return -EIO;
>>   }
>> -machine_subsys_initcall(, rng_init);
>> diff --git a/arch/powerpc/platforms/microwatt/setup.c 
>> b/arch/powerpc/platforms/microwatt/setup.c
>> index 0b02603bdb74..23c996dcc870 100644
>> --- a/arch/powerpc/platforms/microwatt/setup.c
>> +++ b/arch/powerpc/platforms/microwatt/setup.c
>> @@ -32,10 +32,18 @@ static int __init microwatt_populate(void)
>>   }
>>   machine_arch_initcall(microwatt, microwatt_populate);
>> +__init void microwatt_rng_init(void);
>> +
>> +static void __init microwatt_setup_arch(void)
>> +{
>> +    microwatt_rng_init();
>> +}
>> +
>>   define_machine(microwatt) {
>>       .name            = "microwatt",
>>       .probe            = microwatt_probe,
>>       .init_IRQ        = microwatt_init_IRQ,
>> +    .setup_arch        = microwatt_setup_arch,
>>       .progress        = udbg_progress,
>>       .calibrate_decr        = generic_calibrate_decr,
>>   };
>> diff --git a/arch/powerpc/platforms/powernv/rng.c 
>> b/arch/powerpc/platforms/powernv/rng.c
>> index e3d44b36ae98..ef24e72a1b69 100644
>> --- a/arch/powerpc/platforms/powernv/rng.c
>> +++ b/arch/powerpc/platforms/powernv/rng.c
>> @@ -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);
>> diff --git a/arch/powerpc/platforms/powernv/setup.c 
>> b/arch/powerpc/platforms/powernv/setup.c
>> index 824c3ad7a0fa..a0c5217bc5c0 100644
>> --- a/arch/powerpc/platforms/powernv/setup.c
>> +++ b/arch/powerpc/platforms/powernv/setup.c
>> @@ -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)
>> diff --git a/arch/powerpc/platforms/pseries/rng.c 
>> b/arch/powerpc/platforms/pseries/rng.c
>> index 6268545947b8..d39bfce39aa1 100644
>> --- a/arch/powerpc/platforms/pseries/rng.c
>> +++ b/arch/powerpc/platforms/pseries/rng.c
>> @@ -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);
>> diff --git a/arch/powerpc/platforms/pseries/setup.c 
>> b/arch/powerpc/platforms/pseries/setup.c
>> index afb074269b42..7f3ee2658163 100644
>> --- a/arch/powerpc/platforms/pseries/setup.c
>> +++ b/arch/powerpc/platforms/pseries/setup.c
>> @@ -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)
Jason A. Donenfeld June 11, 2022, 9:20 a.m. UTC | #3
Hi Christophe,

On Sat, Jun 11, 2022 at 09:16:24AM +0000, Christophe Leroy wrote:
> Le 11/06/2022 à 10:11, Jason A. Donenfeld a écrit :
> > The platform's RNG must be available before random_init() in order to be
> > useful for initial seeding, which in turn means that it needs to be
> > called from setup_arch(), rather than from an init call. Fortunately,
> > each platform already has a setup_arch function pointer, which means
> > it's easy to wire this up for each of the three platforms that have an
> > RNG. This commit also removes some noisy log messages that don't add
> > much.
> 
> Can't we use one of the machine initcalls for that ?
> Like machine_early_initcall() or machine_arch_initcall() ?

No, unfortunately. I tried this, and it's still too late. This must be
done in setup_arch().

> Today it is using  machine_subsys_initcall() and you didn't remove it. 
> It means rng_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
Jason A. Donenfeld June 11, 2022, 9:22 a.m. UTC | #4
Hi Christophe,

On Sat, Jun 11, 2022 at 11:17:23AM +0200, Christophe Leroy wrote:
> 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")

Jason
Christophe Leroy June 11, 2022, 9:23 a.m. UTC | #5
Le 11/06/2022 à 11:20, Jason A. Donenfeld a écrit :
> Hi Christophe,
> 
> On Sat, Jun 11, 2022 at 09:16:24AM +0000, Christophe Leroy wrote:
>> Le 11/06/2022 à 10:11, Jason A. Donenfeld a écrit :
>>> The platform's RNG must be available before random_init() in order to be
>>> useful for initial seeding, which in turn means that it needs to be
>>> called from setup_arch(), rather than from an init call. Fortunately,
>>> each platform already has a setup_arch function pointer, which means
>>> it's easy to wire this up for each of the three platforms that have an
>>> RNG. This commit also removes some noisy log messages that don't add
>>> much.
>>
>> Can't we use one of the machine initcalls for that ?
>> Like machine_early_initcall() or machine_arch_initcall() ?
> 
> No, unfortunately. I tried this, and it's still too late. This must be
> done in setup_arch().

Ok

> 
>> Today it is using  machine_subsys_initcall() and you didn't remove it.
>> It means rng_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 $

Oops, I overlooked it, sorry.

Christophe
Christophe Leroy June 11, 2022, 9:27 a.m. UTC | #6
Le 11/06/2022 à 11:22, Jason A. Donenfeld a écrit :
> Hi Christophe,
> 
> On Sat, Jun 11, 2022 at 11:17:23AM +0200, Christophe Leroy wrote:
>> 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")
> 

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
Jason A. Donenfeld June 11, 2022, 9:58 a.m. UTC | #7
Hi Christophe,

On Sat, Jun 11, 2022 at 09:27:43AM +0000, Christophe Leroy wrote:
> Le 11/06/2022 à 11:22, Jason A. Donenfeld a écrit :
> > Hi Christophe,
> > 
> > On Sat, Jun 11, 2022 at 11:17:23AM +0200, Christophe Leroy wrote:
> >> 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")
> > 
> 
> 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.

> 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
Jason A. Donenfeld June 11, 2022, 10:06 a.m. UTC | #8
Hey again,

On Sat, Jun 11, 2022 at 11:58:23AM +0200, Jason A. Donenfeld wrote:
> Anyway, sure, I'll do that and send a v2 series.

This is now done here:
https://lore.kernel.org/lkml/20220611100447.5066-1-Jason@zx2c4.com/

Jason
Christophe Leroy June 11, 2022, 10:41 a.m. UTC | #9
Le 11/06/2022 à 11:58, Jason A. Donenfeld a écrit :
> Hi Christophe,
> 
> On Sat, Jun 11, 2022 at 09:27:43AM +0000, Christophe Leroy wrote:
>> Le 11/06/2022 à 11:22, Jason A. Donenfeld a écrit :
>>> Hi Christophe,
>>>
>>> On Sat, Jun 11, 2022 at 11:17:23AM +0200, Christophe Leroy wrote:
>>>> 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")
>>>
>>
>> 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.

> 
>> 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.


> 
> 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
diff mbox series

Patch

diff --git a/arch/powerpc/platforms/microwatt/rng.c b/arch/powerpc/platforms/microwatt/rng.c
index 7bc4d1cbfaf0..d13f656910ad 100644
--- a/arch/powerpc/platforms/microwatt/rng.c
+++ b/arch/powerpc/platforms/microwatt/rng.c
@@ -29,7 +29,7 @@  static int microwatt_get_random_darn(unsigned long *v)
 	return 1;
 }
 
-static __init int rng_init(void)
+__init void microwatt_rng_init(void)
 {
 	unsigned long val;
 	int i;
@@ -37,12 +37,7 @@  static __init int rng_init(void)
 	for (i = 0; i < 10; i++) {
 		if (microwatt_get_random_darn(&val)) {
 			ppc_md.get_random_seed = microwatt_get_random_darn;
-			return 0;
+			return;
 		}
 	}
-
-	pr_warn("Unable to use DARN for get_random_seed()\n");
-
-	return -EIO;
 }
-machine_subsys_initcall(, rng_init);
diff --git a/arch/powerpc/platforms/microwatt/setup.c b/arch/powerpc/platforms/microwatt/setup.c
index 0b02603bdb74..23c996dcc870 100644
--- a/arch/powerpc/platforms/microwatt/setup.c
+++ b/arch/powerpc/platforms/microwatt/setup.c
@@ -32,10 +32,18 @@  static int __init microwatt_populate(void)
 }
 machine_arch_initcall(microwatt, microwatt_populate);
 
+__init void microwatt_rng_init(void);
+
+static void __init microwatt_setup_arch(void)
+{
+	microwatt_rng_init();
+}
+
 define_machine(microwatt) {
 	.name			= "microwatt",
 	.probe			= microwatt_probe,
 	.init_IRQ		= microwatt_init_IRQ,
+	.setup_arch		= microwatt_setup_arch,
 	.progress		= udbg_progress,
 	.calibrate_decr		= generic_calibrate_decr,
 };
diff --git a/arch/powerpc/platforms/powernv/rng.c b/arch/powerpc/platforms/powernv/rng.c
index e3d44b36ae98..ef24e72a1b69 100644
--- a/arch/powerpc/platforms/powernv/rng.c
+++ b/arch/powerpc/platforms/powernv/rng.c
@@ -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);
diff --git a/arch/powerpc/platforms/powernv/setup.c b/arch/powerpc/platforms/powernv/setup.c
index 824c3ad7a0fa..a0c5217bc5c0 100644
--- a/arch/powerpc/platforms/powernv/setup.c
+++ b/arch/powerpc/platforms/powernv/setup.c
@@ -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)
diff --git a/arch/powerpc/platforms/pseries/rng.c b/arch/powerpc/platforms/pseries/rng.c
index 6268545947b8..d39bfce39aa1 100644
--- a/arch/powerpc/platforms/pseries/rng.c
+++ b/arch/powerpc/platforms/pseries/rng.c
@@ -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);
diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index afb074269b42..7f3ee2658163 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -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)