Re: [PATCH v6 15/36] KVM: x86: Fix compute_guest_tsc() to handle negative time deltas

David Woodhouse <[email protected]>
Newsgroups org.xenproject.lists.xen-devel,org.kernel.vger.kvm,org.kernel.vger.linux-doc,org.kernel.vger.linux-kernel,org.kernel.vger.linux-kselftest
Message-ID <[email protected]>
On Fri, 2026-07-24 at 14:27 -0700, Sean Christopherson wrote:
> On Fri, Jul 03, 2026, David Woodhouse wrote:
> > From: David Woodhouse <[email protected]>
> > 
> > The compute_guest_tsc() function computes the guest TSC at a given
> > kernel_ns timestamp. When the master clock reference point
> > (master_kernel_ns) is earlier than vcpu->arch.this_tsc_nsec, the delta
> > is negative. Since pvclock_scale_delta() takes a u64, the negative
> > value wraps to a huge positive number, producing a wildly wrong result.
> > 
> > Handle negative deltas explicitly by negating the delta, scaling it,
> > and subtracting from this_tsc_write.
> 
> Does this need 
> 
>   Cc: [email protected]
> 
> or is this a "technically a bug fix, but can't happen in practice" sort of thing?

Honestly, there's so much hosed in kvmclock that we could debate a
cc:stable for half of this series. I'm not doing *any* of this to
actually add new features. For this one I'm not sure it's reachable in
practice; I think I did it mostly to shut Sashiko up.

I think even in the KVM_SET_CLOCK_GUEST it can't trigger, although I
have fantasies about changing the way KVM_SET_CLOCK_GUEST works to fix
that final ±1ns imprecision (which requires separate work on the
timekeeping core), that *might* trigger the negative delta here...
smime.p7s (application/pkcs7-signature, 6 KB) - not displayed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.