diff mbox

[v12,3/4] i386: Enable TOPOEXT feature on AMD EPYC CPU

Message ID 1528295806-90593-4-git-send-email-babu.moger@amd.com (mailing list archive)
State New, archived
Headers show

Commit Message

Moger, Babu June 6, 2018, 2:36 p.m. UTC
Enable TOPOEXT feature on EPYC CPU. This is required to support
hyperthreading on VM guests. Also extend xlevel to 0x8000001E.

Disable TOPOEXT feature for legacy machines.

Signed-off-by: Babu Moger <babu.moger@amd.com>
---
 include/hw/i386/pc.h |  4 ++++
 target/i386/cpu.c    | 11 +++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)

Comments

Eduardo Habkost June 6, 2018, 10:39 p.m. UTC | #1
On Wed, Jun 06, 2018 at 10:36:45AM -0400, Babu Moger wrote:
> Enable TOPOEXT feature on EPYC CPU. This is required to support
> hyperthreading on VM guests. Also extend xlevel to 0x8000001E.
> 
> Disable TOPOEXT feature for legacy machines.
> 
> Signed-off-by: Babu Moger <babu.moger@amd.com>

Now, I just noticed we have a problem here:

"-machine pc -cpu EPYC -smp 64" works today

This patch makes it stop working, but it shouldn't.

On the other hand, I believe you expect:
* "-machine pc -cpu EPYC -smp 8" to automatically enable topoext.
* "-machine pc -cpu Opteron_G1 -smp 8" to not enable topoext.
* What about "-machine -cpu Opteron_G1 -smp 8,threads=2"?


We also have other requirements, I will try to enumerate all of
them below:

0) "-topoext" explicitly configured (any machine-type):
* Must never enable topoext.

1) "+topoext" explicitly configured (any machine-type):
* Must validate topology and refuse to start if unsupported.

2) Older machine-types:
* Must never enable topoext automatically, even if using "EPYC"
  or "threads=2"

3) "EPYC" CPU model (on new machine-types):
* Should enable topoext automatically, but only if topology is
  supported.
* Must not error out if topology is not supported.
* Should this enable topoext automatically even if threads=1?

4) Other AMD CPU models with "threads=2" (on new machine-types):
* We might want to make this enable topoext automatically, too.
  What do you think?

Is the above description accurate?  Do you agree with these
requirements?

We're trying to use the "topoext" property to cover all cases
above, but it looks like we need at least 2 bits to represent all
possible cases.


Maybe we can represent the cases above with two properties:
"topoext" and "auto-topoext".  Then each case would be
represented by:

0) "-topoext" explicitly configured (any machine-type):
* Will clear TOPOEXT on env->features and set TOPOEXT on
  env->user_features
  (already done today)

1) "+topoext" explicitly configured (any machine-type):
* Will set TOPOEXT on both env->user_features and env->features
  (already done today)

2) Older machine-types:
* Will set auto-topoext=off (can be done on compat_props)
* Will set topoext=off on EPYC CPU model (so TOPOEXT won't be set
  by default on env->features) (can be done on compat_props)

3) "EPYC" CPU model (on new machine-types):
* Will set auto-topoext=on (can be the default for all CPU
  models)
* Will set TOPOEXT on env->features) (can be done on CPU model table)

4) Other AMD CPU models with "threads=2" (on new machine-types):
* Will set auto-topoext=on (can be the default on all CPU models)
* Will keep TOPOEXT disabled on env->features (done on the CPU
  model table)


Then the rules would be:

  if {auto_topoext && TOPOEXT not in env->user_features) {
      if (supported_topology) {
          if (threads > 1)
              set TOPOEXT in env->features
      } else
          unset TOPOEXT in env->features
  }

  if (TOPOEXT in env->features && !supported_topology)
      error;
  }

I think this would fulfill all the requirements above.  Please
help me confirm that.
Moger, Babu June 8, 2018, 6:40 p.m. UTC | #2
Hi Eduardo, 
Sorry for the late response. Got pulled into something else.

