From patchwork Tue Mar 21 11:47:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 13182653 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D3967C74A5B for ; Tue, 21 Mar 2023 11:48:10 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.512361.792353 (Exim 4.92) (envelope-from ) id 1peaT9-0001DW-HV; Tue, 21 Mar 2023 11:47:59 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 512361.792353; Tue, 21 Mar 2023 11:47:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1peaT9-0001DP-CT; Tue, 21 Mar 2023 11:47:59 +0000 Received: by outflank-mailman (input) for mailman id 512361; Tue, 21 Mar 2023 11:47:58 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1peaT8-0001D8-0x for xen-devel@lists.xenproject.org; Tue, 21 Mar 2023 11:47:58 +0000 Received: from esa2.hc3370-68.iphmx.com (esa2.hc3370-68.iphmx.com [216.71.145.153]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 367e2b73-c7de-11ed-87f5-c1b5be75604c; Tue, 21 Mar 2023 12:47:55 +0100 (CET) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 367e2b73-c7de-11ed-87f5-c1b5be75604c DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1679399275; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=U9Ac8kfawVwJyTiVqm0kbmJdZ36EQ83/TJ8nOn83CLs=; b=Drvn3K4fAOsjBqKHJD5V8VQPZIPWLGrQFjPTiQY1B5h2SWony8oBd3eD JLo6NFSYWMwzEnSWWn1U4qBsYMNC0tg6ZG9W5Gli6O66NbW/MumfxnhFl ug519Ko1rPQRq7nQjuI7I0yIR/xMoDH7NehUZtEWy98/qkNkHArqPmJPQ w=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 5.1 X-MesageID: 101602006 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED IronPort-Data: A9a23:j1AOMaJH058XRtNXFE+R5ZUlxSXFcZb7ZxGr2PjKsXjdYENS1TZRz TBMUGmEb/mKY2r2fNsjbY+1oUNQ65LVzdNiGwFlqX01Q3x08seUXt7xwmUcnc+xBpaaEB84t ZV2hv3odp1coqr0/0/1WlTZhSAgk/rOHvykU7Ss1hlZHWdMUD0mhQ9oh9k3i4tphcnRKw6Ws Jb5rta31GWNglaYCUpJrfPTwP9TlK6q4mhA5QZnPakjUGL2zBH5MrpOfcldEFOgKmVkNrbSb /rOyri/4lTY838FYj9yuu+mGqGiaue60Tmm0hK6aYD76vRxjnVaPpIAHOgdcS9qZwChxLid/ jnvWauYEm/FNoWU8AgUvoIx/ytWZcWq85efSZSzXFD6I+QrvBIAzt03ZHzaM7H09c5cGXth6 6M8Dwood0yJgs2W3L+6cshj05FLwMnDZOvzu1llxDDdS/0nXYrCU+PB4towMDUY354UW6yEP oxANGQpNU6bC/FMEg5/5JYWh+qyiXTuNTFJoUmRpII84nTJzRw327/oWDbQUoXSHJsNxB7A+ Aoq+Uz6AEAWK/LPxACo90iJhrTNpDnDaac7QejQGvlC3wTImz175ActfUu2p7y1h1CzX/pbK lcI4Ww+oK4q7kupQ9LhGRqirxasvBQRRt5RGO0S8xyWx+zf5APxLncAZi5MbpohrsBebT4lz FiShPvyGCdi9raSTBq19KqQrD60ETgYKykFfyBsZRAe/9DprYU3jxTOZtVuCqi4ipvyAz6Y/ tyRhHFg3fNJ15dNjvjluwmd2FpAu6QlUCYe/h/4QD2ByTlcfdKvYqOI9VXa1ddPedPxoka6g JQUpySPxLlQUsDWynHdGb5l8KKBvKjcbmCF6bJ7N9x4rmn2pSb+FWxFyGsmTHqFJProbtMAj KX7nQpKrKFeM3KxBUOcS9LgUp96pUQM+DmMaxw1UjatSsIrHON/1HsyDXN8Jki0+KTWrYkxO I2AbeGnBmsABKJswVKeHrlCgORwmXhgnjuDH/gXKihLN5LEPBaopUotagPSPojVE59oUC2Kq o0CZqNmOj1UUfHkYzm/zLP/2WsidCBhbbiv8pQ/XrfacmJb9JQJVqa5LUUJINc+wcy4V47go xmAZ6Ov4AOi2CadclnaNBiOqtrHBP5CkJ7yBgR0VX7A5pTpSd3HAHs3H3fvQYQayQ== IronPort-HdrOrdr: A9a23:LiKQ46hEUK1UdSstc2eIy4eMcHBQXrkji2hC6mlwRA09TyX4ra CTdZEgviMc5wx9ZJhNo7q90cq7IE80i6Qb3WB5B97LYOCMggeVxe9Zg7ff/w== X-IronPort-AV: E=Sophos;i="5.98,278,1673931600"; d="scan'208";a="101602006" From: Sergey Dyasli To: CC: Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , Anthony PERARD , Juergen Gross , George Dunlap , Julien Grall , Stefano Stabellini , Sergey Dyasli Subject: [PATCH v3 1/3] tools/xenctrl: add xc_get_cpu_version() Date: Tue, 21 Mar 2023 11:47:43 +0000 Message-ID: <20230321114745.11044-2-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230321114745.11044-1-sergey.dyasli@citrix.com> References: <20230321114745.11044-1-sergey.dyasli@citrix.com> MIME-Version: 1.0 As a wrapper for XENPF_get_cpu_version platform op. Signed-off-by: Sergey Dyasli --- tools/include/xenctrl.h | 1 + tools/libs/ctrl/xc_misc.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 23037874d3..8aa747dc2e 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1186,6 +1186,7 @@ int xc_physinfo(xc_interface *xch, xc_physinfo_t *info); int xc_cputopoinfo(xc_interface *xch, unsigned *max_cpus, xc_cputopo_t *cputopo); int xc_microcode_update(xc_interface *xch, const void *buf, size_t len); +int xc_get_cpu_version(xc_interface *xch, struct xenpf_pcpu_version *cpu_ver); int xc_numainfo(xc_interface *xch, unsigned *max_nodes, xc_meminfo_t *meminfo, uint32_t *distance); int xc_pcitopoinfo(xc_interface *xch, unsigned num_devs, diff --git a/tools/libs/ctrl/xc_misc.c b/tools/libs/ctrl/xc_misc.c index 265f15ec2d..f2f6e4348e 100644 --- a/tools/libs/ctrl/xc_misc.c +++ b/tools/libs/ctrl/xc_misc.c @@ -226,6 +226,26 @@ int xc_microcode_update(xc_interface *xch, const void *buf, size_t len) return ret; } +int xc_get_cpu_version(xc_interface *xch, struct xenpf_pcpu_version *cpu_ver) +{ + int ret; + DECLARE_PLATFORM_OP; + + if ( !xch || !cpu_ver ) + return -1; + + platform_op.cmd = XENPF_get_cpu_version; + platform_op.u.pcpu_version.xen_cpuid = cpu_ver->xen_cpuid; + + ret = do_platform_op(xch, &platform_op); + if ( ret != 0 ) + return ret; + + *cpu_ver = platform_op.u.pcpu_version; + + return 0; +} + int xc_cputopoinfo(xc_interface *xch, unsigned *max_cpus, xc_cputopo_t *cputopo) { From patchwork Tue Mar 21 11:47:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 13182654 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E2535C7618D for ; Tue, 21 Mar 2023 11:48:10 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.512363.792373 (Exim 4.92) (envelope-from ) id 1peaTB-0001hP-56; Tue, 21 Mar 2023 11:48:01 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 512363.792373; Tue, 21 Mar 2023 11:48:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1peaTB-0001hI-1P; Tue, 21 Mar 2023 11:48:01 +0000 Received: by outflank-mailman (input) for mailman id 512363; Tue, 21 Mar 2023 11:47:59 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1peaT8-0001D8-Ud for xen-devel@lists.xenproject.org; Tue, 21 Mar 2023 11:47:59 +0000 Received: from esa3.hc3370-68.iphmx.com (esa3.hc3370-68.iphmx.com [216.71.145.155]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 381d7b49-c7de-11ed-87f5-c1b5be75604c; Tue, 21 Mar 2023 12:47:57 +0100 (CET) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 381d7b49-c7de-11ed-87f5-c1b5be75604c DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1679399277; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=fGE0T9aXdCXHzzRWPZzgGMfJeXlC0Uh4tsC4r6B01fo=; b=Me3RD6DpJ8hqAfGt4HfYVG7VhQBuAxMG3lPN+TE2irto9wV0yy4ITVv4 XrhKXC3GfWY9EMGCfLNrjx6Tc3nLZ0TC7FPreBQUunYiJU/yX8Jy1/dyE AbW7qsCtoIoepkLLdI5ecjYJkLt3XS1bCaRaQxROZYJ7qvQVhu9xDs0sU 8=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 5.1 X-MesageID: 101693125 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED IronPort-Data: A9a23:wKH6oq4df3XJpcQbzXry6QxRtAzHchMFZxGqfqrLsTDasY5as4F+v jQZDGjTbq2LZmr3Kdp/bojioU0C65/WyNZhSQNsrSkxHi5G8cbLO4+Ufxz6V8+wwm8vb2o8t plDNYOQRCwQZiWBzvt4GuG59RGQ7YnRGvynTraCYnsrLeNdYH9JoQp5nOIkiZJfj9G8Agec0 fv/uMSaM1K+s9JOGjt8B5mr9VU+7JwehBtC5gZlPasR5QeH/5UoJMl3yZ+ZfiOQrrZ8RoZWd 86bpJml82XQ+QsaC9/Nut4XpWVTH9Y+lSDX4pZnc/DKbipq/0Te4Y5iXBYoUm9Fii3hojxE4 I4lWapc6+seFvakdOw1C3G0GszlVEFM0OevzXOX6aR/w6BaGpdFLjoH4EweZOUlFuhL7W5m8 PYRFxtKPh65nrys0J2pGs5B3u0CFZy+VG8fkikIITDxCP8nRdbIQrnQ5M8e1zA17ixMNa+AP YxDM2MpNUmeJUQVYT/7C7pn9AusrmLyaTJVuRSZtKMs52n7xw1tyrn9dtHSf7RmQO0Mxh/G9 zmfpTmR7hcyEIbG9mO88WCX1sDspi/RWJ5VFI2H36s/6LGU7jNKU0BHPbehmtG7hVS5QMl3M FEP92wlqq1a3E62StjwWTWorXjCuQQTM/JLCPEz4gyJzqvS4i6aC3ICQzoHb8Yp3Oc0TzE30 l6Cn/vyGCdi9raSTBq15rqS6D+/JyURBWsDfjMfCxsI5cH5p4M+hQ6JScxseIaqivXlFDe2x CqFxBXSnJ1K05RNjf/iuwma3XT1/MOhohMJChv/W2is0Sg+NICfftKy+XfJvdFtdK+4dwzU1 JQboPRy/NziHLnUynPcG7tQTOjyjxqWGGaC2AAyRvHN4xzooif+Jt4IvVmSMW8zaq45lSnVj Fg/UO+7zLtaJzOUYKB+eOpd4Ox6nPG7RbwJuh05B+eig6SdlyfdpkmCnWbKgwjQfLEEyMnTw 6uzf8e2Fmo9Aq961jewTOp1+eZ1mXFlnjyLG8ujn07PPV+iiJi9E+9tDbdzRrphsPPsTPrpH yZ3aJLRlkQ3vBzWaSjL648DRW03wYwALcmu8aR/L7fbSiI/QTFJNhMk6e54E2CTt/8OzbmgE 7DUchIw9WcTclWedFjRMCs/OO2HsFQWhStTABHA9G2AgxALCbtDJo9GH3frVdHLLNBe8MM= IronPort-HdrOrdr: A9a23:+ZASzK4Wu5SatQ3fgAPXwOrXdLJyesId70hD6qkRc20xTiX8ra rCoB1173PJYVoqN03I4OrwX5VoIkmsl6Kdg7NwAV7KZmCPhILPFu9fBODZsl7d8kPFl9K14p 0QF5SWWOeaMbGjt7eB3OBjKadZ/DBbytHPuQ4D9QYXcei1UdAc0+8XYjzra3FLeA== X-IronPort-AV: E=Sophos;i="5.98,278,1673931600"; d="scan'208";a="101693125" From: Sergey Dyasli To: CC: Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , Anthony PERARD , Juergen Gross , George Dunlap , Julien Grall , Stefano Stabellini , Sergey Dyasli Subject: [PATCH v3 2/3] x86/platform: introduce XENPF_get_ucode_version Date: Tue, 21 Mar 2023 11:47:44 +0000 Message-ID: <20230321114745.11044-3-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230321114745.11044-1-sergey.dyasli@citrix.com> References: <20230321114745.11044-1-sergey.dyasli@citrix.com> MIME-Version: 1.0 Currently it's impossible to get CPU's microcode revision after late loading without looking into Xen logs which is not always convenient. Add a new platform op in order to get the required data from Xen and provide a wrapper for libxenctrl. Signed-off-by: Sergey Dyasli --- tools/include/xenctrl.h | 2 ++ tools/libs/ctrl/xc_misc.c | 21 +++++++++++++++++ xen/arch/x86/platform_hypercall.c | 30 ++++++++++++++++++++++++ xen/arch/x86/x86_64/platform_hypercall.c | 4 ++++ xen/include/public/platform.h | 12 ++++++++++ xen/include/xlat.lst | 1 + 6 files changed, 70 insertions(+) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 8aa747dc2e..d3ef7a48a5 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1187,6 +1187,8 @@ int xc_cputopoinfo(xc_interface *xch, unsigned *max_cpus, xc_cputopo_t *cputopo); int xc_microcode_update(xc_interface *xch, const void *buf, size_t len); int xc_get_cpu_version(xc_interface *xch, struct xenpf_pcpu_version *cpu_ver); +int xc_get_ucode_version(xc_interface *xch, + struct xenpf_ucode_version *ucode_ver); int xc_numainfo(xc_interface *xch, unsigned *max_nodes, xc_meminfo_t *meminfo, uint32_t *distance); int xc_pcitopoinfo(xc_interface *xch, unsigned num_devs, diff --git a/tools/libs/ctrl/xc_misc.c b/tools/libs/ctrl/xc_misc.c index f2f6e4348e..b93477d189 100644 --- a/tools/libs/ctrl/xc_misc.c +++ b/tools/libs/ctrl/xc_misc.c @@ -246,6 +246,27 @@ int xc_get_cpu_version(xc_interface *xch, struct xenpf_pcpu_version *cpu_ver) return 0; } +int xc_get_ucode_version(xc_interface *xch, + struct xenpf_ucode_version *ucode_ver) +{ + int ret; + DECLARE_PLATFORM_OP; + + if ( !xch || !ucode_ver ) + return -1; + + platform_op.cmd = XENPF_get_ucode_version; + platform_op.u.ucode_version.xen_cpuid = ucode_ver->xen_cpuid; + + ret = do_platform_op(xch, &platform_op); + if ( ret != 0 ) + return ret; + + *ucode_ver = platform_op.u.ucode_version; + + return 0; +} + int xc_cputopoinfo(xc_interface *xch, unsigned *max_cpus, xc_cputopo_t *cputopo) { diff --git a/xen/arch/x86/platform_hypercall.c b/xen/arch/x86/platform_hypercall.c index a2d9526355..d0818fea47 100644 --- a/xen/arch/x86/platform_hypercall.c +++ b/xen/arch/x86/platform_hypercall.c @@ -640,6 +640,36 @@ ret_t do_platform_op( } break; + case XENPF_get_ucode_version: + { + struct xenpf_ucode_version *ver = &op->u.ucode_version; + + if ( !get_cpu_maps() ) + { + ret = -EBUSY; + break; + } + + if ( (ver->xen_cpuid >= nr_cpu_ids) || !cpu_online(ver->xen_cpuid) ) + { + ret = -ENOENT; + } + else + { + const struct cpu_signature *sig = &per_cpu(cpu_sig, ver->xen_cpuid); + + ver->cpu_signature = sig->sig; + ver->pf = sig->pf; + ver->ucode_revision = sig->rev; + } + + put_cpu_maps(); + + if ( __copy_field_to_guest(u_xenpf_op, op, u.ucode_version) ) + ret = -EFAULT; + } + break; + case XENPF_cpu_online: { int cpu = op->u.cpu_ol.cpuid; diff --git a/xen/arch/x86/x86_64/platform_hypercall.c b/xen/arch/x86/x86_64/platform_hypercall.c index 5bf6b958d2..b876fd0c4a 100644 --- a/xen/arch/x86/x86_64/platform_hypercall.c +++ b/xen/arch/x86/x86_64/platform_hypercall.c @@ -28,6 +28,10 @@ CHECK_pf_pcpuinfo; CHECK_pf_pcpu_version; #undef xen_pf_pcpu_version +#define xen_pf_ucode_version xenpf_ucode_version +CHECK_pf_ucode_version; +#undef xen_pf_pucode_version + #define xen_pf_enter_acpi_sleep xenpf_enter_acpi_sleep CHECK_pf_enter_acpi_sleep; #undef xen_pf_enter_acpi_sleep diff --git a/xen/include/public/platform.h b/xen/include/public/platform.h index 60caa5ce7e..232df79d5f 100644 --- a/xen/include/public/platform.h +++ b/xen/include/public/platform.h @@ -614,6 +614,17 @@ DEFINE_XEN_GUEST_HANDLE(xenpf_symdata_t); typedef struct dom0_vga_console_info xenpf_dom0_console_t; DEFINE_XEN_GUEST_HANDLE(xenpf_dom0_console_t); +#define XENPF_get_ucode_version 65 +struct xenpf_ucode_version { + uint32_t xen_cpuid; /* IN: CPU number to get the revision from. */ + uint32_t cpu_signature; /* OUT: CPU signature (CPUID.1.EAX). */ + uint32_t pf; /* OUT: Processor Flags. */ + /* Only applicable to Intel. */ + uint32_t ucode_revision; /* OUT: Microcode Revision. */ +}; +typedef struct xenpf_ucode_version xenpf_ucode_version_t; +DEFINE_XEN_GUEST_HANDLE(xenpf_ucode_version_t); + /* * ` enum neg_errnoval * ` HYPERVISOR_platform_op(const struct xen_platform_op*); @@ -645,6 +656,7 @@ struct xen_platform_op { xenpf_resource_op_t resource_op; xenpf_symdata_t symdata; xenpf_dom0_console_t dom0_console; + xenpf_ucode_version_t ucode_version; uint8_t pad[128]; } u; }; diff --git a/xen/include/xlat.lst b/xen/include/xlat.lst index d601a8a984..164f700eb6 100644 --- a/xen/include/xlat.lst +++ b/xen/include/xlat.lst @@ -157,6 +157,7 @@ ? xenpf_pcpuinfo platform.h ? xenpf_pcpu_version platform.h ? xenpf_resource_entry platform.h +? xenpf_ucode_version platform.h ? pmu_data pmu.h ? pmu_params pmu.h ! sched_poll sched.h From patchwork Tue Mar 21 11:47:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 13182655 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E6ECEC761AF for ; Tue, 21 Mar 2023 11:48:10 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.512364.792383 (Exim 4.92) (envelope-from ) id 1peaTC-0001wx-Eo; Tue, 21 Mar 2023 11:48:02 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 512364.792383; Tue, 21 Mar 2023 11:48:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1peaTC-0001wq-9c; Tue, 21 Mar 2023 11:48:02 +0000 Received: by outflank-mailman (input) for mailman id 512364; Tue, 21 Mar 2023 11:48:00 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1peaTA-0001D8-7A for xen-devel@lists.xenproject.org; Tue, 21 Mar 2023 11:48:00 +0000 Received: from esa3.hc3370-68.iphmx.com (esa3.hc3370-68.iphmx.com [216.71.145.155]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 3a1cc7c3-c7de-11ed-87f5-c1b5be75604c; Tue, 21 Mar 2023 12:47:59 +0100 (CET) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 3a1cc7c3-c7de-11ed-87f5-c1b5be75604c DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1679399279; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=yPgkIRATgOC2FbBBzbnMPFmEbRwaB2aFJyQAh88EYlA=; b=AdhU3IvIKBPjkN4jzRJ4ZW4AaVYe816RnLOvqD/JpGVsg0v541heBy7G Repi88XW0IE3Y5ts4Gx1JyAixgOyuY299OuV9Zca4G1qWM+4YuCffD92g 71PWjt63LWRWZ0gxuVpq5NStMt4Py6C7LlW4q1QAg6CPAfZgEKDeoYmkl k=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 5.1 X-MesageID: 101693127 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED IronPort-Data: A9a23:5LsfWaxu2AIDQ8YbeFN6t+cDxirEfRIJ4+MujC+fZmUNrF6WrkVRn WQfDG3QO/iJMGf8LdEkOonl9RgEv8LRzYI1HlY9qyAxQypGp/SeCIXCJC8cHc8wwu7rFxs7s ppEOrEsCOhuExcwcz/0auCJQUFUjP3OHfykTrafYEidfCc8IA85kxVvhuUltYBhhNm9Emult Mj75sbSIzdJ4RYtWo4vw//F+UMHUMja4mtC5QRlP6kT5TcyqlFOZH4hDfDpR5fHatE88t6SH 47r0Ly/92XFyBYhYvvNfmHTKxBirhb6ZGBiu1IOM0SQqkEqSh8ai87XAME0e0ZP4whlqvgqo Dl7WT5cfi9yVkHEsLx1vxC1iEiSN4UekFPMCSDXXcB+UyQq2pYjqhljJBheAGEWxgp4KXBzz PgqJA8yVRmOo/CV+JGeV/lhict2eaEHPKtH0p1h5TTQDPJgSpHfWaTao9Rf2V/chOgXQ6yYP ZBAL2MyMlKZOUYn1lQ/UfrSmM+zi2PwfiwepEOcvq42y2PS0BZwwP7mN9+9ltmiHJ0MwBfD/ ziZl4j/Ki5AMYOT5X2/zk2xvveMrXyjCKEjSLLto5aGh3XMnzdOWXX6T2CTo/ajjVWlc8lCM EFS8S0rxYAw6UiqQ9/VTxC+5nmesXY0QMFMGuc37AWMzKv84AuDAGUACDlbZ7QOtsU7WDgr3 V+hhM7yCHpkt7j9YWKQ8PKYoC2/PQARLHQefmkUQA0d+d7hrYovyBXVQb5LD6qdntDzXzbqz Fi3QDMW3utJy5RRjuPioA6B2mj3znTUcuIrzhTqZ2aX4jxGX4eoQ56L0Xv+8OZNI4nMGzFto 0M4d9iiAPEmVM/SxXfTHbVUR9lF9N7ebmSC3AcH840Jsm30piX9Jd04DCRWfh8BDyoSRdP+j KY/Uyt17YQbAnalZLQfj2mZW5VzlviI+TgIu5npgjtyjntZLlXvENlGPxL44owUuBFEfVsDE Zmaa92wKn0RFL5qyjG7L89Ej+B6nXthnT2IHcChp/hC7VZ4TCTNIYrpzXPUNrxphE97nOkl2 4kGbJbbo/mueOb/fjPW4eYuELz+FlBiXcqeg5UOLoare1M2cFzN/teMmNvNjaQ+xP8L/goJl 1ngMnJlJK3X3CCacl/RNiA9AF4tNL4mxU8G0eUXFQ7A8xAejUyHts/zq7NfkWEbydFe IronPort-HdrOrdr: A9a23:mdADxqxh7kdHM7ognWX1KrPwDr1zdoMgy1knxilNoH1uA6mlfq WV9pkmPHDP5Ar5NEtOpTn4AtjmfZq+z+8W3WByB9eftWDd0QOVxedZg7cKqAeQeBEWmNQ96U 5WSdkbNDShNzNHZB7BkXOF+gwbsaG6GX2T9IHjJqtWPHpXgn9bnnpE4mnyKDwOeDV7 X-IronPort-AV: E=Sophos;i="5.98,278,1673931600"; d="scan'208";a="101693127" From: Sergey Dyasli To: CC: Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , Anthony PERARD , Juergen Gross , George Dunlap , Julien Grall , Stefano Stabellini , Sergey Dyasli Subject: [PATCH v3 3/3] tools/xen-ucode: print information about currently loaded ucode Date: Tue, 21 Mar 2023 11:47:45 +0000 Message-ID: <20230321114745.11044-4-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230321114745.11044-1-sergey.dyasli@citrix.com> References: <20230321114745.11044-1-sergey.dyasli@citrix.com> MIME-Version: 1.0 Add an option to xen-ucode tool to print the currently loaded ucode version and also print it during usage info. Print CPU signature and processor flags as well. The raw data comes from XENPF_get_cpu_version and XENPF_get_ucode_version platform ops. Example output: Intel: Current CPU signature is: 06-55-04 (raw 0x50654) Current CPU microcode revision is: 0x2006e05 Current CPU processor flags are: 0x1 AMD: Current CPU signature is: fam19h (raw 0xa00f11) Current CPU microcode revision is: 0xa0011a8 Signed-off-by: Sergey Dyasli --- tools/misc/xen-ucode.c | 66 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tools/misc/xen-ucode.c b/tools/misc/xen-ucode.c index ad32face2b..b9037ce6a1 100644 --- a/tools/misc/xen-ucode.c +++ b/tools/misc/xen-ucode.c @@ -12,6 +12,65 @@ #include #include +static const char intel_id[] = "GenuineIntel"; +static const char amd_id[] = "AuthenticAMD"; + +static void show_curr_cpu(FILE *f) +{ + int ret; + xc_interface *xch; + struct xenpf_pcpu_version cpu_ver = { .xen_cpuid = 0 }; + struct xenpf_ucode_version ucode_ver = { .xen_cpuid = 0 }; + bool intel = false, amd = false; + + xch = xc_interface_open(0, 0, 0); + if ( xch == NULL ) + return; + + ret = xc_get_cpu_version(xch, &cpu_ver); + if ( ret ) + return; + + ret = xc_get_ucode_version(xch, &ucode_ver); + if ( ret ) + return; + + if ( memcmp(cpu_ver.vendor_id, intel_id, + sizeof(cpu_ver.vendor_id)) == 0 ) + intel = true; + else if ( memcmp(cpu_ver.vendor_id, amd_id, + sizeof(cpu_ver.vendor_id)) == 0 ) + amd = true; + + /* + * 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 ( intel ) + { + fprintf(f, "Current CPU signature is: %02x-%02x-%02x (raw %#x)\n", + cpu_ver.family, cpu_ver.model, cpu_ver.stepping, + ucode_ver.cpu_signature); + } + else if ( amd ) + { + fprintf(f, "Current CPU signature is: fam%xh (raw %#x)\n", + cpu_ver.family, ucode_ver.cpu_signature); + } + + if ( intel || amd ) + fprintf(f, "Current CPU microcode revision is: %#x\n", + ucode_ver.ucode_revision); + + if ( intel ) + fprintf(f, "Current CPU processor flags are: %#x\n", ucode_ver.pf); + + xc_interface_close(xch); +} + int main(int argc, char *argv[]) { int fd, ret; @@ -25,9 +84,16 @@ int main(int argc, char *argv[]) fprintf(stderr, "xen-ucode: Xen microcode updating tool\n" "Usage: %s \n", argv[0]); + show_curr_cpu(stderr); 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 )