[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH v6 01/12] misc/xenmicrocode: Upload a microcode blob to the hypervisor


  • To: Chao Gao <chao.gao@xxxxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Sergey Dyasli <sergey.dyasli@xxxxxxxxxx>
  • Date: Mon, 25 Mar 2019 09:38:21 +0000
  • Autocrypt: addr=sergey.dyasli@xxxxxxxxxx; keydata= mQINBFtMVHEBEADc/hZcLexrB6vGTdGqEUsYZkFGQh6Z1OO7bCtM1go1RugSMeq9tkFHQSOc 9c7W9NVQqLgn8eefikIHxgic6tGgKoIQKcPuSsnqGao2YabsTSSoeatvmO5HkR0xGaUd+M6j iqv3cD7/WL602NhphT4ucKXCz93w0TeoJ3gleLuILxmzg1gDhKtMdkZv6TngWpKgIMRfoyHQ jsVzPbTTjJl/a9Cw99vuhFuEJfzbLA80hCwhoPM+ZQGFDcG4c25GQGQFFatpbQUhNirWW5b1 r2yVOziSJsvfTLnyzEizCvU+r/Ek2Kh0eAsRFr35m2X+X3CfxKrZcePxzAf273p4nc3YIK9h cwa4ZpDksun0E2l0pIxg/pPBXTNbH+OX1I+BfWDZWlPiPxgkiKdgYPS2qv53dJ+k9x6HkuCy i61IcjXRtVgL5nPGakyOFQ+07S4HIJlw98a6NrptWOFkxDt38x87mSM7aSWp1kjyGqQTGoKB VEx5BdRS5gFdYGCQFc8KVGEWPPGdeYx9Pj2wTaweKV0qZT69lmf/P5149Pc81SRhuc0hUX9K DnYBa1iSHaDjifMsNXKzj8Y8zVm+J6DZo/D10IUxMuExvbPa/8nsertWxoDSbWcF1cyvZp9X tUEukuPoTKO4Vzg7xVNj9pbK9GPxSYcafJUgDeKEIlkn3iVIPwARAQABtChTZXJnZXkgRHlh c2xpIDxzZXJnZXkuZHlhc2xpQGNpdHJpeC5jb20+iQJOBBMBCgA4FiEEkI7HMI5EbM2FLA1L Aa+w5JvbyusFAltMVHECGwMFCwkI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/kx+fyzVyEioLSwkjDvdG++4GQ5r6PHQ7BbdEWhA==
  • Cc: "sergey.dyasli@xxxxxxxxxx >> Sergey Dyasli" <sergey.dyasli@xxxxxxxxxx>, Wei Liu <wei.liu2@xxxxxxxxxx>, Ashok Raj <ashok.raj@xxxxxxxxx>, Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>, Ian Jackson <ian.jackson@xxxxxxxxxxxxx>, Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Delivery-date: Mon, 25 Mar 2019 09:38:32 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Openpgp: preference=signencrypt

On 11/03/2019 07:57, Chao Gao wrote:
> This patch provides a tool for late microcode update.
> 
> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>
> Signed-off-by: Chao Gao <chao.gao@xxxxxxxxx>
> ---
>  tools/libxc/include/xenctrl.h |  1 +
>  tools/libxc/xc_misc.c         | 20 ++++++++++
>  tools/misc/Makefile           |  4 ++
>  tools/misc/xenmicrocode.c     | 89 
> +++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 114 insertions(+)
>  create mode 100644 tools/misc/xenmicrocode.c
> 
> diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h
> index 31cdda7..c69699b 100644
> --- a/tools/libxc/include/xenctrl.h
> +++ b/tools/libxc/include/xenctrl.h
> @@ -1245,6 +1245,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_platform_op(xc_interface *xch, struct xen_platform_op *op);
>  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..061c7a5 100644
> --- a/tools/libxc/xc_misc.c
> +++ b/tools/libxc/xc_misc.c
> @@ -226,6 +226,26 @@ int xc_physinfo(xc_interface *xch,
>      return 0;
>  }
>  
> +int xc_platform_op(xc_interface *xch, struct xen_platform_op *op)
> +{
> +    int ret = 0;
> +    DECLARE_PLATFORM_OP;
> +    DECLARE_HYPERCALL_BOUNCE(op, sizeof(*op), 
> XC_HYPERCALL_BUFFER_BOUNCE_BOTH);

So I've found that the bouncing in this function is not needed.
In fact, it gets in a way when Xen is returning information via xen_platform_op.
I ended up having only the single line in this function:

        return do_platform_op(xch, op);

Not sure how correct this is, but it seems to work for ucode application and
XENPF_get_cpu_version.

Thanks,
Sergey

> +
> +    if ( xc_hypercall_bounce_pre(xch, op) )
> +    {
> +        PERROR("Could not bounce xen_platform_op memory buffer");
> +        return -1;
> +    }
> +    op->interface_version = XENPF_INTERFACE_VERSION;
> +
> +    platform_op = *op;
> +    ret = do_platform_op(xch, &platform_op);
> +    xc_hypercall_bounce_post(xch, op);
> +
> +    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 51adb6f..c297a75 100644
> --- a/tools/misc/Makefile
> +++ b/tools/misc/Makefile
> @@ -22,6 +22,7 @@ INSTALL_SBIN-$(CONFIG_X86)     += xen-hvmcrash
>  INSTALL_SBIN-$(CONFIG_X86)     += xen-hvmctx
>  INSTALL_SBIN-$(CONFIG_X86)     += xen-lowmemd
>  INSTALL_SBIN-$(CONFIG_X86)     += xen-mfndump
> +INSTALL_SBIN-$(CONFIG_X86)     += xenmicrocode
>  INSTALL_SBIN                   += xen-tmem-list-parse
>  INSTALL_SBIN                   += xencov
>  INSTALL_SBIN                   += xenlockprof
> @@ -114,4 +115,7 @@ xen-lowmemd: xen-lowmemd.o
>  xencov: xencov.o
>       $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
>  
> +xenmicrocode: xenmicrocode.o
> +     $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
> +
>  -include $(DEPS_INCLUDE)
> diff --git a/tools/misc/xenmicrocode.c b/tools/misc/xenmicrocode.c
> new file mode 100644
> index 0000000..e6c8a3d
> --- /dev/null
> +++ b/tools/misc/xenmicrocode.c
> @@ -0,0 +1,89 @@
> +#define _GNU_SOURCE
> +
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <sys/mman.h>
> +#include <errno.h>
> +#include <string.h>
> +#include <inttypes.h>
> +#include <unistd.h>
> +#include <sys/types.h>
> +#include <sys/stat.h>
> +#include <fcntl.h>
> +#include <xenctrl.h>
> +
> +void show_help(void)
> +{
> +    fprintf(stderr,
> +            "xenmicrocode: Xen microcode updating tool\n"
> +            "Usage: xenmicrocode <microcode blob>\n");
> +}
> +
> +int main(int argc, char *argv[])
> +{
> +    int fd, len, ret;
> +    char *filename, *buf;
> +    struct stat st;
> +    struct xen_platform_op op;
> +    xc_interface *xch;
> +    DECLARE_HYPERCALL_BUFFER(struct xenpf_microcode_update, uc);
> +
> +    if (argc < 2)
> +    {
> +        show_help();
> +        return 0;
> +    }
> +
> +    filename = argv[1];
> +    fd = 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) != 0) {
> +        fprintf(stderr, "Could not get the size of %s. (err: %s)\n",
> +                filename, strerror(errno));
> +        return errno;
> +    }
> +
> +    len = st.st_size;
> +    buf = mmap(0, len, PROT_READ, MAP_PRIVATE, fd, 0);
> +    if (buf == MAP_FAILED) {
> +        fprintf(stderr, "mmap failed. (error: %s)\n", strerror(errno));
> +        return errno;
> +    }
> +
> +    xch = xc_interface_open(0,0,0);
> +    if (xch == NULL)
> +    {
> +        fprintf(stderr, "Error opening xc interface. (err: %s)\n",
> +                strerror(errno));
> +        return errno;
> +    }
> +
> +    uc = xc_hypercall_buffer_alloc(xch, uc, len);
> +    if (uc == NULL)
> +        return -1;
> +
> +    memcpy(uc, buf, len);
> +    set_xen_guest_handle(op.u.microcode.data, uc);
> +    op.cmd = XENPF_microcode_update;
> +    op.interface_version = XENPF_INTERFACE_VERSION;
> +    op.u.microcode.length = len;
> +    ret = xc_platform_op(xch, &op);
> +    if ( ret )
> +        fprintf(stderr, "Failed to update microcode. (err: %d)\n", ret);
> +
> +    xc_hypercall_buffer_free(xch, uc);
> +    xc_interface_close(xch);
> +
> +    if (munmap(buf, len)) {
> +        printf("Could not unmap: %d(%s)\n", errno, strerror(errno));
> +        return errno;
> +    }
> +    close(fd);
> +
> +    return 0;
> +}
> 

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.