kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Woodhouse <dwmw2@infradead.org>
To: Sean Christopherson <seanjc@google.com>
Cc: Paul Durrant <pdurrant@amazon.co.uk>,
	Fred Griffoul <fgriffo@amazon.co.uk>,
	 Colin Percival <cperciva@tarsnap.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	 Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	 "x86@kernel.org" <x86@kernel.org>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Vitaly Kuznetsov <vkuznets@redhat.com>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	 "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Graf (AWS), Alexander" <graf@amazon.de>,
	 Ajay Kaher <ajay.kaher@broadcom.com>,
	Alexey Makhalov <alexey.makhalov@broadcom.com>
Subject: Re: [PATCH v2 0/3] Support "generic" CPUID timing leaf as KVM guest and host
Date: Thu, 04 Sep 2025 15:51:15 +0200	[thread overview]
Message-ID: <62d1231571c44b166a18181d724b32da33b38efb.camel@infradead.org> (raw)
In-Reply-To: <aLmTXb6PO02idqeM@google.com>

[-- Attachment #1: Type: text/plain, Size: 3498 bytes --]

On Thu, 2025-09-04 at 06:25 -0700, Sean Christopherson wrote:
> On Thu, Sep 04, 2025, David Woodhouse wrote:
> > On Thu, 2025-09-04 at 04:59 -0700, Sean Christopherson wrote:
> > > 
> > > I thought the original problem being solved was that the _guest_ doesn't know the
> > > effective TSC frequency?  Userspace can already get the effectively TSC frequency
> > > via KVM_GET_TSC_KHZ, why do we need another uAPI to provide that?  (Honest question,
> > > I feel like I'm missing something)
> > 
> > I believe that KVM_GET_TSC_KHZ returns what userspace *asked* for the
> > TSC frequency to be (vcpu->arch.virtual_tsc_khz), not what it actually
> > ended up being based on the measured host frequency and the available
> > scaling granularity (vcpu->hw_tsc_khz).
> 
> Ah, I see where you're coming from.  Purely out of curiosity, have you done the
> math to see if slop would be a problem in practice?  No worries if you haven't,
> just genuinely (and lazily) curious.

It's in the single-digit MHz range generally. Probably not a problem in
practice since the TSC varies with environmental conditions *anyway*
and needs to be refined with NTP/etc.

I'm more interested in getting the scaling information exactly right
for the VMClock case, where we expose microsecond-precision time to the
guest in terms of the TSC.

> Anyways, I'm a-ok reporting that information in KVM_GET_SUPPORTED_CPUID (again,
> only with constant TSC and scaling).  Reporting the effective frequency would be
> useful for the host too, e.g. for sanity checks.  What I specifically want to
> avoid is modifying guest CPUID at runtime.

Hm, in some cases I thought KVM had deliberately moved *to* doing CPUID
updates at runtime, so that its doesn't have to exempt the changable
leaves from the sanity checks which prevent userspace from updating
CPUID for a CPU which has already been run.

It's not just the existing Xen TSC leaf which is updated at runtime in
kvm_cpuid().

But I don't mind too much. If we give userspace a way to *know* the
effective frequency, I'm OK with requiring that userspace do so and
populate the corresponding CPUID leaves for itself, for Xen and KVM
alike. We'd need to expose the FSB frequency too, not just TSC.

I was only going with the runtime update because we are literally
already *doing* it this way in KVM.

> Hmm, the only wrinkle is that, if there is slop, KVM could report different
> information when run on different platforms, e.g. after live migration.  But so
> long as that possibility is documented, I don't think it's truly problematic.
> And it's another argument for not modifying guest CPUID directly; I'd rather let
> userspace figure out whether or not they care about the divergence than silently
> change things from the guest's perspective.
> 
> Alternatively (or in addition to), part of me wants to stealtily update
> KVM_GET_TSC_KHZ to report back the effective frequency, but I can see that being
> problematic, e.g. if a naive VMM reads KVM_GET_TSC_KHZ when saving vCPU state for
> live migration and after enough migrations, the slop ends up drastically skewing
> the guest's frequency.

Indeed. And I also want to tell userspace the precise *ratio* being
applied by hardware scaling, for the VMClock case where userspace
definitely knows *better* about what the host TSC frequency is at this
precise moment, and has to tell the guest what *its* TSC frequency is,
with the same precision.

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5069 bytes --]

  reply	other threads:[~2025-09-04 13:51 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-16 10:09 [PATCH v2 0/3] Support "generic" CPUID timing leaf as KVM guest and host David Woodhouse
2025-08-16 10:10 ` [PATCH v2 1/3] KVM: x86: Restore caching of KVM CPUID base David Woodhouse
2025-08-16 10:10 ` [PATCH v2 2/3] KVM: x86: Provide TSC frequency in "generic" timing infomation CPUID leaf David Woodhouse
2025-08-16 10:10 ` [PATCH v2 3/3] x86/kvm: Obtain TSC frequency from CPUID if present David Woodhouse
2025-08-21 16:26 ` [PATCH v2 0/3] Support "generic" CPUID timing leaf as KVM guest and host Sean Christopherson
2025-08-21 17:37   ` David Woodhouse
2025-08-21 19:27     ` Sean Christopherson
2025-08-21 20:42       ` David Woodhouse
2025-08-21 20:48         ` Sean Christopherson
2025-08-21 21:10           ` David Woodhouse
2025-08-22  1:57             ` Colin Percival
     [not found]             ` <01000198cf7ec03e-dfc78632-42ee-480b-8b51-3446fbb555d1-000000@email.amazonses.com>
2025-08-26 19:30               ` Sean Christopherson
2025-08-27  9:30                 ` David Woodhouse
2025-08-28 23:40                   ` Sean Christopherson
2025-08-29  9:50                     ` David Woodhouse
2025-08-29 11:08                       ` Durrant, Paul
2025-08-29 11:19                         ` David Woodhouse
2025-08-29 20:36                           ` Sean Christopherson
2025-09-02  8:31                             ` David Woodhouse
2025-09-02 17:49                               ` Sean Christopherson
2025-09-02 18:23                                 ` David Woodhouse
2025-09-04 11:59                                   ` Sean Christopherson
2025-09-04 12:14                                     ` David Woodhouse
2025-09-04 13:25                                       ` Sean Christopherson
2025-09-04 13:51                                         ` David Woodhouse [this message]
2025-09-05  7:57                                           ` 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=62d1231571c44b166a18181d724b32da33b38efb.camel@infradead.org \
    --to=dwmw2@infradead.org \
    --cc=ajay.kaher@broadcom.com \
    --cc=alexey.makhalov@broadcom.com \
    --cc=bp@alien8.de \
    --cc=cperciva@tarsnap.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=fgriffo@amazon.co.uk \
    --cc=graf@amazon.de \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=pdurrant@amazon.co.uk \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=vkuznets@redhat.com \
    --cc=x86@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).