]> git.baikalelectronics.ru Git - kernel.git/commitdiff
KVM: x86/pmu: Adjust precise_ip to emulate Ice Lake guest PDIR counter
authorLike Xu <like.xu@linux.intel.com>
Mon, 11 Apr 2022 10:19:38 +0000 (18:19 +0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 8 Jun 2022 08:48:00 +0000 (04:48 -0400)
The PEBS-PDIR facility on Ice Lake server is supported on IA31_FIXED0 only.
If the guest configures counter 32 and PEBS is enabled, the PEBS-PDIR
facility is supposed to be used, in which case KVM adjusts attr.precise_ip
to 3 and request host perf to assign the exactly requested counter or fail.

The CPU model check is also required since some platforms may place the
PEBS-PDIR facility in another counter index.

Signed-off-by: Like Xu <like.xu@linux.intel.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Message-Id: <20220411101946.20262-10-likexu@tencent.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/events/intel/core.c
arch/x86/kvm/pmu.c
arch/x86/kvm/pmu.h

index 70a5c66789df1429aa1c296a6dbfdb6d5353449e..7ef7fd4ab29bd32ac3c9c66ba13b4d4ef4bcddae 100644 (file)
@@ -4024,8 +4024,8 @@ static struct perf_guest_switch_msr *intel_guest_get_msrs(int *nr, void *data)
 
        if (!x86_pmu.pebs_ept)
                return arr;
-       pebs_enable = (*nr)++;
 
+       pebs_enable = (*nr)++;
        arr[pebs_enable] = (struct perf_guest_switch_msr){
                .msr = MSR_IA32_PEBS_ENABLE,
                .host = cpuc->pebs_enabled & ~cpuc->intel_ctrl_guest_mask,
index cdefcb091ac85eec7985d476539101c3c1044394..162dfe23c07162c63a01bc0121215a9ccc4f3a39 100644 (file)
@@ -175,6 +175,8 @@ static void pmc_reprogram_counter(struct kvm_pmc *pmc, u32 type,
                 * could possibly care here is unsupported and needs changes.
                 */
                attr.precise_ip = 1;
+               if (x86_match_cpu(vmx_icl_pebs_cpu) && pmc->idx == 32)
+                       attr.precise_ip = 3;
        }
 
        event = perf_event_create_kernel_counter(&attr, -1, current,
index e745f443b6a8fac72e4ff85c11067fad300f9a30..5966ce18a82ba5eaa18d21cb681cd06ba02371b7 100644 (file)
@@ -4,6 +4,8 @@
 
 #include <linux/nospec.h>
 
+#include <asm/cpu_device_id.h>
+
 #define vcpu_to_pmu(vcpu) (&(vcpu)->arch.pmu)
 #define pmu_to_vcpu(pmu)  (container_of((pmu), struct kvm_vcpu, arch.pmu))
 #define pmc_to_pmu(pmc)   (&(pmc)->vcpu->arch.pmu)
 #define VMWARE_BACKDOOR_PMC_REAL_TIME          0x10001
 #define VMWARE_BACKDOOR_PMC_APPARENT_TIME      0x10002
 
+static const struct x86_cpu_id vmx_icl_pebs_cpu[] = {
+       X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_D, NULL),
+       X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_X, NULL),
+       {}
+};
+
 struct kvm_event_hw_type_mapping {
        u8 eventsel;
        u8 unit_mask;