From: Xiong Zhang <xiong.y.zhang@xxxxxxxxxxxxxxx> Before restore guest PMU context, call perf_guest_enter() to let perf core sched out all exclude_guest perf events and switch PMI to dedicated KVM_GUEST_PMI_VECTOR. After save guest PMU context, call perf_guest_exit() to let perf core switch PMI back to NMI and sched in exclude_guest perf events. Signed-off-by: Xiong Zhang <xiong.y.zhang@xxxxxxxxxxxxxxx> Tested-by: Yongwei Ma <yongwei.ma@xxxxxxxxx> Signed-off-by: Mingwei Zhang <mizhang@xxxxxxxxxx> --- 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 545930f743b9..5cc539bdcc7e 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); } + + 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(); + perf_guest_enter(kvm_lapic_get_reg(vcpu->arch.apic, APIC_LVTPC)); + static_call_cond(kvm_x86_pmu_restore_pmu_context)(vcpu); /* -- 2.46.0.rc1.232.g9752f9e123-goog