env: add size parameter to spdk_mem_map_translate

Change-Id: I808101edaf4d75613baf19a950915f1d8e75b1af
Signed-off-by: zkhatami88 <z.khatami88@gmail.com>
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/413154
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Zahra Khatami <zahra.k.khatami@oracle.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
zkhatami88 2018-05-31 14:44:49 -07:00 committed by Jim Harris
parent f32b3ea9f4
commit 0cdb08b0e0
7 changed files with 29 additions and 19 deletions

View File

@ -9,6 +9,12 @@ on each call. This allows multiple callers to query I/O statistics without confl
with each other. Existing users will need to adjust their code to record the previous with each other. Existing users will need to adjust their code to record the previous
I/O statistics to calculate the delta between calls. I/O statistics to calculate the delta between calls.
### Env
The spdk_mem_map_translate() function now takes a size parameter to indicate the size of
the memory region. This can be used by environment implementations to validate the
requested translation.
### git pre-commit and pre-push hooks ### git pre-commit and pre-push hooks
The pre-commit hook will run `scripts/check_format.sh` and verify there are no formating The pre-commit hook will run `scripts/check_format.sh` and verify there are no formating

View File

@ -1007,10 +1007,12 @@ int spdk_mem_map_clear_translation(struct spdk_mem_map *map, uint64_t vaddr, uin
* *
* \param map Memory map. * \param map Memory map.
* \param vaddr Virtual address. * \param vaddr Virtual address.
* \param size Size of memory region.
* *
* \return the translation of 2MB hugepage mapping. * \return the translation of vaddr stored in the map, or default_translation
* as specified in spdk_mem_map_alloc() if vaddr is not present in the map.
*/ */
uint64_t spdk_mem_map_translate(const struct spdk_mem_map *map, uint64_t vaddr); uint64_t spdk_mem_map_translate(const struct spdk_mem_map *map, uint64_t vaddr, uint64_t size);
/** /**
* Register the specified memory region for address translation. * Register the specified memory region for address translation.

View File

@ -239,7 +239,7 @@ spdk_mem_register(void *vaddr, size_t len)
uint64_t ref_count; uint64_t ref_count;
/* In g_mem_reg_map, the "translation" is the reference count */ /* In g_mem_reg_map, the "translation" is the reference count */
ref_count = spdk_mem_map_translate(g_mem_reg_map, (uint64_t)vaddr); ref_count = spdk_mem_map_translate(g_mem_reg_map, (uint64_t)vaddr, VALUE_2MB);
spdk_mem_map_set_translation(g_mem_reg_map, (uint64_t)vaddr, VALUE_2MB, ref_count + 1); spdk_mem_map_set_translation(g_mem_reg_map, (uint64_t)vaddr, VALUE_2MB, ref_count + 1);
if (ref_count > 0) { if (ref_count > 0) {
@ -302,7 +302,7 @@ spdk_mem_unregister(void *vaddr, size_t len)
seg_vaddr = vaddr; seg_vaddr = vaddr;
seg_len = len; seg_len = len;
while (seg_len > 0) { while (seg_len > 0) {
ref_count = spdk_mem_map_translate(g_mem_reg_map, (uint64_t)seg_vaddr); ref_count = spdk_mem_map_translate(g_mem_reg_map, (uint64_t)seg_vaddr, VALUE_2MB);
if (ref_count == 0) { if (ref_count == 0) {
pthread_mutex_unlock(&g_spdk_mem_map_mutex); pthread_mutex_unlock(&g_spdk_mem_map_mutex);
return -EINVAL; return -EINVAL;
@ -315,7 +315,7 @@ spdk_mem_unregister(void *vaddr, size_t len)
seg_len = 0; seg_len = 0;
while (len > 0) { while (len > 0) {
/* In g_mem_reg_map, the "translation" is the reference count */ /* In g_mem_reg_map, the "translation" is the reference count */
ref_count = spdk_mem_map_translate(g_mem_reg_map, (uint64_t)vaddr); ref_count = spdk_mem_map_translate(g_mem_reg_map, (uint64_t)vaddr, VALUE_2MB);
spdk_mem_map_set_translation(g_mem_reg_map, (uint64_t)vaddr, VALUE_2MB, ref_count - 1); spdk_mem_map_set_translation(g_mem_reg_map, (uint64_t)vaddr, VALUE_2MB, ref_count - 1);
if (ref_count > 1) { if (ref_count > 1) {
@ -471,7 +471,7 @@ spdk_mem_map_clear_translation(struct spdk_mem_map *map, uint64_t vaddr, uint64_
} }
uint64_t uint64_t
spdk_mem_map_translate(const struct spdk_mem_map *map, uint64_t vaddr) spdk_mem_map_translate(const struct spdk_mem_map *map, uint64_t vaddr, uint64_t size)
{ {
const struct map_1gb *map_1gb; const struct map_1gb *map_1gb;
const struct map_2mb *map_2mb; const struct map_2mb *map_2mb;

View File

@ -404,7 +404,7 @@ spdk_vtophys_notify(void *cb_ctx, struct spdk_mem_map *map,
* we need to unmap the range from the IOMMU * we need to unmap the range from the IOMMU
*/ */
if (g_vfio.enabled) { if (g_vfio.enabled) {
paddr = spdk_mem_map_translate(map, (uint64_t)vaddr); paddr = spdk_mem_map_translate(map, (uint64_t)vaddr, VALUE_2MB);
rc = vtophys_iommu_unmap_dma(paddr, VALUE_2MB); rc = vtophys_iommu_unmap_dma(paddr, VALUE_2MB);
if (rc) { if (rc) {
return -EFAULT; return -EFAULT;
@ -618,7 +618,7 @@ spdk_vtophys(void *buf)
vaddr = (uint64_t)buf; vaddr = (uint64_t)buf;
paddr_2mb = spdk_mem_map_translate(g_vtophys_map, vaddr); paddr_2mb = spdk_mem_map_translate(g_vtophys_map, vaddr, VALUE_2MB);
/* /*
* SPDK_VTOPHYS_ERROR has all bits set, so if the lookup returned SPDK_VTOPHYS_ERROR, * SPDK_VTOPHYS_ERROR has all bits set, so if the lookup returned SPDK_VTOPHYS_ERROR,

View File

@ -687,7 +687,7 @@ nvme_rdma_mr_map_notify(void *cb_ctx, struct spdk_mem_map *map,
} }
break; break;
case SPDK_MEM_MAP_NOTIFY_UNREGISTER: case SPDK_MEM_MAP_NOTIFY_UNREGISTER:
mr = (struct ibv_mr *)spdk_mem_map_translate(map, (uint64_t)vaddr); mr = (struct ibv_mr *)spdk_mem_map_translate(map, (uint64_t)vaddr, size);
rc = spdk_mem_map_clear_translation(map, (uint64_t)vaddr, size); rc = spdk_mem_map_clear_translation(map, (uint64_t)vaddr, size);
if (mr) { if (mr) {
ibv_dereg_mr(mr); ibv_dereg_mr(mr);
@ -911,7 +911,8 @@ nvme_rdma_build_contig_request(struct nvme_rdma_qpair *rqpair, struct nvme_reque
assert(req->payload_size != 0); assert(req->payload_size != 0);
assert(nvme_payload_type(&req->payload) == NVME_PAYLOAD_TYPE_CONTIG); assert(nvme_payload_type(&req->payload) == NVME_PAYLOAD_TYPE_CONTIG);
mr = (struct ibv_mr *)spdk_mem_map_translate(rqpair->mr_map->map, (uint64_t)payload); mr = (struct ibv_mr *)spdk_mem_map_translate(rqpair->mr_map->map, (uint64_t)payload,
req->payload_size);
if (mr == NULL) { if (mr == NULL) {
return -1; return -1;
} }
@ -954,7 +955,8 @@ nvme_rdma_build_sgl_request(struct nvme_rdma_qpair *rqpair, struct nvme_request
return -1; return -1;
} }
mr = (struct ibv_mr *)spdk_mem_map_translate(rqpair->mr_map->map, (uint64_t)virt_addr); mr = (struct ibv_mr *)spdk_mem_map_translate(rqpair->mr_map->map, (uint64_t)virt_addr,
req->payload_size);
if (mr == NULL) { if (mr == NULL) {
return -1; return -1;
} }

View File

@ -779,7 +779,7 @@ spdk_nvmf_rdma_mem_notify(void *cb_ctx, struct spdk_mem_map *map,
} }
break; break;
case SPDK_MEM_MAP_NOTIFY_UNREGISTER: case SPDK_MEM_MAP_NOTIFY_UNREGISTER:
mr = (struct ibv_mr *)spdk_mem_map_translate(map, (uint64_t)vaddr); mr = (struct ibv_mr *)spdk_mem_map_translate(map, (uint64_t)vaddr, size);
spdk_mem_map_clear_translation(map, (uint64_t)vaddr, size); spdk_mem_map_clear_translation(map, (uint64_t)vaddr, size);
if (mr) { if (mr) {
ibv_dereg_mr(mr); ibv_dereg_mr(mr);
@ -871,7 +871,7 @@ spdk_nvmf_rdma_request_fill_iovs(struct spdk_nvmf_rdma_transport *rtransport,
rdma_req->data.wr.sg_list[i].addr = (uintptr_t)(rdma_req->req.iov[i].iov_base); rdma_req->data.wr.sg_list[i].addr = (uintptr_t)(rdma_req->req.iov[i].iov_base);
rdma_req->data.wr.sg_list[i].length = rdma_req->req.iov[i].iov_len; rdma_req->data.wr.sg_list[i].length = rdma_req->req.iov[i].iov_len;
rdma_req->data.wr.sg_list[i].lkey = ((struct ibv_mr *)spdk_mem_map_translate(device->map, rdma_req->data.wr.sg_list[i].lkey = ((struct ibv_mr *)spdk_mem_map_translate(device->map,
(uint64_t)buf))->lkey; (uint64_t)buf, rdma_req->req.iov[i].iov_len))->lkey;
length -= rdma_req->req.iov[i].iov_len; length -= rdma_req->req.iov[i].iov_len;
i++; i++;

View File

@ -125,7 +125,7 @@ test_mem_map_translation(void)
SPDK_CU_ASSERT_FATAL(map != NULL); SPDK_CU_ASSERT_FATAL(map != NULL);
/* Try to get translation for address with no translation */ /* Try to get translation for address with no translation */
addr = spdk_mem_map_translate(map, 10); addr = spdk_mem_map_translate(map, 10, VALUE_2MB);
CU_ASSERT(addr == default_translation); CU_ASSERT(addr == default_translation);
/* Set translation for region of non-2MB multiple size */ /* Set translation for region of non-2MB multiple size */
@ -149,15 +149,15 @@ test_mem_map_translation(void)
CU_ASSERT(rc == 0); CU_ASSERT(rc == 0);
/* Get translation for first page */ /* Get translation for first page */
addr = spdk_mem_map_translate(map, 0); addr = spdk_mem_map_translate(map, 0, VALUE_2MB);
CU_ASSERT(addr == 0); CU_ASSERT(addr == 0);
/* Verify translation for 2nd page is the default */ /* Verify translation for 2nd page is the default */
addr = spdk_mem_map_translate(map, VALUE_2MB); addr = spdk_mem_map_translate(map, VALUE_2MB, VALUE_2MB);
CU_ASSERT(addr == default_translation); CU_ASSERT(addr == default_translation);
/* Get translation for third page */ /* Get translation for third page */
addr = spdk_mem_map_translate(map, 2 * VALUE_2MB); addr = spdk_mem_map_translate(map, 2 * VALUE_2MB, VALUE_2MB);
/* /*
* Note that addr should be 0, not 4MB. When we set the * Note that addr should be 0, not 4MB. When we set the
* translation above, we said the whole 6MB region * translation above, we said the whole 6MB region
@ -170,7 +170,7 @@ test_mem_map_translation(void)
CU_ASSERT(rc == 0); CU_ASSERT(rc == 0);
/* Get translation for the first page */ /* Get translation for the first page */
addr = spdk_mem_map_translate(map, 0); addr = spdk_mem_map_translate(map, 0, VALUE_2MB);
CU_ASSERT(addr == default_translation); CU_ASSERT(addr == default_translation);
/* Clear translation for the third page */ /* Clear translation for the third page */
@ -178,7 +178,7 @@ test_mem_map_translation(void)
CU_ASSERT(rc == 0); CU_ASSERT(rc == 0);
/* Get translation for the third page */ /* Get translation for the third page */
addr = spdk_mem_map_translate(map, 2 * VALUE_2MB); addr = spdk_mem_map_translate(map, 2 * VALUE_2MB, VALUE_2MB);
CU_ASSERT(addr == default_translation); CU_ASSERT(addr == default_translation);
spdk_mem_map_free(&map); spdk_mem_map_free(&map);