From c45669cf8968c3726a88c216bcbd2e63de18138c Mon Sep 17 00:00:00 2001 From: Dariusz Stojaczyk Date: Fri, 16 Mar 2018 17:40:49 +0100 Subject: [PATCH] env/dpdk: support memsegs without phys addr assigned If those are encountered, SPDK will get physical addreses by itself (either IOVAs from vfio or real physical addreses from /proc/self/pagemap). Change-Id: I321892f7dfb26054087a86cd24502efff05883ea Signed-off-by: Dariusz Stojaczyk Reviewed-on: https://review.gerrithub.io/404138 Tested-by: SPDK Automated Test System Reviewed-by: Daniel Verkamp Reviewed-by: Jim Harris --- lib/env_dpdk/env.c | 14 ++++++++++++-- lib/env_dpdk/vtophys.c | 7 +++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/env_dpdk/env.c b/lib/env_dpdk/env.c index 1088cb707..5dc12a8ba 100644 --- a/lib/env_dpdk/env.c +++ b/lib/env_dpdk/env.c @@ -45,11 +45,21 @@ static uint64_t virt_to_phys(void *vaddr) { + uint64_t ret; + #if RTE_VERSION >= RTE_VERSION_NUM(17, 11, 0, 3) - return rte_malloc_virt2iova(vaddr); + ret = rte_malloc_virt2iova(vaddr); + if (ret != RTE_BAD_IOVA) { + return ret; + } #else - return rte_malloc_virt2phy(vaddr); + ret = rte_malloc_virt2phy(vaddr); + if (ret != RTE_BAD_PHYS_ADDR) { + return ret; + } #endif + + return spdk_vtophys(vaddr); } void * diff --git a/lib/env_dpdk/vtophys.c b/lib/env_dpdk/vtophys.c index 49cbe215e..aa9da36fa 100644 --- a/lib/env_dpdk/vtophys.c +++ b/lib/env_dpdk/vtophys.c @@ -208,6 +208,13 @@ vtophys_get_paddr_memseg(uint64_t vaddr) if (vaddr >= (uintptr_t)seg->addr && vaddr < ((uintptr_t)seg->addr + seg->len)) { paddr = seg->phys_addr; +#if RTE_VERSION >= RTE_VERSION_NUM(17, 11, 0, 3) + if (paddr == RTE_BAD_IOVA) { +#else + if (paddr == RTE_BAD_PHYS_ADDR) { +#endif + return SPDK_VTOPHYS_ERROR; + } paddr += (vaddr - (uintptr_t)seg->addr); return paddr; }