From: Xiong Zhang <xiong.y.zhang@xxxxxxxxxxxxxxx> Switch PMI handler at KVM context switch boundary because KVM uses a separate maskable interrupt vector other than the NMI handler for the host PMU to process its own PMIs. So invoke the perf API that allows registration of the PMI handler. Signed-off-by: Xiong Zhang <xiong.y.zhang@xxxxxxxxxxxxxxx> Signed-off-by: Dapeng Mi <dapeng1.mi@xxxxxxxxxxxxxxx> --- arch/x86/kvm/pmu.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c index 2ad71020a2c0..a12012a00c11 100644 --- a/arch/x86/kvm/pmu.c +++ b/arch/x86/kvm/pmu.c @@ -1097,6 +1097,8 @@ void kvm_pmu_save_pmu_context(struct kvm_vcpu *vcpu) if (pmc->counter) wrmsrl(pmc->msr_counter, 0); } + + x86_perf_guest_exit(); } void kvm_pmu_restore_pmu_context(struct kvm_vcpu *vcpu) @@ -1107,6 +1109,8 @@ void kvm_pmu_restore_pmu_context(struct kvm_vcpu *vcpu) lockdep_assert_irqs_disabled(); + x86_perf_guest_enter(kvm_lapic_get_reg(vcpu->arch.apic, APIC_LVTPC)); + static_call_cond(kvm_x86_pmu_restore_pmu_context)(vcpu); /* -- 2.45.0.rc1.225.g2a3ae87e7f-goog