KVM: x86/xen: Update Xen CPUID Leaf 4 (tsc info) sub-leaves, if present
Subsystems (4)
PATCH v4 1/1 KVM: x86/xen: Update Xen CPUID Leaf 4 (tsc info) sub-leaves, if present
The scaling information in subleaf 1 should match the values set by KVM in the 'vcpu_info' sub-structure 'time_info' (a.k.a. pvclock_vcpu_time_info) which is shared with the guest, but is not directly available to the VMM. The offset values are not set since a TSC offset is already applied. The TSC frequency should also be set in sub-leaf 2.
Cache pointers to the sub-leaves when CPUID is updated by the VMM and populate the relevant information prior to 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()
v4:
- Update commit comment
--- 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
Sean Christopherson
maintainerQuoted 8 lines · Paul Durrant
The scaling information in subleaf 1 should match the values set by KVM in the '
vcpu_info' sub-structure 'time_info' (a.k.a.pvclock_vcpu_time_info) which is shared with the guest, but is not directly available to the VMM. The offset values are not set since a TSC offset is already applied. The TSC frequency should also be set in sub-leaf 2.Cache pointers to the sub-leaves when CPUID is updated by the VMM and populate the relevant information prior to entering the guest.
All of my comments about the code still apply.
https://lore.kernel.org/all/[email protected]
Quoted 3 lines
Signed-off-by Paul Durrant <[email protected]>---
Cc: David Woodhouse <[email protected]>
Cc: can go in the changelog, it's helpful info to carry with the commit as it documents who was made aware of the patch, e.g. show who may have had a cance to object/review.
Quoted 9 lines
v2:
- Make sure sub-leaf pointers are NULLed if the time leaf is removedv3:
- Add leaf limit check inkvm_xen_set_cpuid()v4:
- Update commit comment
Please start with the most recent verison and work backardwards, that way reviewers can quickly see the delta for _this_ version. I.e.
v4:
v3:
v2:
v1:
Quoted 24 lines
-----Original Message-----
From: Sean Christopherson <[email protected]>
Sent: 27 June 2022 16:19
To: Durrant, Paul <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; David Woodhouse <[email protected]>; Paolo Bonzini <[email protected]>; Vitaly Kuznetsov <[email protected]>; Wanpeng Li <[email protected]>; Jim Mattson <[email protected]>; Joerg Roedel <[email protected]>; Thomas Gleixner <[email protected]>; Ingo Molnar <[email protected]>; Borislav Petkov <[email protected]>; Dave Hansen <[email protected]>; H. Peter Anvin <[email protected]>
Subject: RE: [EXTERNAL][PATCH v4] KVM: x86/xen: Update Xen CPUID Leaf 4 (tsc info) sub-leaves, if presentCAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
Quoted 6 lines · Paul Durrant
The scaling information in subleaf 1 should match the values set by KVM in the '
vcpu_info' sub-structure 'time_info' (a.k.a.pvclock_vcpu_time_info) which is shared with the guest, but is not directly available to the VMM. The offset values are not set since a TSC offset is already applied. The TSC frequency should also be set in sub-leaf 2.
Quoted 7 lines
Quoted 2 lines
Cache pointers to the sub-leaves when CPUID is updated by the VMM and populate the relevant information prior to entering the guest.
All of my comments about the code still apply.
Apologies. Not sure how I missed them; I'll send a response shortly.
Quoted 22 lines
Quoted 3 lines
Signed-off-by Paul Durrant <[email protected]>---
Cc: David Woodhouse <[email protected]>Cc: can go in the changelog, it's helpful info to carry with the commit as it documents who was made aware of the patch, e.g. show who may have had a cance to object/review.
Quoted 9 lines
v2:
- Make sure sub-leaf pointers are NULLed if the time leaf is removedv3:
- Add leaf limit check inkvm_xen_set_cpuid()v4:
- Update commit commentPlease start with the most recent verison and work backardwards, that way reviewers can quickly see the delta for _this_ version. I.e.
Quoted 7 lines
v4:
v3:
v2:
v1:
Ok.
Paul