Use host cpuid facilities
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
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 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
PATCH 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->edx,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->edx,6 );break ; }
Signature · 1 line
1.7.3.1
Re: [PATCH 2/2] KVM: Mask KVM_GET_SUPPORTED_CPUID data with Linux cpuid info
Quoted 25 lines · Avi Kivity
This allows Linux to mask cpuid bits if, for example, nx is enabled on only some cpus.
Signed-off-by Avi Kivity <[email protected]>--- arch/x86/kvm/x86.c | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-)arch/x86/kvm/x86.c +5
-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) {
arch/x86/kvm/x86.c static void do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, · line 2313
Quoted 6 lines
arch/x86/kvm/x86.c +2
-0@@ -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->edx,4 );
ecx?
arch/x86/kvm/x86.c static void do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, · line 2406
Quoted 10 lines
arch/x86/kvm/x86.c +2
-0/* 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->edx,6 );
ecx?
Re: [PATCH 2/2] KVM: Mask KVM_GET_SUPPORTED_CPUID data with Linux cpuid info
Quoted 33 lines · Marcelo Tosatti
Quoted 16 lines · Avi Kivity
This allows Linux to mask cpuid bits if, for example, nx is enabled on only some cpus.
Signed-off-by Avi Kivity<[email protected]>---
arch/x86/kvm/x86.c | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-)diff --git
a/arch/x86/kvm/x86.cb/arch/x86/kvm/x86.cindex 48ce015..54fda7e 100644
---a/arch/x86/kvm/x86.c
+++b/arch/x86/kvm/x86.c
@@ -2229,6 +2229,11 @@ out:
return r;
}Quoted 15 lines
+static void
cpuid_mask(u32 *word, int wordnum)
+{
+ *word&= boot_cpu_data.x86_capability[wordnum];
+}
+
static void do_cpuid_1_ent(structkvm_cpuid_entry2*entry, u32 function,
u32 index)
{
@@ -2303,7 +2308,9 @@ static void do_cpuid_ent(structkvm_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->edx, 4);
Quoted 2 lines
ecx?
Yes. Will repost.
Signature · 1 line
error compiling committee.c: too many arguments to function