diff mbox series

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

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

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: a4da0d50b2a0 ("powerpc: Implement arch_get_random_long/int() for powernv")
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 arch/powerpc/platforms/powernv/rng.c   | 17 ++++-------------
 arch/powerpc/platforms/powernv/setup.c |  4 ++++
 2 files changed, 8 insertions(+), 13 deletions(-)

Comments

Christophe Leroy June 11, 2022, 2:42 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: a4da0d50b2a0 ("powerpc: Implement arch_get_random_long/int() for powernv")
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> ---
>   arch/powerpc/platforms/powernv/rng.c   | 17 ++++-------------
>   arch/powerpc/platforms/powernv/setup.c |  4 ++++
>   2 files changed, 8 insertions(+), 13 deletions(-)
> 
> 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);
> +

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.

>   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)
Jason A. Donenfeld June 11, 2022, 2:47 p.m. UTC | #2
Hi Christophe,

On Sat, Jun 11, 2022 at 4:42 PM Christophe Leroy
<christophe.leroy@csgroup.eu> wrote:
> 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).

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.

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

Patch

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)