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 6199DEB3629 for ; Mon, 2 Mar 2026 17:52:21 +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=w6/q0PlUhQsQqCgtm8MH8kpDBLtZoKxA/5qdQMwsczA=; b=NvzXBL8TwclDSX0UFeOnedCYhw YHDvot2TkdKLrzEHV1HyI1/xOB0favT7phBT8CTTmFPmcGHzUZLiHAwvMPsLQvtrRYB6eJz8yhLU1 03OW9/R28anqdqg3GwMyjmuyjnb6IM2KiI9IDMbcAEYJJpR/6RatRt+6XtQkkamAdJKUVfkWC7RXq y4/Rpyf3vO9ZemuHU4R9LfH+cL/3gL4IiD2kqdRfuJSOuTial6SaLGBfskhPkyTyXHdOzxZ7L7H1I jR9DOJyizZHmCExI5tHvIJb1zhFpj8HOXBlD6zeGKCxyvKTj1smGtyId2WR5xj3FYo+ABtfUZvHBg 3isAzy1g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vx7RH-0000000DcyV-3oMv; Mon, 02 Mar 2026 17:52:15 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vx7RH-0000000Dcy8-1Brr for linux-arm-kernel@lists.infradead.org; Mon, 02 Mar 2026 17:52:15 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id 6773160126; Mon, 2 Mar 2026 17:52:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF105C2BC87; Mon, 2 Mar 2026 17:52:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772473934; bh=K8AbHsz72TSgP2bdOzk1adrzjtFHygOozSMVIl4YU5E=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Un2wc4GcAn+A+x3q/r96Cd4A2DUNx1rVQJVZ2ThgSQ4ele3Q9GCq9n2yPBQgMjdRs KNqvXv29i8kqjRUSapwR3pMNdMBMGqS9p7St3M0Xr8q2X4xfo47AbBbhtzvjg/sNrY 9O+aRTGPuPasBqklO2yQhGZkyyYjeWNEsNPkv2tSIH2lJ5T91wlFFc/Uf4y2WXY4m7 +Piw1dCw0Y7GeKY1Dsun4X3febHf6UndTUb8wOdxOmzXLQsOLqy3Rci6UmlYPSwgD+ PUrPluICHRDEjcFM/eHAtK7+h0HgFKvvWgXerpuFQI9FnH56ZRdD8TWrU3BfIyYyEH slyajjKYbk0ig== 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 1vx7RD-0000000FLem-1iil; Mon, 02 Mar 2026 17:52:11 +0000 Date: Mon, 02 Mar 2026 17:52:10 +0000 Message-ID: <86o6l686gl.wl-maz@kernel.org> From: Marc Zyngier To: Ben Horgan Cc: amitsinght@marvell.com, baisheng.gao@unisoc.com, baolin.wang@linux.alibaba.com, carl@os.amperecomputing.com, dave.martin@arm.com, david@kernel.org, dfustini@baylibre.com, fenghuay@nvidia.com, gshan@redhat.com, james.morse@arm.com, jonathan.cameron@huawei.com, kobak@nvidia.com, lcherian@marvell.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, peternewman@google.com, punit.agrawal@oss.qualcomm.com, quic_jiles@quicinc.com, reinette.chatre@intel.com, rohit.mathew@arm.com, scott@os.amperecomputing.com, sdonthineni@nvidia.com, tan.shaopeng@fujitsu.com, xhao@linux.alibaba.com, catalin.marinas@arm.com, will@kernel.org, corbet@lwn.net, oupton@kernel.org, joey.gouly@arm.com, suzuki.poulose@arm.com, kvmarm@lists.linux.dev, zengheng4@huawei.com, linux-doc@vger.kernel.org, Shaopeng Tan Subject: Re: [PATCH v5 02/41] KVM: arm64: Preserve host MPAM configuration when changing traps In-Reply-To: <20260224175720.2663924-3-ben.horgan@arm.com> References: <20260224175720.2663924-1-ben.horgan@arm.com> <20260224175720.2663924-3-ben.horgan@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/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: ben.horgan@arm.com, amitsinght@marvell.com, baisheng.gao@unisoc.com, baolin.wang@linux.alibaba.com, carl@os.amperecomputing.com, dave.martin@arm.com, david@kernel.org, dfustini@baylibre.com, fenghuay@nvidia.com, gshan@redhat.com, james.morse@arm.com, jonathan.cameron@huawei.com, kobak@nvidia.com, lcherian@marvell.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, peternewman@google.com, punit.agrawal@oss.qualcomm.com, quic_jiles@quicinc.com, reinette.chatre@intel.com, rohit.mathew@arm.com, scott@os.amperecomputing.com, sdonthineni@nvidia.com, tan.shaopeng@fujitsu.com, xhao@linux.alibaba.com, catalin.marinas@arm.com, will@kernel.org, corbet@lwn.net, oupton@kernel.org, joey.gouly@arm.com, suzuki.poulose@arm.com, kvmarm@lists.linux.dev, zengheng4@huawei.com, linux-doc@vger.kernel.org, tan.shaopeng@jp.fujitsu.com 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, 24 Feb 2026 17:56:41 +0000, Ben Horgan wrote: > > When kvm enables or disables MPAM traps to EL2 it clears all other bits in nit: s/kvm/KVM/g > MPAM2_EL2. Notably, it clears the partition ids (PARTIDs) and performance > monitoring groups (PMGs). Avoid changing these bits in anticipation of > adding support for MPAM in the kernel. Otherwise, on a VHE system with the > host running at EL2 where MPAM2_EL2 and MPAM1_EL1 access the same register, > any attempt to use MPAM to monitor or partition resources for kernel space > would be foiled by running a KVM guest. Additionally, MPAM2_EL2.EnMPAMSM is > always set to 0 which causes MPAMSM_EL1 to always trap. Keep EnMPAMSM set > to 1 when not in a guest so that the kernel can use MPAMSM_EL1. > > Tested-by: Gavin Shan > Tested-by: Shaopeng Tan > Tested-by: Peter Newman > Tested-by: Zeng Heng > Reviewed-by: Shaopeng Tan > Reviewed-by: Jonathan Cameron > Reviewed-by: Gavin Shan > Signed-off-by: Ben Horgan > --- > arch/arm64/kvm/hyp/include/hyp/switch.h | 12 ++++++++---- > 1 file changed, 8 insertions(+), 4 deletions(-) > > diff --git a/arch/arm64/kvm/hyp/include/hyp/switch.h b/arch/arm64/kvm/hyp/include/hyp/switch.h > index 2597e8bda867..0b50ddd530f3 100644 > --- a/arch/arm64/kvm/hyp/include/hyp/switch.h > +++ b/arch/arm64/kvm/hyp/include/hyp/switch.h > @@ -267,7 +267,8 @@ static inline void __deactivate_traps_hfgxtr(struct kvm_vcpu *vcpu) > > static inline void __activate_traps_mpam(struct kvm_vcpu *vcpu) > { > - u64 r = MPAM2_EL2_TRAPMPAM0EL1 | MPAM2_EL2_TRAPMPAM1EL1; > + u64 clr = MPAM2_EL2_EnMPAMSM; > + u64 set = MPAM2_EL2_TRAPMPAM0EL1 | MPAM2_EL2_TRAPMPAM1EL1; > > if (!system_supports_mpam()) > return; > @@ -277,18 +278,21 @@ static inline void __activate_traps_mpam(struct kvm_vcpu *vcpu) > write_sysreg_s(MPAMHCR_EL2_TRAP_MPAMIDR_EL1, SYS_MPAMHCR_EL2); > } else { > /* From v1.1 TIDR can trap MPAMIDR, set it unconditionally */ > - r |= MPAM2_EL2_TIDR; > + set |= MPAM2_EL2_TIDR; > } > > - write_sysreg_s(r, SYS_MPAM2_EL2); > + sysreg_clear_set_s(SYS_MPAM2_EL2, clr, set); > } > > static inline void __deactivate_traps_mpam(void) > { > + u64 clr = MPAM2_EL2_TRAPMPAM0EL1 | MPAM2_EL2_TRAPMPAM1EL1 | MPAM2_EL2_TIDR; > + u64 set = MPAM2_EL2_EnMPAMSM; > + > if (!system_supports_mpam()) > return; > > - write_sysreg_s(0, SYS_MPAM2_EL2); > + sysreg_clear_set_s(SYS_MPAM2_EL2, clr, set); > > if (system_supports_mpam_hcr()) > write_sysreg_s(MPAMHCR_HOST_FLAGS, SYS_MPAMHCR_EL2); Acked-by: Marc Zyngier M. -- Without deviation from the norm, progress is not possible.