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: 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,  "H. Peter Anvin" <hpa@zytor.com>,
	Vitaly Kuznetsov <vkuznets@redhat.com>,
	kvm@vger.kernel.org,  linux-kernel@vger.kernel.org,
	graf@amazon.de,  Ajay Kaher <ajay.kaher@broadcom.com>,
	Alexey Makhalov <alexey.makhalov@broadcom.com>,
	 Colin Percival <cperciva@tarsnap.com>
Subject: Re: [PATCH v2 0/3] Support "generic" CPUID timing leaf as KVM guest and host
Date: Thu, 21 Aug 2025 12:27:27 -0700	[thread overview]
Message-ID: <aKdzH2b8ShTVeWhx@google.com> (raw)
In-Reply-To: <933dc95ead067cf1b362f7b8c3ce9a72e31658d2.camel@infradead.org>

On Thu, Aug 21, 2025, David Woodhouse wrote:
> On Thu, 2025-08-21 at 09:26 -0700, Sean Christopherson wrote:
> > On Sat, Aug 16, 2025, David Woodhouse wrote:
> > > In https://lkml.org/lkml/2008/10/1/246 VMware proposed a generic standard
> > > for harmonising CPUID between hypervisors. It was mostly shot down in
> > > flames, but the generic timing leaf at 0x4000_0010 didn't quite die.
> > > 
> > > Mostly the hypervisor leaves at 0x4000_0xxx are very hypervisor-specific,
> > > but XNU and FreeBSD as guests will look for 0x4000_0010 unconditionally,
> > > under any hypervisor. The EC2 Nitro hypervisor has also exposed TSC
> > > frequency information in this leaf, since 2020.
> > > 
> > > As things stand, KVM guests have to reverse-calculate the TSC frequency
> > > from the mul/shift information given to them in the KVM clock to convert
> > > ticks into nanoseconds, with a corresponding loss of precision.
> > 
> > I would rather have the VMM use the Intel-define CPUID.0x15 to enumerate the
> > TSC frequency. 
> 
> The problem with that is that it's been quite unreliable. The kernel
> doesn't trust it even on chips as recent (hah) as Skylake. I'd be
> happier to trust what the hypervisor explicitly gives us. But yes, it
> should be *one* of the sources of information before we reverse-
> calculate it from the pvclock. 

Sorry, by "the VMM use" I mean have the host, e.g. QEMU, explicitly define TSC
frequency in CPUID.0x15 and CPU frequency in CPUID.0x16.  And then on the
KVM-as-a-guest side of things, trust those leaves when they're available.

So same idea as having the VMM fill 0x4000_0010, but piggyback the Intel-defined
leaves instead of the VMware-defined leaf.  One of the reasons I'd like to go
that route is to avoid having to choose one or the other when running under TDX,
where CPUID.{0x15,0x16} are provided by the "trusted" TDX-Module, but any PV
leaf is not.

Dunno how feasible it is to get non-Linux guests on board though...

  reply	other threads:[~2025-08-21 19:27 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-16 10:09 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-12-16 20:27   ` Sean Christopherson
2025-12-16 21:10     ` Doug Covelli
2025-12-16 22:59       ` Sean Christopherson
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 [this message]
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
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
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=aKdzH2b8ShTVeWhx@google.com \
    --to=seanjc@google.com \
    --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=dwmw2@infradead.org \
    --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=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

Powered by JetHome