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

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


  • To: Sergey Dyasli <sergey.dyasli@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 5 Apr 2023 11:11:32 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=rsIizMNRMggsxTCY+Sd25aj3DYEvJ4MtxDRw2VgDX44=; b=VG3p5wPCbAui+vxCWYV2gHzfY16jnXOXp0aQPYDtm3xrFvg+YzebkPjfCwrIWTEweq8mtBiLJTZWIqVGUfhDJXSYnBFJm+0Pz3+gMm05ahpPQp5qWQhxiezh0+6I8Ge5bue+AwbdkSo2/1Zp7wCnC4cHOXRJs7MQHZt5bDznk1psb6QmxlSbEQag0zcXmQz0xUc9MgDvdhvBeS1aZ1D3trwGwdCO4n9qTxoj3QCIWrCef+VYT9LmG5pokCIno+pWU1N55WL5Cd4GI5jlP5s2r+5CHZAkcA59Nd1XPORdUV4ZTmy1NCX4+7nxNsjIGC5Tx/cQExjj9sc3dJAfUsAbOQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Dqqp3kNObjQSdp/LiiaRn7qG//2OqMJZx0AwmnFpHvpT9mJIXN+PSlIOjv/vUDw8xd5hbC4Mkgr6yp8XDvY2/aICNqhqs9eIYVpDElE7LElddvYvM54icm5fXg59gXEKcPv7Mes/IZZB2TfzF7EbyTBVC2rDxSWTVp3b+PxprFGbd3P01IBLH81026WjXx6kHY8GEeNFXOEFTp102acI2Bp4UPVDIOwzAI2OxQhn0L4s9naIK1cNhMHGmadWp1AxQOui6y7bJn03Z5mNJwrA9uYUHXDuI+/ZuXr6yXvjH1b1hDJdonKfIERZ1buIhAftdDAFLGThILJEs4lSW56OUw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: 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>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Wed, 05 Apr 2023 09:11:50 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 04.04.2023 18:06, Sergey Dyasli wrote:
> 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

Wouldn't it make sense to also report the model number here, even if
ucode blob file names (currently) don't include it?

While for the revision always printing 8 digits is definitely helpful, I
wonder whether the two top nibbles of the raw value wouldn't better be
omitted. (I understand Andrew did ask for this, but it's unclear to me
why he extended this request to the raw fields.)

> --- 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 };

As mentioned before - the current state of the system may be
inconsistent, so I question the entire lack of a way to know of
this by using this tool (even if via a specific command line
option, defaulting to CPU0-only).

> +    ret = xc_get_cpu_version(xch, &cpu_ver);
> +    if ( ret )
> +    {
> +        fprintf(f, "Failed to get CPU information. (err: %s)\n",
> +                strerror(errno));
> +        exit(1);

Errors want to go to stderr, I would say (just like is already the case
in main()).

> +    }
> +
> +    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);

Nit: Indentation (also below). I think you mean

        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);

I recall you had it this way before, but I don't see why this information
needs to be part of argument error handling. Furthermore, considering the
possibility of hitting an error path in show_curr_cpu(), I think ...

> +        fprintf(stderr, "Usage: %s <microcode blob>\n", argv[0]);

... this would need printing first, and perhaps ...

>          exit(2);

... the exit code also shouldn't be anything other than 2 in that event.

Jan



 


Rackspace

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