]> xenbits.xensource.com Git - people/sstabellini/xen-unstable.git/.git/commitdiff
x86/cpu: Introduce x86_cpuid_vendor_to_str() and drop cpu_dev.c_vendor[]
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 4 Apr 2019 18:19:20 +0000 (19:19 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 5 Apr 2019 10:09:08 +0000 (11:09 +0100)
cpu_dev.c_vendor[] is a char[8] array which is printed using %s in two
locations.  This leads to subtle lack-of-NUL bugs when using an 8 character
vendor name.

Introduce x86_cpuid_vendor_to_str() to turn an x86_vendor into a printable
string, use it in the two locations that c_vendor is used, and drop c_vendor.

This drops the final user of X86_VENDOR_NUM, so drop that as well.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/cpu/amd.c
xen/arch/x86/cpu/centaur.c
xen/arch/x86/cpu/common.c
xen/arch/x86/cpu/cpu.h
xen/arch/x86/cpu/intel.c
xen/arch/x86/cpu/shanghai.c
xen/include/asm-x86/x86-vendors.h
xen/include/xen/lib/x86/cpuid.h
xen/lib/x86/cpuid.c

index d58952b222ba6b3de70f4b09efe471d427cb33cd..e19a5ead3e023e1a576d8d28153cafc3f1f31721 100644 (file)
@@ -793,7 +793,6 @@ static void init_amd(struct cpuinfo_x86 *c)
 }
 
 const struct cpu_dev amd_cpu_dev = {
-       .c_vendor       = "AMD",
        .c_early_init   = early_init_amd,
        .c_init         = init_amd,
 };
index 268f4d44d713f2edeeb235d475f5730b5f4d832b..34a5bfcaeef22aefae6ffcca63cf87c5b65c898c 100644 (file)
@@ -55,6 +55,5 @@ static void init_centaur(struct cpuinfo_x86 *c)
 }
 
 const struct cpu_dev centaur_cpu_dev = {
-       .c_vendor       = "Centaur",
        .c_init         = init_centaur,
 };
index c7b1f34239a5965d8bd8766fba91b4b4269c3073..fa8548ecdc9981008a5509e76757cf872ce9a8db 100644 (file)
@@ -102,7 +102,6 @@ static void default_init(struct cpuinfo_x86 * c)
 
 static const struct cpu_dev default_cpu = {
        .c_init = default_init,
-       .c_vendor = "Unknown",
 };
 static const struct cpu_dev *this_cpu = &default_cpu;
 
@@ -306,7 +305,7 @@ void __init early_cpu_init(void)
 
        printk(XENLOG_INFO
               "CPU Vendor: %s, Family %u (%#x), Model %u (%#x), Stepping %u (raw %08x)\n",
-              this_cpu->c_vendor, c->x86, c->x86,
+              x86_cpuid_vendor_to_str(c->x86_vendor), c->x86, c->x86,
               c->x86_model, c->x86_model, c->x86_mask, eax);
 
        eax = cpuid_eax(0x80000000);
@@ -661,12 +660,8 @@ void print_cpu_info(unsigned int cpu)
 
        printk("CPU%u: ", cpu);
 
-       if (c->x86_vendor < X86_VENDOR_NUM)
-               vendor = this_cpu->c_vendor;
-       else
-               vendor = c->x86_vendor_id;
-
-       if (vendor && strncmp(c->x86_model_id, vendor, strlen(vendor)))
+       vendor = x86_cpuid_vendor_to_str(c->x86_vendor);
+       if (strncmp(c->x86_model_id, vendor, strlen(vendor)))
                printk("%s ", vendor);
 
        if (!c->x86_model_id[0])
index 62e4b03c0cbe6bbb5f4d08bb4e444ec44630796a..54bd0d31740db12c5813a62f5a349fcbde6ad30e 100644 (file)
@@ -1,7 +1,5 @@
 /* attempt to consolidate cpu attributes */
 struct cpu_dev {
-       char    c_vendor[8];
-
        void            (*c_early_init)(struct cpuinfo_x86 *c);
        void            (*c_init)(struct cpuinfo_x86 * c);
 };
index fcb37083d84527d235899f0c7b8165ba93e992b5..0dd8f986078de4f8ff9d95f423da2f24fce8fa3f 100644 (file)
@@ -349,7 +349,6 @@ static void init_intel(struct cpuinfo_x86 *c)
 }
 
 const struct cpu_dev intel_cpu_dev = {
-       .c_vendor       = "Intel",
        .c_early_init   = early_init_intel,
        .c_init         = init_intel,
 };
index 189e13eaef6b0d01339eb029835d14d7bc1c1fe9..08a81f0f0c8e5709704da1bdad8d5a67a4ddb9c8 100644 (file)
@@ -16,6 +16,5 @@ static void init_shanghai(struct cpuinfo_x86 *c)
 }
 
 const struct cpu_dev shanghai_cpu_dev = {
-    .c_vendor   = "  Shang",
     .c_init     = init_shanghai,
 };
index 774ceac74dc47d304d077c48ec35404e2f2d0803..fca7396ad7758b9470af7f022d9e5c65b01e330d 100644 (file)
@@ -30,6 +30,4 @@
 #define X86_VENDOR_SHANGHAI_ECX 0x20206961U
 #define X86_VENDOR_SHANGHAI_EDX 0x68676e61U
 
-#define X86_VENDOR_NUM 5
-
 #endif /* __XEN_X86_VENDORS_H__ */
index c7a3bffeda1a35282aed5edf17c2533d94a6e0ca..022757f99579a804445c8db6db4a14d8a7f2b8a6 100644 (file)
@@ -71,6 +71,12 @@ static inline void cpuid_count_leaf(
  */
 unsigned int x86_cpuid_lookup_vendor(uint32_t ebx, uint32_t ecx, uint32_t edx);
 
+/**
+ * Given Xen's internal vendor ID, return a string suitable for printing.
+ * Returns "Unknown" for any unrecognised ID.
+ */
+const char *x86_cpuid_vendor_to_str(unsigned int vendor);
+
 #define CPUID_GUEST_NR_BASIC      (0xdu + 1)
 #define CPUID_GUEST_NR_CACHE      (5u + 1)
 #define CPUID_GUEST_NR_FEAT       (0u + 1)
index 311d19e471dd11fdb0607f9cdce87d3157430f8f..23619c79678a62cc18fdf49cea428b240a112c4d 100644 (file)
@@ -34,6 +34,18 @@ unsigned int x86_cpuid_lookup_vendor(uint32_t ebx, uint32_t ecx, uint32_t edx)
     return X86_VENDOR_UNKNOWN;
 }
 
+const char *x86_cpuid_vendor_to_str(unsigned int vendor)
+{
+    switch ( vendor )
+    {
+    case X86_VENDOR_INTEL:    return "Intel";
+    case X86_VENDOR_AMD:      return "AMD";
+    case X86_VENDOR_CENTAUR:  return "Centaur";
+    case X86_VENDOR_SHANGHAI: return "Shanghai";
+    default:                  return "Unknown";
+    }
+}
+
 /* Recalculate the content in a CPUID policy which is derived from raw data. */
 static void recalculate_synth(struct cpuid_policy *p)
 {