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 2DE5EC433F5 for ; Fri, 4 Feb 2022 10:59:49 +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=uAOYVoR5xltvFsWhVrW7F/m/vOmtKZOMjZkKbN8xbDA=; b=PXQP/2bgDJvmSP oRHCsvy9etkCCN475a70e8tqhVWJoA7nX3e0U1vA0nspFaPYDFO1t7+uspfe7ac2SwiPwRrTAORDa eKGgiFmvL/0e3Ek54rBZeRvxXSZR8wYmiE9x5TsZktn3Ks89rEPScwqT2V5uq18Hb7WXsMUVfvd3S d/dsDjbWIlfh/VIhnCVojrRVKvrZ7QhSIa3m2Bi5GLrrg7EC2YlpV2IPWSv5p8Co72kuKMS6/eDkM zelaEbp95F8n7qQDXdxGKcSNRJh5QmOM/E6wySVGd80UgNAyCGYNPCNjmiyadZO+4GCFljCQd8pgU dtaQxbJBsjtz6PuIG3TA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nFwIX-0042df-Ux; Fri, 04 Feb 2022 10:58:38 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nFwIU-0042cw-OW for linux-arm-kernel@lists.infradead.org; Fri, 04 Feb 2022 10:58:36 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 338E22B; Fri, 4 Feb 2022 02:58:33 -0800 (PST) Received: from monolith.localdoman (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6062B3F774; Fri, 4 Feb 2022 02:58:30 -0800 (PST) Date: Fri, 4 Feb 2022 10:58:40 +0000 From: Alexandru Elisei 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 , "Russell King (Oracle)" , James Morse , Suzuki K Poulose , karl.heubaum@oracle.com, mihai.carabas@oracle.com, miguel.luis@oracle.com, kernel-team@android.com Subject: Re: [PATCH v6 19/64] KVM: arm64: nv: Trap SPSR_EL1, ELR_EL1 and VBAR_EL1 from virtual EL2 Message-ID: References: <20220128121912.509006-1-maz@kernel.org> <20220128121912.509006-20-maz@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220128121912.509006-20-maz@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220204_025834_911968_69945CEB X-CRM114-Status: GOOD ( 22.47 ) 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 Hi Marc, On Fri, Jan 28, 2022 at 12:18:27PM +0000, Marc Zyngier wrote: > From: Jintack Lim > > For the same reason we trap virtual memory register accesses at virtual > EL2, we need to trap SPSR_EL1, ELR_EL1 and VBAR_EL1 accesses. ARM v8.3 > introduces the HCR_EL2.NV1 bit to be able to trap on those register > accesses in EL1. Do not set this bit until the whole nesting support is > completed. > > Signed-off-by: Jintack Lim > Signed-off-by: Marc Zyngier > --- > arch/arm64/kvm/sys_regs.c | 29 ++++++++++++++++++++++++++++- > 1 file changed, 28 insertions(+), 1 deletion(-) > > diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c > index 9d3520f1d17a..4f2bcc1e0c25 100644 > --- a/arch/arm64/kvm/sys_regs.c > +++ b/arch/arm64/kvm/sys_regs.c > @@ -1650,6 +1650,30 @@ static bool access_sp_el1(struct kvm_vcpu *vcpu, > return true; > } > > +static bool access_elr(struct kvm_vcpu *vcpu, > + struct sys_reg_params *p, > + const struct sys_reg_desc *r) > +{ > + if (p->is_write) > + vcpu_write_sys_reg(vcpu, p->regval, ELR_EL1); > + else > + p->regval = vcpu_read_sys_reg(vcpu, ELR_EL1); Going over the patch again, I was a bit confused why access_elr() uses vcpu_{read,write}_sys_reg(), but access_spsr() uses __vcpu_sys_reg(). In the end, vcpu_{read,write}_sys_reg() will write to the shadow copy of the registers, as the guest is executing at virtual non-VHE EL2, so the two are equivalent. It's obviously me nitpicking, but the inconsistency is unexpected. How about using vcpu_{read,write}_sys_reg() for access_spsr() below? Thanks, Alex > + > + return true; > +} > + > +static bool access_spsr(struct kvm_vcpu *vcpu, > + struct sys_reg_params *p, > + const struct sys_reg_desc *r) > +{ > + if (p->is_write) > + __vcpu_sys_reg(vcpu, SPSR_EL1) = p->regval; > + else > + p->regval = __vcpu_sys_reg(vcpu, SPSR_EL1); > + > + return true; > +} > + > static bool access_spsr_el2(struct kvm_vcpu *vcpu, > struct sys_reg_params *p, > const struct sys_reg_desc *r) > @@ -1812,6 +1836,9 @@ static const struct sys_reg_desc sys_reg_descs[] = { > PTRAUTH_KEY(APDB), > PTRAUTH_KEY(APGA), > > + { SYS_DESC(SYS_SPSR_EL1), access_spsr}, > + { SYS_DESC(SYS_ELR_EL1), access_elr}, > + > { SYS_DESC(SYS_AFSR0_EL1), access_vm_reg, reset_unknown, AFSR0_EL1 }, > { SYS_DESC(SYS_AFSR1_EL1), access_vm_reg, reset_unknown, AFSR1_EL1 }, > { SYS_DESC(SYS_ESR_EL1), access_vm_reg, reset_unknown, ESR_EL1 }, > @@ -1859,7 +1886,7 @@ static const struct sys_reg_desc sys_reg_descs[] = { > { SYS_DESC(SYS_LORC_EL1), trap_loregion }, > { SYS_DESC(SYS_LORID_EL1), trap_loregion }, > > - { SYS_DESC(SYS_VBAR_EL1), NULL, reset_val, VBAR_EL1, 0 }, > + { SYS_DESC(SYS_VBAR_EL1), access_rw, reset_val, VBAR_EL1, 0 }, > { SYS_DESC(SYS_DISR_EL1), NULL, reset_val, DISR_EL1, 0 }, > > { SYS_DESC(SYS_ICC_IAR0_EL1), write_to_read_only }, > -- > 2.30.2 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel