aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOwen Hofmann <osh@google.com>2014-11-03 19:57:18 -0500
committerPaolo Bonzini <pbonzini@redhat.com>2014-11-08 02:20:54 -0500
commit09a0c3f110b2fbe3bd03817c416d00968666fd74 (patch)
tree97dbcecc9d44cb67f97bac0a814fec8dff663ff0
parented9aad215ff3374ffd720b83d26fda91e4367090 (diff)
kvm: x86: Fix kvm clock versioning.
kvm updates the version number for the guest paravirt clock structure by incrementing the version of its private copy. It does not read the guest version, so will write version = 2 in the first update for every new VM, including after restoring a saved state. If guest state is saved during reading the clock, it could read and accept struct fields and guest TSC from two different updates. This changes the code to increment the guest version and write it back. Signed-off-by: Owen Hofmann <osh@google.com> Reviewed-by: Marcelo Tosatti <mtosatti@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--arch/x86/kvm/x86.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index e0260ccd78a4..8bf37d0ab404 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1636,16 +1636,16 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
1636 vcpu->hv_clock.system_time = kernel_ns + v->kvm->arch.kvmclock_offset; 1636 vcpu->hv_clock.system_time = kernel_ns + v->kvm->arch.kvmclock_offset;
1637 vcpu->last_guest_tsc = tsc_timestamp; 1637 vcpu->last_guest_tsc = tsc_timestamp;
1638 1638
1639 if (unlikely(kvm_read_guest_cached(v->kvm, &vcpu->pv_time,
1640 &guest_hv_clock, sizeof(guest_hv_clock))))
1641 return 0;
1642
1639 /* 1643 /*
1640 * The interface expects us to write an even number signaling that the 1644 * The interface expects us to write an even number signaling that the
1641 * update is finished. Since the guest won't see the intermediate 1645 * update is finished. Since the guest won't see the intermediate
1642 * state, we just increase by 2 at the end. 1646 * state, we just increase by 2 at the end.
1643 */ 1647 */
1644 vcpu->hv_clock.version += 2; 1648 vcpu->hv_clock.version = guest_hv_clock.version + 2;
1645
1646 if (unlikely(kvm_read_guest_cached(v->kvm, &vcpu->pv_time,
1647 &guest_hv_clock, sizeof(guest_hv_clock))))
1648 return 0;
1649 1649
1650 /* retain PVCLOCK_GUEST_STOPPED if set in guest copy */ 1650 /* retain PVCLOCK_GUEST_STOPPED if set in guest copy */
1651 pvclock_flags = (guest_hv_clock.flags & PVCLOCK_GUEST_STOPPED); 1651 pvclock_flags = (guest_hv_clock.flags & PVCLOCK_GUEST_STOPPED);