[dpdk-dev,v2,25/41] eal: map/unmap 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(+)
@@ -34,6 +34,7 @@
#include <rte_eal.h>
#include <rte_memory.h>
#include <rte_spinlock.h>
+#include <rte_vfio.h>
#include "eal_filesystem.h"
#include "eal_internal_cfg.h"
@@ -476,6 +477,10 @@ 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_eal_iova_mode() == RTE_IOVA_VA &&
+ rte_vfio_dma_map(ms->addr_64, iova, size))
+ RTE_LOG(DEBUG, EAL, "Cannot register segment with VFIO\n");
return 0;
mapped:
@@ -507,6 +512,12 @@ free_page(struct rte_memseg *ms, struct hugepage_info *hi,
char path[PATH_MAX];
int fd, ret;
+ /* unmap the segment from VFIO */
+ if (rte_eal_iova_mode() == RTE_IOVA_VA &&
+ rte_vfio_dma_unmap(ms->addr_64, ms->iova, ms->len)) {
+ RTE_LOG(DEBUG, EAL, "Cannot unregister segment with VFIO\n");
+ }
+
if (mmap(ms->addr, ms->hugepage_sz, PROT_READ,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0) ==
MAP_FAILED) {