Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2907733iog; Mon, 27 Jun 2022 05:32:29 -0700 (PDT) X-Google-Smtp-Source: AGRyM1stCiOjOW0J6kRlLUYvqsXESZzt5h2XyZKus6Ewec6tvxEm9qkY9FAw1sAdVFek/vARR0FR X-Received: by 2002:a17:902:e844:b0:16a:32d9:722c with SMTP id t4-20020a170902e84400b0016a32d9722cmr14372307plg.40.1656333148752; Mon, 27 Jun 2022 05:32:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656333148; cv=none; d=google.com; s=arc-20160816; b=zYu/1G76iz/lSOTeRXFqxAr0EzCyq2rBBh+PVRHQrML6hDLFZCBXkZbd2HqdYggIGG u6ib7qM0ovVUdfqzQ90NIsV+DUZZBn8bhT/p4wS/DaLVG9ATbEAj+WNcgIr0I0m3v6ge 6A2rrSW8J2ta54F8+mX3wo9h5q6g/xUY4PUM69/Ha9OArpnXNIuurkY+B+vO6S8rZg1t GlNvXFGkCFNJIqbWmdIrm4EIjBencdfUl3qUZ76oGcDS/PAGKnEZ5YKbPuFU8ETj2jTn LIwDjp9eHCdpZbIxktw+OALlUH5ysO+BIrrcGdb4EGRA3xyIiaJZP+LILaO06PoPPqop RfZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=JvrUKPtea92s204/lg298mEPqcDvggAimfzLb1wWepk=; b=nOE5wsVa+ZZ5dO7hiQ5BQ5Pzfi2j0YVm/EydXbLqQrgIak2Rym3uhDXgbXGcM1LPIU 44YOUaZFVg8TJG7hB6MKkEBkjJfO+G7aNT4QCD87tOClTGvEm1+ApwmPG/3C/R8FzV84 6zEs7mHbRJv6PW8eN3EQjIncpVJ40zA1quhfSggnWHhvFOsIXmbUfCIOnNw5BanVXYEs EC7x6UVgPYUgL9qvITnTK11HixicElA9OdB7sJ/VQCfmM14xw4vTYUQ+d5uJo3egE6Kc u/dtJu4guIlEvawFGL25d9tBfNbvyAnouW+hPdl2126mJKa21zCQ5rrz5TQdBRqJG2Ol Kfdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2cM51C4D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b9-20020a170903228900b0016184b32d35si8219819plh.174.2022.06.27.05.32.16; Mon, 27 Jun 2022 05:32:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2cM51C4D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239268AbiF0L7V (ORCPT + 99 others); Mon, 27 Jun 2022 07:59:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238742AbiF0Lwd (ORCPT ); Mon, 27 Jun 2022 07:52:33 -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 5F290B878; Mon, 27 Jun 2022 04:45:29 -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 16E18B80D37; Mon, 27 Jun 2022 11:45:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 605B5C36AE2; Mon, 27 Jun 2022 11:45:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656330326; bh=xOz26b464Jr+wd4R4JClEqCLPVOgcpYimj+WmATziVQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2cM51C4DaTBnm8TLkLr8JTANy4fz94uQ+aQTRs+7ZCsj0OK2AXzvEQd5W1N5jvgLj QjjB9TivitBLrftAdMgXmKlTZSkvlk7HjU3vkreEqHTWW7KaSB6bjebbh+34PAHCJ4 BMKq7+/0jqWgfTTlusd0OgqeJFI/cLwAB5gi+phA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Jason A. Donenfeld" , Christophe Leroy , Michael Ellerman Subject: [PATCH 5.18 160/181] powerpc/powernv: wire up rng during setup_arch Date: Mon, 27 Jun 2022 13:22:13 +0200 Message-Id: <20220627111949.324846589@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220627111944.553492442@linuxfoundation.org> References: <20220627111944.553492442@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jason A. Donenfeld commit f3eac426657d985b97c92fa5f7ae1d43f04721f3 upstream. 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. Complicating things, however, is that POWER8 systems need some per-cpu state and kmalloc, which isn't available at this stage. So we split things up into an early phase and a later opportunistic phase. This commit also removes some noisy log messages that don't add much. Fixes: a4da0d50b2a0 ("powerpc: Implement arch_get_random_long/int() for powernv") Cc: stable@vger.kernel.org # v3.13+ Signed-off-by: Jason A. Donenfeld Reviewed-by: Christophe Leroy [mpe: Add of_node_put(), use pnv naming, minor change log editing] Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20220621140849.127227-1-Jason@zx2c4.com Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/platforms/powernv/powernv.h | 2 + arch/powerpc/platforms/powernv/rng.c | 52 +++++++++++++++++++++---------- arch/powerpc/platforms/powernv/setup.c | 2 + 3 files changed, 40 insertions(+), 16 deletions(-) --- 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, u32 __init memcons_get_size(struct memcons *mc); struct memcons *__init memcons_init(struct device_node *node, const char *mc_prop_name); +void pnv_rng_init(void); + #endif /* _POWERNV_H */ --- a/arch/powerpc/platforms/powernv/rng.c +++ b/arch/powerpc/platforms/powernv/rng.c @@ -17,6 +17,7 @@ #include #include #include +#include "powernv.h" #define DARN_ERR 0xFFFFFFFFFFFFFFFFul @@ -28,7 +29,6 @@ struct powernv_rng { static DEFINE_PER_CPU(struct powernv_rng *, powernv_rng); - int powernv_hwrng_present(void) { struct powernv_rng *rng; @@ -98,9 +98,6 @@ static int __init initialise_darn(void) return 0; } } - - pr_warn("Unable to use DARN for get_random_seed()\n"); - return -EIO; } @@ -163,32 +160,55 @@ static __init int rng_create(struct devi 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) +static int __init pnv_get_random_long_early(unsigned long *v) { struct device_node *dn; - int rc; + + if (!slab_is_available()) + return 0; + + if (cmpxchg(&ppc_md.get_random_seed, pnv_get_random_long_early, + NULL) != pnv_get_random_long_early) + return 0; for_each_compatible_node(dn, NULL, "ibm,power-rng") { - rc = rng_create(dn); - if (rc) { - pr_err("Failed creating rng for %pOF (%d).\n", - dn, rc); + if (rng_create(dn)) continue; - } - /* Create devices for hwrng driver */ of_platform_device_create(dn, NULL, NULL); } - initialise_darn(); + if (!ppc_md.get_random_seed) + return 0; + return ppc_md.get_random_seed(v); +} + +void __init pnv_rng_init(void) +{ + struct device_node *dn; + /* Prefer darn over the rest. */ + if (!initialise_darn()) + return; + + dn = of_find_compatible_node(NULL, NULL, "ibm,power-rng"); + if (dn) + ppc_md.get_random_seed = pnv_get_random_long_early; + + of_node_put(dn); +} + +static int __init pnv_rng_late_init(void) +{ + unsigned long v; + /* In case it wasn't called during init for some other reason. */ + if (ppc_md.get_random_seed == pnv_get_random_long_early) + pnv_get_random_long_early(&v); return 0; } -machine_subsys_initcall(powernv, rng_init); +machine_subsys_initcall(powernv, pnv_rng_late_init); --- 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(); /* XXX PMCS */ + + pnv_rng_init(); } static void __init pnv_init(void)