From patchwork Tue Feb 28 17:39:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 13155105 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 79EE7C6FA8E for ; Tue, 28 Feb 2023 17:40:17 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.503619.775943 (Exim 4.92) (envelope-from ) id 1pX3xQ-00079U-OY; Tue, 28 Feb 2023 17:40:08 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 503619.775943; Tue, 28 Feb 2023 17:40:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pX3xQ-00077z-JF; Tue, 28 Feb 2023 17:40:08 +0000 Received: by outflank-mailman (input) for mailman id 503619; Tue, 28 Feb 2023 17:40:07 +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 1pX3xO-0006WI-UU for xen-devel@lists.xenproject.org; Tue, 28 Feb 2023 17:40:07 +0000 Received: from esa4.hc3370-68.iphmx.com (esa4.hc3370-68.iphmx.com [216.71.155.144]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ef57482e-b78e-11ed-a550-8520e6686977; Tue, 28 Feb 2023 18:40:05 +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: ef57482e-b78e-11ed-a550-8520e6686977 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1677606004; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=K+j4WJCkOxdn46mcun2tYyo0EwVo6CxR547z8EwP1Wk=; b=hn6936WubqsBfq8vtIBgAzKnMEEeh2lgvfdh5f80AB04KF9/BJxkFnDu O0MZBNcsZxNGFPMXji4GubKjDpiGwEwP26eUtdU1Z2U5ltaVggqa5jmC7 bOwQtima2Ap/2h+VCe2vCcNauQ2kayOE/Y0MClamKVYzYLbP0hepRhqvk s=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 101312543 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED IronPort-Data: A9a23:lP4rBKC5e5R+VhVW/+fjw5YqxClBgxIJ4kV8jS/XYbTApDklgjEOm GIeXWnQOf2LM2XyetAjYYzg/RkF6MfSz95hQQY4rX1jcSlH+JHPbTi7wuUcHAvJd5GeExg3h yk6QoOdRCzhZiaE/n9BCpC48T8nk/nOHuGmYAL9EngZbRd+Tys8gg5Ulec8g4p56fC0GArIs t7pyyHlEAbNNwVcbyRFu8pvlDs15K6p4GlC7gRkDRx2lAS2e0c9Xcp3yZ6ZdxMUcqEMdsamS uDKyq2O/2+x13/B3fv8z94X2mVTKlLjFVDmZkh+AsBOsTAbzsAG6Y4pNeJ0VKtio27hc+ada jl6ncfYpQ8BZsUgkQmGOvVSO3kW0aZuoNcrLZUj2CA6IoKvn3bEmp1T4E8K0YIw18VLUTBM3 PwhEw8kdzyCruW9kKmyRbw57igjBJGD0II3v3hhyXfSDOo8QICFSKLPjTNa9G5u3IYUR6+YP pdHL2M1N3wsYDUWUrsTIIkzhuillz/zYjRDrFO9rqsr+WnDigd21dABNfKMIoXRHJ8Iwh3wS mTuwkHpJS0UCu6m2DvC1l2xrMqfxTrdR9dHfFG/3qEz2wDCroAJMzUUWkG8uuKRkVOlVpRUL El80igzqak/8mS7Q9+7WAe3yFafpQIVUddUF+w86SmOx7DS7gLfAXILJhZDYtE7sM49RRQxy 0SE2djuAFRHoLCTDH6Q6LqQhTezIjQOa38PYzceSgkI6MWlp5s85jrQSv5zHajzicf6cQwc2 BjT8nJ43e9Ky5dWiePipwuvby+QSobhYy0JtlTVd2Kc1TxQfaKkToujuUPS4qMVRGqGdWWps H8BksmYyekBC5CRiSCAKNkw8KGVC+Wta2OF3wM2d3U133H0oiP4I9gMiN1rDB0xWvvobwMFd 6M6Vel5wJZIdEWnYqZsC25aI5R7lPOwfTgJux29UzavXnSTXFXalM2NTRTKt4wIrKTLufBXB HtjWZzwZUv28Iw+pNZMe88T0KUw2gc1zn7JSJbwwnyPiOTBOyPPE+ZdbArSP4jVCZ9oRy2Pr r5i2zaikU0DAIUSnAGMmWLsEbz6BSdiXs2nwyCmXuWCPhBnCAkc5wz5mNscl3het/0NzI/gp yjtMnK0PXKj3RUr3y3WMCE8AF4uNL4jxU8G0dsEZg74iiVzMN30s8/ytfIfJNEayQCq9tYsJ 9FtRilKKq4npujvk9jFUaTAkQ== IronPort-HdrOrdr: A9a23:M7EdZqvktGcXvi5gaOrui5S+7skDi9V00zEX/kB9WHVpm5qj5q STdZUguSMc5wx9ZJhNo6H4BEDEewK7yXcX2+Ys1NWZLWzbUTCTXeJfBOLZqlXd8m/FltK1s5 0QEZSWJ+eAdWSS5vyKhzVQfexL/PC3tIi0gO/F1XdkSkVPY6FkqyN0EBySHEEzZAQuP/QEPa vZztdDryC7eXwRKuCyBnxAYvPKoMfCno/nZxlDJxNP0mizZGOTg4LHLw== X-IronPort-AV: E=Sophos;i="5.98,222,1673931600"; d="scan'208";a="101312543" 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 v2/RFC 1/3] xen/hypfs: add initial cpuinfo directory Date: Tue, 28 Feb 2023 17:39:30 +0000 Message-ID: <20230228173932.28510-2-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230228173932.28510-1-sergey.dyasli@citrix.com> References: <20230228173932.28510-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. Leverage xenhypfs to expose struct cpu_signature in a new cpuinfo dir. The tree structure is: / cpuinfo/ cpu-signature microcode-revision processor-flags The most useful bit is cpu microcode revision which will get updated after late ucode loading. Signed-off-by: Sergey Dyasli --- xen/arch/x86/cpu/common.c | 58 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/xen/arch/x86/cpu/common.c b/xen/arch/x86/cpu/common.c index 5ad347534a..aa864fdbab 100644 --- a/xen/arch/x86/cpu/common.c +++ b/xen/arch/x86/cpu/common.c @@ -1005,3 +1005,61 @@ const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id table[]) } return NULL; } + +#ifdef CONFIG_HYPFS +#include +#include +#include + +static unsigned int cpu_signature; +static unsigned int processor_flags; +static unsigned int ucode_revision; + +int cf_check hypfs_read_cpusig( + const struct hypfs_entry *entry, XEN_GUEST_HANDLE_PARAM(void) uaddr) +{ + const struct hypfs_entry_leaf *l; + unsigned int size = entry->funcs->getsize(entry); + const struct cpu_signature *sig = &per_cpu(cpu_sig, + cpumask_first(&cpu_online_map)); + + l = container_of(entry, const struct hypfs_entry_leaf, e); + + cpu_signature = sig->sig; + processor_flags = sig->pf; + ucode_revision = sig->rev; + + return copy_to_guest(uaddr, l->u.content, size) ? -EFAULT : 0; +} + +const struct hypfs_funcs ucode_rev_funcs = { + .enter = hypfs_node_enter, + .exit = hypfs_node_exit, + .read = hypfs_read_cpusig, + .write = hypfs_write_deny, + .getsize = hypfs_getsize, + .findentry = hypfs_leaf_findentry, +}; + +static HYPFS_DIR_INIT(cpuinfo, "cpuinfo"); +static HYPFS_FIXEDSIZE_INIT(signature, XEN_HYPFS_TYPE_UINT, "cpu-signature", + cpu_signature, &ucode_rev_funcs, 0); +static HYPFS_FIXEDSIZE_INIT(pf, XEN_HYPFS_TYPE_UINT, "processor-flags", + processor_flags, &ucode_rev_funcs, 0); +static HYPFS_FIXEDSIZE_INIT(revision, XEN_HYPFS_TYPE_UINT, "microcode-revision", + ucode_revision, &ucode_rev_funcs, 0); + +static int __init cf_check cpuinfo_init(void) +{ + hypfs_add_dir(&hypfs_root, &cpuinfo, true); + hypfs_add_leaf(&cpuinfo, &signature, true); + + if ( boot_cpu_data.x86_vendor == X86_VENDOR_INTEL ) + hypfs_add_leaf(&cpuinfo, &pf, true); + + hypfs_add_leaf(&cpuinfo, &revision, true); + + return 0; +} +__initcall(cpuinfo_init); +#endif /* CONFIG_HYPFS */ From patchwork Tue Feb 28 17:39:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 13155103 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 318A9C64ED6 for ; Tue, 28 Feb 2023 17:40:17 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.503620.775952 (Exim 4.92) (envelope-from ) id 1pX3xR-0007I3-7z; Tue, 28 Feb 2023 17:40:09 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 503620.775952; Tue, 28 Feb 2023 17:40:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pX3xQ-0007HM-V1; Tue, 28 Feb 2023 17:40:08 +0000 Received: by outflank-mailman (input) for mailman id 503620; Tue, 28 Feb 2023 17:40:07 +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 1pX3xP-0006sS-HB for xen-devel@lists.xenproject.org; Tue, 28 Feb 2023 17:40:07 +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 efab59e6-b78e-11ed-9695-2f268f93b82a; Tue, 28 Feb 2023 18:40:06 +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: efab59e6-b78e-11ed-9695-2f268f93b82a DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1677606006; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=U9Ac8kfawVwJyTiVqm0kbmJdZ36EQ83/TJ8nOn83CLs=; b=ZyNxqXQE7XpitWStBxkVZKonIsFUdM37MDIlrdvN2SBFWluioPjaLbbD mMLBEQvc2f1z7b1kTeeWunC3Fl1SPen+6a+XX31JDTh5tKK8xqdwhzl+/ OSLqPLps8GjhQAhsYrwS8JIwAoB18fF/ZIPLhsrgClKJOADd3k1cYJWsR Y=; Authentication-Results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 101312544 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 X-Policy: $RELAYED IronPort-Data: A9a23:/ZIn368CLMgzU7CS/cvyDrUDTn6TJUtcMsCJ2f8bNWPcYEJGY0x3y jFLXDrUMqr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ynnMmcBkQqXuJEyAVnSApyVQO+1DMkXQLNSFXBEAGtELFB4Odb+sfdOLMBoFVTlncQ6pcNJo zA+U53oKpxypv7volzxsbGVQFReSSmW IronPort-HdrOrdr: A9a23:U9KYOqvnPFYs4oODgEjJyNm+7skDi9V00zEX/kB9WHVpm5qj5q STdZUguSMc5wx9ZJhNo6H4BEDEewK7yXcX2+Ys1NWZLWzbUTCTXeJfBOLZqlXd8m/FltK1s5 0QEZSWJ+eAdWSS5vyKhzVQfexL/PC3tIi0gO/F1XdkSkVPY6FkqyN0EBySHEEzZAQuP/QEPa vZztdDryC7eXwRKuCyBnxAYvPKoMfCno/nZxlDJxNP0mizZGOTg4LHLw== X-IronPort-AV: E=Sophos;i="5.98,222,1673931600"; d="scan'208";a="101312544" 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 v2 2/3] tools/xenctrl: add xc_get_cpu_version() Date: Tue, 28 Feb 2023 17:39:31 +0000 Message-ID: <20230228173932.28510-3-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230228173932.28510-1-sergey.dyasli@citrix.com> References: <20230228173932.28510-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 Feb 28 17:39:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Dyasli X-Patchwork-Id: 13155106 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 9ECE3C7EE30 for ; Tue, 28 Feb 2023 17:40:17 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.503618.775938 (Exim 4.92) (envelope-from ) id 1pX3xQ-000764-Ea; Tue, 28 Feb 2023 17:40:08 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 503618.775938; Tue, 28 Feb 2023 17:40:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pX3xQ-00075v-B9; Tue, 28 Feb 2023 17:40:08 +0000 Received: by outflank-mailman (input) for mailman id 503618; Tue, 28 Feb 2023 17:40:07 +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 1pX3xP-0006sS-0Z for xen-devel@lists.xenproject.org; Tue, 28 Feb 2023 17:40:07 +0000 Received: from esa5.hc3370-68.iphmx.com (esa5.hc3370-68.iphmx.com [216.71.155.168]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ef28cf96-b78e-11ed-9695-2f268f93b82a; Tue, 28 Feb 2023 18:40:05 +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: ef28cf96-b78e-11ed-9695-2f268f93b82a DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1677606005; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=kdC88fnrW3jwxtsuxpGeNQRlenhGudj0ts02zqy7nC0=; b=UIRFRGfdI5Bj1Qio7ep0z3zGvALT3C8U5fEaQdy26WAQnzhe0zUsyZxx D+v3LRoxyVw1nYxPTf6p6yFwe8fqGBqnQwju+OLR44eg4T9d2saUx/WOj EWtMohFvoKmvhfqNaDZMazxXLPWRKf7Dk8NjsCh0ofcTIPG+F616gnx3Y g=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none X-SBRS: 4.0 X-MesageID: 97712737 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.156.123 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dbArSP4jVCZ9oRy2Pr r5i2zaikU0DAIUSnAGMmWLsEbz6BSdiXs2nwyCmXuWCPhBnCAkc5wz5mNscl3het/0NzI/gp yjtMnK0PXKj3RUr3y3WMCE8AF4uNL4jxU8G0dsEZg74iiVzMN30s8/ytfIfJNEayQCq9tYsJ 9FtRilKKq4npujvk9jFUaTAkQ== IronPort-HdrOrdr: A9a23:cVrne6ky+hi/320npnxreUI5IC3pDfIs3DAbv31ZSRFFG/Fxl6 iV88jztCWE7gr5N0tApTntAsS9qDbnhPxICOoqTNCftWvd2FdARbsKheCJ/9SjIVyaygc079 YFT0EUMrPN5DZB4foSmDPIcOod/A== X-IronPort-AV: E=Sophos;i="5.98,222,1673931600"; d="scan'208";a="97712737" 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 v2 3/3] tools/xen-ucode: print information about currently loaded ucode Date: Tue, 28 Feb 2023 17:39:32 +0000 Message-ID: <20230228173932.28510-4-sergey.dyasli@citrix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230228173932.28510-1-sergey.dyasli@citrix.com> References: <20230228173932.28510-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 cpuinfo directory in xenhypfs and from XENPF_get_cpu_version platform op. 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/Makefile | 2 +- tools/misc/xen-ucode.c | 97 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 1 deletion(-) diff --git a/tools/misc/Makefile b/tools/misc/Makefile index 1c6e1d6a04..e345ac76db 100644 --- a/tools/misc/Makefile +++ b/tools/misc/Makefile @@ -136,6 +136,6 @@ xencov: xencov.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) xen-ucode: xen-ucode.o - $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) + $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(LDLIBS_libxenhypfs) $(APPEND_LDFLAGS) -include $(DEPS_INCLUDE) diff --git a/tools/misc/xen-ucode.c b/tools/misc/xen-ucode.c index ad32face2b..7e657689f4 100644 --- a/tools/misc/xen-ucode.c +++ b/tools/misc/xen-ucode.c @@ -11,6 +11,96 @@ #include #include #include +#include + +static const char intel_id[] = "GenuineIntel"; +static const char amd_id[] = "AuthenticAMD"; + +static const char sig_path[] = "/cpuinfo/cpu-signature"; +static const char rev_path[] = "/cpuinfo/microcode-revision"; +static const char pf_path[] = "/cpuinfo/processor-flags"; + +static int hypfs_read_uint(struct xenhypfs_handle *hdl, const char *path, + unsigned int *var) +{ + char *result; + result = xenhypfs_read(hdl, path); + if ( !result ) + return -1; + + errno = 0; + *var = strtol(result, NULL, 10); + if ( errno ) + return -1; + + return 0; +} + +static void show_curr_cpu(FILE *f) +{ + int ret; + struct xenhypfs_handle *hdl; + xc_interface *xch; + struct xenpf_pcpu_version cpu_ver = {0}; + bool intel = false, amd = false; + unsigned int cpu_signature, pf, ucode_revision; + + hdl = xenhypfs_open(NULL, 0); + if ( !hdl ) + return; + + xch = xc_interface_open(0, 0, 0); + if ( xch == NULL ) + return; + + ret = xc_get_cpu_version(xch, &cpu_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; + + if ( hypfs_read_uint(hdl, sig_path, &cpu_signature) != 0 ) + return; + + if ( hypfs_read_uint(hdl, rev_path, &ucode_revision) != 0 ) + return; + + if ( intel && hypfs_read_uint(hdl, pf_path, &pf) != 0 ) + return; + + /* + * 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, + cpu_signature); + } + else if ( amd ) + { + fprintf(f, "Current CPU signature is: fam%xh (raw %#x)\n", + cpu_ver.family, cpu_signature); + } + + if ( intel || amd ) + fprintf(f, "Current CPU microcode revision is: %#x\n", ucode_revision); + + if ( intel ) + fprintf(f, "Current CPU processor flags are: %#x\n", pf); + + xc_interface_close(xch); + xenhypfs_close(hdl); +} int main(int argc, char *argv[]) { @@ -25,9 +115,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 )