]> git.baikalelectronics.ru Git - kernel.git/commitdiff
perf/x86/core: Pass "struct kvm_pmu *" to determine the guest values
authorLike Xu <like.xu@linux.intel.com>
Mon, 11 Apr 2022 10:19:32 +0000 (18:19 +0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 8 Jun 2022 08:47:45 +0000 (04:47 -0400)
Splitting the logic for determining the guest values is unnecessarily
confusing, and potentially fragile. Perf should have full knowledge and
control of what values are loaded for the guest.

If we change .guest_get_msrs() to take a struct kvm_pmu pointer, then it
can generate the full set of guest values by grabbing guest ds_area and
pebs_data_cfg. Alternatively, .guest_get_msrs() could take the desired
guest MSR values directly (ds_area and pebs_data_cfg), but kvm_pmu is
vendor agnostic, so we don't see any reason to not just pass the pointer.

Suggested-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Like Xu <like.xu@linux.intel.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Message-Id: <20220411101946.20262-4-likexu@tencent.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/events/core.c
arch/x86/events/intel/core.c
arch/x86/events/perf_event.h
arch/x86/include/asm/perf_event.h
arch/x86/kvm/vmx/vmx.c

index a9ebd096dfb443f27eb11067de6680a6a4b447b8..330825160b9a25e041f57ca0b98a8cee9a808a0e 100644 (file)
@@ -693,9 +693,9 @@ void x86_pmu_disable_all(void)
        }
 }
 
-struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr)
+struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr, void *data)
 {
-       return static_call(x86_pmu_guest_get_msrs)(nr);
+       return static_call(x86_pmu_guest_get_msrs)(nr, data);
 }
 EXPORT_SYMBOL_GPL(perf_guest_get_msrs);
 
index 8e5036f32e842d6a78780b60cdcc1969f67912d5..b56ead52790a61eee1cff8888ac0a9f65d1c52cf 100644 (file)
@@ -3972,7 +3972,7 @@ static int intel_pmu_hw_config(struct perf_event *event)
        return 0;
 }
 
-static struct perf_guest_switch_msr *intel_guest_get_msrs(int *nr)
+static struct perf_guest_switch_msr *intel_guest_get_msrs(int *nr, void *data)
 {
        struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
        struct perf_guest_switch_msr *arr = cpuc->guest_switch_msrs;
@@ -4005,7 +4005,7 @@ static struct perf_guest_switch_msr *intel_guest_get_msrs(int *nr)
        return arr;
 }
 
-static struct perf_guest_switch_msr *core_guest_get_msrs(int *nr)
+static struct perf_guest_switch_msr *core_guest_get_msrs(int *nr, void *data)
 {
        struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
        struct perf_guest_switch_msr *arr = cpuc->guest_switch_msrs;
index 4910dc41433bc273c050766885027af0a1368756..07fdef4f9ad259a6200dd6e7855b2018b8eb8ce4 100644 (file)
@@ -903,7 +903,7 @@ struct x86_pmu {
        /*
         * Intel host/guest support (KVM)
         */
-       struct perf_guest_switch_msr *(*guest_get_msrs)(int *nr);
+       struct perf_guest_switch_msr *(*guest_get_msrs)(int *nr, void *data);
 
        /*
         * Check period value for PERF_EVENT_IOC_PERIOD ioctl.
index f95ab4da6fea85407daf45fde8937f19a13fb6e0..58e2fcbb8bcc843f6c09ff1f2289a4e630cd6cd9 100644 (file)
@@ -519,10 +519,10 @@ static inline void perf_check_microcode(void) { }
 #endif
 
 #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_CPU_SUP_INTEL)
-extern struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr);
+extern struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr, void *data);
 extern int x86_perf_get_lbr(struct x86_pmu_lbr *lbr);
 #else
-struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr);
+struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr, void *data);
 static inline int x86_perf_get_lbr(struct x86_pmu_lbr *lbr)
 {
        return -1;
index f3175dae25aac71a6605c61fac481d563e5a4e5c..070b02162db646aef39522fcc11bae055513195a 100644 (file)
@@ -6794,9 +6794,10 @@ static void atomic_switch_perf_msrs(struct vcpu_vmx *vmx)
 {
        int i, nr_msrs;
        struct perf_guest_switch_msr *msrs;
+       struct kvm_pmu *pmu = vcpu_to_pmu(&vmx->vcpu);
 
        /* Note, nr_msrs may be garbage if perf_guest_get_msrs() returns NULL. */
-       msrs = perf_guest_get_msrs(&nr_msrs);
+       msrs = perf_guest_get_msrs(&nr_msrs, (void *)pmu);
        if (!msrs)
                return;