Commit 09a0c3f1 authored by Owen Hofmann's avatar Owen Hofmann Committed by Paolo Bonzini

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: default avatarOwen Hofmann <osh@google.com>
Reviewed-by: default avatarMarcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent ed9aad21
...@@ -1636,16 +1636,16 @@ static int kvm_guest_time_update(struct kvm_vcpu *v) ...@@ -1636,16 +1636,16 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
vcpu->hv_clock.system_time = kernel_ns + v->kvm->arch.kvmclock_offset; vcpu->hv_clock.system_time = kernel_ns + v->kvm->arch.kvmclock_offset;
vcpu->last_guest_tsc = tsc_timestamp; vcpu->last_guest_tsc = tsc_timestamp;
if (unlikely(kvm_read_guest_cached(v->kvm, &vcpu->pv_time,
&guest_hv_clock, sizeof(guest_hv_clock))))
return 0;
/* /*
* The interface expects us to write an even number signaling that the * The interface expects us to write an even number signaling that the
* update is finished. Since the guest won't see the intermediate * update is finished. Since the guest won't see the intermediate
* state, we just increase by 2 at the end. * state, we just increase by 2 at the end.
*/ */
vcpu->hv_clock.version += 2; vcpu->hv_clock.version = guest_hv_clock.version + 2;
if (unlikely(kvm_read_guest_cached(v->kvm, &vcpu->pv_time,
&guest_hv_clock, sizeof(guest_hv_clock))))
return 0;
/* retain PVCLOCK_GUEST_STOPPED if set in guest copy */ /* retain PVCLOCK_GUEST_STOPPED if set in guest copy */
pvclock_flags = (guest_hv_clock.flags & PVCLOCK_GUEST_STOPPED); pvclock_flags = (guest_hv_clock.flags & PVCLOCK_GUEST_STOPPED);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment