Commit d288c412 authored by Seth Howell's avatar Seth Howell Committed by Jim Harris
Browse files

env_dpdk: change behavior of spdk_mem_map_translate



The function now takes a pointer as it's last argument, and copies the
size of the memory region for which the translation is validinto that
pointer.
For now, that will always be 2MB. However that behavior can change in
the future.

This series of changes is aimed at enabling spdk_mem_map_translate to
report back to the user the length of the valid mem_map up to the
function that requested the translation.
This will be useful when retrieving memory regions associated with I/O
buffers in NVMe-oF. For large I/O it will be possible that the buffer is
split over multiple MRs and the I/O will have to be split into multiple
SGLs.

Change-Id: I8686c166ec956507f5ae55cf602341281482cb89
Signed-off-by: default avatarSeth Howell <seth.howell@intel.com>
Reviewed-on: https://review.gerrithub.io/424888


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent 7e408509
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -22,6 +22,12 @@ does not at this time confer any SPDK ABI compatibility claims.

spdk_bdev_alias_del_all() was added to delete all alias from block device.

### Environment Abstraction Layer and Event Framework

The size parameter of spdk_mem_map_translate is now a pointer. This allows the
function to report back the actual size of the translation relative to the original
request made by the user.

### iscsi

Parameter names of `set_iscsi_options` and `get_iscsi_global_params` RPC
+3 −2
Original line number Diff line number Diff line
@@ -1032,12 +1032,13 @@ int spdk_mem_map_clear_translation(struct spdk_mem_map *map, uint64_t vaddr, uin
 *
 * \param map Memory map.
 * \param vaddr Virtual address.
 * \param size Size of memory region.
 * \param size Contains the size of the memory region pointed to by vaddr.
 * Updated with the size of the memory region for which the translation is valid.
 *
 * \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 size);
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.
+11 −4
Original line number Diff line number Diff line
@@ -239,7 +239,7 @@ spdk_mem_register(void *vaddr, size_t len)
		uint64_t ref_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, VALUE_2MB);
		ref_count = spdk_mem_map_translate(g_mem_reg_map, (uint64_t)vaddr, NULL);
		spdk_mem_map_set_translation(g_mem_reg_map, (uint64_t)vaddr, VALUE_2MB, ref_count + 1);

		if (ref_count > 0) {
@@ -302,7 +302,7 @@ spdk_mem_unregister(void *vaddr, size_t len)
	seg_vaddr = vaddr;
	seg_len = len;
	while (seg_len > 0) {
		ref_count = spdk_mem_map_translate(g_mem_reg_map, (uint64_t)seg_vaddr, VALUE_2MB);
		ref_count = spdk_mem_map_translate(g_mem_reg_map, (uint64_t)seg_vaddr, NULL);
		if (ref_count == 0) {
			pthread_mutex_unlock(&g_spdk_mem_map_mutex);
			return -EINVAL;
@@ -315,7 +315,7 @@ spdk_mem_unregister(void *vaddr, size_t len)
	seg_len = 0;
	while (len > 0) {
		/* In g_mem_reg_map, the "translation" is the reference count */
		ref_count = spdk_mem_map_translate(g_mem_reg_map, (uint64_t)vaddr, VALUE_2MB);
		ref_count = spdk_mem_map_translate(g_mem_reg_map, (uint64_t)vaddr, NULL);
		spdk_mem_map_set_translation(g_mem_reg_map, (uint64_t)vaddr, VALUE_2MB, ref_count - 1);

		if (ref_count > 1) {
@@ -475,7 +475,7 @@ spdk_mem_map_clear_translation(struct spdk_mem_map *map, uint64_t vaddr, uint64_
}

uint64_t
spdk_mem_map_translate(const struct spdk_mem_map *map, uint64_t vaddr, uint64_t size)
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_2mb *map_2mb;
@@ -483,6 +483,10 @@ spdk_mem_map_translate(const struct spdk_mem_map *map, uint64_t vaddr, uint64_t
	uint64_t idx_1gb;
	uint64_t vfn_2mb;

	if (size != NULL) {
		*size = 0;
	}

	if (spdk_unlikely(vaddr & ~MASK_256TB)) {
		DEBUG_PRINT("invalid usermode virtual address %p\n", (void *)vaddr);
		return map->default_translation;
@@ -498,6 +502,9 @@ spdk_mem_map_translate(const struct spdk_mem_map *map, uint64_t vaddr, uint64_t
	}

	map_2mb = &map_1gb->map[idx_1gb];
	if (size != NULL) {
		*size = VALUE_2MB;
	}

	return map_2mb->translation_2mb;
}
+6 −2
Original line number Diff line number Diff line
@@ -405,7 +405,11 @@ spdk_vtophys_notify(void *cb_ctx, struct spdk_mem_map *map,
				 * we need to unmap the range from the IOMMU
				 */
				if (g_vfio.enabled) {
					paddr = spdk_mem_map_translate(map, (uint64_t)vaddr, VALUE_2MB);
					uint64_t buffer_len;
					paddr = spdk_mem_map_translate(map, (uint64_t)vaddr, &buffer_len);
					if (buffer_len != VALUE_2MB) {
						return -EINVAL;
					}
					rc = vtophys_iommu_unmap_dma(paddr, VALUE_2MB);
					if (rc) {
						return -EFAULT;
@@ -619,7 +623,7 @@ spdk_vtophys(void *buf)

	vaddr = (uint64_t)buf;

	paddr_2mb = spdk_mem_map_translate(g_vtophys_map, vaddr, VALUE_2MB);
	paddr_2mb = spdk_mem_map_translate(g_vtophys_map, vaddr, NULL);

	/*
	 * SPDK_VTOPHYS_ERROR has all bits set, so if the lookup returned SPDK_VTOPHYS_ERROR,
+5 −5
Original line number Diff line number Diff line
@@ -618,7 +618,7 @@ nvme_rdma_mr_map_notify(void *cb_ctx, struct spdk_mem_map *map,
		}
		break;
	case SPDK_MEM_MAP_NOTIFY_UNREGISTER:
		mr = (struct ibv_mr *)spdk_mem_map_translate(map, (uint64_t)vaddr, size);
		mr = (struct ibv_mr *)spdk_mem_map_translate(map, (uint64_t)vaddr, NULL);
		rc = spdk_mem_map_clear_translation(map, (uint64_t)vaddr, size);
		if (mr) {
			ibv_dereg_mr(mr);
@@ -848,7 +848,7 @@ nvme_rdma_build_contig_inline_request(struct nvme_rdma_qpair *rqpair,
	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, req->payload_size);
			(uint64_t)payload, NULL);

	if (mr == NULL) {
		return -EINVAL;
@@ -885,7 +885,7 @@ nvme_rdma_build_contig_request(struct nvme_rdma_qpair *rqpair,
	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,
			req->payload_size);
			NULL);
	if (mr == NULL) {
		return -1;
	}
@@ -932,7 +932,7 @@ nvme_rdma_build_sgl_request(struct nvme_rdma_qpair *rqpair,
	}

	mr = (struct ibv_mr *)spdk_mem_map_translate(rqpair->mr_map->map, (uint64_t)virt_addr,
			req->payload_size);
			NULL);
	if (mr == NULL) {
		return -1;
	}
@@ -980,7 +980,7 @@ nvme_rdma_build_sgl_inline_request(struct nvme_rdma_qpair *rqpair,
	}

	mr = (struct ibv_mr *)spdk_mem_map_translate(rqpair->mr_map->map, (uint64_t)virt_addr,
			req->payload_size);
			NULL);
	if (mr == NULL) {
		return -1;
	}
Loading