KVM: LAPIC: Fix lapic timer mode transition
authorWanpeng Li <wanpeng.li@hotmail.com>
Thu, 5 Oct 2017 10:53:51 +0000 (03:53 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 12 Oct 2017 12:01:50 +0000 (14:01 +0200)
SDM 10.5.4.1 TSC-Deadline Mode mentioned that "Transitioning between TSC-Deadline
mode and other timer modes also disarms the timer". So the APIC Timer Initial Count
Register for one-shot/periodic mode should be reset. This patch do it.

Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
[Removed unnecessary definition of APIC_LVT_TIMER_MASK.]
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
arch/x86/kvm/lapic.c

index 69c5612be786fbc7909b6f81a8d0a29f2cd324a6..6723e2ca3d9d26e6170f89d75e084d9248030ab1 100644 (file)
@@ -1307,6 +1307,9 @@ static void apic_update_lvtt(struct kvm_lapic *apic)
                        apic->lapic_timer.timer_mode_mask;
 
        if (apic->lapic_timer.timer_mode != timer_mode) {
+               if (apic_lvtt_tscdeadline(apic) != (timer_mode ==
+                               APIC_LVT_TIMER_TSCDEADLINE))
+                       kvm_lapic_set_reg(apic, APIC_TMICT, 0);
                apic->lapic_timer.timer_mode = timer_mode;
                hrtimer_cancel(&apic->lapic_timer.timer);
        }