Re: [PATCH v9 06/21] KVM: x86: Avoid NTP frequency skew for KVM clock on 32-bit host
Sean Christopherson <[email protected]>
| Newsgroups | org.kernel.vger.kvm,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
On Mon, Aug 10, 2026, Sean Christopherson wrote: > From: David Woodhouse <[email protected]> > > 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, > enable it for the 32-bit build too so that get_kvmclock_base_ns() can be > unaffected by NTP sync on 32-bit too. > > Signed-off-by: David Woodhouse <[email protected]> > Reviewed-by: Paul Durrant <[email protected]> > [sean: rebase on top of ktime_mono_to_any() usage] > Signed-off-by: Sean Christopherson <[email protected]> > --- ... > @@ -7118,9 +7111,9 @@ int kvm_x86_vendor_init(struct kvm_x86_init_ops *ops) > > if (pi_inject_timer == -1) > pi_inject_timer = housekeeping_enabled(HK_TYPE_TIMER); > -#ifdef CONFIG_X86_64 > pvclock_gtod_register_notifier(&pvclock_gtod_notifier); From https://sashiko.dev/#/patchset/20260810225500.869288-1-seanjc%40google.com: : Does this add unnecessary overhead to the timekeeper update path on 32-bit : builds? : : The commit message notes a rebase on top of ktime_mono_to_any() usage. Because : of that rebase, get_kvmclock_base_ns() now uses ktime_mono_to_any() directly : and no longer reads from pvclock_gtod_data. : : Since all other readers of pvclock_gtod_data remain guarded by CONFIG_X86_64, : is pvclock_gtod_data now effectively write-only on 32-bit? This would mean : update_pvclock_gtod() runs on every host core timekeeping update just to : populate an unused struct. Huh. Indeed. Now that "Compute kvmclock base without pvclock_gtod_data" will land before this patch, there's no need to register KVM's notifier on 32-bit, and this patch is simply: diff --git arch/x86/kvm/x86.c arch/x86/kvm/x86.c index 67c762b3bf28..edafe13f74cf 100644 --- arch/x86/kvm/x86.c +++ 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) { I'll post a v10, since this is a non-trivial change.