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

[PATCH v4 3/3] tools/xen-ucode: print information about currently loaded ucode


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Sergey Dyasli <sergey.dyasli@xxxxxxxxxx>
  • Date: Tue, 4 Apr 2023 17:06:55 +0100
  • Authentication-results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Sergey Dyasli <sergey.dyasli@xxxxxxxxxx>
  • Delivery-date: Tue, 04 Apr 2023 16:07:37 +0000
  • Ironport-data: A9a23:AUokrKgTGvkjyX7osJTilRLbX161VhAKZh0ujC45NGQN5FlHY01je htvWGCOPPuCajOhc912PI61/BgDupXTx9AxHFQ6+SkwQX4b9cadCdqndUqhZCn6wu8v7q5Ex 55HNoSfdpBcolv0/ErF3m3J9CEkvU2wbuOgTrWCYmYpHlUMpB4J0XpLg/Q+jpNjne+3CgaMv cKai8DEMRqu1iUc3lg8sspvkzsy+qWi0N8klgZmP6sT4AeCzyN94K83fsldEVOpGuG4IcbiL wrz5OnR1n/U+R4rFuSknt7TGqHdauePVeQmoiM+t5mK2nCulARrukoIHKN0hXNsoyeIh7hMJ OBl7vRcf+uL0prkw4zxWzEAe8130DYvFLXveRBTuuTLp6HKnueFL1yDwyjaMKVBktubD12i+ tQ0IgwPTAGvqtm73a2iGvI8vJwJfO3CadZ3VnFIlVk1DN4jSJHHBa7L+cVZzHE7gcUm8fT2P pRDL2A1NVKZPkMJYw1MYH49tL7Aan3XaDBCp1+E46Ym6nPXzSR60aT3McqTcduPLSlQth/A+ D2coz2lXXn2MvSA8TeO90vwltbItgKlWdNRN+P72eV11Qj7Kms7V0RNCArTTeOCol6zXZdTJ lIZ/gIqrLMu7wq7Q9/lRRq6rXWY+BkGVLJ4Eec39QWMwar8+BuCCy4PSTspQMMinN87Q3otz FDht9HmHzt0q5WOVGmQsLyTqFuaOzURLGIETT8JS00C+daLiJookhvFQ9JnEai0pt74Azf9x 3aNtidWulkIpZdVjePhpwmB2m/y4MGTFWbZ+zk7QEqJ5D97Rp+JSrel9EfCve0QFt6zHn2o6 S1sd9el0AweMX2cvHXTEL1TRO3ytqrt3C702gA2QcR4n9i50zv6JN0LvmkjTKt8GpxcEQIFd nM/ru+4CHV7GHKxJZF6bIuqYyjB5fixTI+1Phw4gzcnX3SQSONk1Hs0DaJo9zqx+HXAaIlmU XthTe6iDGwBFYNsxyesSuEW3NcDn35unT6PG8GhlE75gdJygUJ5rp9caDOzgh0RtvvY8G05D f4EXyd19/mveLKnOXSGmWLiBVsLMWI6FfjLliCjTcbaelAOMDh4W5fsLUYJJ9QNc1J9yr2Zo RlQmyZwlDLCuJEwAV7QNSo5MO+3DM4XQLBSFXVEAGtEEkMLOe6HhJrzvbNtJdHLKMQLISZIc sQ4
  • Ironport-hdrordr: A9a23:5XLDkKPTjTUy48BcTuqjsMiBIKoaSvp037BL7TEVdfUxSKb0qy nAppgmPHPP5wr5IUtQ4OxoW5PwI080l6QU3WB5B97LYOCBggWVxepZnOjfKlPbehEWwdQtsZ uII5IUNDQpNykAsS8h2njfLz/8+qjhzEl1v5an856yd3ARV51d
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Add an option to xen-ucode tool to print the currently loaded ucode
revision and also print it during usage info.  Print CPU signature and
platform flags as well.  The raw data comes from XENPF_get_cpu_version
and XENPF_get_ucode_revision platform ops.

Example output:
    Intel:
    CPU signature 06-55-04 (raw 0x00050654) pf 0x1 revision 0x02006e05

    AMD:
    CPU signature fam19h (raw 0x00a00f11) revision 0x0a0011ce

