From 517cdec3d4b28ccf5dae2dd03dee2a0a1eef1981 Mon Sep 17 00:00:00 2001 From: Colton Lewis Date: Wed, 30 Sep 2026 21:18:34 +0000 Subject: [PATCH] KVM: arm64: Check ID_AA64DFR0_EL1.PMUVer in pmu_visibility() pmu_visibility() currently checks kvm_vcpu_has_pmu(), which only tests whether the vCPU was initialized with KVM_ARM_VCPU_PMU_V3. If userspace initializes a vCPU with KVM_ARM_VCPU_PMU_V3 and subsequently hides FEAT_PMUv3 via ID_AA64DFR0_EL1.PMUVer, KVM continues to expose the PMU system registers instead of emulating guest accesses as UNDEF. Check ID_AA64DFR0_EL1.PMUVer directly via kvm_has_feat() in pmu_visibility() so that PMU system registers are marked REG_HIDDEN whenever FEAT_PMUv3 is not advertised in the ID registers. Suggested-by: Oliver Upton Assisted-by: LLM Signed-off-by: Colton Lewis Link: https://patch.msgid.link/20260930211834.2773546-3-coltonlewis@google.com Signed-off-by: Marc Zyngier --- arch/arm64/kvm/sys_regs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 87f96c9bd2fe..8315a188676f 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -1028,7 +1028,7 @@ static unsigned int hidden_visibility(const struct kvm_vcpu *vcpu, static unsigned int pmu_visibility(const struct kvm_vcpu *vcpu, const struct sys_reg_desc *r) { - if (kvm_vcpu_has_pmu(vcpu)) + if (kvm_has_feat(vcpu->kvm, ID_AA64DFR0_EL1, PMUVer, IMP)) return 0; return REG_HIDDEN;