[RFC v2 23/23] eal: map/unmap memory with VFIO when alloc/free pages
From: Anatoly Burakov <hidden>
Date: 2017-12-19 11:14:57
Subsystem:
library code, the rest · Maintainers:
Andrew Morton, Linus Torvalds
From: Anatoly Burakov <hidden>
Date: 2017-12-19 11:14:57
Subsystem:
library code, the rest · Maintainers:
Andrew Morton, Linus Torvalds
Signed-off-by: Anatoly Burakov <redacted> --- lib/librte_eal/linuxapp/eal/eal_memalloc.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
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?
--
2.7.4