Commit 59605ea6 authored by Tomasz Zawadzki's avatar Tomasz Zawadzki
Browse files

lib/env_dpdk: make phys_addr in spdk_*_malloc() invalid



`phys_addr` parameter was deprecated in SPDK 19.04 and it's
use was discouraged with additional error logs.

Parameters cannot really be removed, this would be the same
as adding new function and removing old one, without any
deprecation period.
There are quite a few spdk_*_malloc() functions and their usage
is quite broad. Adding another set of such functions
[ex. spdk_*_malloc_without_phys_addr()] would bloat the API.

Instead this patch proposes to change behaviour when `phys_addr`
is provided. Passing non-NULL parameter would return NULL.
This enforces the suggested use of spdk_vtophys().

Signed-off-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Change-Id: I0b83b220a04af8a2c1fa0bfe7838ec9d5f857ec0
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6875


Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarKrzysztof Karas <krzysztof.karas@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
Community-CI: Mellanox Build Bot
parent f6e79231
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -6,6 +6,12 @@

Updated DPDK submodule to DPDK 23.03.

### env

The `phys_addr` parameter in spdk_*_malloc() functions is now invalid. Passing non-NULL value
will return NULL from the functions. The parameter was deprecated in SPDK 19.04.
For retrieving physical addresses, spdk_vtophys() should be used instead.

## v23.05

