From: Eduardo Habkost <ehabkost@redhat.com>
To: kvm@vger.kernel.org
Cc: Paolo Bonzini <pbonzini@redhat.com>
Subject: [PATCH 3/3] x86: Check level, xlevel before returning CPUID data
Date: Thu, 28 Aug 2014 15:02:30 -0300 [thread overview]
Message-ID: <1409248950-16268-4-git-send-email-ehabkost@redhat.com> (raw)
In-Reply-To: <1409248950-16268-1-git-send-email-ehabkost@redhat.com>
None of the existing code using cpuid checks level or xlevel before
running it. Instead of changing all callers, make the cpuid() function
check if the requested leaf is available, before returning any data.
All existing callers of cpuid() and cpuid_indexed() are checks for the
presence of feature bits, so it is safe to return all zeroes when the
requested CPUID leaf is not available.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
lib/x86/processor.h | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/lib/x86/processor.h b/lib/x86/processor.h
index d4e295b..7973879 100644
--- a/lib/x86/processor.h
+++ b/lib/x86/processor.h
@@ -280,7 +280,7 @@ static inline ulong read_dr7(void)
struct cpuid { u32 a, b, c, d; };
-static inline struct cpuid cpuid_indexed(u32 function, u32 index)
+static inline struct cpuid raw_cpuid(u32 function, u32 index)
{
struct cpuid r;
asm volatile ("cpuid"
@@ -289,6 +289,14 @@ static inline struct cpuid cpuid_indexed(u32 function, u32 index)
return r;
}
+static inline struct cpuid cpuid_indexed(u32 function, u32 index)
+{
+ u32 level = raw_cpuid(function & 0xf0000000, 0).a;
+ if (level < function)
+ return (struct cpuid) { 0, 0, 0, 0 };
+ return raw_cpuid(function, index);
+}
+
static inline struct cpuid cpuid(u32 function)
{
return cpuid_indexed(function, 0);
@@ -296,9 +304,9 @@ static inline struct cpuid cpuid(u32 function)
static inline u8 cpuid_maxphyaddr(void)
{
- if (cpuid(0x80000000).a < 0x80000008)
+ if (raw_cpuid(0x80000000, 0).a < 0x80000008)
return 36;
- return cpuid(0x80000008).a & 0xff;
+ return raw_cpuid(0x80000008, 0).a & 0xff;
}
--
1.9.3
next prev parent reply other threads:[~2014-08-28 18:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-28 18:02 [PATCH 0/3] kvm-unit-tests: Check CPUID level/xlevel before using CPUID data Eduardo Habkost
2014-08-28 18:02 ` [PATCH 1/3] x86: apic: Look up MAXPHYADDR on CPUID correctly Eduardo Habkost
2014-08-28 18:02 ` [PATCH 2/3] x86: vmx: Use cpuid_maxphyaddr() Eduardo Habkost
2014-08-28 18:02 ` Eduardo Habkost [this message]
2014-08-29 7:54 ` [PATCH 0/3] kvm-unit-tests: Check CPUID level/xlevel before using CPUID data Paolo Bonzini
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=1409248950-16268-4-git-send-email-ehabkost@redhat.com \
--to=ehabkost@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox