From ea364da63858a9f6024b5abf8b4856f12b6ea822 Mon Sep 17 00:00:00 2001 From: Changpeng Liu Date: Tue, 27 Oct 2020 23:19:15 -0400 Subject: [PATCH] env/memory: use stack variable when unmapping the dma region When enable Werror compile option with new kernel(v5.8), there is following error reported due to the data structure change(added a uint8_t data[] variable in new kernel), we can just put the 'unmap' at the end of the data structure to fix the issue, I think it's better to just use a stack variable instead. CC lib/env_dpdk/memory.o memory.c:63:36: error: field 'unmap' with variable sized type 'struct vfio_iommu_type1_dma_unmap' not at the end of a struct or class is a GNU extension [-Werror,-Wgnu-variable-sized-type-not-at-end] struct vfio_iommu_type1_dma_unmap unmap; ^ 1 error generated. Signed-off-by: Changpeng Liu Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/4925 (master) (cherry picked from commit 2c9b5b5af5e4794a3eb3204923c3ca3eb307f386) Change-Id: Icf73a3c48a301e74b92b9ae2e2d8715262b2d056 Signed-off-by: Tomasz Zawadzki Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/4938 Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto Reviewed-by: Aleksey Marchuk Tested-by: SPDK CI Jenkins --- lib/env_dpdk/memory.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/env_dpdk/memory.c b/lib/env_dpdk/memory.c index 8670c30ec..84dd81f2e 100644 --- a/lib/env_dpdk/memory.c +++ b/lib/env_dpdk/memory.c @@ -60,7 +60,6 @@ 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; }; @@ -820,11 +819,6 @@ 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 @@ -865,6 +859,7 @@ vtophys_iommu_unmap_dma(uint64_t iova, uint64_t size) struct spdk_vfio_dma_map *dma_map; uint64_t refcount; int ret; + struct vfio_iommu_type1_dma_unmap unmap = {}; pthread_mutex_lock(&g_vfio.mutex); TAILQ_FOREACH(dma_map, &g_vfio.maps, tailq) { @@ -899,8 +894,11 @@ vtophys_iommu_unmap_dma(uint64_t iova, uint64_t size) goto out_remove; } - - ret = ioctl(g_vfio.fd, VFIO_IOMMU_UNMAP_DMA, &dma_map->unmap); + unmap.argsz = sizeof(unmap); + unmap.flags = 0; + unmap.iova = dma_map->map.iova; + unmap.size = dma_map->map.size; + ret = ioctl(g_vfio.fd, VFIO_IOMMU_UNMAP_DMA, &unmap); if (ret) { DEBUG_PRINT("Cannot clear DMA mapping, error %d\n", errno); pthread_mutex_unlock(&g_vfio.mutex); @@ -1383,7 +1381,12 @@ 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->unmap); + struct vfio_iommu_type1_dma_unmap unmap = {}; + unmap.argsz = sizeof(unmap); + unmap.flags = 0; + unmap.iova = dma_map->map.iova; + unmap.size = dma_map->map.size; + ret = ioctl(g_vfio.fd, VFIO_IOMMU_UNMAP_DMA, &unmap); if (ret) { DEBUG_PRINT("Cannot unmap DMA memory, error %d\n", errno); break;