From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Igor Mammedov <imammedo@redhat.com>,
Richard Henderson <richard.henderson@linaro.org>,
Eduardo Habkost <ehabkost@redhat.com>,
Babu Moger <babu.moger@amd.com>
Subject: [PATCH 2/3] i386: Move asserts to separate x86_cpudef_validate() function
Date: Mon, 1 Feb 2021 17:54:03 -0500 [thread overview]
Message-ID: <20210201225404.3941395-3-ehabkost@redhat.com> (raw)
In-Reply-To: <20210201225404.3941395-1-ehabkost@redhat.com>
Additional sanity checks will be added to the code, so move the
existing asserts to a separate function.
Wrap the whole function in `#ifndef NDEBUG` because the checks
will become more complex than trivial assert() calls.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
target/i386/cpu.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 2bf3ab78056..6285fb00eb8 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -5431,17 +5431,25 @@ static void x86_register_cpu_model_type(const char *name, X86CPUModel *model)
type_register(&ti);
}
-static void x86_register_cpudef_types(X86CPUDefinition *def)
+/* Sanity check CPU model definition before registering it */
+static void x86_cpudef_validate(X86CPUDefinition *def)
{
- X86CPUModel *m;
- const X86CPUVersionDefinition *vdef;
-
+#ifndef NDEBUG
/* AMD aliases are handled at runtime based on CPUID vendor, so
* they shouldn't be set on the CPU model table.
*/
assert(!(def->features[FEAT_8000_0001_EDX] & CPUID_EXT2_AMD_ALIASES));
/* catch mistakes instead of silently truncating model_id when too long */
assert(def->model_id && strlen(def->model_id) <= 48);
+#endif
+}
+
+static void x86_register_cpudef_types(X86CPUDefinition *def)
+{
+ X86CPUModel *m;
+ const X86CPUVersionDefinition *vdef;
+
+ x86_cpudef_validate(def);
/* Unversioned model: */
m = g_new0(X86CPUModel, 1);
--
2.28.0
next prev parent reply other threads:[~2021-02-01 22:56 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-01 22:54 [PATCH 0/3] i386: Ensure feature names are always defined Eduardo Habkost
2021-02-01 22:54 ` [PATCH 1/3] i386: Add missing "vmx-ept-wb" feature name Eduardo Habkost
2021-02-01 22:59 ` Paolo Bonzini
2021-02-01 23:05 ` Eduardo Habkost
2021-02-01 23:28 ` Paolo Bonzini
2021-02-02 0:18 ` Eduardo Habkost
2021-02-02 7:54 ` Paolo Bonzini
2021-02-02 15:25 ` Eduardo Habkost
2021-02-01 22:54 ` Eduardo Habkost [this message]
2021-02-02 16:02 ` [PATCH 2/3] i386: Move asserts to separate x86_cpudef_validate() function Philippe Mathieu-Daudé
2021-02-01 22:54 ` [PATCH 3/3] i386: Sanity check CPU model feature sets Eduardo Habkost
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=20210201225404.3941395-3-ehabkost@redhat.com \
--to=ehabkost@redhat.com \
--cc=babu.moger@amd.com \
--cc=imammedo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/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 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).