[dpdk-dev,RFC,v2,23/23] eal: map/unmap memory with VFIO when alloc/free pages

Message ID 4d6dbd867adc051a3cf444d365c2aae604821f77.1513681966.git.anatoly.burakov@intel.com (mailing list archive)
State Superseded, archived
Headers

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation fail Compilation issues

Commit Message

Burakov, Anatoly Dec. 19, 2017, 11:14 a.m. UTC
  Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 lib/librte_eal/linuxapp/eal/eal_memalloc.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
  

Patch

diff --git a/lib/librte_eal/linuxapp/eal/eal_memalloc.c b/lib/librte_eal/linuxapp/eal/eal_memalloc.c
index 13172a0..8b3f219 100755
--- a/lib/librte_eal/linuxapp/eal/eal_memalloc.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memalloc.c
@@ -61,6 +61,7 @@ 
 #include <rte_eal_memconfig.h>
 #include <rte_eal.h>
 #include <rte_memory.h>
+#include <rte_iommu.h>
 
 #include "eal_filesystem.h"
 #include "eal_internal_cfg.h"
@@ -259,6 +260,11 @@  alloc_page(struct rte_memseg *ms, void *addr, uint64_t size, int socket_id,
 	ms->iova = iova;
 	ms->socket_id = socket_id;
 
+	/* map the segment so that VFIO has access to it */
+	if (rte_iommu_dma_map(ms->addr_64, iova, size)) {
+		RTE_LOG(DEBUG, EAL, "Cannot register segment with VFIO\n");
+	}
+
 	goto out;
 
 mapped:
@@ -295,6 +301,11 @@  free_page(struct rte_memseg *ms, struct hugepage_info *hi, unsigned list_idx,
 				list_idx * RTE_MAX_MEMSEG_PER_LIST + seg_idx);
 	}
 
+	/* unmap the segment from VFIO */
+	if (rte_iommu_dma_unmap(ms->addr_64, ms->iova, ms->len)) {
+		RTE_LOG(DEBUG, EAL, "Cannot unregister segment with VFIO\n");
+	}
+
 	munmap(ms->addr, ms->hugepage_sz);
 
 	// TODO: race condition?