public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [KVM timekeeping fixes 1/4] Fix kvmclock bug
@ 2010-09-19  0:38 Zachary Amsden
  2010-09-19  0:38 ` [KVM timekeeping fixes 2/4] Make math work for other scales Zachary Amsden
  2010-09-20 15:41 ` [KVM timekeeping fixes 1/4] Fix kvmclock bug Marcelo Tosatti
  0 siblings, 2 replies; 10+ messages in thread
From: Zachary Amsden @ 2010-09-19  0:38 UTC (permalink / raw)
  To: kvm
  Cc: Zachary Amsden, Avi Kivity, Marcelo Tosatti, Glauber Costa,
	linux-kernel

If preempted after kvmclock values are updated, but before hardware
virtualization is entered, the last tsc time as read by the guest is
never set.  It underflows the next time kvmclock is updated if there
has not yet been a successful entry / exit into hardware virt.

Fix this by simply setting last_tsc to the newly read tsc value so
that any computed nsec advance of kvmclock is nulled.

Signed-off-by: Zachary Amsden <zamsden@redhat.com>
---
 arch/x86/kvm/x86.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index a51635e..0b021e1 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1095,6 +1095,7 @@ static int kvm_write_guest_time(struct kvm_vcpu *v)
 	vcpu->hv_clock.tsc_timestamp = tsc_timestamp;
 	vcpu->hv_clock.system_time = kernel_ns + v->kvm->arch.kvmclock_offset;
 	vcpu->last_kernel_ns = kernel_ns;
+	vcpu->last_guest_tsc = tsc_timestamp;
 	vcpu->hv_clock.flags = 0;
 
 	/*
-- 
1.6.6.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2010-09-24  0:10 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-19  0:38 [KVM timekeeping fixes 1/4] Fix kvmclock bug Zachary Amsden
2010-09-19  0:38 ` [KVM timekeeping fixes 2/4] Make math work for other scales Zachary Amsden
2010-09-19  0:38   ` [KVM timekeeping fixes 3/4] Rename timer function Zachary Amsden
2010-09-19  0:38     ` [KVM timekeeping fixes 4/4] TSC catchup mode Zachary Amsden
2010-09-20 15:38       ` Marcelo Tosatti
2010-09-21  1:11         ` Zachary Amsden
2010-09-21 18:18           ` Marcelo Tosatti
2010-09-22 19:25             ` Zachary Amsden
2010-09-23 19:57               ` Marcelo Tosatti
2010-09-20 15:41 ` [KVM timekeeping fixes 1/4] Fix kvmclock bug Marcelo Tosatti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox