kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] Support "generic" CPUID timing leaf as KVM guest and host
@ 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
                   ` (3 more replies)
  0 siblings, 4 replies; 26+ messages in thread
From: David Woodhouse @ 2025-08-16 10:09 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
	Vitaly Kuznetsov, kvm, linux-kernel, graf, Ajay Kaher,
	Alexey Makhalov, Colin Percival

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.

There's certainly no way we can sanely use 0x4000_0010 for anything *else*
at this point. Just adopt it, as both guest and host. We already have the
infrastructure for keeping the TSC frequency information up to date for
the Xen CPUID leaf anyway, so do precisely the same for this one.

v2:
  • Fix inadvertent C++ism pointed out by syzbot:
    https://ci.syzbot.org/series/a9510b1a-8024-41ce-9775-675f5c165e20

David Woodhouse (3):
      KVM: x86: Restore caching of KVM CPUID base
      KVM: x86: Provide TSC frequency in "generic" timing infomation CPUID leaf
      x86/kvm: Obtain TSC frequency from CPUID if present

 arch/x86/include/asm/kvm_host.h      |  1 +
 arch/x86/include/asm/kvm_para.h      |  1 +
 arch/x86/include/uapi/asm/kvm_para.h | 11 +++++++++++
 arch/x86/kernel/kvm.c                | 10 ++++++++++
 arch/x86/kernel/kvmclock.c           |  7 ++++++-
 arch/x86/kvm/cpuid.c                 | 23 ++++++++++++++++++-----
 6 files changed, 47 insertions(+), 6 deletions(-)


^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2025-09-05  7:57 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2025-09-05  7:57                                           ` Sean Christopherson

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).