[dpdk-dev,RFC,23/23] eal/memalloc: register/unregister memory with VFIO when alloc/free pages
Checks
Commit Message
Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
lib/librte_eal/linuxapp/eal/eal_memalloc.c | 11 +++++++++++
1 file changed, 11 insertions(+)
@@ -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?