All of lore.kernel.org
 help / color / mirror / Atom feed
From: Babu Moger <babu.moger@amd.com>
To: <pbonzini@redhat.com>, <richard.henderson@linaro.org>
Cc: <weijiang.yang@intel.com>, <philmd@linaro.org>,
	<dwmw@amazon.co.uk>, <paul@xen.org>, <joao.m.martins@oracle.com>,
	<qemu-devel@nongnu.org>, <mtosatti@redhat.com>,
	<kvm@vger.kernel.org>, <mst@redhat.com>,
	<marcel.apfelbaum@gmail.com>, <yang.zhong@intel.com>,
	<jing2.liu@intel.com>, <vkuznets@redhat.com>,
	<michael.roth@amd.com>, <wei.huang2@amd.com>,
	<berrange@redhat.com>, <babu.moger@amd.com>, <bdas@redhat.com>
Subject: [PATCH v4 1/7] target/i386: allow versioned CPUs to specify new cache_info
Date: Thu, 4 May 2023 15:53:06 -0500	[thread overview]
Message-ID: <20230504205313.225073-2-babu.moger@amd.com> (raw)
In-Reply-To: <20230504205313.225073-1-babu.moger@amd.com>

From: Michael Roth <michael.roth@amd.com>

New EPYC CPUs versions require small changes to their cache_info's.
Because current QEMU x86 CPU definition does not support versioned
cach_info, we would have to declare a new CPU type for each such case.
To avoid the dup work, add "cache_info" in X86CPUVersionDefinition",
to allow new cache_info pointers to be specified for a new CPU version.

Co-developed-by: Wei Huang <wei.huang2@amd.com>
Signed-off-by: Wei Huang <wei.huang2@amd.com>
Signed-off-by: Michael Roth <michael.roth@amd.com>
Signed-off-by: Babu Moger <babu.moger@amd.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
---
 target/i386/cpu.c | 35 ++++++++++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 deletions(-)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 6576287e5b..6e5d2779c9 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -1598,6 +1598,7 @@ typedef struct X86CPUVersionDefinition {
     const char *alias;
     const char *note;
     PropValue *props;
+    const CPUCaches *const cache_info;
 } X86CPUVersionDefinition;
 
 /* Base definition for a CPU model */
@@ -5192,6 +5193,31 @@ static void x86_cpu_apply_version_props(X86CPU *cpu, X86CPUModel *model)
     assert(vdef->version == version);
 }
 
+static const CPUCaches *x86_cpu_get_versioned_cache_info(X86CPU *cpu,
+                                                         X86CPUModel *model)
+{
+    const X86CPUVersionDefinition *vdef;
+    X86CPUVersion version = x86_cpu_model_resolve_version(model);
+    const CPUCaches *cache_info = model->cpudef->cache_info;
+
+    if (version == CPU_VERSION_LEGACY) {
+        return cache_info;
+    }
+
+    for (vdef = x86_cpu_def_get_versions(model->cpudef); vdef->version; vdef++) {
+        if (vdef->cache_info) {
+            cache_info = vdef->cache_info;
+        }
+
+        if (vdef->version == version) {
+            break;
+        }
+    }
+
+    assert(vdef->version == version);
+    return cache_info;
+}
+
 /*
  * Load data from X86CPUDefinition into a X86CPU object.
  * Only for builtin_x86_defs models initialized with x86_register_cpudef_types.
@@ -5224,7 +5250,7 @@ static void x86_cpu_load_model(X86CPU *cpu, X86CPUModel *model)
     }
 
     /* legacy-cache defaults to 'off' if CPU model provides cache info */
-    cpu->legacy_cache = !def->cache_info;
+    cpu->legacy_cache = !x86_cpu_get_versioned_cache_info(cpu, model);
 
     env->features[FEAT_1_ECX] |= CPUID_EXT_HYPERVISOR;
 
@@ -6703,14 +6729,17 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
 
     /* Cache information initialization */
     if (!cpu->legacy_cache) {
-        if (!xcc->model || !xcc->model->cpudef->cache_info) {
+        const CPUCaches *cache_info =
+            x86_cpu_get_versioned_cache_info(cpu, xcc->model);
+
+        if (!xcc->model || !cache_info) {
             g_autofree char *name = x86_cpu_class_get_model_name(xcc);
             error_setg(errp,
                        "CPU model '%s' doesn't support legacy-cache=off", name);
             return;
         }
         env->cache_info_cpuid2 = env->cache_info_cpuid4 = env->cache_info_amd =
-            *xcc->model->cpudef->cache_info;
+            *cache_info;
     } else {
         /* Build legacy cache information */
         env->cache_info_cpuid2.l1d_cache = &legacy_l1d_cache;
-- 
2.34.1


  reply	other threads:[~2023-05-04 20:54 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-04 20:53 [PATCH v4 0/7] Add EPYC-Genoa model and update previous EPYC Models Babu Moger
2023-05-04 20:53 ` Babu Moger [this message]
2023-05-04 20:53 ` [PATCH v4 2/7] target/i386: Add new EPYC CPU versions with updated cache_info Babu Moger
2023-05-04 20:53   ` Babu Moger
2023-05-04 20:53 ` [PATCH v4 3/7] target/i386: Add a couple of feature bits in 8000_0008_EBX Babu Moger
2023-05-04 20:53   ` Babu Moger
2023-05-04 20:53 ` [PATCH v4 4/7] target/i386: Add feature bits for CPUID_Fn80000021_EAX Babu Moger
2023-05-05  8:29   ` Paolo Bonzini
2023-05-04 20:53 ` [PATCH v4 5/7] target/i386: Add missing feature bits in EPYC-Milan model Babu Moger
2023-05-04 20:53 ` [PATCH v4 6/7] target/i386: Add VNMI and automatic IBRS feature bits Babu Moger
2023-05-04 20:53 ` [PATCH v4 7/7] target/i386: Add EPYC-Genoa model to support Zen 4 processor series Babu Moger
2023-05-05  8:31 ` [PATCH v4 0/7] Add EPYC-Genoa model and update previous EPYC Models Paolo Bonzini
2023-05-05 17:15   ` Moger, Babu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230504205313.225073-2-babu.moger@amd.com \
    --to=babu.moger@amd.com \
    --cc=bdas@redhat.com \
    --cc=berrange@redhat.com \
    --cc=dwmw@amazon.co.uk \
    --cc=jing2.liu@intel.com \
    --cc=joao.m.martins@oracle.com \
    --cc=kvm@vger.kernel.org \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=michael.roth@amd.com \
    --cc=mst@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=paul@xen.org \
    --cc=pbonzini@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=vkuznets@redhat.com \
    --cc=wei.huang2@amd.com \
    --cc=weijiang.yang@intel.com \
    --cc=yang.zhong@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.