> -----Original Message-----
> From: Eduardo Habkost [mailto:ehabkost@redhat.com]
> Sent: Wednesday, June 6, 2018 5:40 PM
> To: Moger, Babu <Babu.Moger@amd.com>
> Cc: mst@redhat.com; marcel.apfelbaum@gmail.com; pbonzini@redhat.com;
> rth@twiddle.net; mtosatti@redhat.com; qemu-devel@nongnu.org;
> kvm@vger.kernel.org; kash@tripleback.net; geoff@hostfission.com
> Subject: Re: [PATCH v12 3/4] i386: Enable TOPOEXT feature on AMD EPYC
> CPU
> 
> On Wed, Jun 06, 2018 at 10:36:45AM -0400, Babu Moger wrote:
> > Enable TOPOEXT feature on EPYC CPU. This is required to support
> > hyperthreading on VM guests. Also extend xlevel to 0x8000001E.
> >
> > Disable TOPOEXT feature for legacy machines.
> >
> > Signed-off-by: Babu Moger <babu.moger@amd.com>
> 
> Now, I just noticed we have a problem here:
> 
> "-machine pc -cpu EPYC -smp 64" works today
> 
> This patch makes it stop working, but it shouldn't.

No. It works fine. I have tested it.

> 
> On the other hand, I believe you expect:
> * "-machine pc -cpu EPYC -smp 8" to automatically enable topoext.
Yes. Only on new machines-types
> * "-machine pc -cpu Opteron_G1 -smp 8" to not enable topoext.
Yes.
> * What about "-machine -cpu Opteron_G1 -smp 8,threads=2"?
No. This should not enable topoext.  Topoext is not supported by Opteron_G1.
This should warn about hyperthreading and continue.
> 
> 
> We also have other requirements, I will try to enumerate all of
> them below:
> 
> 0) "-topoext" explicitly configured (any machine-type):
> * Must never enable topoext.
Yes.
> 
> 1) "+topoext" explicitly configured (any machine-type):
> * Must validate topology and refuse to start if unsupported.

Yes.

> 
> 2) Older machine-types:
> * Must never enable topoext automatically, even if using "EPYC"
>   or "threads=2"
> 
Yes.

> 3) "EPYC" CPU model (on new machine-types):
> * Should enable topoext automatically, but only if topology is
>   supported.
> * Must not error out if topology is not supported.
In new machine types we will enable topoext for "EPYC" CPU model.
Right now(old machine type) we can disable for all the CPU models. 
So, we don't need two bits(topoext and auto-topoext)

I thought we should error out if topology cannot be supported. But we can warn(disable topoext) and continue that is another option.

> * Should this enable topoext automatically even if threads=1?

Yes. We should enable even with threads=1.

> 
> 4) Other AMD CPU models with "threads=2" (on new machine-types):
> * We might want to make this enable topoext automatically, too.
>   What do you think?

  No. We should not enable topoext here. We should depend on CPU model table here.

> 
> Is the above description accurate?  Do you agree with these
> requirements?

With these requirements in mind, I will send that patches. We can start our discussion.
We don't need one more bits. That is my opinion. 


