@@ -2852,10 +2852,9 @@ static int handle_pmi_common(struct pt_regs *regs, u64 status)
*/
if (__test_and_clear_bit(GLOBAL_STATUS_TRACE_TOPAPMI_BIT, (unsigned long *)&status)) {
handled++;
- if (unlikely(perf_guest_cbs && perf_guest_cbs->is_in_guest() &&
- perf_guest_cbs->handle_intel_pt_intr))
- perf_guest_cbs->handle_intel_pt_intr();
- else
+ if (likely(!perf_guest_cbs ||
+ !perf_guest_cbs->handle_intel_pt_intr ||
+ perf_guest_cbs->handle_intel_pt_intr()))
intel_pt_interrupt();
}
@@ -41,7 +41,7 @@ struct kvm_pmu_ops {
void (*reset)(struct kvm_vcpu *vcpu);
void (*deliver_pmi)(struct kvm_vcpu *vcpu);
void (*cleanup)(struct kvm_vcpu *vcpu);
- void (*handle_intel_pt_intr)(void);
+ int (*handle_intel_pt_intr)(void);
};
static inline u64 pmc_bitmask(struct kvm_pmc *pmc)
@@ -8292,13 +8292,17 @@ static unsigned long kvm_get_guest_ip(void)
return ip;
}
-static void kvm_handle_intel_pt_intr(void)
+static int kvm_handle_intel_pt_intr(void)
{
struct kvm_vcpu *vcpu = __this_cpu_read(current_vcpu);
+ if (!vcpu)
+ return -ENXIO;
+
kvm_make_request(KVM_REQ_PMI, vcpu);
__set_bit(MSR_CORE_PERF_GLOBAL_OVF_CTRL_TRACE_TOPA_PMI_BIT,
(unsigned long *)&vcpu->arch.pmu.global_status);
+ return 0;
}
static struct perf_guest_info_callbacks kvm_guest_cbs = {
@@ -30,7 +30,7 @@ struct perf_guest_info_callbacks {
int (*is_in_guest)(void);
int (*is_user_mode)(void);
unsigned long (*get_guest_ip)(void);
- void (*handle_intel_pt_intr)(void);
+ int (*handle_intel_pt_intr)(void);
};
#ifdef CONFIG_HAVE_HW_BREAKPOINT
Move the check for a non-NULL current_vcpu into KVM's PT intr handler instead of relying on the caller to perform the check. In addition to ensuring KVM's handler won't dereference a NULL pointer (and making it obvious that it can't), this avoids a reptoline when KVM is configured to run PT in "system mode", in which case handle_intel_pt_intr will be NULL. No functional change intended. Signed-off-by: Sean Christopherson <seanjc@google.com> --- arch/x86/events/intel/core.c | 7 +++---- arch/x86/kvm/pmu.h | 2 +- arch/x86/kvm/x86.c | 6 +++++- include/linux/perf_event.h | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-)