[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 10/11] vfio-pci: Allow mmap of MSIX BAR
From: |
Alex Williamson |
Subject: |
[Qemu-devel] [PULL 10/11] vfio-pci: Allow mmap of MSIX BAR |
Date: |
Tue, 13 Mar 2018 14:19:01 -0600 |
User-agent: |
StGit/0.18-102-gdf9f |
From: Alexey Kardashevskiy <address@hidden>
At the moment we unconditionally avoid mapping MSIX data of a BAR and
emulate MSIX table in QEMU. However it is 1) not always necessary as
a platform may provide a paravirt interface for MSIX configuration;
2) can affect the speed of MMIO access by emulating them in QEMU when
frequently accessed registers share same system page with MSIX data,
this is particularly a problem for systems with the page size bigger
than 4KB.
A new capability - VFIO_REGION_INFO_CAP_MSIX_MAPPABLE - has been added
to the kernel [1] which tells the userspace that mapping of the MSIX data
is possible now. This makes use of it so from now on QEMU tries mapping
the entire BAR as a whole and emulate MSIX on top of that.
[1]
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a32295c612c57990d17fb0f41e7134394b2f35f6
Signed-off-by: Alexey Kardashevskiy <address@hidden>
Reviewed-by: David Gibson <address@hidden>
Signed-off-by: Alex Williamson <address@hidden>
---
hw/vfio/common.c | 15 +++++++++++++++
hw/vfio/pci.c | 9 +++++++++
include/hw/vfio/vfio-common.h | 1 +
3 files changed, 25 insertions(+)
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 07c03d78b666..5e8471621800 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -1471,6 +1471,21 @@ int vfio_get_dev_region_info(VFIODevice *vbasedev,
uint32_t type,
return -ENODEV;
}
+bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_type)
+{
+ struct vfio_region_info *info = NULL;
+ bool ret = false;
+
+ if (!vfio_get_region_info(vbasedev, region, &info)) {
+ if (vfio_get_region_info_cap(info, cap_type)) {
+ ret = true;
+ }
+ g_free(info);
+ }
+
+ return ret;
+}
+
/*
* Interfaces for IBM EEH (Enhanced Error Handling)
*/
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index b9d2c12b8273..02974f4eb976 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -1294,6 +1294,15 @@ static void vfio_pci_fixup_msix_region(VFIOPCIDevice
*vdev)
off_t start, end;
VFIORegion *region = &vdev->bars[vdev->msix->table_bar].region;
+ /*
+ * If the host driver allows mapping of a MSIX data, we are going to
+ * do map the entire BAR and emulate MSIX table on top of that.
+ */
+ if (vfio_has_region_cap(&vdev->vbasedev, region->nr,
+ VFIO_REGION_INFO_CAP_MSIX_MAPPABLE)) {
+ return;
+ }
+
/*
* We expect to find a single mmap covering the whole BAR, anything else
* means it's either unsupported or already setup.
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index c5efa32750e7..d9360148e6a7 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -193,6 +193,7 @@ int vfio_get_region_info(VFIODevice *vbasedev, int index,
struct vfio_region_info **info);
int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type,
uint32_t subtype, struct vfio_region_info **info);
+bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_type);
#endif
extern const MemoryListener vfio_prereg_listener;
- [Qemu-devel] [PULL 00/11] vfio updates for QEMU-2.12 soft freeze, Alex Williamson, 2018/03/13
- [Qemu-devel] [PULL 01/11] standard-headers: add drm/drm_fourcc.h, Alex Williamson, 2018/03/13
- [Qemu-devel] [PULL 02/11] ui/pixman: add qemu_drm_format_to_pixman(), Alex Williamson, 2018/03/13
- [Qemu-devel] [PULL 03/11] console: minimal hotplug suport, Alex Williamson, 2018/03/13
- [Qemu-devel] [PULL 04/11] secondary-vga: properly close QemuConsole on unplug, Alex Williamson, 2018/03/13
- [Qemu-devel] [PULL 05/11] vfio/common: cleanup in vfio_region_finalize, Alex Williamson, 2018/03/13
- [Qemu-devel] [PULL 06/11] vfio/display: core & wireup, Alex Williamson, 2018/03/13
- [Qemu-devel] [PULL 07/11] vfio/display: adding region support, Alex Williamson, 2018/03/13
- [Qemu-devel] [PULL 08/11] vfio/display: adding dmabuf support, Alex Williamson, 2018/03/13
- [Qemu-devel] [PULL 09/11] vfio/pci: Relax DMA map errors for MMIO regions, Alex Williamson, 2018/03/13
- [Qemu-devel] [PULL 10/11] vfio-pci: Allow mmap of MSIX BAR,
Alex Williamson <=
- [Qemu-devel] [PULL 11/11] ppc/spapr, vfio: Turn off MSIX emulation for VFIO devices, Alex Williamson, 2018/03/13
- Re: [Qemu-devel] [PULL 00/11] vfio updates for QEMU-2.12 soft freeze, Peter Maydell, 2018/03/16