On Fri, 2026-05-15 at 12:19 -0700, Sean Christopherson wrote: > Add a helper to register non-native, i.e. PV and CoCo, CPU and TSC > frequency calibration routines. This will allow consolidating handling > of common TSC properties that are forced by hypervisor (PV routines), > and will also allow adding sanity checks to guard against overriding a > TSC calibration routine with a routine that is less robust/trusted. > > Make the CPU calibration routine optional, as Xen (very sanely) doesn't > assume the CPU runs as the same frequency as the TSC. > > Wrap the helper in an #ifdef to document that the kernel overrides > the native routines when running as a VM, and to guard against unwanted > usage. Add a TODO to call out that AMD_MEM_ENCRYPT is a mess and doesn't > depend on HYPERVISOR_GUEST because it gates both guest and host code. > > No functional change intended. > > Reviewed-by: Michael Kelley <[email protected]> > Tested-by: Michael Kelley <[email protected]> > Signed-off-by: Sean Christopherson <[email protected]>
Mildly concerned that we might want to support multiple options — does it have CPUID 0x15? Does it have 0x40000x10? Does it have a pvclock? There are various permutations of those which are perhaps best handled by *trying* each one, in some order, and populating a struct with the answers? But on the basis that perfect is the enemy of good, Reviewed-by: David Woodhouse <[email protected]> > diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c > index b5991d53fc0e..e9e7394140dd 100644 > --- a/arch/x86/kernel/kvmclock.c > +++ b/arch/x86/kernel/kvmclock.c > @@ -321,8 +321,8 @@ void __init kvmclock_init(void) > flags = pvclock_read_flags(&hv_clock_boot[0].pvti); > kvm_sched_clock_init(flags & PVCLOCK_TSC_STABLE_BIT); > > - x86_platform.calibrate_tsc = kvm_get_tsc_khz; > - x86_platform.calibrate_cpu = kvm_get_tsc_khz; > + tsc_register_calibration_routines(kvm_get_tsc_khz, kvm_get_tsc_khz); > + > x86_platform.get_wallclock = kvm_get_wallclock; > x86_platform.set_wallclock = kvm_set_wallclock; > #ifdef CONFIG_X86_LOCAL_APIC Can we move those (and maybe everything in the context there too) up *before* the check for no-kvmclock at the top of the function? Probably in a separate patch.
smime.p7s
Description: S/MIME cryptographic signature

