From nobody Wed Apr 29 09:34:22 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 901D0CCA47A for ; Sat, 11 Jun 2022 15:10:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237745AbiFKPKg (ORCPT ); Sat, 11 Jun 2022 11:10:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237639AbiFKPK3 (ORCPT ); Sat, 11 Jun 2022 11:10:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6891D38A6; Sat, 11 Jun 2022 08:10:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D4C7C61012; Sat, 11 Jun 2022 15:10:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4952C34116; Sat, 11 Jun 2022 15:10:26 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="fi/Fit2A" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1654960225; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WtiQjpbrmFMKm8d6BMUt1LLUM1Fss83aLjhZrpuPa8s=; b=fi/Fit2Ac2yfEKIE3LESs5pbpE5Qy0X/dsCadZc398g2mcii6u14EquZ3G+PUeCkNzSrPw 9ll8uim29ds+8p9hfSOr4pBW4oacKLCFUdjU/aVxRl60a1nm9EUXeGn7pMo3zOKbeByuEp qBfMr4kkW2NZQO9oNr/QhqtuW8uA308= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 01cd7939 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Sat, 11 Jun 2022 15:10:25 +0000 (UTC) From: "Jason A. Donenfeld" To: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Michael Ellerman Cc: "Jason A. Donenfeld" , stable@vger.kernel.org, Christophe Leroy Subject: [PATCH v3 1/3] powerpc/microwatt: wire up rng during setup_arch Date: Sat, 11 Jun 2022 17:10:13 +0200 Message-Id: <20220611151015.548325-2-Jason@zx2c4.com> In-Reply-To: <20220611151015.548325-1-Jason@zx2c4.com> References: <20220611151015.548325-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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. This commit also removes some noisy log messages that don't add much. Cc: stable@vger.kernel.org Cc: Michael Ellerman Cc: Christophe Leroy Fixes: c25769fddaec ("powerpc/microwatt: Add support for hardware random nu= mber generator") Signed-off-by: Jason A. Donenfeld Reviewed-by: Christophe Leroy --- arch/powerpc/platforms/microwatt/microwatt.h | 7 +++++++ arch/powerpc/platforms/microwatt/rng.c | 10 +++------- arch/powerpc/platforms/microwatt/setup.c | 8 ++++++++ 3 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 arch/powerpc/platforms/microwatt/microwatt.h diff --git a/arch/powerpc/platforms/microwatt/microwatt.h b/arch/powerpc/pl= atforms/microwatt/microwatt.h new file mode 100644 index 000000000000..335417e95e66 --- /dev/null +++ b/arch/powerpc/platforms/microwatt/microwatt.h @@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _MICROWATT_H +#define _MICROWATT_H + +void microwatt_rng_init(void); + +#endif /* _MICROWATT_H */ diff --git a/arch/powerpc/platforms/microwatt/rng.c b/arch/powerpc/platform= s/microwatt/rng.c index 7bc4d1cbfaf0..8ece87d005c8 100644 --- a/arch/powerpc/platforms/microwatt/rng.c +++ b/arch/powerpc/platforms/microwatt/rng.c @@ -11,6 +11,7 @@ #include #include #include +#include "microwatt.h" =20 #define DARN_ERR 0xFFFFFFFFFFFFFFFFul =20 @@ -29,7 +30,7 @@ static int microwatt_get_random_darn(unsigned long *v) return 1; } =20 -static __init int rng_init(void) +void __init microwatt_rng_init(void) { unsigned long val; int i; @@ -37,12 +38,7 @@ static __init int rng_init(void) for (i =3D 0; i < 10; i++) { if (microwatt_get_random_darn(&val)) { ppc_md.get_random_seed =3D 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/platfo= rms/microwatt/setup.c index 0b02603bdb74..6b32539395a4 100644 --- a/arch/powerpc/platforms/microwatt/setup.c +++ b/arch/powerpc/platforms/microwatt/setup.c @@ -16,6 +16,8 @@ #include #include =20 +#include "microwatt.h" + static void __init microwatt_init_IRQ(void) { xics_init(); @@ -32,10 +34,16 @@ static int __init microwatt_populate(void) } machine_arch_initcall(microwatt, microwatt_populate); =20 +static void __init microwatt_setup_arch(void) +{ + microwatt_rng_init(); +} + define_machine(microwatt) { .name =3D "microwatt", .probe =3D microwatt_probe, .init_IRQ =3D microwatt_init_IRQ, + .setup_arch =3D microwatt_setup_arch, .progress =3D udbg_progress, .calibrate_decr =3D generic_calibrate_decr, }; --=20 2.35.1 From nobody Wed Apr 29 09:34:22 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3741CC43334 for ; Sat, 11 Jun 2022 15:10:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237743AbiFKPKl (ORCPT ); Sat, 11 Jun 2022 11:10:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237788AbiFKPKd (ORCPT ); Sat, 11 Jun 2022 11:10:33 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D023C2B248; Sat, 11 Jun 2022 08:10:32 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 78B0DB8013C; Sat, 11 Jun 2022 15:10:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C450C34116; Sat, 11 Jun 2022 15:10:29 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="Jf/zYard" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1654960228; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QdcNQU1UhQ5cbCNPYnKzZnO7muhDqBUHBRz3u3Gocpo=; b=Jf/zYardCd2cfsyECtXtggUTkQrJ/lSwOjTEtrOF+VdtGXDbsXv9DvnzD2EXhj6qchVSP3 535T/Y19QmFhaZItU7bLjuSqtbhLZoyVL+Se7QssvDyeN7czw+My2qNvy6HHPOBVYm1S2+ 2K2++mq5Z+ghzFW71DX4+rEFv2kvgS0= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 3ce93f86 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Sat, 11 Jun 2022 15:10:27 +0000 (UTC) From: "Jason A. Donenfeld" To: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Michael Ellerman Cc: "Jason A. Donenfeld" , stable@vger.kernel.org, Christophe Leroy Subject: [PATCH v3 2/3] powerpc/powernv: wire up rng during setup_arch Date: Sat, 11 Jun 2022 17:10:14 +0200 Message-Id: <20220611151015.548325-3-Jason@zx2c4.com> In-Reply-To: <20220611151015.548325-1-Jason@zx2c4.com> References: <20220611151015.548325-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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. This commit also removes some noisy log messages that don't add much. Cc: stable@vger.kernel.org Cc: Michael Ellerman Cc: Christophe Leroy Fixes: a4da0d50b2a0 ("powerpc: Implement arch_get_random_long/int() for pow= ernv") Signed-off-by: Jason A. Donenfeld Reviewed-by: Christophe Leroy --- arch/powerpc/platforms/powernv/powernv.h | 2 ++ arch/powerpc/platforms/powernv/rng.c | 18 +++++------------- arch/powerpc/platforms/powernv/setup.c | 2 ++ 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/arch/powerpc/platforms/powernv/powernv.h b/arch/powerpc/platfo= rms/powernv/powernv.h index e297bf4abfcb..fd3f5e1eb10b 100644 --- a/arch/powerpc/platforms/powernv/powernv.h +++ b/arch/powerpc/platforms/powernv/powernv.h @@ -42,4 +42,6 @@ ssize_t memcons_copy(struct memcons *mc, char *to, loff_t= pos, size_t count); u32 __init memcons_get_size(struct memcons *mc); struct memcons *__init memcons_init(struct device_node *node, const char *= mc_prop_name); =20 +void powernv_rng_init(void); + #endif /* _POWERNV_H */ diff --git a/arch/powerpc/platforms/powernv/rng.c b/arch/powerpc/platforms/= powernv/rng.c index e3d44b36ae98..c86bf097e407 100644 --- a/arch/powerpc/platforms/powernv/rng.c +++ b/arch/powerpc/platforms/powernv/rng.c @@ -17,6 +17,7 @@ #include #include #include +#include "powernv.h" =20 #define DARN_ERR 0xFFFFFFFFFFFFFFFFul =20 @@ -84,24 +85,20 @@ static int powernv_get_random_darn(unsigned long *v) return 1; } =20 -static int __init initialise_darn(void) +static void __init initialise_darn(void) { unsigned long val; int i; =20 if (!cpu_has_feature(CPU_FTR_ARCH_300)) - return -ENODEV; + return; =20 for (i =3D 0; i < 10; i++) { if (powernv_get_random_darn(&val)) { ppc_md.get_random_seed =3D powernv_get_random_darn; - return 0; + return; } } - - pr_warn("Unable to use DARN for get_random_seed()\n"); - - return -EIO; } =20 int powernv_get_random_long(unsigned long *v) @@ -163,14 +160,12 @@ static __init int rng_create(struct device_node *dn) =20 rng_init_per_cpu(rng, dn); =20 - pr_info_once("Registering arch random hook.\n"); - ppc_md.get_random_seed =3D powernv_get_random_long; =20 return 0; } =20 -static __init int rng_init(void) +void __init powernv_rng_init(void) { struct device_node *dn; int rc; @@ -188,7 +183,4 @@ static __init int rng_init(void) } =20 initialise_darn(); - - return 0; } -machine_subsys_initcall(powernv, rng_init); diff --git a/arch/powerpc/platforms/powernv/setup.c b/arch/powerpc/platform= s/powernv/setup.c index 824c3ad7a0fa..a5fcb6796b22 100644 --- a/arch/powerpc/platforms/powernv/setup.c +++ b/arch/powerpc/platforms/powernv/setup.c @@ -203,6 +203,8 @@ static void __init pnv_setup_arch(void) pnv_check_guarded_cores(); =20 /* XXX PMCS */ + + powernv_rng_init(); } =20 static void __init pnv_init(void) --=20 2.35.1 From nobody Wed Apr 29 09:34:22 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7F45C433EF for ; Sat, 11 Jun 2022 15:10:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238156AbiFKPKr (ORCPT ); Sat, 11 Jun 2022 11:10:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237777AbiFKPKg (ORCPT ); Sat, 11 Jun 2022 11:10:36 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A59AC29355; Sat, 11 Jun 2022 08:10:34 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 57A85B801BE; Sat, 11 Jun 2022 15:10:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 81D18C3411B; Sat, 11 Jun 2022 15:10:31 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="cGYm9RxK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1654960230; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0LQjJTWz/52luVdReTEzZ+cYNsAEl10033oh+mJalHY=; b=cGYm9RxK/ieb0qRTsBiP6zy/JKkBcHPgu5Cx9SDNte4aAkcrGUDVCAnxZoUpD4TkMmcaNa KpvBn+ezV4HJWNcRH/ghV8nX9stepJVq+/C9HFnVVbYNMPWFwzsEtITiS7uAS7Q0tkXAjZ sY5+ZEQNFeVoYAHUly7UUxwZegz75pE= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id bfdd7694 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Sat, 11 Jun 2022 15:10:30 +0000 (UTC) From: "Jason A. Donenfeld" To: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Michael Ellerman Cc: "Jason A. Donenfeld" , stable@vger.kernel.org, Christophe Leroy Subject: [PATCH v3 3/3] powerpc/pseries: wire up rng during setup_arch Date: Sat, 11 Jun 2022 17:10:15 +0200 Message-Id: <20220611151015.548325-4-Jason@zx2c4.com> In-Reply-To: <20220611151015.548325-1-Jason@zx2c4.com> References: <20220611151015.548325-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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. This commit also removes some noisy log messages that don't add much. Cc: stable@vger.kernel.org Cc: Michael Ellerman Cc: Christophe Leroy Fixes: a489043f4626 ("powerpc/pseries: Implement arch_get_random_long() bas= ed on H_RANDOM") Signed-off-by: Jason A. Donenfeld Reviewed-by: Christophe Leroy --- arch/powerpc/platforms/pseries/pseries.h | 2 ++ arch/powerpc/platforms/pseries/rng.c | 11 +++-------- arch/powerpc/platforms/pseries/setup.c | 1 + 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/arch/powerpc/platforms/pseries/pseries.h b/arch/powerpc/platfo= rms/pseries/pseries.h index f5c916c839c9..1d75b7742ef0 100644 --- a/arch/powerpc/platforms/pseries/pseries.h +++ b/arch/powerpc/platforms/pseries/pseries.h @@ -122,4 +122,6 @@ void pseries_lpar_read_hblkrm_characteristics(void); static inline void pseries_lpar_read_hblkrm_characteristics(void) { } #endif =20 +void pseries_rng_init(void); + #endif /* _PSERIES_PSERIES_H */ diff --git a/arch/powerpc/platforms/pseries/rng.c b/arch/powerpc/platforms/= pseries/rng.c index 6268545947b8..6ddfdeaace9e 100644 --- a/arch/powerpc/platforms/pseries/rng.c +++ b/arch/powerpc/platforms/pseries/rng.c @@ -10,6 +10,7 @@ #include #include #include +#include "pseries.h" =20 =20 static int pseries_get_random_long(unsigned long *v) @@ -24,19 +25,13 @@ static int pseries_get_random_long(unsigned long *v) return 0; } =20 -static __init int rng_init(void) +void __init pseries_rng_init(void) { struct device_node *dn; =20 dn =3D 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 =3D 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/platform= s/pseries/setup.c index afb074269b42..ee4f1db49515 100644 --- a/arch/powerpc/platforms/pseries/setup.c +++ b/arch/powerpc/platforms/pseries/setup.c @@ -839,6 +839,7 @@ static void __init pSeries_setup_arch(void) } =20 ppc_md.pcibios_root_bridge_prepare =3D pseries_root_bridge_prepare; + pseries_rng_init(); } =20 static void pseries_panic(char *str) --=20 2.35.1