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 289DCCC6B39 for ; Thu, 15 Oct 2026 16:41:27 +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=henc3B1x6U66Cc4wCHQGaVrAN5txXPadaIqIa3phigg=; b=cZtVQvMUkTf5lmAuBTC/KbjNTP 4lYIVZLt3De7yRq6JWdiobhlM81iOASw2Bf+lc1ANcEvc6pqsuh5iYX07oyxuCEr7xg3wWY410pDu ToabWO7Gxe8NdVOlnNDjqAaV8nD078vx68XgkL0igNq9tMpJ1mSqqchnpRWZ8qMlIIrL5VjpX09W4 L2TQE3slASWm2Kt4hOifyrXl6JpRVRqAUmVP/LnAcXgb6LcPAySZadJIuYec4n4W0RtKCktA/e8HR ZUcUM79h8FsnSNmtgrrDq3Qh2p1+yVurERx37vcroh3uGBgWIQIJUqy1UrAn7tO81dZrm+qKcuFYM IHlWLN5g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1xHOW8-00000000sTl-29rw; Thu, 15 Oct 2026 16:41:20 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1xHOW7-00000000sTH-29mA for linux-arm-kernel@lists.infradead.org; Thu, 15 Oct 2026 16:41:19 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 4555243DE8; Thu, 15 Oct 2026 16:41:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 25A601F000C4; Thu, 15 Oct 2026 16:41:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1792082479; bh=henc3B1x6U66Cc4wCHQGaVrAN5txXPadaIqIa3phigg=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=NJHxIYDaSvcn1zskfakCyzzkc4KWk3YVFRCCFczSgr9+0yFWlKhBdpJBkyXq9TYCm UpnV/NdQv/Uai4CJwhme57ZoMqNE+fi6g2DBo1JuZ+tKOI2rlzyrappiw537FK2L/M +cxsHhaQTaDhaqT48R/MhPUHuIP3m2djDD55Pe4CvQFroaLfCf7ZmNc1mfSah1HBh6 TGVgaDxGN65O5ma+wW77JN8Eojz79vvI4xLTEcgznOKA1DrNqgYuCxpdp8QvEwq1h2 97xsMCBod6WJ+hYnrGuGLMrVJNPQ3PMwcuusePSij0E6VG5N/y+xCbs5rYOKrR4Es6 Z44/hp0IG1asg== 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 1xHOW4-00000003OzH-2KmN; Thu, 15 Oct 2026 16:41:16 +0000 Date: Thu, 15 Oct 2026 17:41:16 +0100 Message-ID: <86h5im29xv.wl-maz@kernel.org> From: Marc Zyngier To: Fuad Tabba Cc: Oliver Upton , kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Mark Rutland , Mark Brown , Lorenzo Stoakes , Fuad Tabba , linux-kernel@vger.kernel.org Subject: Re: [PATCH] KVM: arm64: Only enable S1PIE and S1POE for a guest with TCR2 and ATS1A In-Reply-To: <20261015153041.3770032-1-fuad.tabba@linux.dev> References: <20261015153041.3770032-1-fuad.tabba@linux.dev> 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: fuad.tabba@linux.dev, oupton@kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, joey.gouly@arm.com, seiden@linux.ibm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com, broonie@kernel.org, ljs@kernel.org, tabba@google.com, linux-kernel@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false 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 Thu, 15 Oct 2026 16:30:41 +0100, Fuad Tabba wrote: > > The world switch skips PIR_EL1, PIRE0_EL1 and POR_EL1 for a guest > without TCR2, but KVM doesn't trap them for a guest with S1PIE or > S1POE. Userspace can hide TCR2 while leaving either visible, and such a > guest then accesses registers that are neither trapped nor switched. > > Under VHE, that leaks values between guests. POR_EL1, which the host > kernel doesn't use, leaks between guests in every mode. On nVHE and > hVHE, pKVM included, the host's own EL1 registers are saved and restored > according to the running guest's features, so the host kernel resumes > with its stage-1 permissions taken from the guest's PIR_EL1 and > PIRE0_EL1. > > As per the architecture, S1PIE and S1POE imply TCR2 and ATS1A. Only > enable them for a guest that has both. A guest that has S1PIE or S1POE > without TCR2 or ATS1A still sees the feature in its ID registers, but > its accesses to that feature's registers UNDEF. > > Fixes: 70ed7238297fb ("KVM: arm64: Sanitise ID_AA64MMFR3_EL1") > Fixes: d4a89e5aee23e ("KVM: arm64: Expose S1PIE to guests") > Reported-by: Mark Brown > Link: https://lore.kernel.org/r/20260930-arm64-gcs-v21-2-3556644cd927@kernel.org > Suggested-by: Marc Zyngier > Link: https://lore.kernel.org/r/86fqyn2che.wl-maz@kernel.org > Cc: stable@vger.kernel.org > Signed-off-by: Fuad Tabba > --- > I'm sending this on its own because it affects the host on nVHE and in > pKVM, so that it can go to kvmarm/fixes and stable rather than land > with the GCS series. It's the data-driven fix Marc asked for on Mark's > v21 02/15 [1]. > > Following Mark's point on Lorenzo's draft [2], only feat_s1pie() and > feat_s1poe() test TCR2 and ATS1A, so kvm_has_s1pie() and the world > switch are unchanged. I've left the guest's ID registers alone, since > updating them is the larger rework Mark described. > > I've got a reproducer showing the host's PIR_EL1 overwritten on nVHE > and in pKVM, and can share it privately. > > Based on Linux 7.3-rc3 (fd73f4a665989; also applies to kvmarm/fixes > 71cc2c67fb8f8). > > [1] https://lore.kernel.org/r/86fqyn2che.wl-maz@kernel.org > [2] https://lore.kernel.org/r/ae24e80c-1b34-4827-9c93-e80b987e9cd7@sirena.org.uk > > arch/arm64/kvm/config.c | 23 +++++++++++++++++++---- > 1 file changed, 19 insertions(+), 4 deletions(-) > > diff --git a/arch/arm64/kvm/config.c b/arch/arm64/kvm/config.c > index 1053676551aff..5e5277c721d52 100644 > --- a/arch/arm64/kvm/config.c > +++ b/arch/arm64/kvm/config.c > @@ -280,6 +280,21 @@ static bool feat_anerr(struct kvm *kvm) > kvm_has_feat(kvm, ID_AA64MMFR3_EL1, SNERR, FEAT_ANERR)); > } > > +/* S1PIE and S1POE imply TCR2 and ATS1A, but userspace can set them independently */ > +static bool feat_s1pie(struct kvm *kvm) > +{ > + return (kvm_has_feat(kvm, FEAT_S1PIE) && > + kvm_has_feat(kvm, FEAT_TCR2) && > + kvm_has_feat(kvm, FEAT_ATS1A)); > +} > + > +static bool feat_s1poe(struct kvm *kvm) > +{ > + return (kvm_has_feat(kvm, FEAT_S1POE) && > + kvm_has_feat(kvm, FEAT_TCR2) && > + kvm_has_feat(kvm, FEAT_ATS1A)); Where's what the relevant bits of the JSON say: (FEAT_S1POE ==> FEAT_TCR2) (FEAT_S1POE ==> FEAT_ATS1A) (FEAT_S1POE ==> FEAT_HPDS) So this is missing an additional check on FEAT_HPDS, which is advertised as: (FEAT_AA64EL1 ==> (FEAT_HPDS <=> (UInt(ID_AA64MMFR1_EL1.HPDS) >= 1))) Thanks, M. -- Without deviation from the norm, progress is not possible.