]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
KVM: x86: make vapics_in_nmi_mode atomic
authorRadim Krčmář <rkrcmar@redhat.com>
Wed, 1 Jul 2015 13:31:49 +0000 (15:31 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 3 Jul 2015 16:55:17 +0000 (18:55 +0200)
Writes were a bit racy, but hard to turn into a bug at the same time.
(Particularly because modern Linux doesn't use this feature anymore.)

Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
[Actually the next patch makes it much, much easier to trigger the race
 so I'm including this one for stable@ as well. - Paolo]
Cc: stable@vger.kernel.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/i8254.c
arch/x86/kvm/lapic.c

index c7fa57b529d2972c6e968a05625f65a4fa3ca14b..2a7f5d782c332d1965ac1c5a23a33289cfce7352 100644 (file)
@@ -607,7 +607,7 @@ struct kvm_arch {
        struct kvm_pic *vpic;
        struct kvm_ioapic *vioapic;
        struct kvm_pit *vpit;
-       int vapics_in_nmi_mode;
+       atomic_t vapics_in_nmi_mode;
        struct mutex apic_map_lock;
        struct kvm_apic_map *apic_map;
 
index 4dce6f8b6129ebea2432840154cc97efd513947b..f90952f64e796eae9049690910a511a7d7ff79dd 100644 (file)
@@ -305,7 +305,7 @@ static void pit_do_work(struct kthread_work *work)
                 * LVT0 to NMI delivery. Other PIC interrupts are just sent to
                 * VCPU0, and only if its LVT0 is in EXTINT mode.
                 */
-               if (kvm->arch.vapics_in_nmi_mode > 0)
+               if (atomic_read(&kvm->arch.vapics_in_nmi_mode) > 0)
                        kvm_for_each_vcpu(i, vcpu, kvm)
                                kvm_apic_nmi_wd_deliver(vcpu);
        }
index 36e9de1b4127c5576ceb292c6ef320eae830df24..607a56b35327f9a1e83f604db2b99c7b09d8ea30 100644 (file)
@@ -1263,10 +1263,10 @@ static void apic_manage_nmi_watchdog(struct kvm_lapic *apic, u32 lvt0_val)
                if (!nmi_wd_enabled) {
                        apic_debug("Receive NMI setting on APIC_LVT0 "
                                   "for cpu %d\n", apic->vcpu->vcpu_id);
-                       apic->vcpu->kvm->arch.vapics_in_nmi_mode++;
+                       atomic_inc(&apic->vcpu->kvm->arch.vapics_in_nmi_mode);
                }
        } else if (nmi_wd_enabled)
-               apic->vcpu->kvm->arch.vapics_in_nmi_mode--;
+               atomic_dec(&apic->vcpu->kvm->arch.vapics_in_nmi_mode);
 }
 
 static int apic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val)