Spdk/lib/env_dpdk
Dariusz Stojaczyk 479134e9d4 vtophys: remap vfio dma memory when necessary
VFIO requires at least one IOMMU group to be added to the
VFIO container to be able to perform any IOMMU operations
on that container. [1] Without any groups added, VFIO_IOMMU_MAP_DMA
would always respond with errno 22 (Invalid argument).

Also, if the last IOMMU group is removed from the container
(device hotremove), all the IOMMU mappings are lost.

In both cases we need to remap vfio memory as soon as the
first IOMMU group is attached. The attach is done inside
DPDK during device attach and we can't hook into it directly.
Instead, this patch hooks into our PCI init/fini callbacks.
There's now a PCI device ref counter in our vfio manager and
a history of all registered memory pages. When the refcount
is increased from 0 to 1, the vtophys will remap all vfio
dma memory.

[1] https://www.kernel.org/doc/Documentation/vfio.txt
"On its own, the container provides little functionality,
with all but a couple version and extension query interfaces
locked away. The user needs to add a group into the container
for the next level of functionality.  [...] With a group
(or groups) attached to a container, the remaining ioctls
become available, enabling access to the VFIO IOMMU
interfaces."

Change-Id: I744e07043dbe7ffd433fc95d604dad39647675f4
Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/390655
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
2017-12-11 11:38:38 -05:00
..
env_internal.h vtophys: remap vfio dma memory when necessary 2017-12-11 11:38:38 -05:00
env.c env/dpdk: use rte_virt2iova instead of rte_virt2phys for DPDK 17.11 2017-11-15 17:52:05 -05:00
env.mk env/dpdk: compile with rte_pci and rte_bus_pci for DPDK 17.11-rc1 2017-11-15 17:52:05 -05:00
init.c env/dpdk: unlink hugepage_info and config files immediately for single process apps 2017-10-20 19:43:26 -04:00
Makefile env: add pci_virtio.c 2017-09-26 14:28:24 -04:00
memory.c env: Remove old translation reference counting 2017-09-01 15:25:24 -04:00
pci_ioat.c env: register PMDs on associated first probe 2017-03-06 12:44:34 -07:00
pci_nvme.c env: register PMDs on associated first probe 2017-03-06 12:44:34 -07:00
pci_virtio.c env: add pci_virtio.c 2017-09-26 14:28:24 -04:00
pci.c vtophys: remap vfio dma memory when necessary 2017-12-11 11:38:38 -05:00
threads.c env: Add wrappers to launch and wait for threads 2017-06-07 12:34:15 -04:00
vtophys.c vtophys: remap vfio dma memory when necessary 2017-12-11 11:38:38 -05:00