]> git.ipfire.org Git - thirdparty/kernel/stable.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)
committerZefan Li <lizefan@huawei.com>
Thu, 22 Oct 2015 01:20:07 +0000 (09:20 +0800)
commit 42720138b06301cc8a7ee8a495a6d021c4b6a9bc upstream.

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]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
[lizf: Backported to 3.4: adjust context]
Signed-off-by: Zefan Li <lizefan@huawei.com>
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/i8254.c
arch/x86/kvm/lapic.c

index 4f787579b329572fb2b12d1406ddc92469e48172..d60facb1a9d484eedbf374aa94236fed3962b171 100644 (file)
@@ -509,7 +509,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;
 
        unsigned int tss_addr;
        struct page *apic_access_page;
index db336f9f2c8c55f44730f14a5a7500adbe12754d..eaad49aa5bed624915fffc4224c2d1cd16456d99 100644 (file)
@@ -317,7 +317,7 @@ static void pit_do_work(struct work_struct *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 578613da251e221ba20ae9cb845c71a84b672ac4..f935b52515bd2989e11c1b45f9b07dd0e6aa8fb5 100644 (file)
@@ -761,10 +761,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)