qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 1/1] target-i386: prevent users from setting threads>1 for AMD CPUs
@ 2014-10-07 19:44 Wei Huang
  2014-10-07 20:58 ` Paolo Bonzini
  0 siblings, 1 reply; 12+ messages in thread
From: Wei Huang @ 2014-10-07 19:44 UTC (permalink / raw)
  To: afaerber; +Cc: wei, qemu-devel

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.

Signed-off-by: Wei Huang <wei@redhat.com>
---
 target-i386/cpu.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index e7bf9de..c377cd2 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -2696,6 +2696,10 @@ static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)
 }
 #endif
 
+#define IS_AMD_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_AMD_1 && \
+                         (env)->cpuid_vendor2 == CPUID_VENDOR_AMD_2 && \
+                         (env)->cpuid_vendor3 == CPUID_VENDOR_AMD_3)
+
 static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
 {
     CPUState *cs = CPU(dev);
@@ -2711,9 +2715,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
     /* On AMD CPUs, some CPUID[8000_0001].EDX bits must match the bits on
      * CPUID[1].EDX.
      */
-    if (env->cpuid_vendor1 == CPUID_VENDOR_AMD_1 &&
-        env->cpuid_vendor2 == CPUID_VENDOR_AMD_2 &&
-        env->cpuid_vendor3 == CPUID_VENDOR_AMD_3) {
+    if (IS_AMD_CPU(env)) {
         env->features[FEAT_8000_0001_EDX] &= ~CPUID_EXT2_AMD_ALIASES;
         env->features[FEAT_8000_0001_EDX] |= (env->features[FEAT_1_EDX]
            & CPUID_EXT2_AMD_ALIASES);
@@ -2742,6 +2744,21 @@ 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 (IS_AMD_CPU(env) && (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;
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [Qemu-devel] [PATCH 1/1] target-i386: prevent users from setting threads>1 for AMD CPUs
@ 2014-10-07 19:17 Wei Huang
  2014-10-07 19:42 ` Wei Huang
  0 siblings, 1 reply; 12+ messages in thread
From: Wei Huang @ 2014-10-07 19:17 UTC (permalink / raw)
  To: afaerber; +Cc: wei, qemu-devel

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.

Signed-off-by: Wei Huang <wei@redhat.com>
---
 target-i386/cpu.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index e7bf9de..01bbcaf 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -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;
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2014-10-21 15:11 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-07 19:44 [Qemu-devel] [PATCH 1/1] target-i386: prevent users from setting threads>1 for AMD CPUs Wei Huang
2014-10-07 20:58 ` Paolo Bonzini
2014-10-07 21:16   ` Wei Huang
2014-10-07 21:36     ` Paolo Bonzini
2014-10-08  0:41       ` Wei Huang
2014-10-08  7:47         ` Paolo Bonzini
2014-10-09 20:22           ` Wei Huang
2014-10-09 21:08             ` Paolo Bonzini
2014-10-09 22:16               ` Eduardo Habkost
2014-10-21 15:11                 ` Wei Huang
  -- strict thread matches above, loose matches on Subject: below --
2014-10-07 19:17 Wei Huang
2014-10-07 19:42 ` Wei Huang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).