Skip to content

Commit bfee4f0

Browse files
Dapeng Misean-jc
authored andcommitted
KVM: x86/pmu: Implement Intel mediated PMU requirements and constraints
Implement Intel PMU requirements and constraints for mediated PMU support. Require host PMU version 4+ so that PERF_GLOBAL_STATUS_SET can be used to precisely load the guest's status value into hardware, and require full- width writes so that KVM can precisely load guest counter values. Disable PEBS and LBRs if mediated PMU support is enabled, as they won't be supported in the initial implementation. Signed-off-by: Dapeng Mi <dapeng1.mi@linux.intel.com> Co-developed-by: Mingwei Zhang <mizhang@google.com> Signed-off-by: Mingwei Zhang <mizhang@google.com> [sean: split to separate patch, add full-width writes dependency] Tested-by: Xudong Hao <xudong.hao@intel.com> Tested-by: Manali Shukla <manali.shukla@amd.com> Link: https://patch.msgid.link/20251206001720.468579-18-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 3e51822 commit bfee4f0

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

arch/x86/kvm/vmx/capabilities.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,8 @@ static inline bool vmx_pt_mode_is_host_guest(void)
395395

396396
static inline bool vmx_pebs_supported(void)
397397
{
398-
return boot_cpu_has(X86_FEATURE_PEBS) && kvm_pmu_cap.pebs_ept;
398+
return boot_cpu_has(X86_FEATURE_PEBS) && kvm_pmu_cap.pebs_ept &&
399+
!enable_mediated_pmu;
399400
}
400401

401402
static inline bool cpu_has_notify_vmexit(void)

arch/x86/kvm/vmx/pmu_intel.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,20 @@ void intel_pmu_cross_mapped_check(struct kvm_pmu *pmu)
767767
}
768768
}
769769

770+
static bool intel_pmu_is_mediated_pmu_supported(struct x86_pmu_capability *host_pmu)
771+
{
772+
u64 host_perf_cap = 0;
773+
774+
if (boot_cpu_has(X86_FEATURE_PDCM))
775+
rdmsrq(MSR_IA32_PERF_CAPABILITIES, host_perf_cap);
776+
777+
/*
778+
* Require v4+ for MSR_CORE_PERF_GLOBAL_STATUS_SET, and full-width
779+
* writes so that KVM can precisely load guest counter values.
780+
*/
781+
return host_pmu->version >= 4 && host_perf_cap & PERF_CAP_FW_WRITES;
782+
}
783+
770784
struct kvm_pmu_ops intel_pmu_ops __initdata = {
771785
.rdpmc_ecx_to_pmc = intel_rdpmc_ecx_to_pmc,
772786
.msr_idx_to_pmc = intel_msr_idx_to_pmc,
@@ -778,6 +792,9 @@ struct kvm_pmu_ops intel_pmu_ops __initdata = {
778792
.reset = intel_pmu_reset,
779793
.deliver_pmi = intel_pmu_deliver_pmi,
780794
.cleanup = intel_pmu_cleanup,
795+
796+
.is_mediated_pmu_supported = intel_pmu_is_mediated_pmu_supported,
797+
781798
.EVENTSEL_EVENT = ARCH_PERFMON_EVENTSEL_EVENT,
782799
.MAX_NR_GP_COUNTERS = KVM_MAX_NR_INTEL_GP_COUNTERS,
783800
.MIN_NR_GP_COUNTERS = 1,

arch/x86/kvm/vmx/vmx.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7958,7 +7958,8 @@ static __init u64 vmx_get_perf_capabilities(void)
79587958
if (boot_cpu_has(X86_FEATURE_PDCM))
79597959
rdmsrq(MSR_IA32_PERF_CAPABILITIES, host_perf_cap);
79607960

7961-
if (!cpu_feature_enabled(X86_FEATURE_ARCH_LBR)) {
7961+
if (!cpu_feature_enabled(X86_FEATURE_ARCH_LBR) &&
7962+
!enable_mediated_pmu) {
79627963
x86_perf_get_lbr(&vmx_lbr_caps);
79637964

79647965
/*

0 commit comments

Comments
 (0)