[PATCH v2 15/16] KVM: x86/pmu: Advertise PerfMon version 5 on Intel hosts
From: Zide Chen
Date: Thu Aug 27 2026 - 18:53:55 EST
From: Dapeng Mi <dapeng1.mi@xxxxxxxxxxxxxxx>
KVM currently caps the guest PerfMon version at 2 for all Intel
platforms. Now that KVM emulates the basic architectural PMU features
introduced in PerfMon versions 3 through 5, raise the guest PerfMon
version to 5. Features that require additional emulation support, e.g.
architectural LBR will be enabled separately.
PerfMon versions 3 and 4 continue to be exposed as version 2 because
KVM cannot safely virtualize AnyThread due to cross-VM information
leakage. PerfMon v5 is supported because it provides the
AnyThread-deprecated capability, allowing KVM to indicate that
AnyThread is deprecated.
When enable_mediated_pmu is disabled or in the non-Intel paths, KVM
retains the existing cap of version 2.
Signed-off-by: Dapeng Mi <dapeng1.mi@xxxxxxxxxxxxxxx>
Signed-off-by: Zide Chen <zide.chen@xxxxxxxxx>
---
v2:
- Cap vPMU v3/v4 to v2, as AnyThread cannot be safely virtualized.
(Sashiko)
---
arch/x86/kvm/pmu.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
index 4cb7c796daac..1a7be7d73b62 100644
--- a/arch/x86/kvm/pmu.c
+++ b/arch/x86/kvm/pmu.c
@@ -175,7 +175,21 @@ void kvm_init_pmu_capability(struct kvm_pmu_ops *pmu_ops)
}
memcpy(&kvm_pmu_cap, &kvm_host_pmu, sizeof(kvm_host_pmu));
- kvm_pmu_cap.version = min(kvm_pmu_cap.version, 2);
+
+ if (is_intel && enable_mediated_pmu) {
+ kvm_pmu_cap.version = min(kvm_pmu_cap.version, 5);
+
+ /*
+ * PMU v3/v4 has AnyThread support, which KVM cannot safely
+ * virtualize. Expose PMU v2 instead of advertising a partially
+ * functional PMU v3/v4 to guests.
+ */
+ if (kvm_pmu_cap.version == 3 || kvm_pmu_cap.version == 4)
+ kvm_pmu_cap.version = 2;
+ } else {
+ kvm_pmu_cap.version = min(kvm_pmu_cap.version, 2);
+ }
+
kvm_pmu_cap.cntr_mask64 &=
GENMASK_ULL(pmu_ops->MAX_NR_GP_COUNTERS - 1, 0);
kvm_pmu_cap.fixed_cntr_mask64 &=
--
2.55.0