[dpdk-stable] patch 'vfio: fix DMA mapping granularity for IOVA as VA' has been queued to stable release 19.11.9

Christian Ehrhardt christian.ehrhardt at canonical.com
Mon May 17 18:07:11 CEST 2021


Hi,

FYI, your patch has been queued to stable release 19.11.9

Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 05/19/21. So please
shout if anyone has objections.

Also note that after the patch there's a diff of the upstream commit vs the
patch applied to the branch. This will indicate if there was any rebasing
needed to apply to the stable branch. If there were code changes for rebasing
(ie: not only metadata diffs), please double check that the rebase was
correctly done.

Queued patches are on a temporary branch at:
https://github.com/cpaelzer/dpdk-stable-queue

This queued commit can be viewed at:
https://github.com/cpaelzer/dpdk-stable-queue/commit/fd3a70f1b26cc21cb43c21d1bbb834feee088ee7

Thanks.

Christian Ehrhardt <christian.ehrhardt at canonical.com>

---
>From fd3a70f1b26cc21cb43c21d1bbb834feee088ee7 Mon Sep 17 00:00:00 2001
From: Nithin Dabilpuram <ndabilpuram at marvell.com>
Date: Fri, 15 Jan 2021 13:02:42 +0530
Subject: [PATCH] vfio: fix DMA mapping granularity for IOVA as VA

[ upstream commit c13ca4e81cac591904c893a65ffbbf446af0268a ]

Partial unmapping is not supported for VFIO IOMMU type1
by kernel. Though kernel gives return as zero, the unmapped size
returned will not be same as expected. So check for
returned unmap size and return error.

For IOVA as PA, DMA mapping is already at memseg size
granularity. Do the same even for IOVA as VA mode as
DMA map/unmap triggered by heap allocations,
maintain granularity of memseg page size so that heap
expansion and contraction does not have this issue.

For user requested DMA map/unmap disallow partial unmapping
for VFIO type1.

Fixes: 73a639085938 ("vfio: allow to map other memory regions")

Signed-off-by: Nithin Dabilpuram <ndabilpuram at marvell.com>
Acked-by: Anatoly Burakov <anatoly.burakov at intel.com>
Acked-by: David Christensen <drc at linux.vnet.ibm.com>
---
 lib/librte_eal/linux/eal/eal_vfio.c | 34 ++++++++++++++++++++++++-----
 lib/librte_eal/linux/eal/eal_vfio.h |  1 +
 2 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/lib/librte_eal/linux/eal/eal_vfio.c b/lib/librte_eal/linux/eal/eal_vfio.c
