Michal Suchanek 08285e
From 887502826549caa7e4215fd9e628f48f14c0825a Mon Sep 17 00:00:00 2001
Michal Suchanek 08285e
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
Michal Suchanek 08285e
Date: Thu, 30 Jun 2022 14:16:54 +0200
Michal Suchanek 08285e
Subject: [PATCH] powerpc/powernv: delay rng platform device creation until
Michal Suchanek 08285e
 later in boot
Michal Suchanek 08285e
Michal Suchanek 08285e
References: bsc#1065729
Michal Suchanek 08285e
Patch-mainline: v5.19-rc6
Michal Suchanek 08285e
Git-commit: 887502826549caa7e4215fd9e628f48f14c0825a
Michal Suchanek 08285e
Michal Suchanek 08285e
The platform device for the rng must be created much later in boot.
Michal Suchanek 08285e
Otherwise it tries to connect to a parent that doesn't yet exist,
Michal Suchanek 08285e
resulting in this splat:
Michal Suchanek 08285e
Michal Suchanek 08285e
  [    0.000478] kobject: '(null)' ((____ptrval____)): is not initialized, yet kobject_get() is being called.
Michal Suchanek 08285e
  [    0.002925] [c000000002a0fb30] [c00000000073b0bc] kobject_get+0x8c/0x100 (unreliable)
Michal Suchanek 08285e
  [    0.003071] [c000000002a0fba0] [c00000000087e464] device_add+0xf4/0xb00
Michal Suchanek 08285e
  [    0.003194] [c000000002a0fc80] [c000000000a7f6e4] of_device_add+0x64/0x80
Michal Suchanek 08285e
  [    0.003321] [c000000002a0fcb0] [c000000000a800d0] of_platform_device_create_pdata+0xd0/0x1b0
Michal Suchanek 08285e
  [    0.003476] [c000000002a0fd00] [c00000000201fa44] pnv_get_random_long_early+0x240/0x2e4
Michal Suchanek 08285e
  [    0.003623] [c000000002a0fe20] [c000000002060c38] random_init+0xc0/0x214
Michal Suchanek 08285e
Michal Suchanek 08285e
This patch fixes the issue by doing the platform device creation inside
Michal Suchanek 08285e
of machine_subsys_initcall.
Michal Suchanek 08285e
Michal Suchanek 08285e
Fixes: f3eac426657d ("powerpc/powernv: wire up rng during setup_arch")
Michal Suchanek 08285e
Cc: stable@vger.kernel.org
Michal Suchanek 08285e
Reported-by: Sachin Sant <sachinp@linux.ibm.com>
Michal Suchanek 08285e
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Michal Suchanek 08285e
Tested-by: Sachin Sant <sachinp@linux.ibm.com>
Michal Suchanek 08285e
[mpe: Change "of node" to "platform device" in change log]
Michal Suchanek 08285e
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Michal Suchanek 08285e
Link: https://lore.kernel.org/r/20220630121654.1939181-1-Jason@zx2c4.com
Michal Suchanek 08285e
Acked-by: Michal Suchanek <msuchanek@suse.de>
Michal Suchanek 08285e
---
Michal Suchanek 08285e
 arch/powerpc/platforms/powernv/rng.c | 16 ++++++++++------
Michal Suchanek 08285e
 1 file changed, 10 insertions(+), 6 deletions(-)
Michal Suchanek 08285e
Michal Suchanek 08285e
diff --git a/arch/powerpc/platforms/powernv/rng.c b/arch/powerpc/platforms/powernv/rng.c
Michal Suchanek 08285e
index 463c78c52cc5..3805ad13b8f3 100644
Michal Suchanek 08285e
--- a/arch/powerpc/platforms/powernv/rng.c
Michal Suchanek 08285e
+++ b/arch/powerpc/platforms/powernv/rng.c
Michal Suchanek 08285e
@@ -176,12 +176,8 @@ static int __init pnv_get_random_long_early(unsigned long *v)
Michal Suchanek 08285e
 		    NULL) != pnv_get_random_long_early)
Michal Suchanek 08285e
 		return 0;
Michal Suchanek 08285e
 
Michal Suchanek 08285e
-	for_each_compatible_node(dn, NULL, "ibm,power-rng") {
Michal Suchanek 08285e
-		if (rng_create(dn))
Michal Suchanek 08285e
-			continue;
Michal Suchanek 08285e
-		/* Create devices for hwrng driver */
Michal Suchanek 08285e
-		of_platform_device_create(dn, NULL, NULL);
Michal Suchanek 08285e
-	}
Michal Suchanek 08285e
+	for_each_compatible_node(dn, NULL, "ibm,power-rng")
Michal Suchanek 08285e
+		rng_create(dn);
Michal Suchanek 08285e
 
Michal Suchanek 08285e
 	if (!ppc_md.get_random_seed)
Michal Suchanek 08285e
 		return 0;
Michal Suchanek 08285e
@@ -205,10 +201,18 @@ void __init pnv_rng_init(void)
Michal Suchanek 08285e
 
Michal Suchanek 08285e
 static int __init pnv_rng_late_init(void)
Michal Suchanek 08285e
 {
Michal Suchanek 08285e
+	struct device_node *dn;
Michal Suchanek 08285e
 	unsigned long v;
Michal Suchanek 08285e
+
Michal Suchanek 08285e
 	/* In case it wasn't called during init for some other reason. */
Michal Suchanek 08285e
 	if (ppc_md.get_random_seed == pnv_get_random_long_early)
Michal Suchanek 08285e
 		pnv_get_random_long_early(&v);
Michal Suchanek 08285e
+
Michal Suchanek 08285e
+	if (ppc_md.get_random_seed == powernv_get_random_long) {
Michal Suchanek 08285e
+		for_each_compatible_node(dn, NULL, "ibm,power-rng")
Michal Suchanek 08285e
+			of_platform_device_create(dn, NULL, NULL);
Michal Suchanek 08285e
+	}
Michal Suchanek 08285e
+
Michal Suchanek 08285e
 	return 0;
Michal Suchanek 08285e
 }
Michal Suchanek 08285e
 machine_subsys_initcall(powernv, pnv_rng_late_init);
Michal Suchanek 08285e
-- 
Michal Suchanek 08285e
2.35.3
Michal Suchanek 08285e