qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH v4 2/9] util: Introduce vfio helpers


From: Alex Williamson
Subject: Re: [Qemu-devel] [PATCH v4 2/9] util: Introduce vfio helpers
Date: Wed, 10 Jan 2018 13:09:56 -0700

On Wed, 10 Jan 2018 17:18:39 +0800
Fam Zheng <address@hidden> wrote:

> This is a library to manage the host vfio interface, which could be used
> to implement userspace device driver code in QEMU such as NVMe or net
> controllers.
> 
> Signed-off-by: Fam Zheng <address@hidden>
> ---
>  include/qemu/vfio-helpers.h |  30 ++
>  util/Makefile.objs          |   1 +
>  util/trace-events           |  11 +
>  util/vfio-helpers.c         | 723 
> ++++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 765 insertions(+)
>  create mode 100644 include/qemu/vfio-helpers.h
>  create mode 100644 util/vfio-helpers.c
> 
> diff --git a/include/qemu/vfio-helpers.h b/include/qemu/vfio-helpers.h
> new file mode 100644
> index 0000000000..6bdba3b66e
> --- /dev/null
> +++ b/include/qemu/vfio-helpers.h
...
> +/**
> + * Map a PCI bar area.
> + */
> +void *qemu_vfio_pci_map_bar(QEMUVFIOState *s, int index, Error **errp)
> +{
> +    void *p;
> +    assert_bar_index_valid(s, index);
> +    p = mmap(NULL, MIN(8192, s->bar_region_info[index].size),
> +             PROT_READ | PROT_WRITE, MAP_SHARED,
> +             s->device, s->bar_region_info[index].offset);
> +    if (p == MAP_FAILED) {
> +        error_setg_errno(errp, errno, "Failed to map BAR region");
> +        p = NULL;
> +    }
> +    return p;
> +}
> +
> +/**
> + * Unmap a PCI bar area.
> + */
> +void qemu_vfio_pci_unmap_bar(QEMUVFIOState *s, int index, void *bar)
> +{
> +    if (bar) {
> +        munmap(bar, MIN(8192, s->bar_region_info[index].size));
> +    }
> +}

What's up with this 8KB thing?  Is it perhaps a hack to avoid
un-mmap'able MSI-X sections of the BAR, which would make this general
purpose library very specific to devices which only operate in the lower
8KB of their MMIO space.  Maybe the interface should have an offset and
size so that the NVMe driver could implement that dependency.  We could
also be testing if the region supports mmap, but I suppose trying and
failing is just as good.  Thanks,

Alex



reply via email to

[Prev in Thread] Current Thread [Next in Thread]