KVM: x86/xen: Update Xen CPUID Leaf 4 (tsc info) sub-leaves, if present
Subsystems (4)
PATCH v5 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.
---
Cc: David Woodhouse <[email protected]>
v5:
- Drop the caching of the CPUID entry pointers and only update the sub-leaves if the CPU frequency has actually changed
v4:
- Update commit comment
v3:
- Add leaf limit check in kvm_xen_set_cpuid()
v2:
- Make sure sub-leaf pointers are NULLed if the time leaf is removed
--- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/cpuid.c | 2 ++ arch/x86/kvm/x86.c | 1 + arch/x86/kvm/xen.c | 51 +++++++++++++++++++++++++++++++++ arch/x86/kvm/xen.h | 10 +++++++ 5 files changed, 65 insertions(+)
arch/x86/include/asm/kvm_host.h +1 -0
@@ -638,6 +638,7 @@ struct kvm_vcpu_xen {struct hrtimer timer;int poll_evtchn;struct timer_list poll_timer; +u32 cpuid_tsc_info; };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_after_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
@@ -3110,6 +3110,7 @@ static int kvm_guest_time_update(struct kvm_vcpu *v) &vcpu->hv_clock.tsc_shift, &vcpu->hv_clock.tsc_to_system_mul); vcpu->hw_tsc_khz = tgt_tsc_khz; +kvm_xen_setup_tsc_info (v); } vcpu->hv_clock.tsc_timestamp = tsc_timestamp;
arch/x86/kvm/xen.c +51 -0
60 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_after_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_after_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
maintainerarch/x86/include/asm/kvm_host.h struct kvm_vcpu_xen { · line 641
Quoted 9 lines · Paul Durrant
arch/x86/include/asm/kvm_host.h +1
-0@@ -638,6 +638,7 @@ struct kvm_vcpu_xen {struct hrtimer timer;int poll_evtchn;struct timer_list poll_timer; +u32 cpuid_tsc_info;
I would prefer to follow vcpu->arch.kvm_cpuid_base and capture the base CPUID function. I have a hard time believing this will be the only case where KVM needs to query XEN CPUID leafs. And cpuid_tsc_info is a confusing name given the helper kvm_xen_setup_tsc_info(); it's odd to see a "setup" helper immediately consume a variable with the same name.
It'll incur another CPUID lookup in the update path to check the limit, but again that should be a rare operation so it doesn't seem too onerous.
arch/x86/kvm/x86.c static int kvm_guest_time_update(struct kvm_vcpu *v) · line 3113
Quoted 9 lines
arch/x86/kvm/x86.c +1
-0@@ -3110,6 +3110,7 @@ static int kvm_guest_time_update(struct kvm_vcpu *v) &vcpu->hv_clock.tsc_shift, &vcpu->hv_clock.tsc_to_system_mul); vcpu->hw_tsc_khz = tgt_tsc_khz; +kvm_xen_setup_tsc_info (v);
Any objection to s/setup/update? KVM Xen uses "setup" for things like configuring the event channel using userspace input, whereas this is purely updating existing data structures.
Quoted 34 lines
arch/x86/kvm/x86.c +0
-0} vcpu->hv_clock.tsc_timestamp = tsc_timestamp;arch/x86/kvm/xen.c +16
-0@@ -10,6 +10,9 @@#include "xen.h" #include "hyperv.h" #include "lapic.h" +#include "cpuid.h" + +#include <asm/xen/cpuid.h> #include <linux/eventfd.h> #include <linux/kvm_host.h> @@ -1855,3 +1858,51 @@ void kvm_xen_destroy_vm(struct kvm *kvm)if (kvm->arch.xen_hvm_config.msr)static_branch_slow_dec_deferred (&kvm_xen_enabled); } + +void kvm_xen_after_set_cpuid (struct kvm_vcpu *vcpu) +{ +u32 base =0 ; +u32 limit; +u32 function; + + vcpu->arch.xen.cpuid_tsc_info =0 ; + +for_each_possible_hypervisor_cpuid_base (function) { +struct kvm_cpuid_entry2 *entry =kvm_find_cpuid_entry (vcpu, function,0 ); + + if (entry &&
arch/x86/kvm/xen.c void kvm_xen_destroy_vm(struct kvm *kvm) · line 1883
Quoted 10 lines
arch/x86/kvm/xen.c +10
-0+ entry->ebx == XEN_CPUID_SIGNATURE_EBX && + entry->ecx == XEN_CPUID_SIGNATURE_ECX && + entry->edx == XEN_CPUID_SIGNATURE_EDX) { + base = function; + limit = entry->eax; +break ; + } + } +if (!base) +return ;
Rather than open code a variant of kvm_update_kvm_cpuid_base(), that helper can be tweaked to take a signature. Along with a patch to provide a #define for Xen's signature as a string, this entire function becomes a one-liner.
If the below looks ok (won't compile, needs prep patches), I'll test and post a proper mini-series.
--- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/cpuid.c | 2 ++ arch/x86/kvm/x86.c | 1 + arch/x86/kvm/xen.c | 30 ++++++++++++++++++++++++++++++ arch/x86/kvm/xen.h | 22 +++++++++++++++++++++- 5 files changed, 55 insertions(+), 1 deletion(-)
arch/x86/include/asm/kvm_host.h +1 -0
@@ -638,6 +638,7 @@ struct kvm_vcpu_xen {struct hrtimer timer;int poll_evtchn;struct timer_list poll_timer; +u32 cpuid_base; };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
@@ -309,6 +310,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_after_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
@@ -3110,6 +3110,7 @@ static int kvm_guest_time_update(struct kvm_vcpu *v) &vcpu->hv_clock.tsc_shift, &vcpu->hv_clock.tsc_to_system_mul); vcpu->hw_tsc_khz = tgt_tsc_khz; +kvm_xen_update_tsc_info (v); } vcpu->hv_clock.tsc_timestamp = tsc_timestamp;
arch/x86/kvm/xen.c +30 -0
@@ -10,6 +10,9 @@#include "xen.h" #include "hyperv.h" #include "lapic.h" +#include "cpuid.h" + +#include <asm/xen/cpuid.h> #include <linux/eventfd.h> #include <linux/kvm_host.h>
@@ -1855,3 +1858,30 @@ void kvm_xen_destroy_vm(struct kvm *kvm)if (kvm->arch.xen_hvm_config.msr)static_branch_slow_dec_deferred (&kvm_xen_enabled); } + +void kvm_xen_update_tsc_info (struct kvm_vcpu *vcpu) +{ +struct kvm_cpuid_entry2 *entry; +u32 function; + +if (!vcpu->arch.xen.cpuid_base) +return ; + + entry =kvm_find_cpuid_entry (vcpu, vcpu->arch.xen.cpuid_base,0 ); +if (WARN_ON_ONCE (!entry)) +return ; + + function = vcpu->arch.xen.cpuid_base |XEN_CPUID_LEAF (3 ); +if (function > entry->eax) +return ; + + entry =kvm_find_cpuid_entry (vcpu, function,1 ); +if (entry) { + entry->ecx = vcpu->arch.hv_clock.tsc_to_system_mul; + entry->edx = vcpu->arch.hv_clock.tsc_shift; + } + + entry =kvm_find_cpuid_entry (vcpu, function,2 ); +if (entry) + entry->eax = vcpu->arch.hw_tsc_khz; +}
arch/x86/kvm/xen.h +21 -1
@@ -9,9 +9,14 @@#ifndef __ARCH_X86_KVM_XEN_H__#define __ARCH_X86_KVM_XEN_H__ -#ifdef CONFIG_KVM_XEN #include <linux/jump_label_ratelimit.h> +#include <asm/xen/cpuid.h> + +#include "cpuid.h" + +#ifdef CONFIG_KVM_XEN +extern struct static_key_false_deferred kvm_xen_enabled;int __kvm_xen_has_interrupt (struct kvm_vcpu *vcpu);
@@ -32,6 +37,13 @@ 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_update_tsc_info (struct kvm_vcpu *vcpu); + +static inline void kvm_xen_after_set_cpuid (struct kvm_vcpu *vcpu) +{ + vcpu->arch.xen.cpuid_base = +kvm_get_hypervisor_cpuid_base (vcpu,XEN_CPUID_SIGNATURE ); +}static inline bool kvm_xen_msr_enabled (struct kvm *kvm) {
@@ -135,6 +147,14 @@ static inline bool kvm_xen_timer_enabled(struct kvm_vcpu *vcpu) {return false; } + +static inline void kvm_xen_after_set_cpuid (struct kvm_vcpu *vcpu) +{ +} + +static inline void kvm_xen_update_tsc_info (struct kvm_vcpu *vcpu) +{ +}#endif int kvm_xen_hypercall (struct kvm_vcpu *vcpu);
base-commit: b08b2f54c49d8f96a22107c444d500dff73ec2a6 --
Quoted 18 lines
-----Original Message-----
From: Sean Christopherson <[email protected]>
Sent: 12 July 2022 00:44
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 v5] 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.
On Wed, Jun 29, 2022, Paul Durrant wrote:
Quoted 15 lines
arch/x86/include/asm/kvm_host.h struct kvm_vcpu_xen { · line 641
Quoted 9 lines
arch/x86/include/asm/kvm_host.h +1
-0@@ -638,6 +638,7 @@ struct kvm_vcpu_xen {struct hrtimer timer;int poll_evtchn;struct timer_list poll_timer; +u32 cpuid_tsc_info;I would prefer to follow
vcpu->arch.kvm_cpuid_baseand capture the base CPUID function. I have a hard time believing this will be the only case where KVM needs to query XEN CPUID leafs. Andcpuid_tsc_infois a confusing name given the helperkvm_xen_setup_tsc_info(); it's odd to see a "setup" helper immediately consume a variable with the same name.
Sure. It is rather shrink-to-fit at the moment... no problem with capturing the base.
Quoted 4 lines
It'll incur another CPUID lookup in the update path to check the limit, but again that should be a rare operation so it doesn't seem too onerous.
We could capture the limit leaf in the general case. It's not Xen-specific after all.
Quoted 5 lines
Quoted 5 lines
arch/x86/kvm/x86.c +0
-0@@ -3110,6 +3110,7 @@ static int kvm_guest_time_update(struct kvm_vcpu *v)
Quoted 9 lines
arch/x86/kvm/x86.c static int kvm_guest_time_update(struct kvm_vcpu *v)
Quoted 4 lines
arch/x86/kvm/x86.c +1
-0&vcpu->hv_clock.tsc_shift, &vcpu->hv_clock.tsc_to_system_mul); vcpu->hw_tsc_khz = tgt_tsc_khz; +kvm_xen_setup_tsc_info (v);Any objection to s/setup/update? KVM Xen uses "setup" for things like configuring the event channel using userspace input, whereas this is purely updating existing data structures.
Sure.
Quoted 40 lines
Quoted 40 lines
arch/x86/kvm/x86.c +0
-0} vcpu->hv_clock.tsc_timestamp = tsc_timestamp;arch/x86/kvm/xen.c +22
-0@@ -10,6 +10,9 @@#include "xen.h" #include "hyperv.h" #include "lapic.h" +#include "cpuid.h" + +#include <asm/xen/cpuid.h> #include <linux/eventfd.h> #include <linux/kvm_host.h> @@ -1855,3 +1858,51 @@ void kvm_xen_destroy_vm(struct kvm *kvm)if (kvm->arch.xen_hvm_config.msr)static_branch_slow_dec_deferred (&kvm_xen_enabled); } + +void kvm_xen_after_set_cpuid (struct kvm_vcpu *vcpu) +{ +u32 base =0 ; +u32 limit; +u32 function; + + vcpu->arch.xen.cpuid_tsc_info =0 ; + +for_each_possible_hypervisor_cpuid_base (function) { +struct kvm_cpuid_entry2 *entry =kvm_find_cpuid_entry (vcpu, function,0 ); + +if (entry && + entry->ebx ==XEN_CPUID_SIGNATURE_EBX && + entry->ecx ==XEN_CPUID_SIGNATURE_ECX && + entry->edx ==XEN_CPUID_SIGNATURE_EDX ) { + base = function; + limit = entry->eax; +break ;
Quoted 9 lines
arch/x86/kvm/xen.c void kvm_xen_destroy_vm(struct kvm *kvm)
Quoted 4 lines
arch/x86/kvm/xen.c +4
-0+ } + } +if (!base) +return ;Rather than open code a variant of
kvm_update_kvm_cpuid_base(), that helper can be tweaked to take a signature. Along with a patch to provide a #define for Xen's signature as a string, this entire function becomes a one-liner.
Sure, but as said above, we could make capturing the limit part of the general function too. It could even be extended to capture the Hyper-V base/limit too. As for defining the sig as a string... I guess it would be neater to use the values from the Xen header, but it'll probably make the code more ugly so a secondary definition is reasonable.
Quoted 2 lines
If the below looks ok (won't compile, needs prep patches), I'll test and post a proper mini-series.
Ok. Thanks,
Paul
Quoted 150 lines
--- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/cpuid.c | 2 ++ arch/x86/kvm/x86.c | 1 + arch/x86/kvm/xen.c | 30 ++++++++++++++++++++++++++++++ arch/x86/kvm/xen.h | 22 +++++++++++++++++++++- 5 files changed, 55 insertions(+), 1 deletion(-)arch/x86/include/asm/kvm_host.h +1
-0@@ -638,6 +638,7 @@ struct kvm_vcpu_xen {struct hrtimer timer;int poll_evtchn;struct timer_list poll_timer; +u32 cpuid_base; };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 @@ -309,6 +310,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_after_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@@ -3110,6 +3110,7 @@ static int kvm_guest_time_update(struct kvm_vcpu *v) &vcpu->hv_clock.tsc_shift, &vcpu->hv_clock.tsc_to_system_mul); vcpu->hw_tsc_khz = tgt_tsc_khz; +kvm_xen_update_tsc_info (v); } vcpu->hv_clock.tsc_timestamp = tsc_timestamp;arch/x86/kvm/xen.c +30
-0@@ -10,6 +10,9 @@#include "xen.h" #include "hyperv.h" #include "lapic.h" +#include "cpuid.h" + +#include <asm/xen/cpuid.h> #include <linux/eventfd.h> #include <linux/kvm_host.h> @@ -1855,3 +1858,30 @@ void kvm_xen_destroy_vm(struct kvm *kvm)if (kvm->arch.xen_hvm_config.msr)static_branch_slow_dec_deferred (&kvm_xen_enabled); } + +void kvm_xen_update_tsc_info (struct kvm_vcpu *vcpu) +{ +struct kvm_cpuid_entry2 *entry; +u32 function; + +if (!vcpu->arch.xen.cpuid_base) +return ; + + entry =kvm_find_cpuid_entry (vcpu, vcpu->arch.xen.cpuid_base,0 ); +if (WARN_ON_ONCE (!entry)) +return ; + + function = vcpu->arch.xen.cpuid_base |XEN_CPUID_LEAF (3 ); +if (function > entry->eax) +return ; + + entry =kvm_find_cpuid_entry (vcpu, function,1 ); +if (entry) { + entry->ecx = vcpu->arch.hv_clock.tsc_to_system_mul; + entry->edx = vcpu->arch.hv_clock.tsc_shift; + } + + entry =kvm_find_cpuid_entry (vcpu, function,2 ); +if (entry) + entry->eax = vcpu->arch.hw_tsc_khz; +}arch/x86/kvm/xen.h +21
-1@@ -9,9 +9,14 @@#ifndef __ARCH_X86_KVM_XEN_H__#define __ARCH_X86_KVM_XEN_H__ -#ifdef CONFIG_KVM_XEN #include <linux/jump_label_ratelimit.h> +#include <asm/xen/cpuid.h> + +#include "cpuid.h" + +#ifdef CONFIG_KVM_XEN +extern struct static_key_false_deferred kvm_xen_enabled;int __kvm_xen_has_interrupt (struct kvm_vcpu *vcpu);@@ -32,6 +37,13 @@ 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_update_tsc_info (struct kvm_vcpu *vcpu); + +static inline void kvm_xen_after_set_cpuid (struct kvm_vcpu *vcpu) +{ + vcpu->arch.xen.cpuid_base = +kvm_get_hypervisor_cpuid_base (vcpu,XEN_CPUID_SIGNATURE ); +}static inline bool kvm_xen_msr_enabled (struct kvm *kvm) {@@ -135,6 +147,14 @@ static inline bool kvm_xen_timer_enabled(struct kvm_vcpu *vcpu) {return false; } + +static inline void kvm_xen_after_set_cpuid (struct kvm_vcpu *vcpu) +{ +} + +static inline void kvm_xen_update_tsc_info (struct kvm_vcpu *vcpu) +{ +}#endif int kvm_xen_hypercall (struct kvm_vcpu *vcpu);base-commit:
b08b2f54c49d8f96a22107c444d500dff73ec2a6--
Sean Christopherson
maintainerQuoted 33 lines · Paul
Quoted 23 lines
Quoted 23 lines
(quoted diff) +19
-0@@ -1855,3 +1858,51 @@ void kvm_xen_destroy_vm(struct kvm *kvm) if (kvm->arch.xen_hvm_config.msr) static_branch_slow_dec_deferred(&kvm_xen_enabled); } + +void kvm_xen_after_set_cpuid(struct kvm_vcpu *vcpu) +{ + u32 base = 0; + u32 limit; + u32 function; + + vcpu->arch.xen.cpuid_tsc_info = 0; + + for_each_possible_hypervisor_cpuid_base(function) { + struct kvm_cpuid_entry2 *entry = kvm_find_cpuid_entry(vcpu, function, 0); + + if (entry && + entry->ebx == XEN_CPUID_SIGNATURE_EBX && + entry->ecx == XEN_CPUID_SIGNATURE_ECX && + entry->edx == XEN_CPUID_SIGNATURE_EDX) { + base = function; + limit = entry->eax; + break;Quoted 9 lines
arch/x86/kvm/xen.c void kvm_xen_destroy_vm(struct kvm *kvm)
Quoted 4 lines
arch/x86/kvm/xen.c +4
-0+ } + } +if (!base) +return ;Rather than open code a variant of
kvm_update_kvm_cpuid_base(), that helper can be tweaked to take a signature. Along with a patch to provide a #define for Xen's signature as a string, this entire function becomes a one-liner.
Quoted 5 lines
Sure, but as said above, we could make capturing the limit part of the general function too. It could even be extended to capture the Hyper-V base/limit too. As for defining the sig as a string... I guess it would be neater to use the values from the Xen header, but it'll probably make the code more ugly so a secondary definition is reasonable.
The base needs to be captured separately for KVM and Xen because KVM (and presumably Xen itself since Xen also allows a variable base) supports advertising multiple hypervisors to the guest. I don't know if there are any guests that will concurrently utilize multiple hypervisor's paravirt features, so maybe we could squeak by, but saving 4 bytes isn't worth the risk.
AFAIK, Hyper-V doesn't allow for a variable base, and so doesn't utilize the for_each_possible... macro.
Quoted 40 lines · Sean Christopherson
Quoted 33 lines · Paul
Quoted 23 lines
Quoted 23 lines
(quoted diff) +19
-0@@ -1855,3 +1858,51 @@ void kvm_xen_destroy_vm(struct kvm *kvm) if (kvm->arch.xen_hvm_config.msr) static_branch_slow_dec_deferred(&kvm_xen_enabled); } + +void kvm_xen_after_set_cpuid(struct kvm_vcpu *vcpu) +{ + u32 base = 0; + u32 limit; + u32 function; + + vcpu->arch.xen.cpuid_tsc_info = 0; + + for_each_possible_hypervisor_cpuid_base(function) { + struct kvm_cpuid_entry2 *entry = kvm_find_cpuid_entry(vcpu, function, 0); + + if (entry && + entry->ebx == XEN_CPUID_SIGNATURE_EBX && + entry->ecx == XEN_CPUID_SIGNATURE_ECX && + entry->edx == XEN_CPUID_SIGNATURE_EDX) { + base = function; + limit = entry->eax; + break;Quoted 9 lines
arch/x86/kvm/xen.c void kvm_xen_destroy_vm(struct kvm *kvm)
Quoted 4 lines
arch/x86/kvm/xen.c +4
-0+ } + } +if (!base) +return ;Rather than open code a variant of
kvm_update_kvm_cpuid_base(), that helper can be tweaked to take a signature. Along with a patch to provide a #define for Xen's signature as a string, this entire function becomes a one-liner.Quoted 5 lines
Sure, but as said above, we could make capturing the limit part of the general function too. It could even be extended to capture the Hyper-V base/limit too. As for defining the sig as a string... I guess it would be neater to use the values from the Xen header, but it'll probably make the code more ugly so a secondary definition is reasonable.
Quoted 8 lines
The base needs to be captured separately for KVM and Xen because KVM (and presumably Xen itself since Xen also allows a variable base) supports advertising multiple hypervisors to the guest. I don't know if there are any guests that will concurrently utilize multiple hypervisor's paravirt features, so maybe we could squeak by, but saving 4 bytes isn't worth the risk.
AFAIK, Hyper-V doesn't allow for a variable base, and so doesn't utilize the
for_each_possible... macro.
FWIW, this matches my understanding too: Windows guests don't seem to check anything besides 0x40000001 and give up if Hyper-V's id is not there.
Signature · 1 line
Vitaly