aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRadim Krčmář <rkrcmar@redhat.com>2015-07-01 09:31:49 -0400
committerPaolo Bonzini <pbonzini@redhat.com>2015-07-03 12:55:17 -0400
commit42720138b06301cc8a7ee8a495a6d021c4b6a9bc (patch)
treefbffa8a4feceef419b8d1f56cd521148095a8ba5
parent2ecd9d29abb171d6e97a4f3eb29d7456a11401b7 (diff)
KVM: x86: make vapics_in_nmi_mode atomic
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>
-rw-r--r--arch/x86/include/asm/kvm_host.h2
-rw-r--r--arch/x86/kvm/i8254.c2
-rw-r--r--arch/x86/kvm/lapic.c4
3 files changed, 4 insertions, 4 deletions
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index c7fa57b529d2..2a7f5d782c33 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -607,7 +607,7 @@ struct kvm_arch {
607 struct kvm_pic *vpic; 607 struct kvm_pic *vpic;
608 struct kvm_ioapic *vioapic; 608 struct kvm_ioapic *vioapic;
609 struct kvm_pit *vpit; 609 struct kvm_pit *vpit;
610 int vapics_in_nmi_mode; 610 atomic_t vapics_in_nmi_mode;
611 struct mutex apic_map_lock; 611 struct mutex apic_map_lock;
612 struct kvm_apic_map *apic_map; 612 struct kvm_apic_map *apic_map;
613 613
diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c
index 4dce6f8b6129..f90952f64e79 100644
--- a/arch/x86/kvm/i8254.c
+++ b/arch/x86/kvm/i8254.c
@@ -305,7 +305,7 @@ static void pit_do_work(struct kthread_work *work)
305 * LVT0 to NMI delivery. Other PIC interrupts are just sent to 305 * LVT0 to NMI delivery. Other PIC interrupts are just sent to
306 * VCPU0, and only if its LVT0 is in EXTINT mode. 306 * VCPU0, and only if its LVT0 is in EXTINT mode.
307 */ 307 */
308 if (kvm->arch.vapics_in_nmi_mode > 0) 308 if (atomic_read(&kvm->arch.vapics_in_nmi_mode) > 0)
309 kvm_for_each_vcpu(i, vcpu, kvm) 309 kvm_for_each_vcpu(i, vcpu, kvm)
310 kvm_apic_nmi_wd_deliver(vcpu); 310 kvm_apic_nmi_wd_deliver(vcpu);
311 } 311 }
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 36e9de1b4127..607a56b35327 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -1263,10 +1263,10 @@ static void apic_manage_nmi_watchdog(struct kvm_lapic *apic, u32 lvt0_val)
1263 if (!nmi_wd_enabled) { 1263 if (!nmi_wd_enabled) {
1264 apic_debug("Receive NMI setting on APIC_LVT0 " 1264 apic_debug("Receive NMI setting on APIC_LVT0 "
1265 "for cpu %d\n", apic->vcpu->vcpu_id); 1265 "for cpu %d\n", apic->vcpu->vcpu_id);
1266 apic->vcpu->kvm->arch.vapics_in_nmi_mode++; 1266 atomic_inc(&apic->vcpu->kvm->arch.vapics_in_nmi_mode);
1267 } 1267 }
1268 } else if (nmi_wd_enabled) 1268 } else if (nmi_wd_enabled)
1269 apic->vcpu->kvm->arch.vapics_in_nmi_mode--; 1269 atomic_dec(&apic->vcpu->kvm->arch.vapics_in_nmi_mode);
1270} 1270}
1271 1271
1272static int apic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val) 1272static int apic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val)