diff mbox

test for lm capable kernel.

Message ID 1255540160-19869-1-git-send-email-glommer@redhat.com
State New
Headers show

Commit Message

Glauber Costa Oct. 14, 2009, 5:09 p.m. UTC
Don't save x86_64-specific msrs if our kernel does not support them.
Code is already in qemu-kvm.git, but the test function is slightly different.
It follows what the test for msr_start does.

Signed-off-by: Glauber Costa <glommer@redhat.com>
---
 target-i386/kvm.c |   37 +++++++++++++++++++++++++++----------
 1 files changed, 27 insertions(+), 10 deletions(-)

Comments

Anthony Liguori Oct. 22, 2009, 4:20 p.m. UTC | #1
Glauber Costa wrote:
> Don't save x86_64-specific msrs if our kernel does not support them.
> Code is already in qemu-kvm.git, but the test function is slightly different.
> It follows what the test for msr_start does.
>   

Repeat after me: "I will not use --target-list when submitting qemu 
patches.  I will not use --target-list when submitting qemu patches."

Fedora enables ccache by default.  After one build, all future builds 
are extremely fast in most cases.  It's really not that bad :-)

> Signed-off-by: Glauber Costa <glommer@redhat.com>
> ---
>  target-i386/kvm.c |   37 +++++++++++++++++++++++++++----------
>  1 files changed, 27 insertions(+), 10 deletions(-)
>
> diff --git a/target-i386/kvm.c b/target-i386/kvm.c
> index 7010999..0e69b57 100644
> --- a/target-i386/kvm.c
> +++ b/target-i386/kvm.c
> @@ -15,6 +15,7 @@
>  #include <sys/types.h>
>  #include <sys/ioctl.h>
>  #include <sys/mman.h>
> +#include <sys/utsname.h>
>  
>  #include <linux/kvm.h>
>  
> @@ -266,6 +267,20 @@ static int kvm_has_msr_star(CPUState *env)
>      return 0;
>  }
>  
> +static int lm_capable_kernel(void)
> +{
> +    static int lm_capable = -1;
> +    struct utsname utsname;
> +
> +    if (lm_capable != -1) {
> +        return lm_capable;
> +    }
> +
> +    uname(&utsname);
> +    lm_capable = (strcmp(utsname.machine, "x86_64") == 0);
> +    return lm_capable;
> +}
> +
>   

This function is unused for qemu-system-i386.

Regards,

Anthony Liguori
Avi Kivity Oct. 22, 2009, 4:51 p.m. UTC | #2
On 10/14/2009 07:09 PM, Glauber Costa wrote:
> Don't save x86_64-specific msrs if our kernel does not support them.
> Code is already in qemu-kvm.git, but the test function is slightly different.
> It follows what the test for msr_start does.
>    

Can't we use KVM_GET_MSR_LIST to see which msrs are supported instead?
Glauber Costa Oct. 22, 2009, 4:56 p.m. UTC | #3
On Thu, Oct 22, 2009 at 06:51:46PM +0200, Avi Kivity wrote:
> On 10/14/2009 07:09 PM, Glauber Costa wrote:
>> Don't save x86_64-specific msrs if our kernel does not support them.
>> Code is already in qemu-kvm.git, but the test function is slightly different.
>> It follows what the test for msr_start does.
>>    
>
> Can't we use KVM_GET_MSR_LIST to see which msrs are supported instead?
that would be good, indeed.

Right now we're doing it for star, but we could keep the list and always
query it.
diff mbox

Patch

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 7010999..0e69b57 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -15,6 +15,7 @@ 
 #include <sys/types.h>
 #include <sys/ioctl.h>
 #include <sys/mman.h>
+#include <sys/utsname.h>
 
 #include <linux/kvm.h>
 
@@ -266,6 +267,20 @@  static int kvm_has_msr_star(CPUState *env)
     return 0;
 }
 
+static int lm_capable_kernel(void)
+{
+    static int lm_capable = -1;
+    struct utsname utsname;
+
+    if (lm_capable != -1) {
+        return lm_capable;
+    }
+
+    uname(&utsname);
+    lm_capable = (strcmp(utsname.machine, "x86_64") == 0);
+    return lm_capable;
+}
+
 int kvm_arch_init(KVMState *s, int smp_cpus)
 {
     int ret;
@@ -478,11 +493,12 @@  static int kvm_put_msrs(CPUState *env)
 	kvm_msr_entry_set(&msrs[n++], MSR_STAR, env->star);
     kvm_msr_entry_set(&msrs[n++], MSR_IA32_TSC, env->tsc);
 #ifdef TARGET_X86_64
-    /* FIXME if lm capable */
-    kvm_msr_entry_set(&msrs[n++], MSR_CSTAR, env->cstar);
-    kvm_msr_entry_set(&msrs[n++], MSR_KERNELGSBASE, env->kernelgsbase);
-    kvm_msr_entry_set(&msrs[n++], MSR_FMASK, env->fmask);
-    kvm_msr_entry_set(&msrs[n++], MSR_LSTAR, env->lstar);
+    if (lm_capable_kernel()) {
+        kvm_msr_entry_set(&msrs[n++], MSR_CSTAR, env->cstar);
+        kvm_msr_entry_set(&msrs[n++], MSR_KERNELGSBASE, env->kernelgsbase);
+        kvm_msr_entry_set(&msrs[n++], MSR_FMASK, env->fmask);
+        kvm_msr_entry_set(&msrs[n++], MSR_LSTAR, env->lstar);
+    }
 #endif
     msr_data.info.nmsrs = n;
 
@@ -611,11 +627,12 @@  static int kvm_get_msrs(CPUState *env)
 	msrs[n++].index = MSR_STAR;
     msrs[n++].index = MSR_IA32_TSC;
 #ifdef TARGET_X86_64
-    /* FIXME lm_capable_kernel */
-    msrs[n++].index = MSR_CSTAR;
-    msrs[n++].index = MSR_KERNELGSBASE;
-    msrs[n++].index = MSR_FMASK;
-    msrs[n++].index = MSR_LSTAR;
+    if (lm_capable_kernel()) {
+        msrs[n++].index = MSR_CSTAR;
+        msrs[n++].index = MSR_KERNELGSBASE;
+        msrs[n++].index = MSR_FMASK;
+        msrs[n++].index = MSR_LSTAR;
+    }
 #endif
     msr_data.info.nmsrs = n;
     ret = kvm_vcpu_ioctl(env, KVM_GET_MSRS, &msr_data);