On Wed, May 20, 2026, David Woodhouse wrote: > On Fri, 2026-05-15 at 12:19 -0700, Sean Christopherson wrote: > > If CPUID.0x16 is present and valid, use the CPU frequency provided by > > CPUID instead of assuming that the virtual CPU runs at the same > > frequency as TSC and/or kvmclock. Back before constant TSCs were a > > thing, treating the TSC and CPU frequencies as one and the same was > > somewhat reasonable, but now it's nonsensical, especially if the > > hypervisor explicitly enumerates the CPU frequency. > > > > Signed-off-by: Sean Christopherson <[email protected]> > > --- > > arch/x86/kernel/kvmclock.c | 16 +++++++++++++++- > > 1 file changed, 15 insertions(+), 1 deletion(-) > > > > diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c > > index 62c8ea2e6769..7607920ae386 100644 > > --- a/arch/x86/kernel/kvmclock.c > > +++ b/arch/x86/kernel/kvmclock.c > > @@ -190,6 +190,20 @@ void kvmclock_cpu_action(enum kvm_guest_cpu_action > > action) > > } > > } > > > > +static unsigned long kvm_get_cpu_khz(void) > > +{ > > + unsigned int cpu_khz; > > + > > + /* > > + * Prefer CPUID over kvmclock when possible, as the base CPU frequency > > + * isn't necessarily the same as the kvmlock "TSC" frequency. > > + */ > > + if (!cpuid_get_cpu_freq(&cpu_khz)) > > + return cpu_khz; > > + > > + return pvclock_tsc_khz(this_cpu_pvti()); > > I'm fine with this in principle but shouldn't the fallback be calling > kvm_get_tsc_khz() instead of directly calling pvclock_tsc_khz()?
Oh, yeah, for this patch, definitely yes, so that there's no side effects. The question really should be answered in the context of "x86/kvmclock: Obtain TSC frequency from CPUID if present", which subtly impacts the CPU frequency, but I think the answer is "yes" there as well.

