Skip to contentSkip to conversation

test for lm capable kernel.

PATCH In review Glauber Costa 3 participants 4 messages Oct 14, 2009 – Oct 22, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 test for lm capable kernel.

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.

---
 target-i386/kvm.c |   37 +++++++++++++++++++++++++++----------
 1 files changed, 27 insertions(+), 10 deletions(-)
target-i386/kvm.c +27 -10
index 7010999..0e69b57 100644
@@ -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);
Signature · 1 line
1.6.2.5
#1 lore raw
Quoted 4 lines · Glauber Costa

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 :-)

Quoted 26 lines
---
 target-i386/kvm.c |   37 +++++++++++++++++++++++++++----------
 1 files changed, 27 insertions(+), 10 deletions(-)
target-i386/kvm.c +6 -0
index 7010999..0e69b57 100644
@@ -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;
+

target-i386/kvm.c static int kvm_has_msr_star(CPUState *env) · line 284

Quoted 10 lines
target-i386/kvm.c +9 -0
+    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

#2 lore raw
In reply to Glauber Costa
Quoted 4 lines · Glauber Costa

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?

Signature · 1 line
error compiling committee.c: too many arguments to function
#3 lore raw
Quoted 7 lines · Avi Kivity
Quoted 4 lines · Glauber Costa

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.