From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DF4AAC433EF for ; Tue, 1 Feb 2022 18:09:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mRLQDDoeSafdbIHCX+F6V5Uu9T0moiymi3AavwuSWR8=; b=Ya15sI/PL+PeQC Juqn5xwuYoFwOQt/3aQAa21kG2LXWj+zzB2QWulPkoZvKXkZ6M5joEuw6v9DWYz++NkkLM/5uRyP7 yNKowU5XuzE6/JSCtlJ2Hlrqhzy4tPsWVPBxy7+fEhvQTc7NqPP7YqkIFvXKpwh0F23dN/JVKXiT+ 3po5lwFYeCpVfRRSjpBqEeddxlS4Ske2YRk9HWv6p52lds4fkQDj9cMeYZrDK/ogItRfuhsVo91Bs cZ6uudgYdHP6SyAh20xMWbQF31KMymhzbK54pAXherLJmJRObQITWKLsjewNdd+D2tKBTX65G43uM +oIP4npRbkHVu+NLBFxA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nExYf-00DHpS-64; Tue, 01 Feb 2022 18:07:13 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:32c8:5054:ff:fe00:142]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nExYb-00DHoh-48 for linux-arm-kernel@lists.infradead.org; Tue, 01 Feb 2022 18:07:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=R0yDYfpqv6G0qJ4TWP//kGvyk3PTrL93oe5AIU5CW6c=; b=alv69qVY7neZLMb2jWDPTVT/gY csZplivBxQyArYTFpA01gUCYds1v3D3yjk/04JAmQowplxF/zLpHbgRywYjI7MZzhpe8b5rTJImCF 8u+e30lFOLj+u6F0l5J9Rnp02ujyEJqlxg61WIA68z6D+DmBLzzHSXtsFpBZcFO6Tvh/Mjmq4Iz8h va2Q1cUEIJ828sh6a+JiVB9LIqPaOD4FVTdK5/xdQ/N6VwVMMxtJtvzVjrpXYTbWhQeRKig5mCKd8 VgsngbRgHt71xMyadE56GZRHyZpxMpQaK/i7az1CJ5mVALEVElJWPO3co4hU1oyuYv2UIbTxLYtP9 quo/zp8w==; Received: from shell.armlinux.org.uk ([fd8f:7570:feb6:1:5054:ff:fe00:4ec]:56978) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nExYR-0000vL-FQ; Tue, 01 Feb 2022 18:06:59 +0000 Received: from linux by shell.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1nExYJ-0002GW-9U; Tue, 01 Feb 2022 18:06:51 +0000 Date: Tue, 1 Feb 2022 18:06:51 +0000 From: "Russell King (Oracle)" To: Marc Zyngier Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, Andre Przywara , Christoffer Dall , Jintack Lim , Haibo Xu , Ganapatrao Kulkarni , Chase Conklin , James Morse , Suzuki K Poulose , Alexandru Elisei , karl.heubaum@oracle.com, mihai.carabas@oracle.com, miguel.luis@oracle.com, kernel-team@android.com Subject: Re: [PATCH v6 17/64] KVM: arm64: nv: Emulate PSTATE.M for a guest hypervisor Message-ID: References: <20220128121912.509006-1-maz@kernel.org> <20220128121912.509006-18-maz@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220128121912.509006-18-maz@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220201_100709_188653_3E675691 X-CRM114-Status: GOOD ( 24.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Jan 28, 2022 at 12:18:25PM +0000, Marc Zyngier wrote: > From: Christoffer Dall > > We can no longer blindly copy the VCPU's PSTATE into SPSR_EL2 and return > to the guest and vice versa when taking an exception to the hypervisor, > because we emulate virtual EL2 in EL1 and therefore have to translate > the mode field from EL2 to EL1 and vice versa. > > This requires keeping track of the state we enter the guest, for which > we transiently use a dedicated flag. > > Signed-off-by: Marc Zyngier > --- > arch/arm64/include/asm/kvm_host.h | 1 + > arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h | 19 ++++++++++++++++- > arch/arm64/kvm/hyp/vhe/switch.c | 24 ++++++++++++++++++++++ > 3 files changed, 43 insertions(+), 1 deletion(-) > > diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h > index 8fffe2888403..fa253f08e0fd 100644 > --- a/arch/arm64/include/asm/kvm_host.h > +++ b/arch/arm64/include/asm/kvm_host.h > @@ -472,6 +472,7 @@ struct kvm_vcpu_arch { > #define KVM_ARM64_DEBUG_STATE_SAVE_SPE (1 << 12) /* Save SPE context if active */ > #define KVM_ARM64_DEBUG_STATE_SAVE_TRBE (1 << 13) /* Save TRBE context if active */ > #define KVM_ARM64_FP_FOREIGN_FPSTATE (1 << 14) > +#define KVM_ARM64_IN_HYP_CONTEXT (1 << 15) /* Guest running in HYP context */ > > #define KVM_GUESTDBG_VALID_MASK (KVM_GUESTDBG_ENABLE | \ > KVM_GUESTDBG_USE_SW_BP | \ > diff --git a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h > index 283f780f5f56..e3689c6ce4cc 100644 > --- a/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h > +++ b/arch/arm64/kvm/hyp/include/hyp/sysreg-sr.h > @@ -157,9 +157,26 @@ static inline void __sysreg_restore_el1_state(struct kvm_cpu_context *ctxt, > write_sysreg_el1(ctxt_sys_reg(ctxt, SPSR_EL1), SYS_SPSR); > } > > +/* Read the VCPU state's PSTATE, but translate (v)EL2 to EL1. */ > +static inline u64 to_hw_pstate(const struct kvm_cpu_context *ctxt) > +{ > + u64 mode = ctxt->regs.pstate & (PSR_MODE_MASK | PSR_MODE32_BIT); > + > + switch (mode) { > + case PSR_MODE_EL2t: > + mode = PSR_MODE_EL1t; > + break; > + case PSR_MODE_EL2h: > + mode = PSR_MODE_EL1h; > + break; > + } > + > + return (ctxt->regs.pstate & ~(PSR_MODE_MASK | PSR_MODE32_BIT)) | mode; > +} > + Wondering if it makes sense to also have the reverse translation as an inline function after the above too, so the two translations are together - but as it's only used (in this patch at least) in switch.c there probably isn't too much point. So: Reviewed-by: Russell King (Oracle) -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last! _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel