Ensure proper env->tsc value for kvmclock_current_nsec calculation. Reported-and-analyzed-by: Marcin GibuÅa <m.gib...@beyond.pl> Cc: qemu-sta...@nongnu.org Signed-off-by: Marcelo Tosatti <mtosa...@redhat.com>
--- hw/i386/kvm/clock.c | 5 +++++ 1 file changed, 5 insertions(+) Index: qemu/hw/i386/kvm/clock.c =================================================================== --- qemu.orig/hw/i386/kvm/clock.c 2014-09-05 10:07:04.116665549 -0300 +++ qemu/hw/i386/kvm/clock.c 2014-09-05 10:31:06.894106473 -0300 @@ -17,6 +17,7 @@ #include "qemu/host-utils.h" #include "sysemu/sysemu.h" #include "sysemu/kvm.h" +#include "sysemu/cpus.h" #include "hw/sysbus.h" #include "hw/kvm/clock.h" @@ -65,6 +66,7 @@ cpu_physical_memory_read(kvmclock_struct_pa, &time, sizeof(time)); + assert(time.tsc_timestamp <= migration_tsc); delta = migration_tsc - time.tsc_timestamp; if (time.tsc_shift < 0) { delta >>= -time.tsc_shift; @@ -123,6 +125,9 @@ if (s->clock_valid) { return; } + + cpu_synchronize_all_states(); + cpu_clean_all_dirty(); ret = kvm_vm_ioctl(kvm_state, KVM_GET_CLOCK, &data); if (ret < 0) { fprintf(stderr, "KVM_GET_CLOCK failed: %s\n", strerror(ret));