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 24FC2C79FB9 for ; Thu, 10 Sep 2026 11:09:06 +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=x7qhrmT6HLun6jsVh88qBFkF1/a9MuNKLp5SlVHYpFk=; b=NyOF9TLTKEAA4mCv6SMwFwPoiQ DmJw3JoTUXbCh+FpLRHJ9rtbO0r6tc9OeYT0qWCo3RxV2DAzORZMuGTD0Q7XNkNKdhYC7ocu5l328 yjS/lngUQ5fY2TsFc5JdsTndH0hhYlEIUqliyACzVvIErfpssjGPmOnDscCTpovjc/2w3/kEOmTzD AbOt6UQ/Vk+1yIxgNnlzcQ4b8/qi/szrniFUdFq6kCDyKImbzUtKw6R3rXkQxvgw4Zge4jnOJCzwP 3wA2q0djMD70j+QxXDkcwRTLjvfFnmy6sxAXR909Nit3swa21JnF6yNjXzRJ6T7K5tWRUroa+c0uU wmmbZOMA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x4ceJ-0000000EAMr-3wQJ; Thu, 10 Sep 2026 11:08:59 +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 1x4ceI-0000000EAMh-1GkM for linux-arm-kernel@lists.infradead.org; Thu, 10 Sep 2026 11:08:58 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id F3FBA4032A; Thu, 10 Sep 2026 11:08:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4D951F000FF; Thu, 10 Sep 2026 11:08:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1789038537; bh=x7qhrmT6HLun6jsVh88qBFkF1/a9MuNKLp5SlVHYpFk=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=YALf3tBpfCON9TZe2Mv4+aJeq7WfpcvlqYIAyIr77+GrgYUoOGwZngBEBus8T5C63 B38VYlbLw2otsmE6g/m4u8EGZuo+WlevckD2sZ7I9VkHtVFNdUIw5x7BKhES76BpDV 7pBISJQsLlAJ7PUnO2Y6h2atyYCHvN/zNjiS3YVqWzwz7lBGQETAXPVEl0nkOeT8wY w71UIu5e9t1QOeFqkmwpXa6dj2tEjKOIZYwOvrjrjUGuF1mStHcgfcLVj89y9LMBO/ REifa/XXAknlsEJYl6gJbBJ4OLAn/1LRsyZMVX/C6eWOXgS8BIXcxm9qttdiqcBcgx iXlQWxq6OOqZQ== 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 1x4ceF-00000007EEC-3kUD; Thu, 10 Sep 2026 11:08:55 +0000 Date: Thu, 10 Sep 2026 12:08:55 +0100 Message-ID: <86se3h748o.wl-maz@kernel.org> From: Marc Zyngier To: Fuad Tabba Cc: Oliver Upton , Catalin Marinas , Will Deacon , James Morse , Ben Horgan , Xi Ruoyao , Mark Rutland , Joey Gouly , Suzuki K Poulose , Zenghui Yu , Steffen Eiden , Gavin Shan , Yuan Yao , Fuad Tabba , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] KVM: arm64: Trap guest MPAM accesses whenever MPAM is implemented In-Reply-To: <20260908145651.2828597-1-fuad.tabba@linux.dev> References: <20260908145651.2828597-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, catalin.marinas@arm.com, will@kernel.org, james.morse@arm.com, ben.horgan@arm.com, xry111@xry111.site, mark.rutland@arm.com, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, seiden@linux.ibm.com, gshan@redhat.com, yaoyuan@linux.alibaba.com, tabba@google.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, 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 Tue, 08 Sep 2026 15:56:51 +0100, Fuad Tabba wrote: > > finalise_el2_state() clears the EL2 MPAM traps whenever the ID > registers advertise MPAM, while KVM sets them only under ARM64_MPAM, > which also requires MPAMEN. Without EL3 nothing sets that enable, so a > guest reaches the MPAM registers while ID_AA64PFR0_EL1.MPAM reads 0 > for it. > > Gate the traps on the ID registers alone: MPAMEN isn't a term in any > MPAM accessor, so they take effect without it. The cap tests the > sanitised ID fields, which never exceed a CPU's own, so it's set only > where finalise_el2_state already wrote MPAM2_EL2. MPAM3_EL3.TRAPLOWER > is clear there, and arm64.nompam turns the cap off too. > > Fixes: 23b33d1e168c ("arm64: head.S: Initialise MPAM EL2 registers and disable traps") > Reviewed-by: Yuan Yao > Signed-off-by: Fuad Tabba > --- > > Notes: > Changes since v1: > - Commit message only. The code is unchanged, so Yuan Yao's > Reviewed-by is carried. > - Fixes: names the commit that cleared the traps, rather than the > one that added KVM's trapping. > - Says why the sanitised ID fields are the safe gate: the cap is set > only where finalise_el2_state already wrote MPAM2_EL2. > > Not covered, and answered on the v1 thread: a machine whose CPUs > differ on MPAM, raised by Ben and by sashiko. > > v1: https://lore.kernel.org/all/20260903160819.831518-1-fuad.tabba@linux.dev/ > > arch/arm64/include/asm/cpufeature.h | 5 +++++ > arch/arm64/kernel/cpufeature.c | 13 +++++++++++++ > arch/arm64/kvm/hyp/include/hyp/switch.h | 4 ++-- > arch/arm64/tools/cpucaps | 1 + > 4 files changed, 21 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h > index 7404a6e83a930..8863ae99596bc 100644 > --- a/arch/arm64/include/asm/cpufeature.h > +++ b/arch/arm64/include/asm/cpufeature.h > @@ -873,6 +873,11 @@ static __always_inline bool system_supports_mpam_hcr(void) > return alternative_has_cap_unlikely(ARM64_MPAM_HCR); > } > > +static __always_inline bool system_supports_mpam_sysregs(void) > +{ > + return alternative_has_cap_unlikely(ARM64_MPAM_SYSREGS); > +} > + What is the rationale for choosing alternative_has_cap_unlikely() instead of cpus_have_final_cap(), which is more wildly used? M. -- Without deviation from the norm, progress is not possible.