[PATCH v3 3/4] KVM: arm64: Ignore writes to PMCR_EL0.N when using strict UAPI

Congkai Tan congkai at amazon.com
Wed Jul 22 13:27:01 PDT 2026


From: Oliver Upton <oupton at kernel.org>

KVM allows userspace to configure the number of event counters by
writing to PMCR_EL0.N. While this makes a bit of sense prior to NV, the
value of the field is context-dependent whether or not the vCPU is at
EL2 or EL1. As such, the vCPU attribute was added afterwards and made
mandatory for NV.

As we're in the process of papering over old mistakes, force userspace
to use the vCPU attribute if KVM_ARM_VCPU_PMU_V3_STRICT is set.

Signed-off-by: Oliver Upton <oupton at kernel.org>
Reviewed-by: Geoff Blake <blakgeof at amazon.com>
Reviewed-by: Haris Okanovic <harisokn at amazon.com>
Signed-off-by: Congkai Tan <congkai at amazon.com>
---
 arch/arm64/kvm/sys_regs.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 4c6f608c4fe5..e93f11b90813 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -1502,6 +1502,7 @@ static int set_pmcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r,
 	 */
 	if (!kvm_vm_has_ran_once(kvm) &&
 	    !vcpu_has_nv(vcpu)	      &&
+	    !kvm_vcpu_has_pmuv3_strict(vcpu) &&
 	    new_n <= kvm_arm_pmu_get_max_counters(kvm))
 		kvm->arch.nr_pmu_counters = new_n;
 
-- 
2.50.1




More information about the linux-arm-kernel mailing list