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 0DF07D10F20 for ; Wed, 26 Nov 2025 10:23:54 +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=qsNVWR8CDRZLg8dU4k4zTbHDGYPRZNVDAiXvM+tJl24=; b=EAKvUHptD410Pp2R7Vb3AhKmLb 1ygU7ON8/mXfl+6GHwoostfeUxxusavXw5P/vvoYzLsgHUJq6RcWZ0eIEJgQtKEt40FNZu0p1RbNq ubIUm5Cnz9iSs4mBp9+9m6In78bTpF2IxZyhWnb6GErQ0r1d/9rTKg7rD+Lp3kenmSO1Vh784JFpm HU51hKblycMy4xnUa2F3i2qruJXWA+sCgxOGyNJPxqH8Eil9qKxYjtvqCw/jYBYAT25dLTde5Cz8Z XPiA/4swdffJCPoWNsu2vDU/BYqbhbgpVnxgJu+4EB5mt+bvP8qBfXIoblXNG5/sQJHX+fC0kQ9sU raN4k8XA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vOCge-0000000EmDF-3GsH; Wed, 26 Nov 2025 10:23:48 +0000 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vOCgc-0000000EmCg-0VFf for linux-arm-kernel@lists.infradead.org; Wed, 26 Nov 2025 10:23:47 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 9D4E143EB6; Wed, 26 Nov 2025 10:23:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77F8CC113D0; Wed, 26 Nov 2025 10:23:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1764152623; bh=//yexraZTyis7WS73zDqwOVJGLnWrX9QT5S4ffp+3a0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=tTxjDVV5hlY1bGW3xlqxUSUlJrOjBiQ7eypyVbZX8NhieoajKUHRXVL+4USS/XJdV bSkQsIi3ub8VWBkEynowfUpOL1xLifXn/izS7tNP6XbNsPCL6DyleiTDLz39hNHHUJ 49rh7/UmeAalAmE8SaHa5x6jWvHoBDcsLyZyJB6A9tVXNfCg8jfV07kMIKSU9kG/pe 8f94800RO+oT6hfOGNNSR2xvoFNziJ+jR9CnuQenMLRWYYGlYkVrQJ/T1th+CZQ1vI LqE440HsXh64t2GavUBiiYTMPmTrHkC8R0ZzeYgMdrOEKJkpgB4X/9yljtZwDVdJCX t6h3w4fliyilg== 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.98.2) (envelope-from ) id 1vOCgX-00000008R5l-2455; Wed, 26 Nov 2025 10:23:41 +0000 Date: Wed, 26 Nov 2025 10:23:41 +0000 Message-ID: <868qftqehe.wl-maz@kernel.org> From: Marc Zyngier To: Fuad Tabba Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, oliver.upton@linux.dev, will@kernel.org, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, vladimir.murzin@arm.com Subject: Re: [PATCH v5 2/9] KVM: arm64: Fix Trace Buffer trap polarity for protected VMs In-Reply-To: <20251118103807.707500-3-tabba@google.com> References: <20251118103807.707500-1-tabba@google.com> <20251118103807.707500-3-tabba@google.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/30.1 (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: tabba@google.com, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, oliver.upton@linux.dev, will@kernel.org, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, vladimir.murzin@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-20251126_022346_246750_A4934D07 X-CRM114-Status: GOOD ( 21.92 ) 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, 18 Nov 2025 10:37:59 +0000, Fuad Tabba wrote: > > The E2TB bits in MDCR_EL2 control trapping of Trace Buffer system > register accesses. These accesses are trapped to EL2 when the bits are > clear. > > The trap initialization logic for protected VMs in pvm_init_traps_mdcr() > had the polarity inverted. When a guest did not support the Trace Buffer > feature, the code was setting E2TB. This incorrectly disabled the trap, > potentially allowing a protected guest to access registers for a feature > it was not given. > > Fix this by inverting the operation. > > Fixes: f50758260bff ("KVM: arm64: Group setting traps for protected VMs by control register") > Signed-off-by: Fuad Tabba > --- > arch/arm64/kvm/hyp/nvhe/pkvm.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/arm64/kvm/hyp/nvhe/pkvm.c b/arch/arm64/kvm/hyp/nvhe/pkvm.c > index 8d06a246dfd1..f6f8996c4f97 100644 > --- a/arch/arm64/kvm/hyp/nvhe/pkvm.c > +++ b/arch/arm64/kvm/hyp/nvhe/pkvm.c > @@ -118,7 +118,7 @@ static void pvm_init_traps_mdcr(struct kvm_vcpu *vcpu) > val |= MDCR_EL2_TTRF; > > if (!kvm_has_feat(kvm, ID_AA64DFR0_EL1, TraceBuffer, IMP)) > - val |= MDCR_EL2_E2TB_MASK; > + val &= ~MDCR_EL2_E2TB_MASK; This does not only change the trapping logic (bit 24). It also change the ownership of the buffer (bit 25). I wonder whether you should do something for that, maybe by clearing TRBLIMITR_EL1.E, because otherwise, you keep tracing, but using an EL2 VA. What could possibly go wrong? Overall, I'm very uneasy about TRBE in the context of pKVM. Thanks, M. -- Without deviation from the norm, progress is not possible.