]> git.baikalelectronics.ru Git - kernel.git/commit
x86/kvm: fix LAPIC timer drift when guest uses periodic mode
authorDavid Vrabel <david.vrabel@nutanix.com>
Fri, 18 May 2018 15:55:46 +0000 (16:55 +0100)
committerRadim Krčmář <rkrcmar@redhat.com>
Thu, 24 May 2018 14:48:55 +0000 (16:48 +0200)
commited4f80b18a2983cecb5c00b755c5dc56b1554be1
tree92827a3a823918d887c3d612a740100f73ab6906
parenta337e323facb740b404a44cc5d8bc7b86b381006
x86/kvm: fix LAPIC timer drift when guest uses periodic mode

Since 4.10, commit 558228078d40 (KVM: LAPIC: add APIC Timer
periodic/oneshot mode VMX preemption timer support), guests using
periodic LAPIC timers (such as FreeBSD 8.4) would see their timers
drift significantly over time.

Differences in the underlying clocks and numerical errors means the
periods of the two timers (hv and sw) are not the same. This
difference will accumulate with every expiry resulting in a large
error between the hv and sw timer.

This means the sw timer may be running slow when compared to the hv
timer. When the timer is switched from hv to sw, the now active sw
timer will expire late. The guest VCPU is reentered and it switches to
using the hv timer. This timer catches up, injecting multiple IRQs
into the guest (of which the guest only sees one as it does not get to
run until the hv timer has caught up) and thus the guest's timer rate
is low (and becomes increasing slower over time as the sw timer lags
further and further behind).

I believe a similar problem would occur if the hv timer is the slower
one, but I have not observed this.

Fix this by synchronizing the deadlines for both timers to the same
time source on every tick. This prevents the errors from accumulating.

Fixes: 558228078d4086251306a0c4edf519ffda933c3a
Cc: Wanpeng Li <wanpeng.li@hotmail.com>
Signed-off-by: David Vrabel <david.vrabel@nutanix.com>
Cc: stable@vger.kernel.org
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Wanpeng Li <wanpengli@tencent.com>
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
arch/x86/kvm/lapic.c