summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Rogers <brogers@suse.com>2012-08-15 11:49:02 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-08-25 19:31:44 -0700
commit0ad5ec517eab8686580de44007d3af1f0e4bf423 (patch)
tree39c7c6e53c8584ae371558d0f39934d657f2bbd2
parent3d359b341ee48bc65c9d1a71a0f4ad20943e78da (diff)
KVM: x86: apply kvmclock offset to guest wall clock time
(cherry picked from commit 4b6486659a7defef82ea51b276024b3aa357fefc) When a guest migrates to a new host, the system time difference from the previous host is used in the updates to the kvmclock system time visible to the guest, resulting in a continuation of correct kvmclock based guest timekeeping. The wall clock component of the kvmclock provided time is currently not updated with this same time offset. Since the Linux guest caches the wall clock based time, this discrepency is not noticed until the guest is rebooted. After reboot the guest's time calculations are off. This patch adjusts the wall clock by the kvmclock_offset, resulting in correct guest time after a reboot. Cc: Zachary Amsden <zamsden@gmail.com> Signed-off-by: Bruce Rogers <brogers@suse.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--arch/x86/kvm/x86.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index be6d54929fa7..14c290de7985 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -907,6 +907,10 @@ static void kvm_write_wall_clock(struct kvm *kvm, gpa_t wall_clock)
*/
getboottime(&boot);
+ if (kvm->arch.kvmclock_offset) {
+ struct timespec ts = ns_to_timespec(kvm->arch.kvmclock_offset);
+ boot = timespec_sub(boot, ts);
+ }
wc.sec = boot.tv_sec;
wc.nsec = boot.tv_nsec;
wc.version = version;