> 
> We're trying to use the "topoext" property to cover all cases
> above, but it looks like we need at least 2 bits to represent all
> possible cases.
> 
> 
> Maybe we can represent the cases above with two properties:
> "topoext" and "auto-topoext".  Then each case would be
> represented by:
> 
> 0) "-topoext" explicitly configured (any machine-type):
> * Will clear TOPOEXT on env->features and set TOPOEXT on
>   env->user_features
>   (already done today)
> 
> 1) "+topoext" explicitly configured (any machine-type):
> * Will set TOPOEXT on both env->user_features and env->features
>   (already done today)
> 
> 2) Older machine-types:
> * Will set auto-topoext=off (can be done on compat_props)
> * Will set topoext=off on EPYC CPU model (so TOPOEXT won't be set
>   by default on env->features) (can be done on compat_props)
> 
> 3) "EPYC" CPU model (on new machine-types):
> * Will set auto-topoext=on (can be the default for all CPU
>   models)
> * Will set TOPOEXT on env->features) (can be done on CPU model table)
> 
> 4) Other AMD CPU models with "threads=2" (on new machine-types):
> * Will set auto-topoext=on (can be the default on all CPU models)
> * Will keep TOPOEXT disabled on env->features (done on the CPU
>   model table)
> 
> 
> Then the rules would be:
> 
>   if {auto_topoext && TOPOEXT not in env->user_features) {
>       if (supported_topology) {
>           if (threads > 1)
>               set TOPOEXT in env->features
>       } else
>           unset TOPOEXT in env->features
>   }
> 
>   if (TOPOEXT in env->features && !supported_topology)
>       error;
>   }
> 
> I think this would fulfill all the requirements above.  Please
> help me confirm that.
> 
> --
> Eduardo
diff mbox

Patch

diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 04d1f8c..2630a91 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -303,6 +303,10 @@  bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
         .driver   = TYPE_X86_CPU,\
         .property = "legacy-cache",\
         .value    = "on",\
+    },{\
+        .driver   = "EPYC-" TYPE_X86_CPU,\
+        .property = "topoext",\
+        .value    = "off",\
     },
 
 #define PC_COMPAT_2_11 \
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index fc5c66d..40bf5cb 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -2568,7 +2568,8 @@  static X86CPUDefinition builtin_x86_defs[] = {
         .features[FEAT_8000_0001_ECX] =
             CPUID_EXT3_OSVW | CPUID_EXT3_3DNOWPREFETCH |
             CPUID_EXT3_MISALIGNSSE | CPUID_EXT3_SSE4A | CPUID_EXT3_ABM |
-            CPUID_EXT3_CR8LEG | CPUID_EXT3_SVM | CPUID_EXT3_LAHF_LM,
+            CPUID_EXT3_CR8LEG | CPUID_EXT3_SVM | CPUID_EXT3_LAHF_LM |
+            CPUID_EXT3_TOPOEXT,
         .features[FEAT_7_0_EBX] =
             CPUID_7_0_EBX_FSGSBASE | CPUID_7_0_EBX_BMI1 | CPUID_7_0_EBX_AVX2 |
             CPUID_7_0_EBX_SMEP | CPUID_7_0_EBX_BMI2 | CPUID_7_0_EBX_RDSEED |
@@ -2613,7 +2614,8 @@  static X86CPUDefinition builtin_x86_defs[] = {
         .features[FEAT_8000_0001_ECX] =
             CPUID_EXT3_OSVW | CPUID_EXT3_3DNOWPREFETCH |
             CPUID_EXT3_MISALIGNSSE | CPUID_EXT3_SSE4A | CPUID_EXT3_ABM |
-            CPUID_EXT3_CR8LEG | CPUID_EXT3_SVM | CPUID_EXT3_LAHF_LM,
+            CPUID_EXT3_CR8LEG | CPUID_EXT3_SVM | CPUID_EXT3_LAHF_LM |
+            CPUID_EXT3_TOPOEXT,
         .features[FEAT_8000_0008_EBX] =
             CPUID_8000_0008_EBX_IBPB,
         .features[FEAT_7_0_EBX] =
@@ -4681,6 +4683,11 @@  static void x86_cpu_expand_features(X86CPU *cpu, Error **errp)
             x86_cpu_adjust_level(cpu, &env->cpuid_min_xlevel, 0x8000000A);
         }
 
+        /* TOPOEXT feature requires 0x8000001E */
+        if (env->features[FEAT_8000_0001_ECX] & CPUID_EXT3_TOPOEXT) {
+            x86_cpu_adjust_level(cpu, &env->cpuid_min_xlevel, 0x8000001E);
+        }
+
         /* SEV requires CPUID[0x8000001F] */
         if (sev_enabled()) {
             x86_cpu_adjust_level(cpu, &env->cpuid_min_xlevel, 0x8000001F);