From 302804d164a1ec4432279bdc3095ac3b252ccea3 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Tue, 21 Feb 2017 15:47:52 -0700 Subject: [PATCH] env/vtophys: make map read-only in spdk_vtophys() Now that all DPDK memory is registered at startup, spdk_vtophys() never needs to add new translations to the vtophys map. This means that any lookup that fails to find an allocated map_1gb will always return SPDK_VTOPHYS_ERROR rather than trying to allocate it and then failing the lookup anyway. Change-Id: I7e6f7af183199651f5808a17810a17970b0e3331 Signed-off-by: Daniel Verkamp --- lib/env_dpdk/vtophys.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/lib/env_dpdk/vtophys.c b/lib/env_dpdk/vtophys.c index 56e7c79b7..849242b48 100644 --- a/lib/env_dpdk/vtophys.c +++ b/lib/env_dpdk/vtophys.c @@ -125,20 +125,6 @@ vtophys_get_map_1gb(uint64_t vfn_2mb) return map_1gb; } -static struct map_2mb * -vtophys_get_map_2mb(uint64_t vfn_2mb) -{ - struct map_1gb *map_1gb; - uint64_t idx_1gb = MAP_1GB_IDX(vfn_2mb); - - map_1gb = vtophys_get_map_1gb(vfn_2mb); - if (!map_1gb) { - return NULL; - } - - return &map_1gb->map[idx_1gb]; -} - static uint64_t vtophys_get_dpdk_paddr(void *vaddr) { @@ -334,7 +320,10 @@ spdk_vtophys_register_dpdk_mem(void) uint64_t spdk_vtophys(void *buf) { + struct map_1gb *map_1gb; struct map_2mb *map_2mb; + uint64_t idx_128tb; + uint64_t idx_1gb; uint64_t vaddr, vfn_2mb, paddr_2mb; vaddr = (uint64_t)buf; @@ -344,12 +333,16 @@ spdk_vtophys(void *buf) } vfn_2mb = vaddr >> SHIFT_2MB; + idx_128tb = MAP_128TB_IDX(vfn_2mb); + idx_1gb = MAP_1GB_IDX(vfn_2mb); - map_2mb = vtophys_get_map_2mb(vfn_2mb); - if (!map_2mb) { + map_1gb = vtophys_map_128tb.map[idx_128tb]; + if (!map_1gb) { return SPDK_VTOPHYS_ERROR; } + map_2mb = &map_1gb->map[idx_1gb]; + paddr_2mb = map_2mb->paddr_2mb; if (paddr_2mb == SPDK_VTOPHYS_ERROR) { return SPDK_VTOPHYS_ERROR;