From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from canpmsgout07.his.huawei.com (canpmsgout07.his.huawei.com [113.46.200.222]) (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 0D5DC3ACA6F; Fri, 11 Sep 2026 08:19:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.222 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789114795; cv=none; b=m99x+luv2/I9c9mrGzEafwEGuFu52efwIMz4wTvsug2dIFun9BdTfENRxK3TYvzwZ2+2YMbL/S/K01WW/8/QjOaF7L/3wmz4jztNQykRLcNm2FwIsL4VP11T7MndgC9a7mPCL66MYp3hW1GKtTluZZdxpxk+F3C+ssK+cKCoDw8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789114795; c=relaxed/simple; bh=z3OYYiSsddSRydFxGjCmoFTiAMj0wTdLvLEaV80PuVo=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=Gp/wqO4K+KdCR2LyDP58w+9cxNC+m/BmgKstZT+YlZNzM+L+1cQLTVLmKTsxnK7nRWxeOnjMyjqsehd+wOw3I1kEYKB1rWp94/uUeQiaw7I88YzhlFJHmgNxEBZtju3NuQl8LcUCWP44szodG1XhajrHjZq2tdsM8BBAtMwmsX4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=pLvxGjqS; arc=none smtp.client-ip=113.46.200.222 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="pLvxGjqS" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=DE5zARm1WiMEsfgjTTF4N0W92kd6jmsXzW2TA0JqO4g=; b=pLvxGjqSDVVZWgMHGLKbmYAIWr8kI0PJBj/87XvcTbLIaUUwBBPvM4zXHtbqC5QTApKmrkpOV MJPHShVGAjcRSKjAbnaK2vII8KR1phaRwEwNbCagERmQXBdiOYYHB9rM7dWNVmO8jQib1n5BITS fJYK8/iSH+RtFpyuoVWlSOc= Received: from mail.maildlp.com (unknown [172.19.162.92]) by canpmsgout07.his.huawei.com (SkyGuard) with ESMTPS id 4hh6cy1D1WzLlX5; Fri, 11 Sep 2026 16:08:50 +0800 (CST) Received: from kwepemk200008.china.huawei.com (unknown [7.202.194.74]) by mail.maildlp.com (Postfix) with ESMTPS id AB37E40565; Fri, 11 Sep 2026 16:19:45 +0800 (CST) Received: from [10.67.109.254] (10.67.109.254) by kwepemk200008.china.huawei.com (7.202.194.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.45; Fri, 11 Sep 2026 16:19:44 +0800 Message-ID: Date: Fri, 11 Sep 2026 16:19:42 +0800 Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 04/40] KVM: arm64: Preserve host MPAM configuration when changing traps To: Ben Horgan CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Shaopeng Tan References: <20260313144617.3420416-1-ben.horgan@arm.com> <20260313144617.3420416-5-ben.horgan@arm.com> From: Jinjie Ruan In-Reply-To: <20260313144617.3420416-5-ben.horgan@arm.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemk200008.china.huawei.com (7.202.194.74) 在 2026/3/13 22:45, Ben Horgan 写道: > When KVM enables or disables MPAM traps to EL2 it clears all other bits in > 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 > Tested-by: Punit Agrawal > Reviewed-by: Zeng Heng > Reviewed-by: Shaopeng Tan > Reviewed-by: Jonathan Cameron > Reviewed-by: Gavin Shan > Acked-by: Marc Zyngier > 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; Reviewed-by: Jinjie Ruan > + > 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);