diff mbox

[3/3] kvmclock: Ensure proper env->tsc value for kvmclock_current_nsec calculation

Message ID 20140905135539.340689829@amt.cnet
State New
Headers show

Commit Message

Marcelo Tosatti Sept. 5, 2014, 1:52 p.m. UTC
Ensure proper env->tsc value for kvmclock_current_nsec calculation.

Reported-and-analyzed-by: Marcin GibuĊ‚a <m.gibula@beyond.pl>
Cc: qemu-stable@nongnu.org
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

---
 hw/i386/kvm/clock.c |    5 +++++
 1 file changed, 5 insertions(+)
diff mbox

Patch

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));