### accel
+14 −23
Original line number Diff line number Diff line
@@ -75,9 +75,7 @@ struct spdk_env_opts {
 * \param align If non-zero, the allocated buffer is aligned to a multiple of
 * align. In this case, it must be a power of two. The returned buffer is always
 * aligned to at least cache line size.
 * \param phys_addr **Deprecated**. Please use spdk_vtophys() for retrieving physical
 * addresses. A pointer to the variable to hold the physical address of
 * the allocated buffer is passed. If NULL, the physical address is not returned.
 * \param unused **Invalid**. If not a NULL, the function will fail and return NULL.
 * \param socket_id Socket ID to allocate memory on, or SPDK_ENV_SOCKET_ID_ANY
 * for any socket.
 * \param flags Combination of SPDK_MALLOC flags (\ref SPDK_MALLOC_DMA, \ref SPDK_MALLOC_SHARE).
@@ -85,7 +83,7 @@ struct spdk_env_opts {
 *
 * \return a pointer to the allocated memory buffer.
 */
void *spdk_malloc(size_t size, size_t align, uint64_t *phys_addr, int socket_id, uint32_t flags);
void *spdk_malloc(size_t size, size_t align, uint64_t *unused, int socket_id, uint32_t flags);

/**
 * Allocate dma/sharable memory based on a given dma_flg. It is a memory buffer
@@ -95,16 +93,14 @@ void *spdk_malloc(size_t size, size_t align, uint64_t *phys_addr, int socket_id,
 * \param align If non-zero, the allocated buffer is aligned to a multiple of
 * align. In this case, it must be a power of two. The returned buffer is always
 * aligned to at least cache line size.
 * \param phys_addr **Deprecated**. Please use spdk_vtophys() for retrieving physical
 * addresses. A pointer to the variable to hold the physical address of
 * the allocated buffer is passed. If NULL, the physical address is not returned.
 * \param unused **Invalid**. If not a NULL, the function will fail and return NULL.
 * \param socket_id Socket ID to allocate memory on, or SPDK_ENV_SOCKET_ID_ANY
 * for any socket.
 * \param flags Combination of SPDK_MALLOC flags (\ref SPDK_MALLOC_DMA, \ref SPDK_MALLOC_SHARE).
 *
 * \return a pointer to the allocated memory buffer.
 */
void *spdk_zmalloc(size_t size, size_t align, uint64_t *phys_addr, int socket_id, uint32_t flags);
void *spdk_zmalloc(size_t size, size_t align, uint64_t *unused, int socket_id, uint32_t flags);

/**
 * Resize a dma/sharable memory buffer with the given new size and alignment.
@@ -162,12 +158,11 @@ void spdk_env_fini(void);
 * \param align If non-zero, the allocated buffer is aligned to a multiple of
 * align. In this case, it must be a power of two. The returned buffer is always
 * aligned to at least cache line size.
 * \param phys_addr A pointer to the variable to hold the physical address of
 * the allocated buffer is passed. If NULL, the physical address is not returned.
 * \param unused **Invalid**. If not a NULL, the function will fail and return NULL.
 *
 * \return a pointer to the allocated memory buffer.
 */
void *spdk_dma_malloc(size_t size, size_t align, uint64_t *phys_addr);
void *spdk_dma_malloc(size_t size, size_t align, uint64_t *unused);

/**
 * Allocate a pinned, memory buffer with the given size, alignment and socket id.
@@ -176,14 +171,13 @@ void *spdk_dma_malloc(size_t size, size_t align, uint64_t *phys_addr);
 * \param align If non-zero, the allocated buffer is aligned to a multiple of
 * align. In this case, it must be a power of two. The returned buffer is always
 * aligned to at least cache line size.
 * \param phys_addr A pointer to the variable to hold the physical address of
 * the allocated buffer is passed. If NULL, the physical address is not returned.
 * \param unused **Invalid**. If not a NULL, the function will fail and return NULL.
 * \param socket_id Socket ID to allocate memory on, or SPDK_ENV_SOCKET_ID_ANY
 * for any socket.
 *
 * \return a pointer to the allocated memory buffer.
 */
void *spdk_dma_malloc_socket(size_t size, size_t align, uint64_t *phys_addr, int socket_id);
void *spdk_dma_malloc_socket(size_t size, size_t align, uint64_t *unused, int socket_id);

/**
 * Allocate a pinned memory buffer with the given size and alignment. The buffer
@@ -193,12 +187,11 @@ void *spdk_dma_malloc_socket(size_t size, size_t align, uint64_t *phys_addr, int
 * \param align If non-zero, the allocated buffer is aligned to a multiple of
 * align. In this case, it must be a power of two. The returned buffer is always
 * aligned to at least cache line size.
 * \param phys_addr A pointer to the variable to hold the physical address of
 * the allocated buffer is passed. If NULL, the physical address is not returned.
 * \param unused **Invalid**. If not a NULL, the function will fail and return NULL.
 *
 * \return a pointer to the allocated memory buffer.
 */
void *spdk_dma_zmalloc(size_t size, size_t align, uint64_t *phys_addr);
void *spdk_dma_zmalloc(size_t size, size_t align, uint64_t *unused);

/**
 * Allocate a pinned memory buffer with the given size, alignment and socket id.
@@ -208,14 +201,13 @@ void *spdk_dma_zmalloc(size_t size, size_t align, uint64_t *phys_addr);
 * \param align If non-zero, the allocated buffer is aligned to a multiple of
 * align. In this case, it must be a power of two. The returned buffer is always
 * aligned to at least cache line size.
 * \param phys_addr A pointer to the variable to hold the physical address of
 * the allocated buffer is passed. If NULL, the physical address is not returned.
 * \param unused **Invalid**. If not a NULL, the function will fail and return NULL.
 * \param socket_id Socket ID to allocate memory on, or SPDK_ENV_SOCKET_ID_ANY
 * for any socket.
 *
 * \return a pointer to the allocated memory buffer.
 */
void *spdk_dma_zmalloc_socket(size_t size, size_t align, uint64_t *phys_addr, int socket_id);
void *spdk_dma_zmalloc_socket(size_t size, size_t align, uint64_t *unused, int socket_id);

/**
 * Resize the allocated and pinned memory buffer with the given new size and
@@ -226,12 +218,11 @@ void *spdk_dma_zmalloc_socket(size_t size, size_t align, uint64_t *phys_addr, in
 * \param align If non-zero, the allocated buffer is aligned to a multiple of
 * align. In this case, it must be a power of two. The returned buffer is always
 * aligned to at least cache line size.
 * \param phys_addr A pointer to the variable to hold the physical address of
 * the allocated buffer is passed. If NULL, the physical address is not returned.
 * \param unused **Invalid**. If not a NULL, the function will fail and return NULL.
 *
 * \return a pointer to the resized memory buffer.
 */
void *spdk_dma_realloc(void *buf, size_t size, size_t align, uint64_t *phys_addr);
void *spdk_dma_realloc(void *buf, size_t size, size_t align, uint64_t *unused);

/**
 * Free a memory buffer previously allocated, for example from spdk_dma_zmalloc().
+19 −53
Original line number Diff line number Diff line
@@ -20,57 +20,26 @@

static __thread bool g_is_thread_unaffinitized;

static uint64_t
virt_to_phys(void *vaddr)
{
	uint64_t ret;

	ret = rte_malloc_virt2iova(vaddr);
	if (ret != RTE_BAD_IOVA) {
		return ret;
	}

	return spdk_vtophys(vaddr, NULL);
}

void *
spdk_malloc(size_t size, size_t align, uint64_t *phys_addr, int socket_id, uint32_t flags)
spdk_malloc(size_t size, size_t align, uint64_t *unused, int socket_id, uint32_t flags)
{
	void *buf;

	if (flags == 0) {
	if (flags == 0 || unused != NULL) {
		return NULL;
	}

	align = spdk_max(align, RTE_CACHE_LINE_SIZE);
	buf = rte_malloc_socket(NULL, size, align, socket_id);
	if (buf && phys_addr) {
#ifdef DEBUG
		SPDK_ERRLOG("phys_addr param in spdk_malloc() is deprecated\n");
#endif
		*phys_addr = virt_to_phys(buf);
	}
	return buf;
	return rte_malloc_socket(NULL, size, align, socket_id);
}

void *
spdk_zmalloc(size_t size, size_t align, uint64_t *phys_addr, int socket_id, uint32_t flags)
spdk_zmalloc(size_t size, size_t align, uint64_t *unused, int socket_id, uint32_t flags)
{
	void *buf;

	if (flags == 0) {
	if (flags == 0 || unused != NULL) {
		return NULL;
	}

	align = spdk_max(align, RTE_CACHE_LINE_SIZE);
	buf = rte_zmalloc_socket(NULL, size, align, socket_id);
	if (buf && phys_addr) {
#ifdef DEBUG
		SPDK_ERRLOG("phys_addr param in spdk_zmalloc() is deprecated\n");
#endif
		*phys_addr = virt_to_phys(buf);
	}
	return buf;
	return rte_zmalloc_socket(NULL, size, align, socket_id);
}

void *
@@ -87,40 +56,37 @@ spdk_free(void *buf)
}

void *
spdk_dma_malloc_socket(size_t size, size_t align, uint64_t *phys_addr, int socket_id)
spdk_dma_malloc_socket(size_t size, size_t align, uint64_t *unused, int socket_id)
{
	return spdk_malloc(size, align, phys_addr, socket_id, (SPDK_MALLOC_DMA | SPDK_MALLOC_SHARE));
	return spdk_malloc(size, align, unused, socket_id, (SPDK_MALLOC_DMA | SPDK_MALLOC_SHARE));
}

void *
spdk_dma_zmalloc_socket(size_t size, size_t align, uint64_t *phys_addr, int socket_id)
spdk_dma_zmalloc_socket(size_t size, size_t align, uint64_t *unused, int socket_id)
{
	return spdk_zmalloc(size, align, phys_addr, socket_id, (SPDK_MALLOC_DMA | SPDK_MALLOC_SHARE));
	return spdk_zmalloc(size, align, unused, socket_id, (SPDK_MALLOC_DMA | SPDK_MALLOC_SHARE));
}

void *
spdk_dma_malloc(size_t size, size_t align, uint64_t *phys_addr)
spdk_dma_malloc(size_t size, size_t align, uint64_t *unused)
{
	return spdk_dma_malloc_socket(size, align, phys_addr, SPDK_ENV_SOCKET_ID_ANY);
	return spdk_dma_malloc_socket(size, align, unused, SPDK_ENV_SOCKET_ID_ANY);
}

void *
spdk_dma_zmalloc(size_t size, size_t align, uint64_t *phys_addr)
spdk_dma_zmalloc(size_t size, size_t align, uint64_t *unused)
{
	return spdk_dma_zmalloc_socket(size, align, phys_addr, SPDK_ENV_SOCKET_ID_ANY);
	return spdk_dma_zmalloc_socket(size, align, unused, SPDK_ENV_SOCKET_ID_ANY);
}

void *
spdk_dma_realloc(void *buf, size_t size, size_t align, uint64_t *phys_addr)
spdk_dma_realloc(void *buf, size_t size, size_t align, uint64_t *unused)
{
	void *new_buf;

	align = spdk_max(align, RTE_CACHE_LINE_SIZE);
	new_buf = rte_realloc(buf, size, align);
	if (new_buf && phys_addr) {
		*phys_addr = virt_to_phys(new_buf);
	if (unused != NULL) {
		return NULL;
	}
	return new_buf;
	align = spdk_max(align, RTE_CACHE_LINE_SIZE);
	return rte_realloc(buf, size, align);
}

void