From: "Daniel P. Berrange" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Richard Henderson <rth@twiddle.net>,
Eduardo Habkost <ehabkost@redhat.com>,
"Daniel P. Berrange" <berrange@redhat.com>
Subject: [Qemu-devel] [PATCH v2 1/2] i386: rewrite way CPUID index is validated
Date: Fri, 5 May 2017 15:27:42 +0100 [thread overview]
Message-ID: <20170505142743.19849-2-berrange@redhat.com> (raw)
In-Reply-To: <20170505142743.19849-1-berrange@redhat.com>
Change the nested if statements into a flat switch, to make
it clearer what validation / capping is being performed on
different CPUID index values.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
target/i386/cpu.c | 43 +++++++++++++++++++++++++------------------
1 file changed, 25 insertions(+), 18 deletions(-)
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 13c0985..3d5903c 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -2628,26 +2628,33 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
uint32_t pkg_offset;
/* test if maximum index reached */
- if (index & 0x80000000) {
+ switch (index & 0xF0000000) {
+ case 0:
+ /* Intel documentation states that invalid EAX input will
+ * return the same information as EAX=cpuid_level
+ * (Intel SDM Vol. 2A - Instruction Set Reference - CPUID)
+ */
+ if (index > env->cpuid_level) {
+ index = env->cpuid_level;
+ }
+ break;
+ case 0x80000000:
if (index > env->cpuid_xlevel) {
- if (env->cpuid_xlevel2 > 0) {
- /* Handle the Centaur's CPUID instruction. */
- if (index > env->cpuid_xlevel2) {
- index = env->cpuid_xlevel2;
- } else if (index < 0xC0000000) {
- index = env->cpuid_xlevel;
- }
- } else {
- /* Intel documentation states that invalid EAX input will
- * return the same information as EAX=cpuid_level
- * (Intel SDM Vol. 2A - Instruction Set Reference - CPUID)
- */
- index = env->cpuid_level;
- }
+ index = env->cpuid_xlevel;
}
- } else {
- if (index > env->cpuid_level)
- index = env->cpuid_level;
+ break;
+ case 0xC0000000:
+ if (index > env->cpuid_xlevel2) {
+ index = env->cpuid_xlevel2;
+ }
+ break;
+ default:
+ /* Intel documentation states that invalid EAX input will
+ * return the same information as EAX=cpuid_level
+ * (Intel SDM Vol. 2A - Instruction Set Reference - CPUID)
+ */
+ index = env->cpuid_level;
+ break;
}
switch(index) {
--
2.9.3
next prev parent reply other threads:[~2017-05-05 14:28 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-05 14:27 [Qemu-devel] [PATCH v2 0/2] Support CPUID signature for TCG Daniel P. Berrange
2017-05-05 14:27 ` Daniel P. Berrange [this message]
2017-05-05 17:41 ` [Qemu-devel] [PATCH v2 1/2] i386: rewrite way CPUID index is validated Eduardo Habkost
2017-05-05 14:27 ` [Qemu-devel] [PATCH v2 2/2] i386: expose "TCGTCGTCGTCG" in the 0x40000000 CPUID leaf Daniel P. Berrange
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=20170505142743.19849-2-berrange@redhat.com \
--to=berrange@redhat.com \
--cc=ehabkost@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
/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).