* [PATCH v2 1/2] KVM: SVM: Replace svm_has() by standard Linux cpuid accessors
2010-11-09 14:15 [PATCH v2 0/2] Use host cpuid facilities Avi Kivity
@ 2010-11-09 14:15 ` Avi Kivity
2010-11-11 14:46 ` Joerg Roedel
2010-11-09 14:15 ` [PATCH v2 2/2] KVM: Mask KVM_GET_SUPPORTED_CPUID data with Linux cpuid info Avi Kivity
2010-11-16 18:34 ` [PATCH v2 0/2] Use host cpuid facilities Marcelo Tosatti
2 siblings, 1 reply; 7+ messages in thread
From: Avi Kivity @ 2010-11-09 14:15 UTC (permalink / raw)
To: Marcelo Tosatti, kvm
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).
Signed-off-by: Avi Kivity <avi@redhat.com>
---
arch/x86/kvm/svm.c | 15 +++++----------
1 files changed, 5 insertions(+), 10 deletions(-)
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 1a5757a..c6a7798 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -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 */
--
1.7.3.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v2 1/2] KVM: SVM: Replace svm_has() by standard Linux cpuid accessors
2010-11-09 14:15 ` [PATCH v2 1/2] KVM: SVM: Replace svm_has() by standard Linux cpuid accessors Avi Kivity
@ 2010-11-11 14:46 ` Joerg Roedel
2010-11-11 14:50 ` Avi Kivity
0 siblings, 1 reply; 7+ messages in thread
From: Joerg Roedel @ 2010-11-11 14:46 UTC (permalink / raw)
To: Avi Kivity; +Cc: Marcelo Tosatti, kvm
On Tue, Nov 09, 2010 at 04:15:42PM +0200, Avi Kivity wrote:
> - 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
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v2 1/2] KVM: SVM: Replace svm_has() by standard Linux cpuid accessors
2010-11-11 14:46 ` Joerg Roedel
@ 2010-11-11 14:50 ` Avi Kivity
2010-11-11 15:10 ` Joerg Roedel
0 siblings, 1 reply; 7+ messages in thread
From: Avi Kivity @ 2010-11-11 14:50 UTC (permalink / raw)
To: Joerg Roedel; +Cc: Marcelo Tosatti, kvm
On 11/11/2010 04:46 PM, Joerg Roedel wrote:
> On Tue, Nov 09, 2010 at 04:15:42PM +0200, Avi Kivity wrote:
> > - 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.
> 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.
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v2 1/2] KVM: SVM: Replace svm_has() by standard Linux cpuid accessors
2010-11-11 14:50 ` Avi Kivity
@ 2010-11-11 15:10 ` Joerg Roedel
0 siblings, 0 replies; 7+ messages in thread
From: Joerg Roedel @ 2010-11-11 15:10 UTC (permalink / raw)
To: Avi Kivity; +Cc: Marcelo Tosatti, kvm
On Thu, Nov 11, 2010 at 04:50:10PM +0200, Avi Kivity wrote:
> On 11/11/2010 04:46 PM, Joerg Roedel wrote:
>> On Tue, Nov 09, 2010 at 04:15:42PM +0200, Avi Kivity wrote:
>> > - 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.
>
>> 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.
Acked-by: Joerg Roedel <joerg.roedel@amd.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 2/2] KVM: Mask KVM_GET_SUPPORTED_CPUID data with Linux cpuid info
2010-11-09 14:15 [PATCH v2 0/2] Use host cpuid facilities Avi Kivity
2010-11-09 14:15 ` [PATCH v2 1/2] KVM: SVM: Replace svm_has() by standard Linux cpuid accessors Avi Kivity
@ 2010-11-09 14:15 ` Avi Kivity
2010-11-16 18:34 ` [PATCH v2 0/2] Use host cpuid facilities Marcelo Tosatti
2 siblings, 0 replies; 7+ messages in thread
From: Avi Kivity @ 2010-11-09 14:15 UTC (permalink / raw)
To: Marcelo Tosatti, kvm
This allows Linux to mask cpuid bits if, for example, nx is enabled on only
some cpus.
Signed-off-by: Avi Kivity <avi@redhat.com>
---
arch/x86/kvm/x86.c | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 2044302..788f064 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -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;
}
--
1.7.3.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v2 0/2] Use host cpuid facilities
2010-11-09 14:15 [PATCH v2 0/2] Use host cpuid facilities Avi Kivity
2010-11-09 14:15 ` [PATCH v2 1/2] KVM: SVM: Replace svm_has() by standard Linux cpuid accessors Avi Kivity
2010-11-09 14:15 ` [PATCH v2 2/2] KVM: Mask KVM_GET_SUPPORTED_CPUID data with Linux cpuid info Avi Kivity
@ 2010-11-16 18:34 ` Marcelo Tosatti
2 siblings, 0 replies; 7+ messages in thread
From: Marcelo Tosatti @ 2010-11-16 18:34 UTC (permalink / raw)
To: Avi Kivity; +Cc: kvm
On Tue, Nov 09, 2010 at 04:15:41PM +0200, Avi Kivity wrote:
> 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(-)
Applied, thanks.
^ permalink raw reply [flat|nested] 7+ messages in thread