From mboxrd@z Thu Jan 1 00:00:00 1970 From: Anatoly Burakov Subject: [RFC v2 23/23] eal: map/unmap memory with VFIO when alloc/free pages Date: Tue, 19 Dec 2017 11:14:50 +0000 Message-ID: <4d6dbd867adc051a3cf444d365c2aae604821f77.1513681966.git.anatoly.burakov@intel.com> References: Cc: andras.kovacs@ericsson.com, laszlo.vadkeri@ericsson.com, keith.wiles@intel.com, benjamin.walker@intel.com, bruce.richardson@intel.com, thomas@monjalon.net To: dev@dpdk.org Return-path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 77E221D7 for ; Tue, 19 Dec 2017 12:14:57 +0100 (CET) In-Reply-To: In-Reply-To: References: List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Signed-off-by: Anatoly Burakov --- 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 #include #include +#include #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