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 <daniel.verkamp@intel.com>
This commit is contained in:
Daniel Verkamp 2017-02-21 15:47:52 -07:00
parent b49de91ef2
commit 302804d164

View File

@ -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;