KVM: x86: Fix kvmclock bug
authorZachary Amsden <zamsden@redhat.com>
Sun, 19 Sep 2010 00:38:12 +0000 (14:38 -1000)
committerAvi Kivity <avi@redhat.com>
Sun, 24 Oct 2010 08:52:56 +0000 (10:52 +0200)
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>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
arch/x86/kvm/x86.c

index a51635ee85ec685e2f1d052767c76c59f0b528f6..0b021e16f9dd9a2ee17619c397b8ff0cda5ea03c 100644 (file)
@@ -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;
 
        /*