Signed-off-by: Sergey Dyasli <sergey.dyasli@xxxxxxxxxx>
---
v3 --> v4:
- changed the output to be 1-line long
- made xc_interface *xch global
- added error checking to xc calls
- added error for unsupported CPU vendor
- changed printf format to 0x%08x for raw signature and revision values
---
 tools/misc/xen-ucode.c | 83 ++++++++++++++++++++++++++++++++++++------
 1 file changed, 71 insertions(+), 12 deletions(-)

diff --git a/tools/misc/xen-ucode.c b/tools/misc/xen-ucode.c
index ad32face2b..bd0bfaaa00 100644
--- a/tools/misc/xen-ucode.c
+++ b/tools/misc/xen-ucode.c
@@ -12,22 +12,89 @@
 #include <fcntl.h>
 #include <xenctrl.h>
 
+static xc_interface *xch;
+
+static const char intel_id[] = "GenuineIntel";
+static const char   amd_id[] = "AuthenticAMD";
+
+static void show_curr_cpu(FILE *f)
+{
+    int ret;
+    struct xenpf_pcpu_version cpu_ver = { .xen_cpuid = 0 };
+    struct xenpf_ucode_revision ucode_rev = { .cpu = 0 };
+
+    ret = xc_get_cpu_version(xch, &cpu_ver);
+    if ( ret )
+    {
+        fprintf(f, "Failed to get CPU information. (err: %s)\n",
+                strerror(errno));
+        exit(1);
+    }
+
+    ret = xc_get_ucode_revision(xch, &ucode_rev);
+    if ( ret )
+    {
+        fprintf(f, "Failed to get microcode information. (err: %s)\n",
+                strerror(errno));
+        exit(1);
+    }
+
+    /*
+     * Print signature in a form that allows to quickly identify which ucode
+     * blob to load, e.g.:
+     *
+     *      Intel:   /lib/firmware/intel-ucode/06-55-04
+     *      AMD:     /lib/firmware/amd-ucode/microcode_amd_fam19h.bin
+     */
+    if ( memcmp(cpu_ver.vendor_id, intel_id,
+                sizeof(cpu_ver.vendor_id)) == 0 )
+    {
+        fprintf(f, "CPU signature %02x-%02x-%02x (raw 0x%08x) pf %#x revision 
0x%08x\n",
+                   cpu_ver.family, cpu_ver.model, cpu_ver.stepping,
+                   ucode_rev.signature, ucode_rev.pf, ucode_rev.revision);
+    }
+    else if ( memcmp(cpu_ver.vendor_id, amd_id,
+                     sizeof(cpu_ver.vendor_id)) == 0 )
+    {
+        fprintf(f, "CPU signature fam%xh (raw 0x%08x) revision 0x%08x\n",
+                   cpu_ver.family, ucode_rev.signature, ucode_rev.revision);
+    }
+    else
+    {
+        fprintf(f, "Unsupported CPU vendor: %s\n", cpu_ver.vendor_id);
+        exit(3);
+    }
+}
+
 int main(int argc, char *argv[])
 {
     int fd, ret;
     char *filename, *buf;
     size_t len;
     struct stat st;
-    xc_interface *xch;
+
+    xch = xc_interface_open(NULL, NULL, 0);
+    if ( xch == NULL )
+    {
+        fprintf(stderr, "Error opening xc interface. (err: %s)\n",
+                strerror(errno));
+        exit(1);
+    }
 
     if ( argc < 2 )
     {
-        fprintf(stderr,
-                "xen-ucode: Xen microcode updating tool\n"
-                "Usage: %s <microcode blob>\n", argv[0]);
+        fprintf(stderr, "xen-ucode: Xen microcode updating tool\n");
+        show_curr_cpu(stderr);
+        fprintf(stderr, "Usage: %s <microcode blob>\n", argv[0]);
         exit(2);
     }
 
+    if ( !strcmp(argv[1], "show-cpu-info") )
+    {
+        show_curr_cpu(stdout);
+        return 0;
+    }
+
     filename = argv[1];
     fd = open(filename, O_RDONLY);
     if ( fd < 0 )
@@ -52,14 +119,6 @@ int main(int argc, char *argv[])
         exit(1);
     }
 
-    xch = xc_interface_open(NULL, NULL, 0);
-    if ( xch == NULL )
-    {
-        fprintf(stderr, "Error opening xc interface. (err: %s)\n",
-                strerror(errno));
-        exit(1);
-    }
-
     ret = xc_microcode_update(xch, buf, len);
     if ( ret )
     {
-- 
2.17.1




 


Rackspace

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