From: Kan Liang <kan.liang@xxxxxxxxxxxxxxx> Implement switch_interrupt interface for x86 PMU, switch PMI to dedicated KVM_GUEST_PMI_VECTOR at perf guest enter, and switch PMI back to NMI at perf guest exit. Signed-off-by: Xiong Zhang <xiong.y.zhang@xxxxxxxxxxxxxxx> Signed-off-by: Kan Liang <kan.liang@xxxxxxxxxxxxxxx> Tested-by: Yongwei Ma <yongwei.ma@xxxxxxxxx> Signed-off-by: Mingwei Zhang <mizhang@xxxxxxxxxx> --- arch/x86/events/core.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index 5bf78cd619bf..b17ef8b6c1a6 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -2673,6 +2673,15 @@ static bool x86_pmu_filter(struct pmu *pmu, int cpu) return ret; } +static void x86_pmu_switch_interrupt(bool enter, u32 guest_lvtpc) +{ + if (enter) + apic_write(APIC_LVTPC, APIC_DM_FIXED | KVM_GUEST_PMI_VECTOR | + (guest_lvtpc & APIC_LVT_MASKED)); + else + apic_write(APIC_LVTPC, APIC_DM_NMI); +} + static struct pmu pmu = { .pmu_enable = x86_pmu_enable, .pmu_disable = x86_pmu_disable, @@ -2702,6 +2711,8 @@ static struct pmu pmu = { .aux_output_match = x86_pmu_aux_output_match, .filter = x86_pmu_filter, + + .switch_interrupt = x86_pmu_switch_interrupt, }; void arch_perf_update_userpage(struct perf_event *event, -- 2.46.0.rc1.232.g9752f9e123-goog