don't expose lm bit if kernel is not 64-bit capable.
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
@@ -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
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.
Signed-off-by Glauber Costa <[email protected]>---
target-i386/helper.c| 6 +++++-1 files changed, 5 insertions(+), 1 deletions(-)target-i386/helper.c +1
-0@@ -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
-1host_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
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."
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_64capable kernel?
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@@ -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.
Quoted 4 lines
It would be better to use
KVM_GET_SUPPORTED_CPUIDfor this (and similar).
uname()can lie, and in theory kvm can supportx86_64on 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."
Quoted 10 lines · Glauber Costa
Quoted 5 lines
It would be better to use
KVM_GET_SUPPORTED_CPUIDfor this (and similar).
uname()can lie, and in theory kvm can supportx86_64on 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
Quoted 8 lines · Anthony Liguori
Quoted 7 lines · Glauber Costa
Quoted 6 lines
It would be better to use
KVM_GET_SUPPORTED_CPUIDfor this (and similar).
uname()can lie, and in theory kvm can supportx86_64on 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."
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
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.
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@@ -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.
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@@ -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.