diff options
author | Radim Krčmář <rkrcmar@redhat.com> | 2014-10-30 10:06:45 -0400 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2014-11-03 06:07:31 -0500 |
commit | e462755cae2bf8297a663278935ad4d59812d2f3 (patch) | |
tree | 5ab71b8f6bf93fab7ab1afa2cb84f3f8f498e540 /arch/x86/kvm/lapic.c | |
parent | 02d5d55b7e39b63feb71bc49a75f58d342527d16 (diff) |
KVM: x86: detect SPIV changes under APICv
APIC-write VM exits are "trap-like": they save CS:RIP values for the
instruction after the write, and more importantly, the handler will
already see the new value in the virtual-APIC page.
This caused a bug if you used KVM_SET_IRQCHIP to set the SW-enabled bit
in the SPIV register. The chain of events is as follows:
* When the irqchip is added to the destination VM, the apic_sw_disabled
static key is incremented (1)
* When the KVM_SET_IRQCHIP ioctl is invoked, it is decremented (0)
* When the guest disables the bit in the SPIV register, e.g. as part of
shutdown, apic_set_spiv does not notice the change and the static key is
_not_ incremented.
* When the guest is destroyed, the static key is decremented (-1),
resulting in this trace:
WARNING: at kernel/jump_label.c:81 __static_key_slow_dec+0xa6/0xb0()
jump label: negative count!
[<ffffffff816bf898>] dump_stack+0x19/0x1b
[<ffffffff8107c6f1>] warn_slowpath_common+0x61/0x80
[<ffffffff8107c76c>] warn_slowpath_fmt+0x5c/0x80
[<ffffffff811931e6>] __static_key_slow_dec+0xa6/0xb0
[<ffffffff81193226>] static_key_slow_dec_deferred+0x16/0x20
[<ffffffffa0637698>] kvm_free_lapic+0x88/0xa0 [kvm]
[<ffffffffa061c63e>] kvm_arch_vcpu_uninit+0x2e/0xe0 [kvm]
[<ffffffffa05ff301>] kvm_vcpu_uninit+0x21/0x40 [kvm]
[<ffffffffa067cec7>] vmx_free_vcpu+0x47/0x70 [kvm_intel]
[<ffffffffa061bc50>] kvm_arch_vcpu_free+0x50/0x60 [kvm]
[<ffffffffa061ca22>] kvm_arch_destroy_vm+0x102/0x260 [kvm]
[<ffffffff810b68fd>] ? synchronize_srcu+0x1d/0x20
[<ffffffffa06030d1>] kvm_put_kvm+0xe1/0x1c0 [kvm]
[<ffffffffa06036f8>] kvm_vcpu_release+0x18/0x20 [kvm]
[<ffffffff81215c62>] __fput+0x102/0x310
[<ffffffff81215f4e>] ____fput+0xe/0x10
[<ffffffff810ab664>] task_work_run+0xb4/0xe0
[<ffffffff81083944>] do_exit+0x304/0xc60
[<ffffffff816c8dfc>] ? _raw_spin_unlock_irq+0x2c/0x50
[<ffffffff810fd22d>] ? trace_hardirqs_on_caller+0xfd/0x1c0
[<ffffffff8108432c>] do_group_exit+0x4c/0xc0
[<ffffffff810843b4>] SyS_exit_group+0x14/0x20
[<ffffffff816d33a9>] system_call_fastpath+0x16/0x1b
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'arch/x86/kvm/lapic.c')
-rw-r--r-- | arch/x86/kvm/lapic.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 66dd1731ab99..80df439d4086 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c | |||
@@ -206,11 +206,13 @@ out: | |||
206 | 206 | ||
207 | static inline void apic_set_spiv(struct kvm_lapic *apic, u32 val) | 207 | static inline void apic_set_spiv(struct kvm_lapic *apic, u32 val) |
208 | { | 208 | { |
209 | u32 prev = kvm_apic_get_reg(apic, APIC_SPIV); | 209 | bool enabled = val & APIC_SPIV_APIC_ENABLED; |
210 | 210 | ||
211 | apic_set_reg(apic, APIC_SPIV, val); | 211 | apic_set_reg(apic, APIC_SPIV, val); |
212 | if ((prev ^ val) & APIC_SPIV_APIC_ENABLED) { | 212 | |
213 | if (val & APIC_SPIV_APIC_ENABLED) { | 213 | if (enabled != apic->sw_enabled) { |
214 | apic->sw_enabled = enabled; | ||
215 | if (enabled) { | ||
214 | static_key_slow_dec_deferred(&apic_sw_disabled); | 216 | static_key_slow_dec_deferred(&apic_sw_disabled); |
215 | recalculate_apic_map(apic->vcpu->kvm); | 217 | recalculate_apic_map(apic->vcpu->kvm); |
216 | } else | 218 | } else |
@@ -1357,7 +1359,7 @@ void kvm_free_lapic(struct kvm_vcpu *vcpu) | |||
1357 | if (!(vcpu->arch.apic_base & MSR_IA32_APICBASE_ENABLE)) | 1359 | if (!(vcpu->arch.apic_base & MSR_IA32_APICBASE_ENABLE)) |
1358 | static_key_slow_dec_deferred(&apic_hw_disabled); | 1360 | static_key_slow_dec_deferred(&apic_hw_disabled); |
1359 | 1361 | ||
1360 | if (!(kvm_apic_get_reg(apic, APIC_SPIV) & APIC_SPIV_APIC_ENABLED)) | 1362 | if (!apic->sw_enabled) |
1361 | static_key_slow_dec_deferred(&apic_sw_disabled); | 1363 | static_key_slow_dec_deferred(&apic_sw_disabled); |
1362 | 1364 | ||
1363 | if (apic->regs) | 1365 | if (apic->regs) |