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 D8836C52D7B for ; Tue, 13 Aug 2024 15:46:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=iWxWg4MMG9BBmUO0U8csQySRb5EGyApB4HPYT/6hwpE=; b=PxiH/SIXlci7cleOIIvI138wnp 2A0kBoaq6FKbY+hbTpY/5r9LhZuJw2rcx1iIBok5heO28vuQxdRogf5243tYtHsdzhOvSJ+6ttQpK fLENfRx6qHjo1B1vNHQOUJDtZ4lyqLPT8SLj/Rgd78rNVg+GuZIJTwFqDzlnWVNCWc8Rm1bIUWxYm O5ZkFvsE/7wnGKI6haSMQ3x6C0XVhCNSBFJ43QMF4inKPhWxnWMwpCrbTATvXgF6yA2Xih4PqncJ+ D7/5CLE7OXJPKKhQ3+yVt+F0Lop5AK+5C2EO641IBfz4iBuQOuGBeNUfTgPdxq0A/BYUuF6R3lDOR xAL08KAw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdtjD-00000004Fnz-35Df; Tue, 13 Aug 2024 15:46:31 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdtib-00000004FiG-3WHR for linux-arm-kernel@lists.infradead.org; Tue, 13 Aug 2024 15:45:55 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id ABA466177E; Tue, 13 Aug 2024 15:45:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F27DC4AF09; Tue, 13 Aug 2024 15:45:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723563952; bh=qiupYbycqVBit5agDXmiS2ivXVrYBP8IffrAeg8D5Vw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=OzzD2/d9xpMH/LzWE9QUn7DlL0zA0MeRBeAmcl4kZeEpC6zuhxBMlUouGmd7/GT3n Ofmx9QLwqa6+UJc5T962vuEviLaGv62x4u56b2l5LYf1qG+2HXUgc9T/9Gzqr81a7O LW1+RIM9F7KzscDDD+rMShK/cWent4kd7oHqIqJBuNcFO3wKfHrvjnnHJvdtur2eCU b1LiGR0c6RC8tM95bCfWEOgEhOi644mvNA+5YZb0fhgQ/mRfuEOckBhB79uTOx+vD1 XqkzRwEQ2Qp3yP1TfOUoDJpSorluR8cDblTTEotfgGuEZYNoaQEOkFBTsDsRRSe4aD NMquau0YWlYKg== Received: from sofa.misterjones.org ([185.219.108.64] helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1sdtiY-003PH1-FD; Tue, 13 Aug 2024 16:45:50 +0100 Date: Tue, 13 Aug 2024 16:45:46 +0100 Message-ID: <878qx05sut.wl-maz@kernel.org> From: Marc Zyngier To: Joey Gouly Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Alexandru Elisei Subject: Re: [PATCH 09/10] KVM: arm64: Handle PIR{,E0}_EL2 traps In-Reply-To: <20240813152452.GD3321997@e124191.cambridge.arm.com> References: <20240813144738.2048302-1-maz@kernel.org> <20240813144738.2048302-10-maz@kernel.org> <20240813152452.GD3321997@e124191.cambridge.arm.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.4 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: joey.gouly@arm.com, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, alexandru.elisei@arm.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240813_084553_986461_4D24B86C X-CRM114-Status: GOOD ( 28.15 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, 13 Aug 2024 16:24:52 +0100, Joey Gouly wrote: > > On Tue, Aug 13, 2024 at 03:47:37PM +0100, Marc Zyngier wrote: > > Add the FEAT_S1PIE EL2 registers the sysreg descriptor array so that > > they can be handled as a trap. > > > > Access to these registers is conditionned on ID_AA64MMFR3_EL1.S1PIE > > being advertised. > > > > Similarly to other other changes, PIRE0_EL2 is guaranteed to trap > > thanks to the D22677 update to the architecture.. > > > > Signed-off-by: Marc Zyngier > > --- > > arch/arm64/kvm/sys_regs.c | 14 ++++++++++++++ > > 1 file changed, 14 insertions(+) > > > > diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c > > index 52250db3c122..a5f604e24e05 100644 > > --- a/arch/arm64/kvm/sys_regs.c > > +++ b/arch/arm64/kvm/sys_regs.c > > @@ -346,6 +346,18 @@ static bool access_rw(struct kvm_vcpu *vcpu, > > return true; > > } > > > > +static bool check_s1pie_access_rw(struct kvm_vcpu *vcpu, > > + struct sys_reg_params *p, > > + const struct sys_reg_desc *r) > > +{ > > + if (!kvm_has_feat(vcpu->kvm, ID_AA64MMFR3_EL1, S1PIE, IMP)) { > > + kvm_inject_undefined(vcpu); > > + return false; > > + } > > + > > + return access_rw(vcpu, p, r); > > +} > > + > > /* > > * See note at ARMv7 ARM B1.14.4 (TL;DR: S/W ops are not easily virtualized). > > */ > > @@ -2827,6 +2839,8 @@ static const struct sys_reg_desc sys_reg_descs[] = { > > EL2_REG(HPFAR_EL2, access_rw, reset_val, 0), > > > > EL2_REG(MAIR_EL2, access_rw, reset_val, 0), > > + EL2_REG(PIRE0_EL2, check_s1pie_access_rw, reset_val, 0), > > + EL2_REG(PIR_EL2, check_s1pie_access_rw, reset_val, 0), > > EL2_REG(AMAIR_EL2, access_rw, reset_val, 0), > > > > EL2_REG(VBAR_EL2, access_rw, reset_val, 0), > > I think we should also use this for PIR_EL1 / PIRE0_EL1? We have NULL for their access field. > > { SYS_DESC(SYS_PIR_EL1), NULL, reset_unknown, PIR_EL1 }, I don't think we need this. In general, the EL1 FEAT_S1PIE registers are directly accessed by the VM, and do not trap. However, if the VM has been configured to not expose S1PIE, then we set the corresponding FGU bits in kvm_calculate_traps(): if (!kvm_has_feat(kvm, ID_AA64MMFR3_EL1, S1PIE, IMP)) kvm->arch.fgu[HFGxTR_GROUP] |= (HFGxTR_EL2_nPIRE0_EL1 | HFGxTR_EL2_nPIR_EL1); The effect of this is that we don't even make to the sysreg array, and inject an UNDEF directly from the point of decoding the trap (see the beginning of triage_sysreg_trap()). For EL2 registers, there is no concept of FGT since they always trap, so no architectural trick we can play to shortcut the handling. Therefore we make it to the handler and have to triage things there. Does it make sense? M. -- Without deviation from the norm, progress is not possible.