diff mbox

[2/3] qemu-kvm: align cpu-features with kvm_supported_cpuid

Message ID 1245261402-26440-3-git-send-email-joerg.roedel@amd.com (mailing list archive)
State New, archived
Headers show

Commit Message

Joerg Roedel June 17, 2009, 5:56 p.m. UTC
The cpuid features exposed to the guest are currently not aligned with the bits
returned by the supported_cpuid ioctl. This patch fixes it.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
 qemu-kvm-x86.c |   28 +++++++++++++++++-----------
 1 files changed, 17 insertions(+), 11 deletions(-)
diff mbox

Patch

diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c
index 729d600..95774c1 100644
--- a/qemu-kvm-x86.c
+++ b/qemu-kvm-x86.c
@@ -578,6 +578,13 @@  int kvm_arch_qemu_init_env(CPUState *cenv)
                 if (i == 0xd && copy.regs[R_EAX] == 0)
                     break;
             }
+        } else if (i == 1) {
+            do_cpuid_ent(&cpuid_ent[cpuid_nent], i, 0, &copy);
+            kvm_trim_features(&cpuid_ent[cpuid_nent].edx,
+                              kvm_arch_get_supported_cpuid(cenv, 1, R_EDX));
+            kvm_trim_features(&cpuid_ent[cpuid_nent].ecx,
+                              kvm_arch_get_supported_cpuid(cenv, 1, R_ECX));
+            cpuid_nent++;
         } else
             do_cpuid_ent(&cpuid_ent[cpuid_nent++], i, 0, &copy);
     }
@@ -586,20 +593,19 @@  int kvm_arch_qemu_init_env(CPUState *cenv)
     qemu_kvm_cpuid_on_env(&copy);
     limit = copy.regs[R_EAX];
 
-    for (i = 0x80000000; i <= limit; ++i)
-	do_cpuid_ent(&cpuid_ent[cpuid_nent++], i, 0, &copy);
+    for (i = 0x80000000; i <= limit; ++i) {
+	do_cpuid_ent(&cpuid_ent[cpuid_nent], i, 0, &copy);
+        if (i == 0x80000001) {
+            kvm_trim_features(&cpuid_ent[cpuid_nent].edx,
+                              kvm_arch_get_supported_cpuid(cenv, 0x80000001, R_EDX));
+            kvm_trim_features(&cpuid_ent[cpuid_nent].ecx,
+                              kvm_arch_get_supported_cpuid(cenv, 0x80000001, R_ECX));
+        }
+        ++cpuid_nent;
+    }
 
     kvm_setup_cpuid2(cenv->kvm_cpu_state.vcpu_ctx, cpuid_nent, cpuid_ent);
 
-    kvm_trim_features(&cenv->cpuid_features,
-                      kvm_arch_get_supported_cpuid(cenv, 1, R_EDX));
-    kvm_trim_features(&cenv->cpuid_ext_features,
-                      kvm_arch_get_supported_cpuid(cenv, 1, R_ECX));
-    kvm_trim_features(&cenv->cpuid_ext2_features,
-                      kvm_arch_get_supported_cpuid(cenv, 0x80000001, R_EDX));
-    kvm_trim_features(&cenv->cpuid_ext3_features,
-                      kvm_arch_get_supported_cpuid(cenv, 0x80000001, R_ECX));
-
     return 0;
 }