Skip to contentSkip to conversation

don't expose lm bit if kernel is not 64-bit capable.

PATCH In review Glauber Costa 5 participants 12 messages Feb 3, 2009 – Feb 4, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 don't expose lm bit if kernel is not 64-bit capable.

If the kernel is not 64-bit capable (even if the host machine is) do not expose the lm bit in guest cpuid.

---
 target-i386/helper.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
target-i386/helper.c +5 -1
index a28ab93..997e4e1 100644
@@ -24,6 +24,7 @@
 #include <inttypes.h>
 #include <signal.h>
 #include <assert.h>
+#include <sys/utsname.h>
 
 #include "cpu.h"
 #include "exec-all.h"
@@ -1520,13 +1521,16 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,
 
         if (kvm_enabled()) {
             uint32_t h_eax, h_edx;
+            struct utsname utsname;
+
+            uname(&utsname);
 
             host_cpuid(0x80000001, &h_eax, NULL, NULL, &h_edx);
 
             /* disable CPU features that the host does not support */
 
             /* long mode */
-            if ((h_edx & 0x20000000) == 0 /* || !lm_capable_kernel */)
+            if ((h_edx & 0x20000000) == 0  || strcmp(utsname.machine, "x86_64"))
                 *edx &= ~0x20000000;
             /* syscall */
             if ((h_edx & 0x00000800) == 0)
Signature · 1 line
1.5.6.5
#1 lore raw
Quoted 21 lines · Glauber Costa

If the kernel is not 64-bit capable (even if the host machine is) do not expose the lm bit in guest cpuid.

---
target-i386/helper.c | 6 +++++-

1 files changed, 5 insertions(+), 1 deletions(-)
target-i386/helper.c +1 -0
index a28ab93..997e4e1 100644
@@ -24,6 +24,7 @@
 #include <inttypes.h>
 #include <signal.h>
 #include <assert.h>
+#include <sys/utsname.h>
 
 #include "cpu.h"
 #include "exec-all.h"

target-i386/helper.c void cpu_x86_cpuid(CPUX86State *env, · line 1527

Quoted 7 lines
target-i386/helper.c +3 -0
@@ -1520,13 +1521,16 @@ void cpu_x86_cpuid(CPUX86State *env,  
 uint32_t index,
 
        if (kvm_enabled()) {
            uint32_t h_eax, h_edx;
+            struct utsname utsname;
+
+            uname(&utsname);

This doesn't really compile on win32, does it?

Why not check for sizeof(long) == 4? That way you'd know that you're running 32-bit code which can only handle 32-bit guests anyway, right? And if you're running 64-bit userspace code, you know that the kernel is 64-bit aware.

Alex

Quoted 19 lines
target-i386/helper.c +1 -1
            host_cpuid(0x80000001, &h_eax, NULL, NULL, &h_edx);
 
            /* disable CPU features that the host does not support */
 
            /* long mode */
-            if ((h_edx & 0x20000000) == 0 /* || !lm_capable_kernel  
 */)
+            if ((h_edx & 0x20000000) == 0  ||  
 strcmp(utsname.machine, "x86_64"))
                *edx &= ~0x20000000;
            /* syscall */
            if ((h_edx & 0x00000800) == 0)
Signature · 1 line
1.5.6.5
#2 lore raw
Quoted 1 line · Alexander Graf

This doesn't really compile on win32, does it?

This is kvm code, and as we don't have kvm for win32 hosts, possibly does not matter.

Quoted 4 lines

Why not check for sizeof(long) == 4? That way you'd know that you're running 32-bit code which can only handle 32-bit guests anyway, right? And if you're running 64-bit userspace code, you know that the kernel is 64-bit aware.

How about qemu/kvm compiled in a 32-bit environment, thus, sizeof long == 4, running in a x86_64 capable kernel?

Signature · 5 lines
Glauber  Costa.
"Free as in Freedom"
http://glommer.net

"The less confident you are, the more serious you have to act."
#3 lore raw
Quoted 7 lines · Glauber Costa
Quoted 2 lines · Alexander Graf

This doesn't really compile on win32, does it?

This is kvm code, and as we don't have kvm for win32 hosts, possibly does not matter.

Would be better to use a kvm accessor to wrap this functionality. kvm_is_lmkernel() or something. Makes things more obviously portable on another platform.

Regards,

Anthony Liguori

Quoted 9 lines
Quoted 4 lines

Why not check for sizeof(long) == 4? That way you'd know that you're running 32-bit code which can only handle 32-bit guests anyway, right? And if you're running 64-bit userspace code, you know that the kernel is 64-bit aware.

How about qemu/kvm compiled in a 32-bit environment, thus, sizeof long == 4, running in a x86_64 capable kernel?

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

If the kernel is not 64-bit capable (even if the host machine is) do not expose the lm bit in guest cpuid.

target-i386/helper.c +1 -0
index a28ab93..997e4e1 100644
@@ -24,6 +24,7 @@
 #include <inttypes.h>
 #include <signal.h>
 #include <assert.h>
+#include <sys/utsname.h>
 
 #include "cpu.h"
 #include "exec-all.h"

target-i386/helper.c void cpu_x86_cpuid(CPUX86State *env, uint32_t index, · line 1527

Quoted 7 lines
target-i386/helper.c +3 -0
@@ -1520,13 +1521,16 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,
 
         if (kvm_enabled()) {
             uint32_t h_eax, h_edx;
+            struct utsname utsname;
+
+            uname(&utsname);
 

It would be better to use KVM_GET_SUPPORTED_CPUID for this (and similar). uname() can lie, and in theory kvm can support x86_64 on i386 kernels (although patches to implement this would be rejected on cost/benefit and aesthetic concerns).

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#5 lore raw
Quoted 4 lines

It would be better to use KVM_GET_SUPPORTED_CPUID for this (and similar).
uname() can lie, and in theory kvm can support x86_64 on i386 kernels
(although patches to implement this would be rejected on cost/benefit and aesthetic concerns).

I sent a patch that implements this last week, but anthony seemed to be more inclined
towards this approach.

Signature · 5 lines
Glauber  Costa.
"Free as in Freedom"
http://glommer.net

"The less confident you are, the more serious you have to act."
#6 lore raw
Quoted 10 lines · Glauber Costa
Quoted 5 lines

It would be better to use KVM_GET_SUPPORTED_CPUID for this (and similar).
uname() can lie, and in theory kvm can support x86_64 on i386 kernels
(although patches to implement this would be rejected on cost/benefit and aesthetic concerns).

I sent a patch that implements this last week, but anthony seemed to be more inclined
towards this approach.

All I said was that if we used KVM_GET_SUPPORTED_CPUID, we had to do something about save/restore since it can mask arbitrary things.

Regards,

Anthony Liguori

#7 lore raw
Quoted 8 lines · Anthony Liguori
Quoted 7 lines · Glauber Costa
Quoted 6 lines

It would be better to use KVM_GET_SUPPORTED_CPUID for this (and similar).
uname() can lie, and in theory kvm can support x86_64 on i386 kernels
(although patches to implement this would be rejected on cost/benefit and aesthetic concerns).

Quoted 8 lines
Quoted 4 lines

I sent a patch that implements this last week, but anthony seemed to be more inclined
towards this approach.

All I said was that if we used KVM_GET_SUPPORTED_CPUID, we had to do something about save/restore since it can mask arbitrary things.

Then I misread you.

Who's the subject of your sentence, that can mask arbitrary things? kvm.ko in its ioctl,
or save/restore?

Signature · 5 lines
Glauber  Costa.
"Free as in Freedom"
http://glommer.net

"The less confident you are, the more serious you have to act."
#8 lore raw
Quoted 7 lines · Glauber Costa
Quoted 5 lines · Anthony Liguori

All I said was that if we used KVM_GET_SUPPORTED_CPUID, we had to do something about save/restore since it can mask arbitrary things.

Quoted 6 lines

Then I misread you.

Who's the subject of your sentence, that can mask arbitrary things? kvm.ko in its ioctl,
or save/restore?

Poor wording on my part. Your previous patch called KVM_GET_SUPPORTED_CPUID which would return the host CPUID bits that KVM supports. QEMU would then use that set to mask out features for the guest.

But the set of bits KVM returns differs on differing platforms. This means that you're now enabling features that were not previously enabled. This isn't a problem, but I'd like to see live migration handle this gracefully either by saving off the CPUID bits for the guest and failing appropriately when trying to enable CPUID bits on a platform that doesn't support it, or an explicit definition of CPUID capabilities.

I don't necessarily have a problem with enabling the most features by default, I just want migration to fail gracefully.

Regards,

Anthony Liguori

#9 lore raw
In reply to Anthony Liguori
Quoted 3 lines · Anthony Liguori

All I said was that if we used KVM_GET_SUPPORTED_CPUID, we had to do something about save/restore since it can mask arbitrary things.

Right, we need to transfer the cpuid bits to the migration target.

btw, we need to read them out of the kernel, since the cpuid instruction accesses hidden processor state (the results of cpuid don't depend simply on input eax and ecx).

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#10 lore raw
In reply to Glauber Costa
Quoted 17 lines · Glauber Costa

If the kernel is not 64-bit capable (even if the host machine is) do not expose the lm bit in guest cpuid.

target-i386/helper.c +1 -0
index a28ab93..997e4e1 100644
@@ -24,6 +24,7 @@
 #include <inttypes.h>
 #include <signal.h>
 #include <assert.h>
+#include <sys/utsname.h>
 
 #include "cpu.h"
 #include "exec-all.h"

target-i386/helper.c void cpu_x86_cpuid(CPUX86State *env, uint32_t index, · line 1527

Quoted 7 lines
target-i386/helper.c +3 -0
@@ -1520,13 +1521,16 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,
 
         if (kvm_enabled()) {
             uint32_t h_eax, h_edx;
+            struct utsname utsname;
+
+            uname(&utsname);
 

It would be better to use KVM_GET_SUPPORTED_CPUID for this (and similar). uname() can lie, and in theory kvm can support x86_64 on i386 kernels (although patches to implement this would be rejected on cost/benefit and aesthetic concerns).

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#11 lore raw
In reply to Glauber Costa
Quoted 17 lines · Glauber Costa

If the kernel is not 64-bit capable (even if the host machine is) do not expose the lm bit in guest cpuid.

target-i386/helper.c +1 -0
index a28ab93..997e4e1 100644
@@ -24,6 +24,7 @@
 #include <inttypes.h>
 #include <signal.h>
 #include <assert.h>
+#include <sys/utsname.h>
 
 #include "cpu.h"
 #include "exec-all.h"

target-i386/helper.c void cpu_x86_cpuid(CPUX86State *env, uint32_t index, · line 1527

Quoted 7 lines
target-i386/helper.c +3 -0
@@ -1520,13 +1521,16 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,
 
         if (kvm_enabled()) {
             uint32_t h_eax, h_edx;
+            struct utsname utsname;
+
+            uname(&utsname);
 

It would be better to use KVM_GET_SUPPORTED_CPUID for this (and similar). uname() can lie, and in theory kvm can support x86_64 on i386 kernels (although patches to implement this would be rejected on cost/benefit and aesthetic concerns).

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.