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

[PATCH 4/5] x86/ucode: Cache results in microcode_scan_module()


  • To: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Mon, 27 Mar 2023 20:41:25 +0100
  • Authentication-results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Jan Beulich <JBeulich@xxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Sergey Dyasli <sergey.dyasli@xxxxxxxxxx>
  • Delivery-date: Mon, 27 Mar 2023 19:41:56 +0000
  • Ironport-data: A9a23:pgESI6A8heWN5RVW/1Pjw5YqxClBgxIJ4kV8jS/XYbTApD0ngTRRz WoeDz2Eb/yJZzD3LtlwPoy+oxtQucLWy4RmQQY4rX1jcSlH+JHPbTi7wuUcHAvJd5GeExg3h yk6QoOdRCzhZiaE/n9BCpC48T8nk/nOHuGmYAL9EngZbRd+Tys8gg5Ulec8g4p56fC0GArIs t7pyyHlEAbNNwVcbyRFu8pvlDs15K6p4GhC4QRkDRx2lAS2e0c9Xcp3yZ6ZdxMUcqEMdsamS uDKyq2O/2+x13/B3fv8z94X2mVTKlLjFVDmZkh+AsBOsTAbzsAG6Y4pNeJ0VKtio27hc+ada jl6ncfYpQ8BZsUgkQmGOvVSO3kW0aZuoNcrLZUj2CA6IoKvn3bEmp1T4E8K0YIwq/R2HF9L/ +EhFnMgdD3c2824/+u/Y7w57igjBJGD0II3v3hhyXfSDOo8QICFSKLPjTNa9G5u3IYUR6+YP pdHL2M1N3wsYDUWUrsTILs4kP2lmT/UdDpApUjOjaE2/3LS3Ep6172F3N/9I4TRHJwIwB/Ez o7A1073OUpZbMeU8iqI4339grbt3im8dJ1HQdVU8dY12QbOlwT/EiY+RVa95PW0lEO6c9ZeM FAPvDojq7Ao806mRcW7WAe3yFamlBMBX9tbE8Uh9RqAjKHT5m6xGWwsXjNHLts8u6cLqScCj wHT2YmzXHo27ePTECjGnluJkd+sEXkHLHI8YCUZdDVGzsPO/90cgC2WSv82RcZZkebJ9SHML yGi9XZh1utN0JRQj81X7nic3Wvy+8Ghohodo1yOAzn7tl4RiJuNPdTA1LTN0RpXwG91pHGlt WNMpcWR5ftm4XqlxH3UG7Vl8F1ECp+43Nzgbb1HRcNJG8yFoSLLQGypyGgWyL1VGsgFYyT1R 0TYpBlc4pReVFPzM/AmMt7oW591l/a4fTgAahwyRoAWCnSWXFHvwc2TTRTIgzCFfLYEyMnTx qt3ge7zVC1HWMyLPRK9RvsH0K9D+x3SMVj7HMihpzz+iOr2WZJgYetdWLd4RrxjvfzsTcS82 4o3CvZmPD0GCbSlOHWOod9KRb3IRFBiba3LRwVsXrbrCmJb9KsJUJc9HZtJl1RZoplo
  • Ironport-hdrordr: A9a23:GqQEYaMZId+AvMBcTgajsMiBIKoaSvp037Eqv3oBLyC9E/b5qy nKpp8mPHDP6Qr5NEtQ/OxoW5PwOE80l6QFmbX5VI3KNGaJhILBFvAY0WKI+UyFJ8SRzJ876Y 5QN4VFJZnXK3MSt6rHCQ+DeeoI8Z283Jrtr8H44FdCcTpDVoFHyENCJjvzKDwUeCB2QZU4EZ aH5tlKvVObFEg/ZNigG38AU/PiirTw5fDbXSI=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

When microcode_scan_module() is used, it's used twice.

The caching of the bootstrap_map() pointer in ucode_blob.data is buggy for
multiple reasons and is going to be removed.

Right now, the boot flow depends on the second pass over
bootstrap_map()/find_cpio_data() altering ucode_blob.data to use the directmap
alias of the CPIO module, where previously it caches the early boostrap
mapping.

If the scan is successful, it will be successful the second time too, but
there's no point repeating the work.  Cache the module index, offset and size
to short circuit things the second time around.

While rearranging this, reduce the scope of the internals of the loop,
changing the type of _blob_start to void and droping the dead stores into cd.

Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
CC: Jan Beulich <JBeulich@xxxxxxxx>
CC: Roger Pau Monné <roger.pau@xxxxxxxxxx>
CC: Wei Liu <wl@xxxxxxx>
CC: Sergey Dyasli <sergey.dyasli@xxxxxxxxxx>
---
 xen/arch/x86/cpu/microcode/core.c | 34 ++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)

diff --git a/xen/arch/x86/cpu/microcode/core.c 
b/xen/arch/x86/cpu/microcode/core.c
index 4d2a896fe78d..7d32bc13db6f 100644
--- a/xen/arch/x86/cpu/microcode/core.c
+++ b/xen/arch/x86/cpu/microcode/core.c
@@ -152,14 +152,30 @@ void __init microcode_scan_module(
     unsigned long *module_map,
     const multiboot_info_t *mbi)
 {
+    static __initdata struct { /* Cached details of a previous successful 
scan. */
+        unsigned long offset;  /* Offset from the start of the CPIO archive. */
+        unsigned long size;    /* Size of the CPIO file. */
+        unsigned int mod_idx;  /* Which multiboot module the CPIO archive is. 
*/
+    } scan;
+
     module_t *mod = (module_t *)__va(mbi->mods_addr);
-    uint64_t *_blob_start;
-    unsigned long _blob_size;
-    struct cpio_data cd;
     const char *p = NULL;
     int i;
 
     ucode_blob.size = 0;
+
+    if ( scan.mod_idx ) /* Previous scan was successful. */
+    {
+        void *map = bootstrap_map(&mod[scan.mod_idx]);
+
+        if ( !map )
+            return;
+
+        ucode_blob.size = scan.size;
+        ucode_blob.data = map + scan.offset;
+        return;
+    }
+
     if ( !ucode_scan )
         return;
 
@@ -175,6 +191,10 @@ void __init microcode_scan_module(
      */
     for ( i = 1 /* Ignore dom0 kernel */; i < mbi->mods_count; i++ )
     {
+        void *_blob_start;
+        unsigned long _blob_size;
+        struct cpio_data cd;
+
         if ( !test_bit(i, module_map) )
             continue;
 
@@ -186,15 +206,19 @@ void __init microcode_scan_module(
                    i, _blob_size);
             continue;
         }
-        cd.data = NULL;
-        cd.size = 0;
+
         cd = find_cpio_data(p, _blob_start, _blob_size);
         if ( cd.data )
         {
+            scan.mod_idx = i;
+            scan.offset  = cd.data - _blob_start;
+            scan.size    = cd.size;
+
             ucode_blob.size = cd.size;
             ucode_blob.data = cd.data;
             break;
         }
+
         bootstrap_map(NULL);
     }
 }
-- 
2.30.2




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.