]> Git Repo - linux.git/commitdiff
KVM: x86: Mask LVTPC when handling a PMI
authorJim Mattson <[email protected]>
Mon, 25 Sep 2023 17:34:47 +0000 (17:34 +0000)
committerSean Christopherson <[email protected]>
Mon, 25 Sep 2023 21:40:29 +0000 (14:40 -0700)
Per the SDM, "When the local APIC handles a performance-monitoring
counters interrupt, it automatically sets the mask flag in the LVT
performance counter register."  Add this behavior to KVM's local APIC
emulation.

Failure to mask the LVTPC entry results in spurious PMIs, e.g. when
running Linux as a guest, PMI handlers that do a "late_ack" spew a large
number of "dazed and confused" spurious NMI warnings.

Fixes: f5132b01386b ("KVM: Expose a version 2 architectural PMU to a guests")
Cc: [email protected]
Signed-off-by: Jim Mattson <[email protected]>
Tested-by: Mingwei Zhang <[email protected]>
Signed-off-by: Mingwei Zhang <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
[sean: massage changelog, correct Fixes]
Signed-off-by: Sean Christopherson <[email protected]>
arch/x86/kvm/lapic.c

index dcd60b39e794d95ab4b1b4046a69ec5cf1a9dffc..3e977dbbf9933d833fadd1a9e643e8db64ffcd49 100644 (file)
@@ -2759,13 +2759,17 @@ int kvm_apic_local_deliver(struct kvm_lapic *apic, int lvt_type)
 {
        u32 reg = kvm_lapic_get_reg(apic, lvt_type);
        int vector, mode, trig_mode;
+       int r;
 
        if (kvm_apic_hw_enabled(apic) && !(reg & APIC_LVT_MASKED)) {
                vector = reg & APIC_VECTOR_MASK;
                mode = reg & APIC_MODE_MASK;
                trig_mode = reg & APIC_LVT_LEVEL_TRIGGER;
-               return __apic_accept_irq(apic, mode, vector, 1, trig_mode,
-                                       NULL);
+
+               r = __apic_accept_irq(apic, mode, vector, 1, trig_mode, NULL);
+               if (r && lvt_type == APIC_LVTPC)
+                       kvm_lapic_set_reg(apic, APIC_LVTPC, reg | APIC_LVT_MASKED);
+               return r;
        }
        return 0;
 }
This page took 0.06218 seconds and 4 git commands to generate.