index 5e6101d9a9..25992ae92f 100644
--- a/lib/librte_eal/linux/eal/eal_vfio.c
+++ b/lib/librte_eal/linux/eal/eal_vfio.c
@@ -69,6 +69,7 @@ static const struct vfio_iommu_type iommu_types[] = {
 	{
 		.type_id = RTE_VFIO_TYPE1,
 		.name = "Type 1",
+		.partial_unmap = false,
 		.dma_map_func = &vfio_type1_dma_map,
 		.dma_user_map_func = &vfio_type1_dma_mem_map
 	},
@@ -76,6 +77,7 @@ static const struct vfio_iommu_type iommu_types[] = {
 	{
 		.type_id = RTE_VFIO_SPAPR,
 		.name = "sPAPR",
+		.partial_unmap = true,
 		.dma_map_func = &vfio_spapr_dma_map,
 		.dma_user_map_func = &vfio_spapr_dma_mem_map
 	},
@@ -83,6 +85,7 @@ static const struct vfio_iommu_type iommu_types[] = {
 	{
 		.type_id = RTE_VFIO_NOIOMMU,
 		.name = "No-IOMMU",
+		.partial_unmap = true,
 		.dma_map_func = &vfio_noiommu_dma_map,
 		.dma_user_map_func = &vfio_noiommu_dma_mem_map
 	},
@@ -523,12 +526,19 @@ vfio_mem_event_callback(enum rte_mem_event type, const void *addr, size_t len,
 	/* for IOVA as VA mode, no need to care for IOVA addresses */
 	if (rte_eal_iova_mode() == RTE_IOVA_VA && msl->external == 0) {
 		uint64_t vfio_va = (uint64_t)(uintptr_t)addr;
-		if (type == RTE_MEM_EVENT_ALLOC)
-			vfio_dma_mem_map(default_vfio_cfg, vfio_va, vfio_va,
-					len, 1);
-		else
-			vfio_dma_mem_map(default_vfio_cfg, vfio_va, vfio_va,
-					len, 0);
+		uint64_t page_sz = msl->page_sz;
+
+		/* Maintain granularity of DMA map/unmap to memseg size */
+		for (; cur_len < len; cur_len += page_sz) {
+			if (type == RTE_MEM_EVENT_ALLOC)
+				vfio_dma_mem_map(default_vfio_cfg, vfio_va,
+						 vfio_va, page_sz, 1);
+			else
+				vfio_dma_mem_map(default_vfio_cfg, vfio_va,
+						 vfio_va, page_sz, 0);
+			vfio_va += page_sz;
+		}
+
 		return;
 	}
 
@@ -1340,6 +1350,12 @@ vfio_type1_dma_mem_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova,
 			RTE_LOG(ERR, EAL, "  cannot clear DMA remapping, error %i (%s)\n",
 					errno, strerror(errno));
 			return -1;
+		} else if (dma_unmap.size != len) {
+			RTE_LOG(ERR, EAL, "  unexpected size %"PRIu64" of DMA "
+				"remapping cleared instead of %"PRIu64"\n",
+				(uint64_t)dma_unmap.size, len);
+			rte_errno = EIO;
+			return -1;
 		}
 	}
 
@@ -1810,6 +1826,12 @@ container_dma_unmap(struct vfio_config *vfio_cfg, uint64_t vaddr, uint64_t iova,
 		/* we're partially unmapping a previously mapped region, so we
 		 * need to split entry into two.
 		 */
+		if (!vfio_cfg->vfio_iommu_type->partial_unmap) {
+			RTE_LOG(DEBUG, EAL, "DMA partial unmap unsupported\n");
+			rte_errno = ENOTSUP;
+			ret = -1;
+			goto out;
+		}
 		if (user_mem_maps->n_maps == VFIO_MAX_USER_MEM_MAPS) {
 			RTE_LOG(ERR, EAL, "Not enough space to store partial mapping\n");
 			rte_errno = ENOMEM;
diff --git a/lib/librte_eal/linux/eal/eal_vfio.h b/lib/librte_eal/linux/eal/eal_vfio.h
index cb2d35fb12..6ebaca6a0c 100644
--- a/lib/librte_eal/linux/eal/eal_vfio.h
+++ b/lib/librte_eal/linux/eal/eal_vfio.h
@@ -113,6 +113,7 @@ typedef int (*vfio_dma_user_func_t)(int fd, uint64_t vaddr, uint64_t iova,
 struct vfio_iommu_type {
 	int type_id;
 	const char *name;
+	bool partial_unmap;
 	vfio_dma_user_func_t dma_user_map_func;
 	vfio_dma_func_t dma_map_func;
 };
-- 
2.31.1

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2021-05-17 17:40:29.684675350 +0200
+++ 0002-vfio-fix-DMA-mapping-granularity-for-IOVA-as-VA.patch	2021-05-17 17:40:29.091808846 +0200
@@ -1 +1 @@
-From c13ca4e81cac591904c893a65ffbbf446af0268a Mon Sep 17 00:00:00 2001
+From fd3a70f1b26cc21cb43c21d1bbb834feee088ee7 Mon Sep 17 00:00:00 2001
@@ -5,0 +6,2 @@
+[ upstream commit c13ca4e81cac591904c893a65ffbbf446af0268a ]
+
@@ -21 +22,0 @@
-Cc: stable at dpdk.org
@@ -27,2 +28,2 @@
- lib/librte_eal/linux/eal_vfio.c | 34 +++++++++++++++++++++++++++------
- lib/librte_eal/linux/eal_vfio.h |  1 +
+ lib/librte_eal/linux/eal/eal_vfio.c | 34 ++++++++++++++++++++++++-----
+ lib/librte_eal/linux/eal/eal_vfio.h |  1 +
@@ -31,5 +32,5 @@
-diff --git a/lib/librte_eal/linux/eal_vfio.c b/lib/librte_eal/linux/eal_vfio.c
-index 64b134d530..b15b75882b 100644
---- a/lib/librte_eal/linux/eal_vfio.c
-+++ b/lib/librte_eal/linux/eal_vfio.c
-@@ -70,6 +70,7 @@ static const struct vfio_iommu_type iommu_types[] = {
+diff --git a/lib/librte_eal/linux/eal/eal_vfio.c b/lib/librte_eal/linux/eal/eal_vfio.c
+index 5e6101d9a9..25992ae92f 100644
+--- a/lib/librte_eal/linux/eal/eal_vfio.c
++++ b/lib/librte_eal/linux/eal/eal_vfio.c
+@@ -69,6 +69,7 @@ static const struct vfio_iommu_type iommu_types[] = {
@@ -43 +44 @@
-@@ -77,6 +78,7 @@ static const struct vfio_iommu_type iommu_types[] = {
+@@ -76,6 +77,7 @@ static const struct vfio_iommu_type iommu_types[] = {
@@ -51 +52 @@
-@@ -84,6 +86,7 @@ static const struct vfio_iommu_type iommu_types[] = {
+@@ -83,6 +85,7 @@ static const struct vfio_iommu_type iommu_types[] = {
@@ -59 +60 @@
-@@ -526,12 +529,19 @@ vfio_mem_event_callback(enum rte_mem_event type, const void *addr, size_t len,
+@@ -523,12 +526,19 @@ vfio_mem_event_callback(enum rte_mem_event type, const void *addr, size_t len,
@@ -85 +86 @@
-@@ -1348,6 +1358,12 @@ vfio_type1_dma_mem_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova,
+@@ -1340,6 +1350,12 @@ vfio_type1_dma_mem_map(int vfio_container_fd, uint64_t vaddr, uint64_t iova,
@@ -98 +99 @@
-@@ -1823,6 +1839,12 @@ container_dma_unmap(struct vfio_config *vfio_cfg, uint64_t vaddr, uint64_t iova,
+@@ -1810,6 +1826,12 @@ container_dma_unmap(struct vfio_config *vfio_cfg, uint64_t vaddr, uint64_t iova,
@@ -111 +112 @@
-diff --git a/lib/librte_eal/linux/eal_vfio.h b/lib/librte_eal/linux/eal_vfio.h
+diff --git a/lib/librte_eal/linux/eal/eal_vfio.h b/lib/librte_eal/linux/eal/eal_vfio.h
@@ -113,2 +114,2 @@
---- a/lib/librte_eal/linux/eal_vfio.h
-+++ b/lib/librte_eal/linux/eal_vfio.h
+--- a/lib/librte_eal/linux/eal/eal_vfio.h
++++ b/lib/librte_eal/linux/eal/eal_vfio.h


More information about the stable mailing list