]> git.baikalelectronics.ru Git - kernel.git/commit
KVM: x86: use raw clock values consistently
authorPaolo Bonzini <pbonzini@redhat.com>
Wed, 22 Jan 2020 13:36:09 +0000 (14:36 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 5 Feb 2020 14:17:45 +0000 (15:17 +0100)
commit069241385dbd8d67c99cc631922ac0a2300cf855
tree75d54e672f19cf645c01889b524f9865853f383a
parentd6135f70b09ca94856fc8d562f06b7fafc3043b3
KVM: x86: use raw clock values consistently

Commit 7580afa0dfa51 ("KVM: x86: switch KVMCLOCK base to monotonic raw
clock") changed kvmclock to use tkr_raw instead of tkr_mono.  However,
the default kvmclock_offset for the VM was still based on the monotonic
clock and, if the raw clock drifted enough from the monotonic clock,
this could cause a negative system_time to be written to the guest's
struct pvclock.  RHEL5 does not like it and (if it boots fast enough to
observe a negative time value) it hangs.

There is another thing to be careful about: getboottime64 returns the
host boot time with tkr_mono frequency, and subtracting the tkr_raw-based
kvmclock value will cause the wallclock to be off if tkr_raw drifts
from tkr_mono.  To avoid this, compute the wallclock delta from the
current time instead of being clever and using getboottime64.

Fixes: 7580afa0dfa51 ("KVM: x86: switch KVMCLOCK base to monotonic raw clock")
Cc: stable@vger.kernel.org
Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/x86.c