[PATCH v10 06/21] KVM: x86: Avoid NTP frequency skew for KVM clock on 32-bit host

From: Sean Christopherson

Date: Wed Aug 26 2026 - 17:35:53 EST


From: David Woodhouse <dwmw@xxxxxxxxxxxx>

Now that 64-bit KVM doesn't consume pvclock_gtod_data when getting the
kvmclock base, use the ktime_mono_to_any() version on 32-bit hosts so
that they too are unaffected by NPT sync.

Note, even if KVM still used pvclock_gtod_data for getting kvmclock base,
it would still be very doable and reasonable to avoid skew on 32-bit hosts,
it's just much simpler now that KVM uses ktime_mono_to_any().

Specifically, commit 53fafdbb8b21 ("KVM: x86: switch KVMCLOCK base to
monotonic raw clock") did so only for 64-bit hosts, by capturing the boot
offset from within the existing clocksource notifier update_pvclock_gtod().

That notifier was added in commit 16e8d74d2da9 ("KVM: x86: notifier for
clocksource changes") but only on x86_64, because its original purpose
was just to disable the "master clock" mode which is only supported on
x86_64.

Now that the notifier is used for more than disabling master clock mode,
enabling it would be trivial for 32-bit builds as well, but as above,
that's a moot point since get_kvmclock_base_ns() no longer relies on the
notifier.

Signed-off-by: David Woodhouse <dwmw@xxxxxxxxxxxx>
Reviewed-by: Paul Durrant <paul@xxxxxxx>
[sean: rebase on top of ktime_mono_to_any() usage]
Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
---
arch/x86/kvm/x86.c | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 46c2c2ea64fe..ed7986669bdb 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -926,19 +926,13 @@ static void update_pvclock_gtod(struct timekeeper *tk)

write_seqcount_end(&vdata->seq);
}
+#endif

static s64 get_kvmclock_base_ns(void)
{
/* Count up from boot time, but with the frequency of the raw clock. */
return ktime_to_ns(ktime_mono_to_any(ktime_get_raw(), TK_OFFS_BOOT));
}
-#else
-static s64 get_kvmclock_base_ns(void)
-{
- /* Master clock not used, so we can just use CLOCK_BOOTTIME. */
- return ktime_get_boottime_ns();
-}
-#endif

static uint32_t div_frac(uint32_t dividend, uint32_t divisor)
{
--
2.55.0.887.g758fc8c411-goog