x86/ucode/amd: Collect CPUID.1.EAX in collect_cpu_info()
authorAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 27 Mar 2020 13:20:12 +0000 (13:20 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 1 Apr 2020 13:00:12 +0000 (14:00 +0100)
... rather than collecting it repeatedly in microcode_fits().  This brings the
behaviour in line with the Intel side.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/cpu/microcode/amd.c
xen/include/asm-x86/microcode.h

index 575f87b487962887e52436781db5788fc55ebcb5..3b73af9d2954c7b7f8f1b736fa894e8ba16b4b65 100644 (file)
@@ -79,6 +79,7 @@ static int collect_cpu_info(struct cpu_signature *csig)
 {
     memset(csig, 0, sizeof(*csig));
 
+    csig->sig = cpuid_eax(1);
     rdmsrl(MSR_AMD_PATCHLEVEL, csig->rev);
 
     pr_debug("microcode: CPU%d collect_cpu_info: patch_id=%#x\n",
@@ -177,12 +178,9 @@ static enum microcode_match_result microcode_fits(
     const struct cpu_signature *sig = &per_cpu(cpu_sig, cpu);
     const struct microcode_header_amd *mc_header = mc_amd->mpb;
     const struct equiv_cpu_entry *equiv_cpu_table = mc_amd->equiv_cpu_table;
-    unsigned int current_cpu_id;
     unsigned int equiv_cpu_id;
 
-    current_cpu_id = cpuid_eax(0x00000001);
-
-    if ( !find_equiv_cpu_id(equiv_cpu_table, current_cpu_id, &equiv_cpu_id) )
+    if ( !find_equiv_cpu_id(equiv_cpu_table, sig->sig, &equiv_cpu_id) )
         return MIS_UCODE;
 
     if ( (mc_header->processor_rev_id) != equiv_cpu_id )
@@ -419,13 +417,10 @@ static struct microcode_patch *cpu_request_microcode(const void *buf,
     struct microcode_patch *patch = NULL;
     size_t offset = 0, saved_size = 0;
     int error = 0;
-    unsigned int current_cpu_id;
     unsigned int equiv_cpu_id;
     unsigned int cpu = smp_processor_id();
     const struct cpu_signature *sig = &per_cpu(cpu_sig, cpu);
 
-    current_cpu_id = cpuid_eax(0x00000001);
-
     if ( bufsize < 4 || *(const uint32_t *)buf != UCODE_MAGIC )
     {
         printk(KERN_ERR "microcode: Wrong microcode patch file magic\n");
@@ -455,7 +450,7 @@ static struct microcode_patch *cpu_request_microcode(const void *buf,
             break;
         }
 
-        if ( find_equiv_cpu_id(mc_amd->equiv_cpu_table, current_cpu_id,
+        if ( find_equiv_cpu_id(mc_amd->equiv_cpu_table, sig->sig,
                                &equiv_cpu_id) )
             break;
 
index 3a8e4e822136a0c14b988c6c179ebafb00e32296..cbbe28cb452690b00760f82dfd24dd1d82b5d3d6 100644 (file)
@@ -7,7 +7,7 @@
 #include <public/xen.h>
 
 struct cpu_signature {
-    /* CPU signature (CPUID.1.EAX).  Only written on Intel. */
+    /* CPU signature (CPUID.1.EAX). */
     unsigned int sig;
 
     /* Platform Flags.  Only applicable to Intel. */