[PATCH 3/3] x86: Check level, xlevel before returning CPUID data

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux