Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3091159rwb; Mon, 15 Aug 2022 17:54:45 -0700 (PDT) X-Google-Smtp-Source: AA6agR67FyR7vSpEeGaWC9zolk7vhoeWaIgX8FTWDiAMSVwiv4NCUU97ln2Hi5BzBXOZCADyy1UX X-Received: by 2002:a17:906:6a28:b0:731:48a0:71d with SMTP id qw40-20020a1709066a2800b0073148a0071dmr11602947ejc.249.1660611284956; Mon, 15 Aug 2022 17:54:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660611284; cv=none; d=google.com; s=arc-20160816; b=Ddf/8u9n/UQRCYkqKw1gNqjqlY1OD85XgSFcpV1RBq4R12K+EU24t8gCMVBCHayZ8F Vrq0xi+vRzwIUg8naPi8ATUEnGRKLcmPLQCpSucPnQtSNiKBNlpfbX8FPuGr6ysn0S/y pXvTN8in6OJXUNG6FStg/dOU45TYjVXCUyc1d51Qr37Y6kpnskjZrR0FPjoYbPZ3XR6d uN/MXpfkWstf/K6J90UEn1tTPk1gUaZcqmjnRZR7HtcuMCNkd6n0+WbFQDVx/+1XIguy EuLKwA8H3wJ4vfZDCGtUBMoFBmelCgbI5O0k+OEk0lZB8xUBzKMft+XhA+sqd4s4uPF/ jC2Q== 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=N9wpxrgyRd8j158bkJVIIKOSg8V6yEgZ+Xq0qiShdpQ=; b=cYoRlyySYsz8Sp7G0/7cQK4y6QDjRnb8eDlL6oU90FvCqyYIqo1ljBVpyuoZTFgWeP mDDRwvs3cQ7OR9pYvp1DMpxs2vENXSHidICz5Tp5NaB4LrygxGS6Y6fkhowLhB+jqEWt RtMImJDTMlK5b1GR5mfwTMpHA2JNW0kvsWSkSVmjsE4KuDxZFtrAagJzkMrtC7SWPfPX 7bZk1Hh9HBlQ0GSpvIIqVE3fUR4dBrnCO4y4YzYdMSOWgzwY2XHzexcUvXIou+HNlwg5 zOT6atJaJ3GmoEVqmivgltDA+epb8yQptLiDitk0qa/L/llOMooJkOI2WCftpH5gTF1z KUUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=evaDNqB9; 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 o6-20020a1709062e8600b007304fac484fsi7632101eji.466.2022.08.15.17.54.19; Mon, 15 Aug 2022 17:54:44 -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=evaDNqB9; 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 S1347703AbiHOXbQ (ORCPT + 99 others); Mon, 15 Aug 2022 19:31:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245481AbiHOXZt (ORCPT ); Mon, 15 Aug 2022 19:25:49 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BA8DBA168; Mon, 15 Aug 2022 13:06:05 -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 B4F3FB81135; Mon, 15 Aug 2022 20:06:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A2CAC433D6; Mon, 15 Aug 2022 20:06:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660593962; bh=1XOe91fxNjGIb2u9g3lgu/kzddDaw0ZvQ1Xl6XRc3yk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=evaDNqB9QF9C/jNwSjmm/FNDqg3wMpTnZwbnSXTvfERcQHx2E0uDQwCqTww+CbvWu BV5KBhriCOD26Dvp81jfrcON9T6JwCgHfAkguHNkatvZTathJqSHJ55nIUwCllxmje KZBm6RLVfbLrMGNJDyF/YLQxIK3lzz69F9fNi1ig= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Jason A. Donenfeld" , Sachin Sant , Michael Ellerman , Sasha Levin Subject: [PATCH 5.18 1035/1095] powerpc/powernv/kvm: Use darn for H_RANDOM on Power9 Date: Mon, 15 Aug 2022 20:07:14 +0200 Message-Id: <20220815180511.894527899@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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 [ Upstream commit 7ef3d06f1bc4a5e62273726f3dc2bd258ae1c71f ] The existing logic in KVM to support guests calling H_RANDOM only works on Power8, because it looks for an RNG in the device tree, but on Power9 we just use darn. In addition the existing code needs to work in real mode, so we have the special cased powernv_get_random_real_mode() to deal with that. Instead just have KVM call ppc_md.get_random_seed(), and do the real mode check inside of there, that way we use whatever RNG is available, including darn on Power9. Fixes: e928e9cb3601 ("KVM: PPC: Book3S HV: Add fast real-mode H_RANDOM implementation.") Cc: stable@vger.kernel.org # v4.1+ Signed-off-by: Jason A. Donenfeld Tested-by: Sachin Sant [mpe: Rebase on previous commit, update change log appropriately] Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20220727143219.2684192-2-mpe@ellerman.id.au Signed-off-by: Sasha Levin --- arch/powerpc/include/asm/archrandom.h | 5 ---- arch/powerpc/kvm/book3s_hv_builtin.c | 7 +++--- arch/powerpc/platforms/powernv/rng.c | 36 ++++++--------------------- 3 files changed, 12 insertions(+), 36 deletions(-) diff --git a/arch/powerpc/include/asm/archrandom.h b/arch/powerpc/include/asm/archrandom.h index 9a53e29680f4..258174304904 100644 --- a/arch/powerpc/include/asm/archrandom.h +++ b/arch/powerpc/include/asm/archrandom.h @@ -38,12 +38,7 @@ static inline bool __must_check arch_get_random_seed_int(unsigned int *v) #endif /* CONFIG_ARCH_RANDOM */ #ifdef CONFIG_PPC_POWERNV -int powernv_hwrng_present(void); int powernv_get_random_long(unsigned long *v); -int powernv_get_random_real_mode(unsigned long *v); -#else -static inline int powernv_hwrng_present(void) { return 0; } -static inline int powernv_get_random_real_mode(unsigned long *v) { return 0; } #endif #endif /* _ASM_POWERPC_ARCHRANDOM_H */ diff --git a/arch/powerpc/kvm/book3s_hv_builtin.c b/arch/powerpc/kvm/book3s_hv_builtin.c index 7e52d0beee77..5e4251b76e75 100644 --- a/arch/powerpc/kvm/book3s_hv_builtin.c +++ b/arch/powerpc/kvm/book3s_hv_builtin.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include @@ -176,13 +176,14 @@ EXPORT_SYMBOL_GPL(kvmppc_hcall_impl_hv_realmode); int kvmppc_hwrng_present(void) { - return powernv_hwrng_present(); + return ppc_md.get_random_seed != NULL; } EXPORT_SYMBOL_GPL(kvmppc_hwrng_present); long kvmppc_rm_h_random(struct kvm_vcpu *vcpu) { - if (powernv_get_random_real_mode(&vcpu->arch.regs.gpr[4])) + if (ppc_md.get_random_seed && + ppc_md.get_random_seed(&vcpu->arch.regs.gpr[4])) return H_SUCCESS; return H_HARDWARE; diff --git a/arch/powerpc/platforms/powernv/rng.c b/arch/powerpc/platforms/powernv/rng.c index 2287c9cd0cd5..d19305292e1e 100644 --- a/arch/powerpc/platforms/powernv/rng.c +++ b/arch/powerpc/platforms/powernv/rng.c @@ -29,15 +29,6 @@ struct powernv_rng { static DEFINE_PER_CPU(struct powernv_rng *, powernv_rng); -int powernv_hwrng_present(void) -{ - struct powernv_rng *rng; - - rng = get_cpu_var(powernv_rng); - put_cpu_var(rng); - return rng != NULL; -} - static unsigned long rng_whiten(struct powernv_rng *rng, unsigned long val) { unsigned long parity; @@ -58,19 +49,6 @@ static unsigned long rng_whiten(struct powernv_rng *rng, unsigned long val) return val; } -int powernv_get_random_real_mode(unsigned long *v) -{ - struct powernv_rng *rng; - - rng = raw_cpu_read(powernv_rng); - if (!rng) - return 0; - - *v = rng_whiten(rng, __raw_rm_readq(rng->regs_real)); - - return 1; -} - static int powernv_get_random_darn(unsigned long *v) { unsigned long val; @@ -107,12 +85,14 @@ int powernv_get_random_long(unsigned long *v) { struct powernv_rng *rng; - rng = get_cpu_var(powernv_rng); - - *v = rng_whiten(rng, in_be64(rng->regs)); - - put_cpu_var(rng); - + if (mfmsr() & MSR_DR) { + rng = get_cpu_var(powernv_rng); + *v = rng_whiten(rng, in_be64(rng->regs)); + put_cpu_var(rng); + } else { + rng = raw_cpu_read(powernv_rng); + *v = rng_whiten(rng, __raw_rm_readq(rng->regs_real)); + } return 1; } EXPORT_SYMBOL_GPL(powernv_get_random_long); -- 2.35.1