Skip to contentSkip to conversation

target-i386: prevent users from setting threads>1 for AMD CPUs

PATCH In review Wei Huang 1 participant 2 messages Oct 7, 2014

lore
Share & tools
lore

Wei Huang

author
#0 lore raw

PATCH 1/1 target-i386: prevent users from setting threads>1 for AMD CPUs

AMD CPU doesn't support hyperthreading. Even though QEMU fixes this issue by setting CPUID_0000_0001_EBX and CPUID_8000_0008_ECX via conversion, it is better to stop end-users in the first place with a warning message.

---
 target-i386/cpu.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
target-i386/cpu.c +18 -0
index e7bf9de..01bbcaf 100644
@@ -2742,6 +2742,24 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
     mce_init(cpu);
     qemu_init_vcpu(cs);
 
+    /* AMD CPU doesn't support hyperthreading. Even though QEMU does fix
+     * this issue by setting CPUID_0000_0001_EBX and CPUID_8000_0008_ECX
+     * correctly, it is still better to stop end-users in the first place
+     * by giving out a warning message.
+     *
+     * NOTE: cs->nr_threads is initialized in qemu_init_vcpu(). So the
+     * following code has to follow qemu_init_vcpu().
+     */
+    if (env->cpuid_vendor1 == CPUID_VENDOR_AMD_1 &&
+        env->cpuid_vendor2 == CPUID_VENDOR_AMD_2 &&
+        env->cpuid_vendor3 == CPUID_VENDOR_AMD_3 &&
+        (cs->nr_threads > 1)) {
+        error_setg(&local_err,
+                   "AMD CPU doesn't support hyperthreading. Please configure "
+                   "-smp options correctly.");
+        goto out;
+    }
+
     x86_cpu_apic_realize(cpu, &local_err);
     if (local_err != NULL) {
         goto out;
Signature · 1 line
1.8.3.1
author
#1 lore raw

Sorry, please skip this version. I am sending out a updated one.

-Wei

Quoted 40 lines · Wei Huang

AMD CPU doesn't support hyperthreading. Even though QEMU fixes this issue by setting CPUID_0000_0001_EBX and CPUID_8000_0008_ECX via conversion, it is better to stop end-users in the first place with a warning message.

---
  target-i386/cpu.c | 18 ++++++++++++++++++
  1 file changed, 18 insertions(+)
target-i386/cpu.c +18 -0
index e7bf9de..01bbcaf 100644
@@ -2742,6 +2742,24 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
      mce_init(cpu);
      qemu_init_vcpu(cs);
 
+    /* AMD CPU doesn't support hyperthreading. Even though QEMU does fix
+     * this issue by setting CPUID_0000_0001_EBX and CPUID_8000_0008_ECX
+     * correctly, it is still better to stop end-users in the first place
+     * by giving out a warning message.
+     *
+     * NOTE: cs->nr_threads is initialized in qemu_init_vcpu(). So the
+     * following code has to follow qemu_init_vcpu().
+     */
+    if (env->cpuid_vendor1 == CPUID_VENDOR_AMD_1 &&
+        env->cpuid_vendor2 == CPUID_VENDOR_AMD_2 &&
+        env->cpuid_vendor3 == CPUID_VENDOR_AMD_3 &&
+        (cs->nr_threads > 1)) {
+        error_setg(&local_err,
+                   "AMD CPU doesn't support hyperthreading. Please configure "
+                   "-smp options correctly.");
+        goto out;
+    }
+
      x86_cpu_apic_realize(cpu, &local_err);
      if (local_err != NULL) {
          goto out;