Subject: [PATCH 5/6] kvmclock: Ensure proper env->tsc value for kvmclock_current_nsec calculation

From: "Dr. David Alan Gilbert (git)" <[email-masked]>
Date: Wed, 22 Oct 2014 09:46:36 +0200

Message-id: <[email-masked]>
Patchwork-id: 61790
O-Subject: [RHEL-7.1 qemu-kvm PATCH 4/5] kvmclock: Ensure proper env->tsc value for kvmclock_current_nsec calculation
Bugzilla: 1098602 1130428
RH-Acked-by: Marcelo Tosatti <[email-masked]>
RH-Acked-by: Eduardo Habkost <[email-masked]>
RH-Acked-by: Paolo Bonzini <[email-masked]>

From: Marcelo Tosatti <[email-masked]>

Ensure proper env->tsc value for kvmclock_current_nsec calculation.

Reported-by: Marcin Gibuła <[email-masked]>
Analyzed-by: Marcin Gibuła <[email-masked]>
Cc: [email-masked]
Signed-off-by: Marcelo Tosatti <[email-masked]>
Signed-off-by: Paolo Bonzini <[email-masked]>
(cherry picked from commit 317b0a6d8ba44e9bf8f9c3dbd776c4536843d82c)
Signed-off-by: Miroslav Rezanina <[email-masked]>
---
 hw/i386/kvm/clock.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/hw/i386/kvm/clock.c b/hw/i386/kvm/clock.c
index 6d6f3a7..53056d4 100644
--- a/hw/i386/kvm/clock.c
+++ b/hw/i386/kvm/clock.c
@@ -16,6 +16,7 @@
 #include "qemu-common.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/kvm.h"
+#include "sysemu/cpus.h"
 #include "hw/sysbus.h"
 #include "hw/kvm/clock.h"
 
@@ -69,6 +70,9 @@ static void kvmclock_vm_state_change(void *opaque, int running,
         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));
-- 
1.8.3.1