From patchwork Tue Apr 4 16:06:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 13200562 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 AD9DDC77B60 for ; Tue, 4 Apr 2023 16:07:42 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.518019.804139 (Exim 4.92) (envelope-from ) id 1pjjC2-0004Qd-NP; Tue, 04 Apr 2023 16:07:34 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 518019.804139; Tue, 04 Apr 2023 16:07:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pjjC2-0004QW-Kb; Tue, 04 Apr 2023 16:07:34 +0000 Received: by outflank-mailman (input) for mailman id 518019; Tue, 04 Apr 2023 16:07:33 +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 1pjjC1-0004Q2-Mv for xen-devel@lists.xenproject.org; Tue, 04 Apr 2023 16:07:33 +0000 Received: from esa4.hc3370-68.iphmx.com (esa4.hc3370-68.iphmx.com [216.71.155.144]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id cca51aa8-d302-11ed-85db-49a42c6b2330; Tue, 04 Apr 2023 18:07:31 +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: cca51aa8-d302-11ed-85db-49a42c6b2330 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1680624451; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=OIB4XE7cSQQtZzws9p9Ga2irS8OnpzPLnMZtppaosBg=; b=GsB7Yy1Jo4Ow6+EFtZiwVjKi0AULlLC1H/ys9LaFkAvARqHohNo0SPOP tToe0+ra4bSeoli/yY5QUf1cAN/w4sMwzy0jegLkfLOG1jVaOxSAbkyvc UsFMfByJHhSwbITbCUCsp3ESrwL0EtYQcRiYOXTihIoHUyHypkIZwab1N k=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 106724130 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED IronPort-Data: A9a23:yu8CZ6pwY/cYEdn6ykTvBwmglPVeBmIuZRIvgKrLsJaIsI4StFCzt garIBmGPKuDYzCgctEjO4u0pkIEsZXQzIRiGQc9rylgQSJE8puZCYyVIHmrMnLJJKUvbq7FA +Y2MYCccZ9uHhcwgj/3b9ANeFEljfngqoLUUbKCYWYpA1c/Ek/NsDo788YhmIlknNOlNA2Ev NL2sqX3NUSsnjV5KQr40YrawP9UlKm06WNwUmAWP6gR5weCzyVNVvrzGInqR5fGatgMdgKFb 76rIIGRpgvx4xorA9W5pbf3GmVirmn6ZFXmZtJ+AsBOszAazsAA+v9T2Mk0MC+7vw6hjdFpo OihgLTrIesf0g8gr8xGO/VQO3kW0aSrY9YrK1Dn2SCY5xWun3cBX5yCpaz5VGEV0r8fPI1Ay RAXAGtSLQDTreG3+ZSQEeJz3fYlc8boI5xK7xmMzRmBZRonaZXKQqGM7t5ExjYgwMtJGJ4yZ eJAN2ApNk6ZJUQSZBFOUslWcOSA3xETdxVDpUiaqLtx73na1whw+LPsLMDUapqBQsA9ckOw/ zqYoD6lW0pCXDCZ4SSP9i20qPGVpgzmSr4rNrK47rl4iWTGkwT/DzVJDADm8JFVkHWWS99Zb kAZ5Ccqhawz71CwCMnwWQWip3yJtQJaXMBfe8U44gyQzqvf4y6CG3MJCDVGbbQOq8seVTEsk FiTkLvBBzN1t6aOYWmA7brSpjS3UQAXMGsDaCksXQYDpd75r+kblQnTR9xuFKq0iNzdGjzqx T2O6i8kiN0uYdUjjvvhuwqd2nT1+8aPF1RujunKYo67xlgmJ571TY+p0H7wtv1fd7SfEVaCo 2dRzqBy89sy4YGxeD2lGbtdRO/xu63UbFUwknY0QcB/qm3FF2qLONkJvWogfBoB3tMsI2eBX aPFhe9GCHa/1lOOZLQ/XY++At9CIUPIRYW8DaC8gjajj/FMmO67EMJGPxT4M5jFyhRErE3GE c7znTyQJXgbE7976zG9Wv0Q17QmrghnmzOLGMylnk78i+TODJJwdVviGALWBt3VEYve+FmFm zqhH5DiJ+pjvB3WPXCMrN97waEiJnknH5Hmw/Fqmhq4ClM+QgkJUqaBqY7NjqQ5x8y5YM+Up CDiMqKZoXKj7UD6xfKiMSo8Mum3Ac4u9RrW/0UEZD6V5pTqWq73hI93Snf9VeJ4nAC/5ZaYl 8U4Rvg= IronPort-HdrOrdr: A9a23:g3P7gK99tCdBf+9fU7Juk+DzI+orL9Y04lQ7vn2ZKCYlF/Bw8v rF8cjzuiWZtN98Yh4dcKm7SdC9qBDnhPxICOsqXYtKNTOO0FdASrsN0WKI+UyCJ8SRzI9gPJ BbAsxD4Y3LZmSSVfyKmzVQyexQpuVvLZrY4ts2E00dNT2CtZsQlTtENg== X-IronPort-AV: E=Sophos;i="5.98,318,1673931600"; d="scan'208";a="106724130" 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 v4 1/3] tools/xenctrl: add xc_get_cpu_version() Date: Tue, 4 Apr 2023 17:06:53 +0100 Message-ID: <20230404160655.2354-2-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230404160655.2354-1-sergey.dyasli@citrix.com> References: <20230404160655.2354-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 --- 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 Tue Apr 4 16:06:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 13200561 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 4DA10C6FD1D for ; Tue, 4 Apr 2023 16:07:26 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.518017.804130 (Exim 4.92) (envelope-from ) id 1pjjBn-00042m-9r; Tue, 04 Apr 2023 16:07:19 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 518017.804130; Tue, 04 Apr 2023 16:07:19 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pjjBn-00042f-6Y; Tue, 04 Apr 2023 16:07:19 +0000 Received: by outflank-mailman (input) for mailman id 518017; Tue, 04 Apr 2023 16:07:18 +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 1pjjBm-00042B-23 for xen-devel@lists.xenproject.org; Tue, 04 Apr 2023 16:07:18 +0000 Received: from esa3.hc3370-68.iphmx.com (esa3.hc3370-68.iphmx.com [216.71.145.155]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c3963683-d302-11ed-b464-930f4c7d94ae; Tue, 04 Apr 2023 18:07:15 +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: c3963683-d302-11ed-b464-930f4c7d94ae DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1680624435; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=QsmKjz9FSvqTsAQ5kNWHSGgpoV1tw0uvDbd0t6jEgvo=; b=NauPj0zhH9qqNc6uPFGBX8VXr0Up6GZZd0gvygJjwLe7C7Koahpvl82A 0MpOcsKx1psg4lBqMqXAlqfnIiBHHHgsZTkqjp0iffgB1d2qv1x6/gHy6 GSAVjeFsxOw+iaWQY/ITmdWbaCOZWZ9XB5qtHI3G4ndR1UTWIelxf/4ou 0=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 104328623 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED IronPort-Data: A9a23:dUgNEal0GTwHMn6zhFqF1jTo5gy2JkRdPkR7XQ2eYbSJt1+Wr1Gzt xIeUG6DOa6IZjD9e91zboXjox8AuZPUyYdrGQRu/C08HiMWpZLJC+rCIxarNUt+DCFhoGFPt JxCN4aafKjYaleG+39B55C49SEUOZmgH+a6U6icfHgqH2eIcQ954Tp7gek1n4V0ttawBgKJq LvartbWfVSowFaYCEpNg064gE4p7aSaVA8w5ARkPqgX5AOGzRH5MbpETU2PByqgKmVrNrbSq 9brlNmR4m7f9hExPdKp+p6TnpoiG+O60aCm0xK6aoD66vRwjnVaPpUTbZLwXXx/mTSR9+2d/ f0W3XCGpaXFCYWX8AgVe0Ew/yiTpsSq8pefSZS0mZT7I0Er7xIAahihZa07FdRwxwp5PY1B3 f1HNzVWV0uqvvm3/a+KbdFql8MAcPC+aevzulk4pd3YJfMvQJSFSKTW/95Imjw3g6iiH96HO ZBfM2A2Kk2dPVsWYAx/5JEWxY9EglHkfidXpUPTqbs++GzS5AdwzKLsIJzefdniqcB9xx7E/ TiWoT6iav0cHNWa1CLZz2qJv+PWgRjXZI43RJLj0cc/1TV/wURMUUZLBDNXu8KRmkO4Ht5SN UEQ0i4vtrQpslymSMHnWB+1q2LCuQQTM/JSGeAn7ACGyoLP/h2UQGMDS1Zpd9gOpMIwAzsw2 TehndzzAid0mKaIUn/b/bCRxRuwJCwUIGkqdSICCwwf7LHLu5ovhxjCStJiFq+djdDvHzz0h TeQo0ADa6471JBRkf/hpBae3mzq/8KSJuIo2unJdmP68QYiXdWMXpep1EXqys5GPYG6EmDU6 RDohPOiAPAy4YClzXLdGLtVQOr4u55pIxWH3wcxQsBJGyCFvif6INsOuGwWyFJBaJ5sRNP/X KPEVeq9Drd3NWDiU6J4apnZ5y8Cnfm5ToSNuhw5g7NzjnlNmOyvpnsGiba4hTyFraTVufhX1 W2nWcitF20GLq9s0SC7QewQuZdymHBmmD+NFMqglUr3uVZ7WJJyYe5dWGZik8hjtP/UyOkr2 4032zS2J+V3D7SlP3i/HX87JlEWN3krba3LRzhsXrfbeGJOQThxY8I9NJt9I+SJaYwJzLaXl px8M2cEoGfCaYrvcl/VMCo7NOu+Bf6SbxsTZEQRALph4FB7Ca7H0UvVX8JfkWUPnAC78cNJc g== IronPort-HdrOrdr: A9a23:A8CGqKNzLcl7FsBcTuqjsMiBIKoaSvp037BL7TEVdfUxSKb0qy nAppgmPHPP5wr5IUtQ4OxoW5PwI080l6QU3WB5B97LYOCBggWVxepZnOjfKlPbehEWwdQtsZ uII5IUNDQpNykAsS8h2njfLz/8+qjhzEl1v5an856yd3ARV51d X-IronPort-AV: E=Sophos;i="5.98,318,1673931600"; d="scan'208";a="104328623" 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 v4 2/3] x86/platform: introduce XENPF_get_ucode_revision Date: Tue, 4 Apr 2023 17:06:54 +0100 Message-ID: <20230404160655.2354-3-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230404160655.2354-1-sergey.dyasli@citrix.com> References: <20230404160655.2354-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 --- 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 Tue Apr 4 16:06:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 13200564 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 704E6C77B6C for ; Tue, 4 Apr 2023 16:07:45 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.518022.804160 (Exim 4.92) (envelope-from ) id 1pjjC5-0004wm-8R; Tue, 04 Apr 2023 16:07:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 518022.804160; Tue, 04 Apr 2023 16:07:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pjjC5-0004wX-5O; Tue, 04 Apr 2023 16:07:37 +0000 Received: by outflank-mailman (input) for mailman id 518022; Tue, 04 Apr 2023 16:07:35 +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 1pjjC3-0004Q2-C0 for xen-devel@lists.xenproject.org; Tue, 04 Apr 2023 16:07:35 +0000 Received: from esa4.hc3370-68.iphmx.com (esa4.hc3370-68.iphmx.com [216.71.155.144]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id cedfab95-d302-11ed-85db-49a42c6b2330; Tue, 04 Apr 2023 18:07:33 +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: cedfab95-d302-11ed-85db-49a42c6b2330 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1680624453; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=uBXu6YZv6BAp5cZzrn3yHrWUC2z5HKvOE9bB6d7ZZR4=; b=C+WTegrat2MbXQD0eTtTXHY77Y/y9cnBEfngiiX/94eFKxSc6DcWn2IU qHfbBIoVSa6O9yxr+/2lq4X2vmIR224w0YZKr/K+zglpfZb8rHFUWcMWo b2cF2j3qvJjhGWnGid2kP37FoS7uKmS1WguBabK1w1Yqcdz8RMQTFANWH Q=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 106724147 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED 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 X-IronPort-AV: E=Sophos;i="5.98,318,1673931600"; d="scan'208";a="106724147" 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 v4 3/3] tools/xen-ucode: print information about currently loaded ucode Date: Tue, 4 Apr 2023 17:06:55 +0100 Message-ID: <20230404160655.2354-4-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230404160655.2354-1-sergey.dyasli@citrix.com> References: <20230404160655.2354-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 fam19h (raw 0x00a00f11) revision 0x0a0011ce Signed-off-by: Sergey Dyasli --- 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 #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 }; + + 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 \n", argv[0]); + fprintf(stderr, "xen-ucode: Xen microcode updating tool\n"); + show_curr_cpu(stderr); + fprintf(stderr, "Usage: %s \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 ) {