Commit 8bf02ebb authored by Radim Krčmář's avatar Radim Krčmář Committed by Kamal Mostafa

KVM: x86: make vapics_in_nmi_mode atomic

commit 42720138 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: default avatarRadim 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: default avatarPaolo Bonzini <pbonzini@redhat.com>
Signed-off-by: default avatarKamal Mostafa <kamal@canonical.com>
parent 4e570fe8
...@@ -572,7 +572,7 @@ struct kvm_arch { ...@@ -572,7 +572,7 @@ struct kvm_arch {
struct kvm_pic *vpic; struct kvm_pic *vpic;
struct kvm_ioapic *vioapic; struct kvm_ioapic *vioapic;
struct kvm_pit *vpit; struct kvm_pit *vpit;
int vapics_in_nmi_mode; atomic_t vapics_in_nmi_mode;
struct mutex apic_map_lock; struct mutex apic_map_lock;
struct kvm_apic_map *apic_map; struct kvm_apic_map *apic_map;
......
...@@ -305,7 +305,7 @@ static void pit_do_work(struct kthread_work *work) ...@@ -305,7 +305,7 @@ static void pit_do_work(struct kthread_work *work)
* LVT0 to NMI delivery. Other PIC interrupts are just sent to * LVT0 to NMI delivery. Other PIC interrupts are just sent to
* VCPU0, and only if its LVT0 is in EXTINT mode. * 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_for_each_vcpu(i, vcpu, kvm)
kvm_apic_nmi_wd_deliver(vcpu); kvm_apic_nmi_wd_deliver(vcpu);
} }
......
...@@ -1115,10 +1115,10 @@ static void apic_manage_nmi_watchdog(struct kvm_lapic *apic, u32 lvt0_val) ...@@ -1115,10 +1115,10 @@ static void apic_manage_nmi_watchdog(struct kvm_lapic *apic, u32 lvt0_val)
if (!nmi_wd_enabled) { if (!nmi_wd_enabled) {
apic_debug("Receive NMI setting on APIC_LVT0 " apic_debug("Receive NMI setting on APIC_LVT0 "
"for cpu %d\n", apic->vcpu->vcpu_id); "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) } 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) static int apic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment