DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] net/ifcvf: fix DMA unmap
@ 2018-04-20 15:13 Xiao Wang
  2018-04-23 17:47 ` [dpdk-dev] [PATCH v2] " Xiao Wang
  0 siblings, 1 reply; 3+ messages in thread
From: Xiao Wang @ 2018-04-20 15:13 UTC (permalink / raw)
  To: ferruh.yigit; +Cc: dev, Xiao Wang

Besides the fix, this patch adds a toggle parameter to ifcvf_dma_map to
avoid code duplication.

Fixes: 7737386d1c22 ("net/ifcvf: add ifcvf vdpa driver")

Signed-off-by: Xiao Wang <xiao.w.wang@intel.com>
---
 drivers/net/ifc/ifcvf_vdpa.c | 55 +++++++++++++++-----------------------------
 1 file changed, 19 insertions(+), 36 deletions(-)

diff --git a/drivers/net/ifc/ifcvf_vdpa.c b/drivers/net/ifc/ifcvf_vdpa.c
index a2b3f0dbf..27316a99f 100644
--- a/drivers/net/ifc/ifcvf_vdpa.c
+++ b/drivers/net/ifc/ifcvf_vdpa.c
@@ -155,7 +155,7 @@ ifcvf_vfio_setup(struct ifcvf_internal *internal)
 }
 
 static int
-ifcvf_dma_map(struct ifcvf_internal *internal)
+ifcvf_dma_map(struct ifcvf_internal *internal, int do_map)
 {
 	uint32_t i;
 	int ret;
@@ -174,45 +174,28 @@ ifcvf_dma_map(struct ifcvf_internal *internal)
 		struct rte_vhost_mem_region *reg;
 
 		reg = &mem->regions[i];
-		DRV_LOG(INFO, "region %u: HVA 0x%" PRIx64 ", "
+		DRV_LOG(INFO, "%s, region %u: HVA 0x%" PRIx64 ", "
 			"GPA 0x%" PRIx64 ", size 0x%" PRIx64 ".",
-			i, reg->host_user_addr, reg->guest_phys_addr,
-			reg->size);
+			do_map ? "DMA map" : "DMA unmap", i,
+			reg->host_user_addr, reg->guest_phys_addr, reg->size);
 
-		rte_vfio_container_dma_map(vfio_container_fd,
+		if (do_map) {
+			ret = rte_vfio_container_dma_map(vfio_container_fd,
 				reg->host_user_addr, reg->guest_phys_addr,
 				reg->size);
-	}
-
-exit:
-	if (mem)
-		free(mem);
-	return ret;
-}
-
-static int
-ifcvf_dma_unmap(struct ifcvf_internal *internal)
-{
-	uint32_t i;
-	int ret = 0;
-	struct rte_vhost_memory *mem = NULL;
-	int vfio_container_fd;
-
-	ret = rte_vhost_get_mem_table(internal->vid, &mem);
-	if (ret < 0) {
-		DRV_LOG(ERR, "failed to get VM memory layout.");
-		goto exit;
-	}
-
-	vfio_container_fd = internal->vfio_container_fd;
-
-	for (i = 0; i < mem->nregions; i++) {
-		struct rte_vhost_mem_region *reg;
-
-		reg = &mem->regions[i];
-		rte_vfio_container_dma_map(vfio_container_fd,
+			if (ret < 0) {
+				DRV_LOG(ERR, "DMA map failed.");
+				goto exit;
+			}
+		} else {
+			ret = rte_vfio_container_dma_unmap(vfio_container_fd,
 				reg->host_user_addr, reg->guest_phys_addr,
 				reg->size);
+			if (ret < 0) {
+				DRV_LOG(ERR, "DMA unmap failed.");
+				goto exit;
+			}
+		}
 	}
 
 exit:
@@ -486,7 +469,7 @@ update_datapath(struct ifcvf_internal *internal)
 	if (!rte_atomic32_read(&internal->running) &&
 	    (rte_atomic32_read(&internal->started) &&
 	     rte_atomic32_read(&internal->dev_attached))) {
-		ret = ifcvf_dma_map(internal);
+		ret = ifcvf_dma_map(internal, 1);
 		if (ret)
 			goto err;
 
@@ -516,7 +499,7 @@ update_datapath(struct ifcvf_internal *internal)
 		if (ret)
 			goto err;
 
-		ret = ifcvf_dma_unmap(internal);
+		ret = ifcvf_dma_map(internal, 0);
 		if (ret)
 			goto err;
 
-- 
2.15.1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [dpdk-dev] [PATCH v2] net/ifcvf: fix DMA unmap
  2018-04-23 17:47 ` [dpdk-dev] [PATCH v2] " Xiao Wang
