KVM: x86/xen: Update Xen CPUID Leaf 4 (tsc info) sub-leaves, if present
Subsystems (4)
PATCH v3 1/1 KVM: x86/xen: Update Xen CPUID Leaf 4 (tsc info) sub-leaves, if present
The scaling information in sub-leaf 1 should match the values in the 'vcpu_info' sub-structure 'time_info' (a.k.a. pvclock_vcpu_time_info) which is shared with the guest. The offset values are not set since a TSC offset is already applied.
The host TSC frequency should also be set in sub-leaf 2.
This patch adds a new kvm_xen_set_cpuid() function that scans for the relevant CPUID leaf when the CPUID information is updated by the VMM and stashes pointers to the sub-leaves in the kvm_vcpu_xen structure. The values are then updated by a call to the, also new, kvm_xen_setup_tsc_info() function made at the end of kvm_guest_time_update() just before entering the guest.
---
Cc: David Woodhouse <[email protected]>
v2:
- Make sure sub-leaf pointers are NULLed if the time leaf is removed
v3:
- Add leaf limit check in kvm_xen_set_cpuid()
--- arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/kvm/cpuid.c | 2 ++ arch/x86/kvm/x86.c | 1 + arch/x86/kvm/xen.c | 49 +++++++++++++++++++++++++++++++++ arch/x86/kvm/xen.h | 10 +++++++ 5 files changed, 64 insertions(+)
arch/x86/include/asm/kvm_host.h +2 -0
@@ -638,6 +638,8 @@ struct kvm_vcpu_xen {struct hrtimer timer;int poll_evtchn;struct timer_list poll_timer; +struct kvm_cpuid_entry2 *tsc_info_1; +struct kvm_cpuid_entry2 *tsc_info_2; };struct kvm_vcpu_arch {
arch/x86/kvm/cpuid.c +2 -0
@@ -25,6 +25,7 @@#include "mmu.h" #include "trace.h" #include "pmu.h" +#include "xen.h" /* * Unlike "struct cpuinfo_x86.x86_capability", kvm_cpu_caps doesn't need to be
@@ -310,6 +311,7 @@ static void kvm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)__cr4_reserved_bits (guest_cpuid_has, vcpu);kvm_hv_set_cpuid (vcpu); +kvm_xen_set_cpuid (vcpu);/* Invoke the vendor callback only after the above state is updated. */ static_call (kvm_x86_vcpu_after_set_cpuid)(vcpu);
arch/x86/kvm/x86.c +1 -0
@@ -3123,6 +3123,7 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)if (vcpu->xen.vcpu_time_info_cache.active)kvm_setup_guest_pvclock (v, &vcpu->xen.vcpu_time_info_cache,0 );kvm_hv_setup_tsc_page (v->kvm, &vcpu->hv_clock); +kvm_xen_setup_tsc_info (v);return 0 ; }
arch/x86/kvm/xen.c +49 -0
58 lines not on this page · raw message
arch/x86/kvm/xen.h +10 -0
@@ -32,6 +32,8 @@ int kvm_xen_set_evtchn_fast(struct kvm_xen_evtchn *xe,int kvm_xen_setup_evtchn (struct kvm *kvm,struct kvm_kernel_irq_routing_entry *e,const struct kvm_irq_routing_entry *ue); +void kvm_xen_set_cpuid (struct kvm_vcpu *vcpu); +void kvm_xen_setup_tsc_info (struct kvm_vcpu *vcpu);static inline bool kvm_xen_msr_enabled (struct kvm *kvm) {
@@ -135,6 +137,14 @@ static inline bool kvm_xen_timer_enabled(struct kvm_vcpu *vcpu) {return false; } + +static inline void kvm_xen_set_cpuid (struct kvm_vcpu *vcpu) +{ +} + +static inline void kvm_xen_setup_tsc_info (struct kvm_vcpu *vcpu) +{ +}#endif int kvm_xen_hypercall (struct kvm_vcpu *vcpu);
Signature · 1 line
2.20.1