KVM reads MSR_IA32_PERF_CAPABILITIES directly, which bypasses the errata workarounds (e.g. RPL018) and sanitizing that perf applies to the value. Use the capabilities reported by perf instead. This also avoids reading the MSR twice during VMX PMU initialization. Signed-off-by: Zide Chen --- v10: - Re-purposed the patch "Snapshot host IA32_PERF_CAPABILITIES" to simple references update. --- arch/x86/kvm/vmx/pmu_intel.c | 7 +------ arch/x86/kvm/vmx/vmx.c | 8 ++------ 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c index 8f72a405e737..f916048b9c54 100644 --- a/arch/x86/kvm/vmx/pmu_intel.c +++ b/arch/x86/kvm/vmx/pmu_intel.c @@ -775,16 +775,11 @@ void intel_pmu_cross_mapped_check(struct kvm_pmu *pmu) static bool intel_pmu_is_mediated_pmu_supported(struct x86_pmu_capability *host_pmu) { - u64 host_perf_cap = 0; - - if (boot_cpu_has(X86_FEATURE_PDCM)) - rdmsrq(MSR_IA32_PERF_CAPABILITIES, host_perf_cap); - /* * Require v4+ for MSR_CORE_PERF_GLOBAL_STATUS_SET, and full-width * writes so that KVM can precisely load guest counter values. */ - if (host_pmu->version < 4 || !(host_perf_cap & PERF_CAP_FW_WRITES)) + if (host_pmu->version < 4 || !(host_pmu->perf_capabilities & PERF_CAP_FW_WRITES)) return false; /* diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index b341af4c6057..f04f2d3884d9 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7889,14 +7889,10 @@ void vmx_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) static __init u64 vmx_get_perf_capabilities(void) { u64 perf_cap = PERF_CAP_FW_WRITES; - u64 host_perf_cap = 0; if (!enable_pmu) return 0; - if (boot_cpu_has(X86_FEATURE_PDCM)) - rdmsrq(MSR_IA32_PERF_CAPABILITIES, host_perf_cap); - if (!cpu_feature_enabled(X86_FEATURE_ARCH_LBR) && !enable_mediated_pmu) { x86_perf_get_lbr(&vmx_lbr_caps); @@ -7909,11 +7905,11 @@ static __init u64 vmx_get_perf_capabilities(void) if (!vmx_lbr_caps.has_callstack) memset(&vmx_lbr_caps, 0, sizeof(vmx_lbr_caps)); else if (vmx_lbr_caps.nr) - perf_cap |= host_perf_cap & PERF_CAP_LBR_FMT; + perf_cap |= kvm_pmu_cap.perf_capabilities & PERF_CAP_LBR_FMT; } if (vmx_pebs_supported()) { - perf_cap |= host_perf_cap & PERF_CAP_PEBS_MASK; + perf_cap |= kvm_pmu_cap.perf_capabilities & PERF_CAP_PEBS_MASK; /* * Disallow adaptive PEBS as it is functionally broken, can be -- 2.56.1