@ 2018-04-23 10:49   ` Ferruh Yigit
  0 siblings, 0 replies; 3+ messages in thread
From: Ferruh Yigit @ 2018-04-23 10:49 UTC (permalink / raw)
  To: Xiao Wang; +Cc: dev

On 4/23/2018 6:47 PM, Xiao Wang wrote:
> Besides the fix, this patch adds a toggle parameter to ifcvf_dma_map to
> avoid code duplication.
> 
> Fixes: 7b0c17368af2 ("net/ifcvf: add ifcvf vdpa driver")
> 
> Signed-off-by: Xiao Wang <xiao.w.wang@intel.com>
> ---
> v2:
> - It's the 7b0c17368af2 commit to be fixed.

Squashed into relevant commit in next-net, thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [dpdk-dev] [PATCH v2] net/ifcvf: fix DMA unmap
  2018-04-20 15:13 [dpdk-dev] [PATCH] net/ifcvf: fix DMA unmap Xiao Wang
@ 2018-04-23 17:47 ` Xiao Wang
  2018-04-23 10:49   ` Ferruh Yigit
  0 siblings, 1 reply; 3+ messages in thread
From: Xiao Wang @ 2018-04-23 17:47 UTC (permalink / raw)
  To: ferruh.yigit; +Cc: dev, Xiao Wang

Besides the fix, this patch adds a toggle parameter to ifcvf_dma_map to
avoid code duplication.

Fixes: 7b0c17368af2 ("net/ifcvf: add ifcvf vdpa driver")

Signed-off-by: Xiao Wang <xiao.w.wang@intel.com>
---
v2:
- It's the 7b0c17368af2 commit to be fixed.
---
 drivers/net/ifc/ifcvf_vdpa.c | 55 +++++++++++++++-----------------------------
 1 file changed, 19 insertions(+), 36 deletions(-)

diff --git a/drivers/net/ifc/ifcvf_vdpa.c b/drivers/net/ifc/ifcvf_vdpa.c
index a2b3f0dbf..27316a99f 100644
--- a/drivers/net/ifc/ifcvf_vdpa.c
+++ b/drivers/net/ifc/ifcvf_vdpa.c
@@ -155,7 +155,7 @@ ifcvf_vfio_setup(struct ifcvf_internal *internal)
 }
 
 static int
-ifcvf_dma_map(struct ifcvf_internal *internal)
+ifcvf_dma_map(struct ifcvf_internal *internal, int do_map)
 {
 	uint32_t i;
 	int ret;
@@ -174,45 +174,28 @@ ifcvf_dma_map(struct ifcvf_internal *internal)
 		struct rte_vhost_mem_region *reg;
 
 		reg = &mem->regions[i];
-		DRV_LOG(INFO, "region %u: HVA 0x%" PRIx64 ", "
+		DRV_LOG(INFO, "%s, region %u: HVA 0x%" PRIx64 ", "
 			"GPA 0x%" PRIx64 ", size 0x%" PRIx64 ".",
-			i, reg->host_user_addr, reg->guest_phys_addr,
-			reg->size);
+			do_map ? "DMA map" : "DMA unmap", i,
+			reg->host_user_addr, reg->guest_phys_addr, reg->size);
 
-		rte_vfio_container_dma_map(vfio_container_fd,
+		if (do_map) {
+			ret = rte_vfio_container_dma_map(vfio_container_fd,
 				reg->host_user_addr, reg->guest_phys_addr,
 				reg->size);
-	}
-
-exit:
-	if (mem)
-		free(mem);
-	return ret;
-}
-
-static int
-ifcvf_dma_unmap(struct ifcvf_internal *internal)
-{
-	uint32_t i;
-	int ret = 0;
-	struct rte_vhost_memory *mem = NULL;
-	int vfio_container_fd;
-
-	ret = rte_vhost_get_mem_table(internal->vid, &mem);
-	if (ret < 0) {
-		DRV_LOG(ERR, "failed to get VM memory layout.");
-		goto exit;
-	}
-
-	vfio_container_fd = internal->vfio_container_fd;
-
-	for (i = 0; i < mem->nregions; i++) {
-		struct rte_vhost_mem_region *reg;
-
-		reg = &mem->regions[i];
-		rte_vfio_container_dma_map(vfio_container_fd,
+			if (ret < 0) {
+				DRV_LOG(ERR, "DMA map failed.");
+				goto exit;
+			}
+		} else {
+			ret = rte_vfio_container_dma_unmap(vfio_container_fd,
 				reg->host_user_addr, reg->guest_phys_addr,
 				reg->size);
+			if (ret < 0) {
+				DRV_LOG(ERR, "DMA unmap failed.");
+				goto exit;
+			}
+		}
 	}
 
 exit:
@@ -486,7 +469,7 @@ update_datapath(struct ifcvf_internal *internal)
 	if (!rte_atomic32_read(&internal->running) &&
 	    (rte_atomic32_read(&internal->started) &&
 	     rte_atomic32_read(&internal->dev_attached))) {
-		ret = ifcvf_dma_map(internal);
+		ret = ifcvf_dma_map(internal, 1);
 		if (ret)
 			goto err;
 
@@ -516,7 +499,7 @@ update_datapath(struct ifcvf_internal *internal)
 		if (ret)
 			goto err;
 
-		ret = ifcvf_dma_unmap(internal);
+		ret = ifcvf_dma_map(internal, 0);
 		if (ret)
 			goto err;
 
-- 
2.15.1

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-04-23 10:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-20 15:13 [dpdk-dev] [PATCH] net/ifcvf: fix DMA unmap Xiao Wang
2018-04-23 17:47 ` [dpdk-dev] [PATCH v2] " Xiao Wang
2018-04-23 10:49   ` Ferruh Yigit

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).