Use host cpuid facilities
v2 cover Use host cpuid facilities
Use the host's cpuid facilities to see if features are supporte. This allows the clearcpuid boot parameter to work, and allows Linux to disable nx if it is not enabled on all cpus.
Avi Kivity (2):
KVM: SVM: Replace svm_has() by standard Linux cpuid accessors
KVM: Mask KVM_GET_SUPPORTED_CPUID data with Linux cpuid info
v2: mask the correct cpuid returned register
arch/x86/kvm/svm.c | 15 +++++---------- arch/x86/kvm/x86.c | 9 +++++++++ 2 files changed, 14 insertions(+), 10 deletions(-)
Signature · 1 line
1.7.3.1
PATCH v2 1/2 KVM: SVM: Replace svm_has() by standard Linux cpuid accessors
Instead of querying cpuid directly, use the Linux accessors (boot_cpu_has, etc.). This allows the things like the clearcpuid kernel command line to work (when it's fixed wrt scattered cpuid bits).
--- arch/x86/kvm/svm.c | 15 +++++---------- 1 files changed, 5 insertions(+), 10 deletions(-)
arch/x86/kvm/svm.c +5 -10
@@ -271,11 +271,6 @@ static u32 svm_msrpm_offset(u32 msr)#define MAX_INST_SIZE 15 -static inline u32 svm_has (u32 feat) -{ -return svm_features & feat; -} -static inline void clgi (void ) { asm volatile (__ex(SVM_CLGI));
@@ -381,7 +376,7 @@ static void svm_queue_exception(struct kvm_vcpu *vcpu, unsigned nr, nested_svm_check_exception(svm, nr, has_error_code, error_code)) return; -if (nr ==BP_VECTOR && !svm_has (SVM_FEATURE_NRIP )) { +if (nr ==BP_VECTOR && !static_cpu_has (X86_FEATURE_NRIPS )) {unsigned long rip, old_rip =kvm_rip_read (&svm->vcpu);/*
@@ -677,7 +672,7 @@ static __init int svm_hardware_setup(void) svm_features =cpuid_edx (SVM_CPUID_FUNC ); -if (!svm_has (SVM_FEATURE_NPT )) +if (!boot_cpu_has (X86_FEATURE_NPT )) npt_enabled = false;if (npt_enabled && !npt) {
@@ -876,7 +871,7 @@ static void init_vmcb(struct vcpu_svm *svm) svm->nested.vmcb =0 ; svm->vcpu.arch.hflags =0 ; -if (svm_has (SVM_FEATURE_PAUSE_FILTER )) { +if (boot_cpu_has (X86_FEATURE_PAUSEFILTER )) { control->pause_filter_count =3000 ; control->intercept |= (1ULL <<INTERCEPT_PAUSE ); }
@@ -2743,7 +2738,7 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data) svm->vmcb->save.sysenter_esp = data;break ;case MSR_IA32_DEBUGCTLMSR : -if (!svm_has (SVM_FEATURE_LBRV )) { +if (!boot_cpu_has (X86_FEATURE_LBRV )) {pr_unimpl (vcpu,"%s: MSR_IA32_DEBUGCTL 0x%llx, nop\n" , __func__, data);break ;
@@ -3527,7 +3522,7 @@ static void svm_set_supported_cpuid(u32 func, struct kvm_cpuid_entry2 *entry)additional features */ /* Support next_rip if host supports it */ -if (svm_has (SVM_FEATURE_NRIP )) +if (boot_cpu_has (X86_FEATURE_NRIPS )) entry->edx |=SVM_FEATURE_NRIP ;/* Support NPT for the guest if enabled */
Signature · 1 line
1.7.3.1
Re: [PATCH v2 1/2] KVM: SVM: Replace svm_has() by standard Linux cpuid accessors
arch/x86/kvm/svm.c static void svm_queue_exception(struct kvm_vcpu *vcpu, unsigned nr, · line 379
Quoted 2 lines · Avi Kivity
arch/x86/kvm/svm.c +1
-1-if (nr ==BP_VECTOR && !svm_has (SVM_FEATURE_NRIP )) { +if (nr ==BP_VECTOR && !static_cpu_has (X86_FEATURE_NRIPS )) {
What is static_cpu_has and why you use it only here and boot_cpu_has in all other places?
Joerg
Re: [PATCH v2 1/2] KVM: SVM: Replace svm_has() by standard Linux cpuid accessors
Quoted 5 lines · Joerg Roedel
Quoted 2 lines · Avi Kivity
- if (nr == BP_VECTOR&& !svm_has(SVM_FEATURE_NRIP)) {
+ if (nr == BP_VECTOR&& !static_cpu_has(X86_FEATURE_NRIPS)) {What is
static_cpu_has
It's like boot_cpu_has, only it works by patching instead of a dynamic test.
Quoted 2 lines
and why you use it only here and
boot_cpu_has
in all other places?
A nano optimization, this is a more commonly used path.
Signature · 1 line
error compiling committee.c: too many arguments to function
Joerg Roedel
Acked-byRe: [PATCH v2 1/2] KVM: SVM: Replace svm_has() by standard Linux cpuid accessors
Quoted 5 lines · Avi Kivity
Quoted 4 lines · Joerg Roedel
Quoted 2 lines · Avi Kivity
- if (nr == BP_VECTOR&& !svm_has(SVM_FEATURE_NRIP)) {
+ if (nr == BP_VECTOR&& !static_cpu_has(X86_FEATURE_NRIPS)) {
Quoted 8 lines
Quoted 1 line
What is
static_cpu_hasIt's like
boot_cpu_has, only it works by patching instead of a dynamic test.Quoted 2 lines
and why you use it only here and
boot_cpu_has
in all other places?A nano optimization, this is a more commonly used path.
Ok, I was just curious because I couldn't find the static_cpu_has by a quick grep. Thanks for the explanation.
PATCH v2 2/2 KVM: Mask KVM_GET_SUPPORTED_CPUID data with Linux cpuid info
In reply to Avi KivityThis allows Linux to mask cpuid bits if, for example, nx is enabled on only some cpus.
--- arch/x86/kvm/x86.c | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-)
arch/x86/kvm/x86.c +9 -0
@@ -2229,6 +2229,11 @@ out:return r; } +static void cpuid_mask (u32 *word,int wordnum) +{ + *word &= boot_cpu_data.x86_capability[wordnum]; +} +static void do_cpuid_1_ent (struct kvm_cpuid_entry2 *entry,u32 function,u32 index) {
@@ -2303,7 +2308,9 @@ static void do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,break ;case 1 : entry->edx &= kvm_supported_word0_x86_features; +cpuid_mask (&entry->edx,0 ); entry->ecx &= kvm_supported_word4_x86_features; +cpuid_mask (&entry->ecx,4 );/* we support x2apic emulation even if host does not support * it since we emulate x2apic in software */ entry->ecx |=F (X2APIC );
@@ -2394,7 +2401,9 @@ static void do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,break ;case 0x80000001 : entry->edx &= kvm_supported_word1_x86_features; +cpuid_mask (&entry->edx,1 ); entry->ecx &= kvm_supported_word6_x86_features; +cpuid_mask (&entry->ecx,6 );break ; }
Signature · 1 line
1.7.3.1
Marcelo Tosatti
AppliedQuoted 4 lines · Avi Kivity
Use the host's cpuid facilities to see if features are supporte. This allows the clearcpuid boot parameter to work, and allows Linux to disable nx if it is not enabled on all cpus.
Quoted 8 lines
Avi Kivity (2):
KVM: SVM: Replacesvm_has()by standard Linux cpuid accessors
KVM: MaskKVM_GET_SUPPORTED_CPUIDdata with Linux cpuid info
v2: mask the correct cpuid returned registerarch/x86/kvm/svm.c | 15 +++++---------- arch/x86/kvm/x86.c | 9 +++++++++ 2 files changed, 14 insertions(+), 10 deletions(-)
Applied, thanks.