Skip to contentSkip to conversation

qemu-kvm: preserve the hypervisor bit while KVM trims the CPUID bits

PATCH Superseded Andre Przywara 2 participants 3 messages Jul 2, 2009 – Jul 7, 2009 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qemu-kvm: preserve the hypervisor bit while KVM trims the CPUID bits

The KVM kernel will disable all bits in CPUID which are not present in the host. As this is mostly true for the hypervisor bit (1.ecx), preserve its value before the trim and restore it afterwards. This is similar to commit 6c0d7ee8, but since qemu-kvm uses another code path it has to be inserted in qemu-kvm-x86.c, too.

---
 qemu-kvm-x86.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
qemu-kvm-x86.c +5 -0
index d6735c1..b02e604 100644
@@ -1211,8 +1211,13 @@ int kvm_arch_qemu_init_env(CPUState *cenv)
 
     kvm_trim_features(&cenv->cpuid_features,
                       kvm_arch_get_supported_cpuid(cenv, 1, R_EDX));
+
+    /* prevent the hypervisor bit from being cleared by the kernel */
+    i = env->cpuid_ext_features & CPUID_EXT_HYPERVISOR;
     kvm_trim_features(&cenv->cpuid_ext_features,
                       kvm_arch_get_supported_cpuid(cenv, 1, R_ECX));
+    env->cpuid_ext_features |= i;
+
     kvm_trim_features(&cenv->cpuid_ext2_features,
                       kvm_arch_get_supported_cpuid(cenv, 0x80000001, R_EDX));
     kvm_trim_features(&cenv->cpuid_ext3_features,
Signature · 1 line
1.6.1.3
#1 lore raw

PATCH v2 1/1 qemu-kvm: preserve the hypervisor bit while KVM trims the CPUID bits

The KVM kernel will disable all bits in CPUID which are not present in the host. As this is mostly true for the hypervisor bit (1.ecx), preserve its value before the trim and restore it afterwards. This is similar to commit 6c0d7ee8, but since qemu-kvm uses another code path it has to be inserted in qemu-kvm-x86.c, too.

---
 qemu-kvm-x86.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

The last patch had a typo (and I compile tested the wrong branch), so here is the correct version.

Regards,
Andre.

qemu-kvm-x86.c +5 -0
index d6735c1..7505380 100644
@@ -1211,8 +1211,13 @@ int kvm_arch_qemu_init_env(CPUState *cenv)
 
     kvm_trim_features(&cenv->cpuid_features,
                       kvm_arch_get_supported_cpuid(cenv, 1, R_EDX));
+
+    /* prevent the hypervisor bit from being cleared by the kernel */
+    i = cenv->cpuid_ext_features & CPUID_EXT_HYPERVISOR;
     kvm_trim_features(&cenv->cpuid_ext_features,
                       kvm_arch_get_supported_cpuid(cenv, 1, R_ECX));
+    cenv->cpuid_ext_features |= i;
+
     kvm_trim_features(&cenv->cpuid_ext2_features,
                       kvm_arch_get_supported_cpuid(cenv, 0x80000001, R_EDX));
     kvm_trim_features(&cenv->cpuid_ext3_features,
Signature · 1 line
1.6.1.3
Applied
#2 lore raw
Quoted 6 lines · Andre Przywara

The KVM kernel will disable all bits in CPUID which are not present in the host. As this is mostly true for the hypervisor bit (1.ecx), preserve its value before the trim and restore it afterwards. This is similar to commit 6c0d7ee8, but since qemu-kvm uses another code path it has to be inserted in qemu-kvm-x86.c, too.

Applied, thanks.

Signature · 1 line
error compiling committee.c: too many arguments to function