From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0415342CB2; Thu, 15 Jan 2026 09:05:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768467933; cv=none; b=FEHc0ZjW5Te/5IH9vwWtDYaPaQXMBUg1PWBuAgdJVfHHAe9yZL1kFZbhXmzNLnpgyKS5mf4pXwYeRmW833AI2Rgbm0BTuZqMH5KL7NaPG/+OpYBgGQSIcV01aO+02wJz6MsAv9elgwkhOCsiz0YP00e1gxmopPo7YWUhTHowhwo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768467933; c=relaxed/simple; bh=SbCaNkzKCMcW9Kc/6M5IX9Rq4Uea6Zy1g6Z7MZnMaOY=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=LQekgAKQPo11qRSzSSopazP8gVZ1JDdbnfSGZUOZZ3R41lQvvjahaPnvUhVGpT4Pghy29Q+vcKsvQ13vKb3hYoyoRhV0hTwQ6myT7Tg4o5DI+NLccgTRyh0JJAw5VMNtpLMMOcuPGPAKGmMjzlSuNv2FaK0tJzk5zY+6+JnCT4o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mqu1/tn/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mqu1/tn/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5CE16C19421; Thu, 15 Jan 2026 09:05:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768467932; bh=SbCaNkzKCMcW9Kc/6M5IX9Rq4Uea6Zy1g6Z7MZnMaOY=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=mqu1/tn/H1Cn66X0wOisAmEkgVqjyp4CrHzPw3OgDvP/7/cBIh3t/MW2MvKutZ7hu BS0BcwtIGbRKcGhqM/Mz5IN///efYhJUMSQFi+93xwhcZruDD6zdgHN2WIAuFgaJHJ 6zRuv/meI2OtrEa52DwTarq31eGXod4jIzPscqZ8vRaFPv58+MTjYbE9Nn4xWRxTx8 L8XUEAEfiRtNwu3TqzzP7ms5KR8W3e2wzgvSO+JjJwYNlddx45/WhjMdW8LXX79ay6 7T3tTMv+tKLNviYUXwbvp7PwYHj13t5pAk2X/ImqL21eJAqHelogqbg05VqgxFcscB RNug2W6D0KpNw== 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 1vgJIH-00000002SKy-1xCP; Thu, 15 Jan 2026 09:05:29 +0000 Date: Thu, 15 Jan 2026 09:05:28 +0000 Message-ID: <86ldhzkzzb.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 Subject: Re: [PATCH v3 12/47] KVM: arm64: Force guest EL1 to use user-space's partid configuration In-Reply-To: <92041294-b332-4b8b-aeed-d8bbad1a7289@arm.com> References: <20260112165914.4086692-1-ben.horgan@arm.com> <20260112165914.4086692-13-ben.horgan@arm.com> <86pl7cl7p7.wl-maz@kernel.org> <92041294-b332-4b8b-aeed-d8bbad1a7289@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) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Wed, 14 Jan 2026 14:50:22 +0000, Ben Horgan wrote: > > Hi Marc, > > On 1/14/26 12:06, Marc Zyngier wrote: > > On Mon, 12 Jan 2026 16:58:39 +0000, > > Ben Horgan wrote: > >> > >> From: James Morse > >> > >> While we trap the guest's attempts to read/write the MPAM control > >> registers, the hardware continues to use them. Guest-EL0 uses KVM's > >> user-space's configuration, as the value is left in the register, and > >> guest-EL1 uses either the host kernel's configuration, or in the case of > >> VHE, the UNKNOWN reset value of MPAM1_EL1. > >> > >> We want to force the guest-EL1 to use KVM's user-space's MPAM > >> configuration. On nVHE rely on MPAM0_EL1 and MPAM1_EL1 always being > >> programmed the same and on VHE copy MPAM0_EL1 into the guest's > >> MPAM1_EL1. There is no need to restore as this is out of context once TGE > >> is set. > >> > >> Signed-off-by: James Morse > >> Signed-off-by: Ben Horgan > >> --- > >> Changes since rfc: > >> Drop the unneeded __mpam_guest_load() in nvhre and the MPAM1_EL1 save restore > >> Defer EL2 handling until next patch > >> > >> Changes since v2: > >> Use mask (Oliver) > >> --- > >> arch/arm64/kvm/hyp/vhe/sysreg-sr.c | 13 +++++++++++++ > >> 1 file changed, 13 insertions(+) > >> > >> diff --git a/arch/arm64/kvm/hyp/vhe/sysreg-sr.c b/arch/arm64/kvm/hyp/vhe/sysreg-sr.c > >> index f28c6cf4fe1b..9fb8e6628611 100644 > >> --- a/arch/arm64/kvm/hyp/vhe/sysreg-sr.c > >> +++ b/arch/arm64/kvm/hyp/vhe/sysreg-sr.c > >> @@ -183,6 +183,18 @@ void sysreg_restore_guest_state_vhe(struct kvm_cpu_context *ctxt) > >> } > >> NOKPROBE_SYMBOL(sysreg_restore_guest_state_vhe); > >> > >> +/* > >> + * The _EL0 value was written by the host's context switch and belongs to the > >> + * VMM. Copy this into the guest's _EL1 register. > >> + */ > >> +static inline void __mpam_guest_load(void) > >> +{ > >> + u64 mask = MPAM0_EL1_PARTID_D | MPAM0_EL1_PARTID_I | MPAM0_EL1_PMG_D | MPAM0_EL1_PMG_I; > >> + > >> + if (system_supports_mpam()) > >> + write_sysreg_el1(read_sysreg_s(SYS_MPAM0_EL1) & mask, SYS_MPAM1); > >> +} > >> + > >> /** > >> * __vcpu_load_switch_sysregs - Load guest system registers to the physical CPU > >> * > >> @@ -222,6 +234,7 @@ void __vcpu_load_switch_sysregs(struct kvm_vcpu *vcpu) > >> */ > >> __sysreg32_restore_state(vcpu); > >> __sysreg_restore_user_state(guest_ctxt); > >> + __mpam_guest_load(); > > > > What's the rationale for doing this independently of rest of the MPAM > > stuff in __activate_traps_mpam()? > > The __activate_traps_mpam() is relevant even for nvhe but > __mpam_guest_load() is only need in vhe as otherwise we can rely on > MPAM1_EL1 and MPAM0_EL0 having the same partid/pmg configuration It is completely unclear to me what enforces this. Please point me to the code that does that. > (although this MPAM policy will likely become configurable sometime down > the line). Or not. the VM only exists as an extension of userspace, and I don't see on what grounds it should get its own MPAM configuration. > Besides that it just makes the naming less exact. I don't care about the naming. I care about how the configuration flow is organised. And so far, this seems extremely messy. Can you please document what gets configured when and in which mode? Thanks, M. -- Without deviation from the norm, progress is not possible.