From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id F3BC81B19 for ; Mon, 23 Apr 2018 11:16:38 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Apr 2018 02:16:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,317,1520924400"; d="scan'208";a="222589012" Received: from dpdk-xiao-1.sh.intel.com ([10.67.111.90]) by fmsmga006.fm.intel.com with ESMTP; 23 Apr 2018 02:16:36 -0700 From: Xiao Wang To: ferruh.yigit@intel.com Cc: dev@dpdk.org, Xiao Wang Date: Tue, 24 Apr 2018 01:47:03 +0800 Message-Id: <20180423174703.17976-1-xiao.w.wang@intel.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180420151331.36613-1-xiao.w.wang@intel.com> References: <20180420151331.36613-1-xiao.w.wang@intel.com> Subject: [dpdk-dev] [PATCH v2] net/ifcvf: fix DMA unmap X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Apr 2018 09:16:39 -0000 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 --- 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