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 C4040C3064D for ; Tue, 25 Jun 2024 18:23:17 +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=MRIpyg3XPp2mR7YCwXrYaVzAgfnFmlT45wm3vbPbYus=; b=GbG7PE7IMPN8WxDIxOcK/a6msG LAWJhFY5w4BfmSt6hab6BG6GNCeVY53DbTh5tKiKLh7xJQlxI8DTcgfzti3gXeHh3hMEyJPoZER7M nzifof/MpSzDhlwSCMw6XKfwq16uemrrXH1xX+lN6wHz1qcFsVNZy0yoamQx+LVEGF/+z5uarflT0 5gzzityyWAlEUPEga+k2/7Mw8DOJp99DOrGNvQIjg6VKfDJXxOSjJXIeXrwCUm8RfTmemYk/RLnWZ mWr4iEuNAzvLZ810cxaOUKzqkijfxmo6wVHLrMtaPm8Vs+GOgpc2YhC7WxRzRjqvMIFSljyWJc6kD yyvAZOFQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sMAoq-0000000458q-0C38; Tue, 25 Jun 2024 18:23:04 +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 1sMAoj-0000000456w-3vNP for linux-arm-kernel@lists.infradead.org; Tue, 25 Jun 2024 18:22:59 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 4479361303; Tue, 25 Jun 2024 18:22:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EAC14C32781; Tue, 25 Jun 2024 18:22:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719339777; bh=/246X5qyiuTadGhYcEfeVpQldePfXhG9N1moYjAlUoY=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=VuaJ6BIQnokLd31r5+JJLHUgrccCKNFn7Bowp9jQyJvau818Rp1Y/OW/G2IwCqHzq WD0mF0uQ88HArh+Ntz043hz8z/yCtZj4DBPiqc2vxv8LyU7cwBhmmyqbphl1hLAop7 vzz5ax8l+yCyv95UFLq+XQnmm6R3SeNr0xpF+ZwNGTskfmL5k89li01AB/jEyAIJIJ R71ARwFHY/FyYR500N5RjExLb0oFRucepMGKLEHjSFLvPgtApFHgJw/IRsgIfr9GSx 7vI7J9Fd5DdJXTRFCP2BFu6ybz3tA8jqILfvH1mDbjXqnxk8RDnUuOqGoi22J5G6RJ q7+2uWeLifpaw== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.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 1sMAog-007GEZ-TW; Tue, 25 Jun 2024 19:22:54 +0100 Date: Tue, 25 Jun 2024 19:22:53 +0100 Message-ID: <86r0ckj30i.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 Subject: Re: [PATCH 1/5] KVM: arm64: Correctly honor the presence of FEAT_TCRX In-Reply-To: <20240625143734.GA1517668@e124191.cambridge.arm.com> References: <20240625130042.259175-1-maz@kernel.org> <20240625130042.259175-2-maz@kernel.org> <20240625143734.GA1517668@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.2 (aarch64-unknown-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 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-20240625_112258_086098_F0033DC6 X-CRM114-Status: GOOD ( 28.32 ) 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, 25 Jun 2024 15:37:34 +0100, Joey Gouly wrote: > > On Tue, Jun 25, 2024 at 02:00:37PM +0100, Marc Zyngier wrote: > > We currently blindly enable TCR2_EL1 use in a guest, irrespective > > of the feature set. This is obviously wrong, and we should actually > > honor the guest configuration and handle the possible trap resulting > > from the guest being buggy. > > > > Signed-off-by: Marc Zyngier > > --- > > arch/arm64/include/asm/kvm_arm.h | 2 +- > > arch/arm64/kvm/sys_regs.c | 9 +++++++++ > > 2 files changed, 10 insertions(+), 1 deletion(-) > > > > diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h > > index b2adc2c6c82a5..e6682a3ace5af 100644 > > --- a/arch/arm64/include/asm/kvm_arm.h > > +++ b/arch/arm64/include/asm/kvm_arm.h > > @@ -102,7 +102,7 @@ > > #define HCR_HOST_NVHE_PROTECTED_FLAGS (HCR_HOST_NVHE_FLAGS | HCR_TSC) > > #define HCR_HOST_VHE_FLAGS (HCR_RW | HCR_TGE | HCR_E2H) > > > > -#define HCRX_GUEST_FLAGS (HCRX_EL2_SMPME | HCRX_EL2_TCR2En) > > +#define HCRX_GUEST_FLAGS (HCRX_EL2_SMPME) > > #define HCRX_HOST_FLAGS (HCRX_EL2_MSCEn | HCRX_EL2_TCR2En | HCRX_EL2_EnFPM) > > > > /* TCR_EL2 Registers bits */ > > diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c > > index 22b45a15d0688..71996d36f3751 100644 > > --- a/arch/arm64/kvm/sys_regs.c > > +++ b/arch/arm64/kvm/sys_regs.c > > @@ -383,6 +383,12 @@ static bool access_vm_reg(struct kvm_vcpu *vcpu, > > bool was_enabled = vcpu_has_cache_enabled(vcpu); > > u64 val, mask, shift; > > > > + if (reg_to_encoding(r) == SYS_TCR2_EL1 && > > + !kvm_has_feat(vcpu->kvm, ID_AA64MMFR3_EL1, TCRX, IMP)) { > > + kvm_inject_undefined(vcpu); > > + return false; > > + } > > + > > If we need to start doing this with more vm(sa) registers, it might make sense > to think of a way to do this without putting a big if/else in here. For now > this is seems fine. One possible solution would be to mimic the FGU behaviour and have a shadow version of HCRX_EL2 that only indicates the trap routing code that something trapped through that bit needs to UNDEF. And yes, I'd expect we'll see a whole lot of new VMSA registers going the same way. > > > BUG_ON(!p->is_write); > > > > get_access_mask(r, &mask, &shift); > > @@ -4060,6 +4066,9 @@ void kvm_init_sysreg(struct kvm_vcpu *vcpu) > > > > if (kvm_has_feat(kvm, ID_AA64ISAR2_EL1, MOPS, IMP)) > > vcpu->arch.hcrx_el2 |= (HCRX_EL2_MSCEn | HCRX_EL2_MCE2); > > + > > + if (kvm_has_feat(kvm, ID_AA64MMFR3_EL1, TCRX, IMP)) > > + vcpu->arch.hcrx_el2 |= HCRX_EL2_TCR2En; > > } > > > > if (test_bit(KVM_ARCH_FLAG_FGU_INITIALIZED, &kvm->arch.flags)) > > Reviewed-by: Joey Gouly Thanks! M. -- Without deviation from the norm, progress is not possible.