From: David Marchand Date: Mon, 18 Oct 2021 08:26:35 +0000 (+0200) Subject: mempool: accept user flags only X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=afdaa60795d525aee4fd21121561df737014cee0;p=dpdk.git 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 Signed-off-by: David Marchand Acked-by: Olivier Matz Acked-by: Andrew Rybchenko --- diff --git a/app/test/test_mempool.c b/app/test/test_mempool.c index 25d61a2aa2..4f399b461d 100644 --- a/app/test/test_mempool.c +++ b/app/test/test_mempool.c @@ -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) diff --git a/lib/mempool/rte_mempool.c b/lib/mempool/rte_mempool.c index c988ebd87a..b75d26c82a 100644 --- a/lib/mempool/rte_mempool.c +++ b/lib/mempool/rte_mempool.c @@ -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; } diff --git a/lib/mempool/rte_mempool.h b/lib/mempool/rte_mempool.h index 300dbdea4a..1e7a3c1527 100644 --- a/lib/mempool/rte_mempool.h +++ b/lib/mempool/rte_mempool.h @@ -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. *