[GIT PULL] KVM: x86: Timekeeping fixes+cleanups for 7.4
From: Sean Christopherson
Date: Fri Oct 16 2026 - 00:45:00 EST
Part 1 of 2 (or maybe 3) of David's war on kvmclock. Ugh, and when looking at
the shortlog, I realized I botched the author on these:
KVM: x86: Use kernel timekeeping snapshot for monotonic clock
KVM: x86: Use kernel timekeeping snapshot to get walltime+TSC
Holler if you would prefer a fixup to get the author right; these have been in
-next for over a month, so I opted to send them as-is instead of doing a super
last minute rewrite.
The following changes since commit d4b7fb647204f0c81dfeae2d1a708e4d858e0c94:
Merge branch 'kvm-xen-longmode' into HEAD (2026-09-04 17:35:03 +0200)
are available in the Git repository at:
https://github.com/kvm-x86/linux.git tags/kvm-x86-clocks-7.4
for you to fetch changes up to d7841275e1fb4ad1e1877e56725ebda5b6e3143d:
KVM: x86: Use kernel timekeeping snapshot to get walltime+TSC (2026-09-11 11:46:19 -0700)
----------------------------------------------------------------
KVM x86 timekeeping fixes and cleanups for 7.4
Fix a variety of warts in KVM's handling of guest TSC, kvmclock, and
timekeeping in general, as a (big) first step towards addressing several
longstanding problems with the kvmclock implementation.
Most notably, fix a precision issue where get_kvmclock_ns() computed the
clock from the *host* TSC without applying guest TSC scaling, causing
systemic drift from the values the guest computes from its own TSC.
As a bonus cleanup, rip out the whole pvclock_gtod_data hack, which was
shadowing the kernel's timekeeping, and use ktime snapshots.
----------------------------------------------------------------
David Woodhouse (14):
KVM: x86: Improve accuracy of KVM clock when TSC scaling is in force
KVM: x86: Explicitly disable TSC scaling without CONSTANT_TSC
KVM: x86: Activate master clock immediately on vCPU creation
KVM: x86: Compute kvmclock base without pvclock_gtod_data
KVM: x86: Avoid NTP frequency skew for KVM clock on 32-bit host
KVM: x86: Wrap all of __get_kvmclock_master_clock() with CONFIG_X86_64=y
KVM: x86: Fall back to non-master-clock if clockread fails in get_kvmclock()
KVM: x86: Fix KVM clock precision in get_kvmclock() with TSC scaling
KVM: x86: Use get_kvmclock() in kvm_get_wall_clock_epoch()
KVM: x86: Fix compute_guest_tsc() to handle negative time deltas
KVM: x86: Upscale TSC to "now", not master clock when updating PV clocks
KVM: x86: Simplify and comment kvm_get_time_scale()
KVM: x86: Remove implicit rdtsc() from kvm_compute_l1_tsc_offset()
KVM: x86: Use kernel timekeeping snapshots for getting kvmclock time since boot
Sean Christopherson (7):
KVM: x86: Update "last guest TSC" snapshot prior to enabling IRQs/preemption
KVM: x86: Drop unnecessary CPU pinning when computing/getting kvmclock
KVM: x86: Move "no master clock" fallback from __get_kvmclock() to get_kvmclock()
KVM: x86: Disable preemption, not IRQs, when getting TSC+freq pair
KVM: x86: Make master clock logic in guest PV clock updates 64-bit only
KVM: x86: Use kernel timekeeping snapshot for monotonic clock
KVM: x86: Use kernel timekeeping snapshot to get walltime+TSC
arch/x86/include/asm/kvm_host.h | 6 +-
arch/x86/kvm/cpuid.c | 1 +
arch/x86/kvm/msrs.c | 3 +-
arch/x86/kvm/svm/svm.c | 3 +-
arch/x86/kvm/vmx/vmx.c | 10 +
arch/x86/kvm/x86.c | 480 ++++++++++++++++++----------------------
arch/x86/kvm/x86.h | 3 +-
7 files changed, 240 insertions(+), 266 deletions(-)