[PATCH v7 22/36] KVM: x86: Remove runtime Xen TSC frequency CPUID update
David Woodhouse <[email protected]> Tue, 28 Jul 2026 15:40:02 +0100
| Newsgroups | gmane.comp.emulators.xen.devel,gmane.comp.emulators.kvm.devel,gmane.linux.documentation,gmane.linux.kernel |
|---|---|
| Message-ID | <[email protected]> |
From: David Woodhouse <[email protected]> Remove the code in kvm_cpuid() that dynamically updates the Xen TSC info CPUID leaf at runtime. This code was updating the wrong sub-leaf anyway (0x40000x03/2 EAX is the *host* TSC frequency per the Xen ABI, not the guest frequency which belongs in 0x40000x03/0 ECX). Userspace now has all the information it needs to populate the Xen TSC info leaves (and the generic 0x40000010 timing leaf) at vCPU setup time: - KVM_GET_CLOCK_GUEST returns the pvclock_vcpu_time_info structure containing tsc_to_system_mul and tsc_shift (Xen leaf index 1) - KVM_VCPU_TSC_SCALE returns the effective TSC and bus frequencies in kHz (Xen leaf index 2, and 0x40000010) - KVM_VCPU_TSC_SCALE returns the raw hardware scaling ratio for precise arithmetic (VMClock) This eliminates the last instance of KVM modifying guest CPUID entries at runtime for timing information. Signed-off-by: David Woodhouse <[email protected]> --- arch/x86/kvm/cpuid.c | 17 ----------------- arch/x86/kvm/xen.h | 13 ------------- 2 files changed, 30 deletions(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 7049f5a5597b..ddb022cb203a 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -16,7 +16,6 @@ #include <linux/vmalloc.h> #include <linux/uaccess.h> #include <linux/sched/stat.h> -#include <linux/units.h> #include <asm/processor.h> #include <asm/user.h> @@ -2133,22 +2132,6 @@ bool kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx, } else if (function == 0x80000007) { if (kvm_hv_invtsc_suppressed(vcpu)) *edx &= ~feature_bit(CONSTANT_TSC); - } else if (IS_ENABLED(CONFIG_KVM_XEN) && - kvm_xen_is_tsc_leaf(vcpu, function)) { - /* - * Update guest TSC frequency information if necessary. - * Ignore failures, there is no sane value that can be - * provided if KVM can't get the TSC frequency. - */ - if (kvm_check_request(KVM_REQ_CLOCK_UPDATE, vcpu)) - kvm_guest_time_update(vcpu); - - if (index == 1) { - *ecx = vcpu->arch.pvclock_tsc_mul; - *edx = vcpu->arch.pvclock_tsc_shift; - } else if (index == 2) { - *eax = div_u64(vcpu->arch.hw_tsc_hz, HZ_PER_KHZ); - } } } else { *eax = *ebx = *ecx = *edx = 0; diff --git a/arch/x86/kvm/xen.h b/arch/x86/kvm/xen.h index 59e6128a7bd3..f372855857a8 100644 --- a/arch/x86/kvm/xen.h +++ b/arch/x86/kvm/xen.h @@ -50,14 +50,6 @@ static inline void kvm_xen_sw_enable_lapic(struct kvm_vcpu *vcpu) kvm_xen_inject_vcpu_vector(vcpu); } -static inline bool kvm_xen_is_tsc_leaf(struct kvm_vcpu *vcpu, u32 function) -{ - return static_branch_unlikely(&kvm_xen_enabled.key) && - vcpu->arch.xen.cpuid.base && - function <= vcpu->arch.xen.cpuid.limit && - function == (vcpu->arch.xen.cpuid.base | XEN_CPUID_LEAF(3)); -} - static inline bool kvm_xen_msr_enabled(struct kvm *kvm) { return static_branch_unlikely(&kvm_xen_enabled.key) && @@ -177,11 +169,6 @@ static inline bool kvm_xen_timer_enabled(struct kvm_vcpu *vcpu) { return false; } - -static inline bool kvm_xen_is_tsc_leaf(struct kvm_vcpu *vcpu, u32 function) -{ - return false; -} #endif int kvm_xen_hypercall(struct kvm_vcpu *vcpu); -- 2.55.0