diff mbox series

[v2,3/3] powerpc/pseries: wire up rng during setup_arch

Message ID 20220611100447.5066-4-Jason@zx2c4.com (mailing list archive)
State Superseded
Headers show
Series powerpc: wire up rng 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_kernel_qemu success Successfully ran 23 jobs.
snowpatch_ozlabs/github-powerpc_clang success Successfully ran 7 jobs.
snowpatch_ozlabs/github-powerpc_sparse success Successfully ran 4 jobs.

Commit Message

Jason A. Donenfeld June 11, 2022, 10:04 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>
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/rng.c   | 11 ++---------
 arch/powerpc/platforms/pseries/setup.c |  3 +++
 2 files changed, 5 insertions(+), 9 deletions(-)

Comments

Christophe Leroy June 11, 2022, 2:45 p.m. UTC | #1
Le 11/06/2022 à 12:04, Jason A. Donenfeld a écrit :
> The platform's RNG must be available before random_init() in order to be
> useful for initial seeding, which in turn means that it needs to be
> called from setup_arch(), rather than from an init call. Fortunately,
> each platform already has a setup_arch function pointer, which means
> it's easy to wire this up for each of the three platforms that have an
> RNG. This commit also removes some noisy log messages that don't add
> much.
> 
> Cc: stable@vger.kernel.org
> Cc: Michael Ellerman <mpe@ellerman.id.au>
> Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
> Fixes: 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/rng.c   | 11 ++---------
>   arch/powerpc/platforms/pseries/setup.c |  3 +++
>   2 files changed, 5 insertions(+), 9 deletions(-)
> 
> 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;
> -

There must be a empty line between declarations and code.

>   	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);
> +

Prototype has to go in a header file, and should be pSeries maybe 
allthough camelCase in throw up on.

>   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, 2:53 p.m. UTC | #2
Hi Christophe,

On Sat, Jun 11, 2022 at 4:45 PM Christophe Leroy
<christophe.leroy@csgroup.eu> wrote:
>
> There must be a empty line between declarations and code.

Ack.

> Prototype has to go in a header file

Already voiced disagreement about this in the other thread.

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

Patch

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)