Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

KVM: arm64: Preserve host MPAM configuration when changing traps

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 <gshan@redhat.com>
Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>
Tested-by: Peter Newman <peternewman@google.com>
Tested-by: Zeng Heng <zengheng4@huawei.com>
Tested-by: Punit Agrawal <punit.agrawal@oss.qualcomm.com>
Tested-by: Jesse Chick <jessechick@os.amperecomputing.com>
Reviewed-by: Zeng Heng <zengheng4@huawei.com>
Reviewed-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com>
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Acked-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: Ben Horgan <ben.horgan@arm.com>
Signed-off-by: James Morse <james.morse@arm.com>

authored by

Ben Horgan and committed by
James Morse
eda1cd1f 29fa1be8

+8 -4
+8 -4
arch/arm64/kvm/hyp/include/hyp/switch.h
··· 267 267 268 268 static inline void __activate_traps_mpam(struct kvm_vcpu *vcpu) 269 269 { 270 - u64 r = MPAM2_EL2_TRAPMPAM0EL1 | MPAM2_EL2_TRAPMPAM1EL1; 270 + u64 clr = MPAM2_EL2_EnMPAMSM; 271 + u64 set = MPAM2_EL2_TRAPMPAM0EL1 | MPAM2_EL2_TRAPMPAM1EL1; 271 272 272 273 if (!system_supports_mpam()) 273 274 return; ··· 278 277 write_sysreg_s(MPAMHCR_EL2_TRAP_MPAMIDR_EL1, SYS_MPAMHCR_EL2); 279 278 } else { 280 279 /* From v1.1 TIDR can trap MPAMIDR, set it unconditionally */ 281 - r |= MPAM2_EL2_TIDR; 280 + set |= MPAM2_EL2_TIDR; 282 281 } 283 282 284 - write_sysreg_s(r, SYS_MPAM2_EL2); 283 + sysreg_clear_set_s(SYS_MPAM2_EL2, clr, set); 285 284 } 286 285 287 286 static inline void __deactivate_traps_mpam(void) 288 287 { 288 + u64 clr = MPAM2_EL2_TRAPMPAM0EL1 | MPAM2_EL2_TRAPMPAM1EL1 | MPAM2_EL2_TIDR; 289 + u64 set = MPAM2_EL2_EnMPAMSM; 290 + 289 291 if (!system_supports_mpam()) 290 292 return; 291 293 292 - write_sysreg_s(0, SYS_MPAM2_EL2); 294 + sysreg_clear_set_s(SYS_MPAM2_EL2, clr, set); 293 295 294 296 if (system_supports_mpam_hcr()) 295 297 write_sysreg_s(MPAMHCR_HOST_FLAGS, SYS_MPAMHCR_EL2);