mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: David Woodhouse <dwmw2@infradead.org>
Cc: pbonzini@redhat.com, Thomas Gleixner <tglx@linutronix.de>,
	kvm@vger.kernel.org,  linux-kernel@vger.kernel.org, paul@xen.org,
	dongli.zhang@oracle.com,  sashiko-reviews@lists.linux.dev
Subject: Re: [PATCH v10 21/21] KVM: x86: Use kernel timekeeping snapshot to get walltime+TSC
Date: Tue, 1 Sep 2026 12:33:50 -0700	[thread overview]
Message-ID: <apconttxYicjmZSd@google.com> (raw)
In-Reply-To: <7eedeed241687f3b5f5953bf6717afd2bf5a58d2.camel@infradead.org>

On Fri, Aug 28, 2026, David Woodhouse wrote:
> On Wed, 2026-08-26 at 21:49 +0000, sashiko-bot@kernel.org wrote:
> > [Severity: High]
> > Does removing KVM's local TSC clamping expose guests to mismatched time pairs?
> > 
> > When establishing the guest's PV clock, KVM provides a master clock
> > snapshot pairing a host TSC with a system time. The previous read_tsc()
> > logic explicitly clamped the TSC to cycle_last to maintain mathematical
> > consistency.
> 
> I think this is basically the same class of issue I brought up in
> https://lore.kernel.org/all/87v7beb7s3.ffs@fw13/ and Thomas said the
> right thing is just to ignore it?
>
> If the discrepancy was more than a few cycles, we shouldn't be in
> masterclock mode anyway, should we?

Agreed.  If a host CPU really has a TSC that is observably behind others, KVM
will mark the TSC unstable when loading a vCPU on that pCPU.

		s64 tsc_delta = !vcpu->arch.last_host_tsc ? 0 :
				rdtsc() - vcpu->arch.last_host_tsc;
		if (tsc_delta < 0)
			mark_tsc_unstable("KVM discovered backwards TSC");

And as Thomas pointed out, the discrepancy will show up at some point.  E.g. even
if the kernel provided a perfect pair, RDTSC from the guest would read a too-low
value since KVM has historically required identical offsets to use masterclock,
i.e. the guest would still be able to observe time going backwards if a vCPU did
__pvclock_clocksource_read() with a TSC that is behind the masterclock reference.

  reply	other threads:[~2026-09-01 19:33 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260826214952.129BB1F000E9@smtp.kernel.org>
2026-08-28 22:46 ` David Woodhouse
2026-09-01 19:33   ` Sean Christopherson [this message]
2026-08-26 21:32 [PATCH v10 00/21] KVM: x86: Cleaning up the KVM clock mess, part 1 Sean Christopherson
2026-08-26 21:33 ` [PATCH v10 21/21] KVM: x86: Use kernel timekeeping snapshot to get walltime+TSC Sean Christopherson
2026-09-01 19:17   ` Sean Christopherson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=apconttxYicjmZSd@google.com \
    --to=seanjc@google.com \
    --cc=dongli.zhang@oracle.com \
    --cc=dwmw2@infradead.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paul@xen.org \
    --cc=pbonzini@redhat.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®