From patchwork Mon Apr 17 13:53:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 13214046 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 5F7EFC77B76 for ; Mon, 17 Apr 2023 13:54:04 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.522143.811341 (Exim 4.92) (envelope-from ) id 1poPIm-0003Vz-SF; Mon, 17 Apr 2023 13:53:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 522143.811341; Mon, 17 Apr 2023 13:53:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1poPIm-0003Vs-PE; Mon, 17 Apr 2023 13:53:52 +0000 Received: by outflank-mailman (input) for mailman id 522143; Mon, 17 Apr 2023 13:53:52 +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 1poPIm-0003Vm-Aq for xen-devel@lists.xenproject.org; Mon, 17 Apr 2023 13:53:52 +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 47b98e0f-dd27-11ed-b21e-6b7b168915f2; Mon, 17 Apr 2023 15:53:51 +0200 (CEST) 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: 47b98e0f-dd27-11ed-b21e-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1681739630; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=UOlxbCFg/XDa6iTXG/9aZ11mIf7hbb1IslY0i63jutw=; b=KfsxBJSV42msJk3pB3dLOX4Qn3G5OqLIBAtZq0GiVJHZ9CJSUbNBrp+R rWRO649wiZcKNLO9yUVoRENu/jRqqF1WUwAq9hz0mK641mSQJVR7RfVrS HGdParPeJvT106jOkE1e2P6xOB8wT6XTf+WOIzzenYOt/o/i6pdNhv2E2 I=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 105714898 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED IronPort-Data: A9a23:rII7j6pNHUHZobOXw4SVeUorQnVeBmIvZRIvgKrLsJaIsI4StFCzt garIBmAPPiOZWfxeYsnYd6+px4OvJHdz9RkQAdqpS82Fn9HpZuZCYyVIHmrMnLJJKUvbq7FA +Y2MYCccZ9uHhcwgj/3b9ANeFEljfngqoLUUbKCYWYpA1c/Ek/NsDo788YhmIlknNOlNA2Ev NL2sqX3NUSsnjV5KQr40YrawP9UlKm06WJwUmAWP6gR5weCziZNVfrzGInqR5fGatgMdgKFb 76rIIGRpgvx4xorA9W5pbf3GmVirmn6ZFXmZtJ+AsBOszAazsAA+v9T2Mk0MC+7vw6hjdFpo OihgLTrIesf0g8gr8xGO/VQO3kW0aSrY9YrK1Dn2SCY5xWun3cBX5yCpaz5VGEV0r8fPI1Ay RAXADstYiqpo86H+puQENlnjN0fcZnPIpxK7xmMzRmBZRonaZXKQqGM7t5ExjYgwMtJGJ4yZ eJAN2ApNk6ZJUQSZBFOUslWcOSA3xETdxVDpUiaqLtx73na1whw+LPsLMDUapqBQsA9ckOw/ zqboD2lUkBKXDCZ4Su1012FmtLMpgTQSY4sCYa9q99UvnTGkwT/DzVJDADm8JFVkHWWS99Zb kAZ5Ccqhawz71CwCMnwWQWip3yJtQJaXMBfe8U44gyQzqvf4y6CG3MJCDVGbbQOq8seVTEsk FiTkLvBBzN1t6aOYWmA7brSpjS3UQAXMGsDaCksXQYDpd75r+kblQnTR9xuFKq0iNzdGjzqx T2O6i8kiN0uYdUjjvvhuwqd2nT1+8aPF1RujunKYo67xghZaLSPQ6CZ03Hwt8ZLJp+lEwmlo mdRzqBy89sy4YGxeD2lGbtdRe3ytqvUbFUwknY0QcB/qm3FF2qLONkJvWogfBoB3tMsI2eBX aPFhe9GCHa/1lOOZLQ/XY++At9CIUPIRYW8DaC8gjajj/FMmO67EMJGPxT4M5jFyhRErE3GE c7znTyQJXgbE7976zG9Wv0Q17QmrghnmzOKG8+jl0n6juLCDJJwdVviGALXBt3VEYve+FmFm zqhH5DiJ+pjvB3WPXCMrN97waEiJnknH5Hmw/Fqmhq4ClM+QgkJUqaBqY7NjqQ5x8y5YM+Up CDiMqKZoXKj7UD6xfKiMCg7Muy0BcYh9BrW/0UEZD6V5pTqWq73hI93Snf9VeBPGDBLpRKsc 8Q4Rg== IronPort-HdrOrdr: A9a23:v9ZHuqgKl24YdpJcsspT+vtzSnBQXssji2hC6mlwRA09TyX4ra 2TdZEgvnXJYVkqKRIdcK+7Scu9qB/nm6KdgrN8AV7BZmnbUQKTRelfBODZrAEIdReeygdV79 YET5RD X-Talos-CUID: 9a23:S61bc2BTFpyKd836EyJH+HQ+PuwUSFT2lkfbKVaEVDZNVqLAHA== X-Talos-MUID: 9a23:ZJs+1A7/fOp8FgmfbKcx3/lcxox504WBIVwwkq4hkNiICzFLPmq8sgqeF9o= X-IronPort-AV: E=Sophos;i="5.99,204,1677560400"; d="scan'208";a="105714898" 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 v5 1/3] tools/xenctrl: add xc_get_cpu_version() Date: Mon, 17 Apr 2023 14:53:33 +0100 Message-ID: <20230417135335.17176-2-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230417135335.17176-1-sergey.dyasli@citrix.com> References: <20230417135335.17176-1-sergey.dyasli@citrix.com> MIME-Version: 1.0 As a wrapper for XENPF_get_cpu_version platform op. Signed-off-by: Sergey Dyasli Reviewed-by: Andrew Cooper --- v4 --> v5: - Added Reviewed-by v3 --> v4: - Replaced DECLARE_PLATFORM_OP - Removed NULL checks --- tools/include/xenctrl.h | 1 + tools/libs/ctrl/xc_misc.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 05967ecc92..34b3b25289 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..90d50faa4f 100644 --- a/tools/libs/ctrl/xc_misc.c +++ b/tools/libs/ctrl/xc_misc.c @@ -226,6 +226,23 @@ 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; + struct xen_platform_op op = { + .cmd = XENPF_get_cpu_version, + .u.pcpu_version.xen_cpuid = cpu_ver->xen_cpuid, + }; + + ret = do_platform_op(xch, &op); + if ( ret != 0 ) + return ret; + + *cpu_ver = op.u.pcpu_version; + + return 0; +} + int xc_cputopoinfo(xc_interface *xch, unsigned *max_cpus, xc_cputopo_t *cputopo) { From patchwork Mon Apr 17 13:53:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 13214049 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 393ACC77B76 for ; Mon, 17 Apr 2023 13:54:12 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.522147.811371 (Exim 4.92) (envelope-from ) id 1poPJ1-0004XO-N3; Mon, 17 Apr 2023 13:54:07 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 522147.811371; Mon, 17 Apr 2023 13:54:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1poPJ1-0004Wn-Jo; Mon, 17 Apr 2023 13:54:07 +0000 Received: by outflank-mailman (input) for mailman id 522147; Mon, 17 Apr 2023 13:54:06 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1poPJ0-00047e-FX for xen-devel@lists.xenproject.org; Mon, 17 Apr 2023 13:54:06 +0000 Received: from esa1.hc3370-68.iphmx.com (esa1.hc3370-68.iphmx.com [216.71.145.142]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 507e64cb-dd27-11ed-8611-37d641c3527e; Mon, 17 Apr 2023 15:54:04 +0200 (CEST) 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: 507e64cb-dd27-11ed-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1681739644; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=TNVm1fLgaF4ksJwYK+L9Xd3vsJAQXLNOU+yZsnmqhF8=; b=TStnw5k8DyPG5+EoF3ebiAgB6qLAMOTYUo2jtcEVWclaWM9x8hIeJKlz EW5jSmZ20YqvD/gZqhPfQ16EXU0E1l8+i+AM62egBE3ixPvm903By3+Zw j+7jkAteZPgKmgDBKnPH02DlydqmK7Jkx78OFkkTfmDs6m96a7EY3kE4U E=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 106220668 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED IronPort-Data: A9a23:FCIWI6PYGGENOVPvrR2Sl8FynXyQoLVcMsEvi/4bfWQNrUpxgjNUz GQeWmmCM6veNDD1coskYN6/8hgPvZbUyYRlSAto+SlhQUwRpJueD7x1DKtS0wC6dZSfER09v 63yTvGacajYm1eF/k/F3oDJ9CU6jufQAOKnUoYoAwgpLSd8UiAtlBl/rOAwh49skLCRDhiE/ Nj/uKUzAnf8s9JPGj9SuvPrRC9H5qyo42tE5wNmPJingXeF/5UrJMNHTU2OByOQrrl8RoaSW +vFxbelyWLVlz9F5gSNy+uTnuUiG9Y+DCDW4pZkc/HKbitq/0Te5p0TJvsEAXq7vh3S9zxHJ HehgrTrIeshFvWkdO3wyHC0GQkmVUFN0OevzXRSLaV/ZqAJGpfh66wGMa04AWEX0r1wOEtvz N0qES5XSD2qhOmM37GET9A506zPLOGzVG8eknRpzDWfBvc6W5HTBa7N4Le03h9p2JoIR6yHI ZNEN3w2Nk+ojx5nYz/7DLolkf2ni2i5fyxRs1aUjaE2/3LS3Ep6172F3N/9I4TUH58NwBjIz o7A11b4GzQ2MM618wiI8kKwod72ty6hQatHQdVU8dY12QbOlwT/EiY+RVa95PW0lEO6c9ZeM FAPvDojq7Ao806mRcW7WAe3yFaGtBMBX9tbE8Uh9RqAjKHT5m6xGWwsXjNHLts8u6ceRzMw0 USSt8j0HjEpu7qQIVqf67OVoDWaKSUTa2gYakcsVhAZ6tPupIUyiBPnTdt5FqOxyNrvFlnNL yui9XZkwe9J1IhSivv9pAqc696xmnTXZlUy3y/2Z0OX1x0jQqOMZIeS9lvk6M8Vee51UWK9U Gg4d9m2tb5eVM3WxXHcHI3hD5nyua/bbWS0bUpHWsB4qm/zoyPLkZV4umkWGat/DioTldYFi mf3sBgZ2pJcNWDCgURfM9PoUJRCIUQN+L3YuhHogjlmOMIZmPevpn0GWKJp9zmFfLIQua8+I 4yHVs2nEGwXD69qpBLvGbdEj+Bznn1jmjuPLXwe8/hA+ePHDEN5tJ9faAfeBgzHxPjsTPrpH yZ3aJLRlkQ3vBzWaSjL648DRW03wYwALcmu8aR/L7fTSjeK7Ul9U5c9N5t9Id0690mU/8+Ul kyAtrhwkgKn3yKccVXUMxiOqtrHBP5CkJ7yBgR0VX7A5pTpSdbHAHs3H3fvQYQayQ== IronPort-HdrOrdr: A9a23:vtywhq4Rd9P0TF1OxwPXwMjXdLJyesId70hD6qhwISY7TiX4rb HJoB11737JYVoqNU3I3OrwWpVoIkmskqKdg7NwAV7KZmCP0wGVxcNZnO7fKlXbaknDH4Vmu5 uIHZITNDSJNykYsfrH X-Talos-CUID: 9a23:uBjjVGHGGAwWRGTxqmI883c+O/kEQETDllH9CkyzM3lqd7isHAo= X-Talos-MUID: 9a23:vnI9FAystrKaxT5FqAv2ErW2aOKaqJavEWUhlYcsgfuJNRxsHAakpjntW6Zyfw== X-IronPort-AV: E=Sophos;i="5.99,204,1677560400"; d="scan'208";a="106220668" 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 v5 2/3] x86/platform: introduce XENPF_get_ucode_revision Date: Mon, 17 Apr 2023 14:53:34 +0100 Message-ID: <20230417135335.17176-3-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230417135335.17176-1-sergey.dyasli@citrix.com> References: <20230417135335.17176-1-sergey.dyasli@citrix.com> MIME-Version: 1.0 Currently it's impossible to get CPU's microcode revision from Xen 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 Reviewed-by: Jan Beulich --- v4 --> v5: - Added Reviewed-by v3 --> v4: - clarified the commit message - Renamed "ucode version" to "ucode revision" - Removed DECLARE_PLATFORM_OP and NULL checks - Added a TODO comment about parked CPUs - Renamed struct xenpf_ucode_revision fields --- tools/include/xenctrl.h | 2 ++ tools/libs/ctrl/xc_misc.c | 18 +++++++++++++++ xen/arch/x86/platform_hypercall.c | 29 ++++++++++++++++++++++++ xen/arch/x86/x86_64/platform_hypercall.c | 4 ++++ xen/include/public/platform.h | 11 +++++++++ xen/include/xlat.lst | 1 + 6 files changed, 65 insertions(+) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 34b3b25289..1149f805ba 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_revision(xc_interface *xch, + struct xenpf_ucode_revision *ucode_rev); 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 90d50faa4f..4159294b2e 100644 --- a/tools/libs/ctrl/xc_misc.c +++ b/tools/libs/ctrl/xc_misc.c @@ -243,6 +243,24 @@ int xc_get_cpu_version(xc_interface *xch, struct xenpf_pcpu_version *cpu_ver) return 0; } +int xc_get_ucode_revision(xc_interface *xch, + struct xenpf_ucode_revision *ucode_rev) +{ + int ret; + struct xen_platform_op op = { + .cmd = XENPF_get_ucode_revision, + .u.ucode_revision.cpu = ucode_rev->cpu, + }; + + ret = do_platform_op(xch, &op); + if ( ret != 0 ) + return ret; + + *ucode_rev = op.u.ucode_revision; + + 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..9ff2da8fc3 100644 --- a/xen/arch/x86/platform_hypercall.c +++ b/xen/arch/x86/platform_hypercall.c @@ -640,6 +640,35 @@ ret_t do_platform_op( } break; + case XENPF_get_ucode_revision: + { + struct xenpf_ucode_revision *rev = &op->u.ucode_revision; + + if ( !get_cpu_maps() ) + { + ret = -EBUSY; + break; + } + + /* TODO: make it possible to know ucode revisions for parked CPUs */ + if ( (rev->cpu >= nr_cpu_ids) || !cpu_online(rev->cpu) ) + ret = -ENOENT; + else + { + const struct cpu_signature *sig = &per_cpu(cpu_sig, rev->cpu); + + rev->signature = sig->sig; + rev->pf = sig->pf; + rev->revision = sig->rev; + } + + put_cpu_maps(); + + if ( __copy_field_to_guest(u_xenpf_op, op, u.ucode_revision) ) + 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..99440f4076 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_revision xenpf_ucode_revision +CHECK_pf_ucode_revision; +#undef xen_pf_pucode_revision + #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..15777b5416 100644 --- a/xen/include/public/platform.h +++ b/xen/include/public/platform.h @@ -614,6 +614,16 @@ 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_revision 65 +struct xenpf_ucode_revision { + uint32_t cpu; /* IN: CPU number to get the revision from. */ + uint32_t signature; /* OUT: CPU signature (CPUID.1.EAX). */ + uint32_t pf; /* OUT: Platform Flags (Intel only) */ + uint32_t revision; /* OUT: Microcode Revision. */ +}; +typedef struct xenpf_ucode_revision xenpf_ucode_revision_t; +DEFINE_XEN_GUEST_HANDLE(xenpf_ucode_revision_t); + /* * ` enum neg_errnoval * ` HYPERVISOR_platform_op(const struct xen_platform_op*); @@ -645,6 +655,7 @@ struct xen_platform_op { xenpf_resource_op_t resource_op; xenpf_symdata_t symdata; xenpf_dom0_console_t dom0_console; + xenpf_ucode_revision_t ucode_revision; uint8_t pad[128]; } u; }; diff --git a/xen/include/xlat.lst b/xen/include/xlat.lst index d601a8a984..9c41948514 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_revision platform.h ? pmu_data pmu.h ? pmu_params pmu.h ! sched_poll sched.h From patchwork Mon Apr 17 13:53:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 13214047 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 016CFC77B70 for ; Mon, 17 Apr 2023 13:54:03 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.522144.811351 (Exim 4.92) (envelope-from ) id 1poPIr-0003m0-4c; Mon, 17 Apr 2023 13:53:57 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 522144.811351; Mon, 17 Apr 2023 13:53:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1poPIr-0003lt-1H; Mon, 17 Apr 2023 13:53:57 +0000 Received: by outflank-mailman (input) for mailman id 522144; Mon, 17 Apr 2023 13:53:56 +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 1poPIq-0003Vm-7O for xen-devel@lists.xenproject.org; Mon, 17 Apr 2023 13:53:56 +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 4af54abe-dd27-11ed-b21e-6b7b168915f2; Mon, 17 Apr 2023 15:53:55 +0200 (CEST) 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: 4af54abe-dd27-11ed-b21e-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1681739635; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=7KS8mI+2XK81GgSuy9LkhsX3/pJwxpsay4LFxPQZ9HE=; b=ML4mF6vfk1UA7dfhfIy84o46AnNrd2IKeasiYeKrVyv/HgYLxT0NrBlP Th1LNcRqrYX4acIQlOpb5388bRd/yGwqPXYdVJlPNP85ZydX7/EhkGD68 32mpLTwFF/9VD8M6YK0b045Qtz/0YFMkTHOx7tY5XhHcgvTyiDQ9a6yvf 4=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 105714904 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED IronPort-Data: A9a23:fOWrdK11+YApajHoh/bD5eRxkn2cJEfYwER7XKvMYLTBsI5bpzYDy GZKUWGAO62KNDb9LohxOd7k9EtU7JHWmtBiQQNrpC1hF35El5HIVI+TRqvS04F+DeWYFR46s J9OAjXkBJppJpMJjk71atANlVEliefTAOK6ULWeUsxIbVcMYD87jh5+kPIOjIdtgNyoayuAo tq3qMDEULOf82cc3lk8tuTS+XuDgNyo4GlD5gBnOqgS1LPjvyJ94Kw3dPnZw0TQGuG4LsbiL 87fwbew+H/u/htFIrtJRZ6iLyXm6paLVeS/oiI+t5qK23CulQRrukoPD9IOaF8/ttm8t4sZJ OOhF3CHYVxB0qXkwIzxWvTDes10FfUuFLTveRBTvSEPpqFvnrSFL/hGVSkL0YMkFulfEWFr5 aUnDiI2S0qjjf6/wre7Y9Y8iZF2RCXrFNt3VnBIyDjYCbAtQIzZQrWM7thdtNsyrpkQR7CEP ZNfMGcxKk2aOHWjOX9OYH46tPylnHbyYntUuVuOoasf6GnP1g1hlrPqNbI5f/TTHZgKxxrJ/ j6uE2LRGCgLKuOS0mW58F2O36yVmh6qfIEQPejtnhJtqALKnTFCYPEMbnOrrP/8hkOgVtZ3L 00P5jFovaU07FasTNT2Q1u/unHslhwWVsdUEuY6wBqQ0aeS6AGcbkAbShZRZdpgs9U5LRQo2 UWOhMjBHiF0vfueTnf13rWJqTK/PwAFIGlEYjULJSMe+MXqqow3ihPJT/5gHbSzg9mzHiv/q w1mtwBn2e9V15RSkfzmoxae2WnESoX1ohAd9gXyTjuayBFCQdSFbZCh613bxMkQI9PMJrWeh 0Toi/Ry/chXU8HUyHfcHbRRdF26z63baWOB2DaDC7Fkrm3woCD7IOi89RkkfC9U3tA4lSgFi aM5kSdY/9dtMXSjdsebiKrhWp1xncAM+TkIP804j+aigbArLmdrBAk0OSatM5nFySDAa50XN 5aBatqLBn0HE6lhxzfeb75DgeZ1mXhmmD6MHcyTI/GbPV22PSf9dFv4GAHWMrBRAF2s+205D Oqzx+PVkk4CAYUSkwHc8JIJLEBiEEXX8ave8pQNHsbae1oOJY3UI6OJqV/XU9A/zvs9eyah1 i3VZ3K0P3Kl3SWddl7SOi46AF4tNL4mxU8G0eUXFQ7A8xAejUyHts/zq7NfkWEbydFe IronPort-HdrOrdr: A9a23:OQ2t/a7VQnXfEhFUYQPXwMjXdLJyesId70hD6qhwISY7TiX4rb HJoB11737JYVoqNU3I3OrwWpVoIkmskqKdg7NwAV7KZmCP0wGVxcNZnO7fKlXbaknDH4Vmu5 uIHZITNDSJNykYsfrH X-Talos-CUID: 9a23:na9ANGFBAGyK2kkGqmJ39GsEQ/8DYEb4llfaP0a6DGZAd+2aHAo= X-Talos-MUID: 9a23:TTtyRwYKBFHTvOBTrQb9mg5vL5hU4YuMUQNXlqhXn8qGHHkl X-IronPort-AV: E=Sophos;i="5.99,204,1677560400"; d="scan'208";a="105714904" 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 v5 3/3] tools/xen-ucode: print information about currently loaded ucode Date: Mon, 17 Apr 2023 14:53:35 +0100 Message-ID: <20230417135335.17176-4-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230417135335.17176-1-sergey.dyasli@citrix.com> References: <20230417135335.17176-1-sergey.dyasli@citrix.com> MIME-Version: 1.0 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 19-01-01 (raw 0x00a00f11) revision 0x0a0011ce Signed-off-by: Sergey Dyasli Acked-by: Andrew Cooper --- v4 --> v5: - Changed AMD output to be FF-MM-SS instead of famXX - Modified usage string - Fixed fprintf indentation - Printing error messages always to stderr - Use appropriate exit codes in show_curr_cpu() --- tools/misc/xen-ucode.c | 85 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 75 insertions(+), 10 deletions(-) diff --git a/tools/misc/xen-ucode.c b/tools/misc/xen-ucode.c index ad32face2b..c6ae6498d6 100644 --- a/tools/misc/xen-ucode.c +++ b/tools/misc/xen-ucode.c @@ -12,22 +12,95 @@ #include #include +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 }; + /* Always exit with 2 when called during usage-info */ + int exit_code = (f == stderr) ? 2 : 1; + + ret = xc_get_cpu_version(xch, &cpu_ver); + if ( ret ) + { + fprintf(stderr, "Failed to get CPU information. (err: %s)\n", + strerror(errno)); + exit(exit_code); + } + + ret = xc_get_ucode_revision(xch, &ucode_rev); + if ( ret ) + { + fprintf(stderr, "Failed to get microcode information. (err: %s)\n", + strerror(errno)); + exit(exit_code); + } + + /* + * 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 %02x-%02x-%02x (raw 0x%08x) revision 0x%08x\n", + cpu_ver.family, cpu_ver.model, cpu_ver.stepping, + ucode_rev.signature, ucode_rev.revision); + } + else + { + fprintf(f, "Unsupported CPU vendor: %s\n", cpu_ver.vendor_id); + exit(exit_code); + } +} + 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 \n", argv[0]); + "Usage: %s [ | show-cpu-info]\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 ) @@ -52,14 +125,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 ) {