mempool: accept user flags only

As reported by Dmitry, RTE_MEMPOOL_F_POOL_CREATED is a flag only
manipulated internally.
This flag is not supposed to be requested from an application and would
probably result in an incorrect behavior if an application did pass it.

At least one other internal flag has been added recently and more may be
introduced later.

Rework the check and export a mask of valid user flags for use in the
unit test.

Fixes: b240af8b10f9 ("mempool: enforce valid flags at creation")

Reported-by: Dmitry Kozlyuk <dkozlyuk@nvidia.com>
Signed-off-by: David Marchand <david.marchand@redhat.com>
Acked-by: Olivier Matz <olivier.matz@6wind.com>
Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
This commit is contained in:
David Marchand 2021-10-18 10:26:35 +02:00
parent fb11ae8816
commit afdaa60795
3 changed files with 15 additions and 13 deletions

View File

@ -207,15 +207,15 @@ static int test_mempool_creation_with_exceeded_cache_size(void)
return 0;
}
static int test_mempool_creation_with_unknown_flag(void)
static int test_mempool_creation_with_invalid_flags(void)
{
struct rte_mempool *mp_cov;
mp_cov = rte_mempool_create("test_mempool_unknown_flag", MEMPOOL_SIZE,
mp_cov = rte_mempool_create("test_mempool_invalid_flags", MEMPOOL_SIZE,
MEMPOOL_ELT_SIZE, 0, 0,
NULL, NULL,
NULL, NULL,
SOCKET_ID_ANY, RTE_MEMPOOL_F_NO_IOVA_CONTIG << 1);
SOCKET_ID_ANY, ~RTE_MEMPOOL_VALID_USER_FLAGS);
if (mp_cov != NULL) {
rte_mempool_free(mp_cov);
@ -1000,7 +1000,7 @@ test_mempool(void)
if (test_mempool_creation_with_exceeded_cache_size() < 0)
GOTO_ERR(ret, err);
if (test_mempool_creation_with_unknown_flag() < 0)
if (test_mempool_creation_with_invalid_flags() < 0)
GOTO_ERR(ret, err);
if (test_mempool_same_name_twice_creation() < 0)

View File

@ -798,13 +798,6 @@ rte_mempool_cache_free(struct rte_mempool_cache *cache)
rte_free(cache);
}
#define MEMPOOL_KNOWN_FLAGS (RTE_MEMPOOL_F_NO_SPREAD \
| RTE_MEMPOOL_F_NO_CACHE_ALIGN \
| RTE_MEMPOOL_F_SP_PUT \
| RTE_MEMPOOL_F_SC_GET \
| RTE_MEMPOOL_F_POOL_CREATED \
| RTE_MEMPOOL_F_NO_IOVA_CONTIG \
)
/* create an empty mempool */
struct rte_mempool *
rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
@ -849,8 +842,8 @@ rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
return NULL;
}
/* enforce no unknown flag is passed by the application */
if ((flags & ~MEMPOOL_KNOWN_FLAGS) != 0) {
/* enforce only user flags are passed by the application */
if ((flags & ~RTE_MEMPOOL_VALID_USER_FLAGS) != 0) {
rte_errno = EINVAL;
return NULL;
}

View File

@ -291,6 +291,15 @@ struct rte_mempool {
/** Internal: no object from the pool can be used for device IO (DMA). */
#define RTE_MEMPOOL_F_NON_IO 0x0040
/**
* This macro lists all the mempool flags an application may request.
*/
#define RTE_MEMPOOL_VALID_USER_FLAGS (RTE_MEMPOOL_F_NO_SPREAD \
| RTE_MEMPOOL_F_NO_CACHE_ALIGN \
| RTE_MEMPOOL_F_SP_PUT \
| RTE_MEMPOOL_F_SC_GET \
| RTE_MEMPOOL_F_NO_IOVA_CONTIG \
)
/**
* @internal When debug is enabled, store some statistics.
*