From nobody Mon Feb 9 09:43:17 2026 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1558945730; cv=none; d=zoho.com; s=zohoarc; b=N4ubIiuy5paHkz379b5j+X7DLp230r6uVgBn87c2pFT7o1z0h39PF7V2IPVdhodxIaFU70X77SIt0aeRGdJTMTbkDM7ae9ClLgYaXnpSh8GYZZatqldPmJ0JzEDnYhGlS7LpMri13xkNwQUIsnMquQg/sdAt5/ScaO3eiz4nvdg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558945730; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=NCzVieFPfZH01VYlPx4HlR2nOz1+N24ookX5vttYYRI=; b=NsvZr9WrTZ/1XrC64yaQJy4CFhTk/2mRSKhELtA27aj4a1Qc3DXjUmHeaLT7SOjdXDP7NZEQwiOKabsExWS6noI/O4HCc/Qy/JMffebRobPJgT6mlheUlnjP8Wtgfs01Aqbp0u6NlHp59/6kTss/jaW7NnGaUidHgdOJ4ULmQCk= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1558945730870129.92292230610587; Mon, 27 May 2019 01:28:50 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hVAyd-00049j-9O; Mon, 27 May 2019 08:27:27 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hVAyc-00049c-6h for xen-devel@lists.xenproject.org; Mon, 27 May 2019 08:27:26 +0000 Received: from mga12.intel.com (unknown [192.55.52.136]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 41731805-8059-11e9-8980-bc764e045a96; Mon, 27 May 2019 08:27:25 +0000 (UTC) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 May 2019 01:27:24 -0700 Received: from gao-cwp.sh.intel.com ([10.239.159.26]) by orsmga005.jf.intel.com with ESMTP; 27 May 2019 01:27:23 -0700 X-Inumbo-ID: 41731805-8059-11e9-8980-bc764e045a96 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 From: Chao Gao To: xen-devel@lists.xenproject.org Date: Mon, 27 May 2019 16:31:22 +0800 Message-Id: <1558945891-3015-2-git-send-email-chao.gao@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1558945891-3015-1-git-send-email-chao.gao@intel.com> References: <1558945891-3015-1-git-send-email-chao.gao@intel.com> Subject: [Xen-devel] [PATCH v7 01/10] misc/xen-ucode: Upload a microcode blob to the hypervisor X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Sergey Dyasli , Ashok Raj , Wei Liu , Konrad Rzeszutek Wilk , Ian Jackson , Chao Gao MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" This patch provides a tool for late microcode update. Signed-off-by: Konrad Rzeszutek Wilk Signed-off-by: Chao Gao Acked-by: Andrew Cooper --- Changes in v7: - introduce xc_microcode_update() rather than xc_platform_op() - avoid creating bounce buffer twice - rename xenmicrocode to xen-ucode, following naming tradition of other tools there. --- tools/libxc/include/xenctrl.h | 1 + tools/libxc/xc_misc.c | 23 +++++++++++++ tools/misc/Makefile | 4 +++ tools/misc/xen-ucode.c | 78 +++++++++++++++++++++++++++++++++++++++= ++++ 4 files changed, 106 insertions(+) create mode 100644 tools/misc/xen-ucode.c diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index 538007a..6d80ae5 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -1244,6 +1244,7 @@ typedef uint32_t xc_node_to_node_dist_t; 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_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/libxc/xc_misc.c b/tools/libxc/xc_misc.c index 5e6714a..85538e0 100644 --- a/tools/libxc/xc_misc.c +++ b/tools/libxc/xc_misc.c @@ -226,6 +226,29 @@ int xc_physinfo(xc_interface *xch, return 0; } =20 +int xc_microcode_update(xc_interface *xch, const void *buf, size_t len) +{ + int ret; + DECLARE_PLATFORM_OP; + DECLARE_HYPERCALL_BUFFER(struct xenpf_microcode_update, uc); + + uc =3D xc_hypercall_buffer_alloc(xch, uc, len); + if (uc =3D=3D NULL) + return -1; + + memcpy(uc, buf, len); + + platform_op.cmd =3D XENPF_microcode_update; + platform_op.u.microcode.length =3D len; + set_xen_guest_handle(platform_op.u.microcode.data, uc); + + ret =3D do_platform_op(xch, &platform_op); + + xc_hypercall_buffer_free(xch, uc); + + return ret; +} + int xc_cputopoinfo(xc_interface *xch, unsigned *max_cpus, xc_cputopo_t *cputopo) { diff --git a/tools/misc/Makefile b/tools/misc/Makefile index d4320dc..63947bf 100644 --- a/tools/misc/Makefile +++ b/tools/misc/Makefile @@ -22,6 +22,7 @@ INSTALL_SBIN-$(CONFIG_X86) +=3D xen-hvmcrash INSTALL_SBIN-$(CONFIG_X86) +=3D xen-hvmctx INSTALL_SBIN-$(CONFIG_X86) +=3D xen-lowmemd INSTALL_SBIN-$(CONFIG_X86) +=3D xen-mfndump +INSTALL_SBIN-$(CONFIG_X86) +=3D xen-ucode INSTALL_SBIN +=3D xencov INSTALL_SBIN +=3D xenlockprof INSTALL_SBIN +=3D xenperf @@ -113,4 +114,7 @@ xen-lowmemd: xen-lowmemd.o xencov: xencov.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) =20 +xen-ucode: xen-ucode.o + $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) + -include $(DEPS_INCLUDE) diff --git a/tools/misc/xen-ucode.c b/tools/misc/xen-ucode.c new file mode 100644 index 0000000..da668ca --- /dev/null +++ b/tools/misc/xen-ucode.c @@ -0,0 +1,78 @@ +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void show_help(void) +{ + fprintf(stderr, + "xenmicrocode: Xen microcode updating tool\n" + "Usage: xenmicrocode \n"); +} + +int main(int argc, char *argv[]) +{ + int fd, len, ret; + char *filename, *buf; + struct stat st; + xc_interface *xch; + + if (argc < 2) + { + show_help(); + return 0; + } + + filename =3D argv[1]; + fd =3D open(filename, O_RDONLY); + if (fd < 0) { + fprintf(stderr, "Could not open %s. (err: %s)\n", + filename, strerror(errno)); + return errno; + } + + if (stat(filename, &st) !=3D 0) { + fprintf(stderr, "Could not get the size of %s. (err: %s)\n", + filename, strerror(errno)); + return errno; + } + + len =3D st.st_size; + buf =3D mmap(0, len, PROT_READ, MAP_PRIVATE, fd, 0); + if (buf =3D=3D MAP_FAILED) { + fprintf(stderr, "mmap failed. (error: %s)\n", strerror(errno)); + return errno; + } + + xch =3D xc_interface_open(0,0,0); + if (xch =3D=3D NULL) + { + fprintf(stderr, "Error opening xc interface. (err: %s)\n", + strerror(errno)); + return errno; + } + + ret =3D xc_microcode_update(xch, buf, len); + if (ret) + fprintf(stderr, "Failed to update microcode. (err: %s)\n", + strerror(errno)); + + xc_interface_close(xch); + + if (munmap(buf, len)) { + printf("Could not unmap: %d(%s)\n", errno, strerror(errno)); + return errno; + } + close(fd); + + return 0; +} --=20 1.8.3.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel