[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



On Mon, Mar 11, 2019 at 03:57:25PM +0800, 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 
> +++++++++++++++++++++++++++++++++++++++++++

Would you mind naming the tool xen-ucode or xen-microcode?

That seems more inline with the naming schemed used for most of the
tools in misc/.

> +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;
> +    }

IMO you could just use fread to read the full contents of the file
into the buffer you allocate and avoid this mmap dance.

Thanks, Roger.

_______________________________________________
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®.