vtophys: fix vfio dma unmap range

We were passing a map structure to unmap ioctl,
where we should obviously pass an unmap structure
instead.

Due to how map/unmap structures are, we were
unmapping much more memory than necessary on pci
hotremove.

Change-Id: Iabbea4b277228dc3de300849f751202f42bded2b
Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/421693
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Dariusz Stojaczyk 2018-08-09 09:48:32 +02:00 committed by Changpeng Liu
parent 701978abab
commit ba00a42d27

View File

@ -69,6 +69,7 @@ int pci_vfio_is_enabled(void);
struct spdk_vfio_dma_map {
struct vfio_iommu_type1_dma_map map;
struct vfio_iommu_type1_dma_unmap unmap;
TAILQ_ENTRY(spdk_vfio_dma_map) tailq;
};
@ -129,6 +130,11 @@ vtophys_iommu_map_dma(uint64_t vaddr, uint64_t iova, uint64_t size)
dma_map->map.iova = iova;
dma_map->map.size = size;
dma_map->unmap.argsz = sizeof(dma_map->unmap);
dma_map->unmap.flags = 0;
dma_map->unmap.iova = iova;
dma_map->unmap.size = size;
pthread_mutex_lock(&g_vfio.mutex);
if (g_vfio.device_ref == 0) {
/* VFIO requires at least one device (IOMMU group) to be added to
@ -165,7 +171,6 @@ out_insert:
static int
vtophys_iommu_unmap_dma(uint64_t iova, uint64_t size)
{
struct vfio_iommu_type1_dma_unmap dma_unmap;
struct spdk_vfio_dma_map *dma_map;
int ret;
@ -190,12 +195,8 @@ vtophys_iommu_unmap_dma(uint64_t iova, uint64_t size)
goto out_remove;
}
dma_unmap.argsz = sizeof(dma_unmap);
dma_unmap.flags = 0;
dma_unmap.iova = iova;
dma_unmap.size = size;
ret = ioctl(g_vfio.fd, VFIO_IOMMU_UNMAP_DMA, &dma_unmap);
ret = ioctl(g_vfio.fd, VFIO_IOMMU_UNMAP_DMA, &dma_map->unmap);
if (ret) {
DEBUG_PRINT("Cannot clear DMA mapping, error %d\n", errno);
pthread_mutex_unlock(&g_vfio.mutex);
@ -586,7 +587,7 @@ spdk_vtophys_pci_device_removed(struct rte_pci_device *pci_device)
* of other, external factors.
*/
TAILQ_FOREACH(dma_map, &g_vfio.maps, tailq) {
ret = ioctl(g_vfio.fd, VFIO_IOMMU_UNMAP_DMA, &dma_map->map);
ret = ioctl(g_vfio.fd, VFIO_IOMMU_UNMAP_DMA, &dma_map->unmap);
if (ret) {
DEBUG_PRINT("Cannot unmap DMA memory, error %d\n", errno);
break;