From: Dapeng Mi 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 Signed-off-by: Zide Chen --- v3: - Simplify version cap logic since mediated PMU already requires version >= 4. (Jim) v2: - Cap vPMU v3/v4 to v2, as AnyThread cannot be safely virtualized. (Sashiko) --- arch/x86/kvm/pmu.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c index afb3e18a9879..f949fdbf359c 100644 --- a/arch/x86/kvm/pmu.c +++ b/arch/x86/kvm/pmu.c @@ -175,7 +175,17 @@ 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); + + /* + * PMU v3/v4 has AnyThread support, which KVM cannot safely virtualize. + * Only expose PMU v5+ for Intel mediated PMU, where AnyThread is + * deprecated; otherwise, cap at PMU v2. + */ + if (is_intel && enable_mediated_pmu && kvm_pmu_cap.version >= 5) + kvm_pmu_cap.version = 5; + 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.56.0