memzone: enforce valid flags when reserving
PATCH 1/1 memzone: enforce valid flags when reserving
If we do not enforce valid flags are passed by an application, this application might face issues in the future when we add more flags.
Signed-off-by David Marchand <[email protected]>
--- app/test/test_memzone.c | 24 ++++++++++++++++++++++++ lib/eal/common/eal_common_memzone.c | 17 +++++++++++++++++ 2 files changed, 41 insertions(+)
app/test/test_memzone.c +24 -0
@@ -82,6 +82,26 @@ test_memzone_invalid_alignment(void)return 0 ; } +static int +test_memzone_invalid_flags (void ) +{ +const struct rte_memzone * mz; + + mz =rte_memzone_lookup (TEST_MEMZONE_NAME ("invalid_flags" )); +if (mz !=NULL ) { +printf ("Zone with invalid flags has been reserved\n" ); +return -1 ; + } + + mz =rte_memzone_reserve (TEST_MEMZONE_NAME ("invalid_flags" ), +100 ,SOCKET_ID_ANY ,RTE_MEMZONE_IOVA_CONTIG <<1 ); +if (mz !=NULL ) { +printf ("Zone with invalid flags has been reserved\n" ); +return -1 ; + } +return 0 ; +} +static int test_memzone_reserving_zone_size_bigger_than_the_maximum (void ) {
@@ -1106,6 +1126,10 @@ test_memzone(void)if (test_memzone_invalid_alignment () <0 )return -1 ; +printf ("test invalid flags for memzone_reserve\n" ); +if (test_memzone_invalid_flags () <0 ) +return -1 ; +printf ("test reserving the largest size memzone possible\n" );if (test_memzone_reserve_max () <0 )return -1 ;
lib/eal/common/eal_common_memzone.c +17 -0
@@ -53,6 +53,18 @@ memzone_lookup_thread_unsafe(const char *name)return NULL ; } +#define MEMZONE_KNOWN_FLAGS (RTE_MEMZONE_2MB \ + | RTE_MEMZONE_1GB \ + | RTE_MEMZONE_16MB \ + | RTE_MEMZONE_16GB \ + | RTE_MEMZONE_256KB \ + | RTE_MEMZONE_256MB \ + | RTE_MEMZONE_512MB \ + | RTE_MEMZONE_4GB \ + | RTE_MEMZONE_SIZE_HINT_ONLY \ + | RTE_MEMZONE_IOVA_CONTIG \ + ) +static const struct rte_memzone * memzone_reserve_aligned_thread_unsafe(const char *name, size_t len, int socket_id, unsigned int flags, unsigned int align,
@@ -128,6 +140,11 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len,return NULL ; } +if ((flags & ~MEMZONE_KNOWN_FLAGS ) !=0 ) { + rte_errno =EINVAL ; +return NULL ; + } +/* only set socket to SOCKET_ID_ANY if we aren't allocating for an * external heap. */
Signature · 1 line
2.23.0
Quoted 4 lines · On Tue, 12 Oct 2021 21:39:26 +0200 David Marchand <[email protected]>…
If we do not enforce valid flags are passed by an application, this application might face issues in the future when we add more flags.
Signed-off-by David Marchand <[email protected]>
Andrew Rybchenko
Acked-byQuoted 10 lines · Stephen Hemminger
Quoted 4 lines · On Tue, 12 Oct 2021 21:39:26 +0200 David Marchand <[email protected]>…
If we do not enforce valid flags are passed by an application, this application might face issues in the future when we add more flags.
Signed-off-by David Marchand <[email protected]>
Acked-by Andrew Rybchenko <[email protected]>
Quoted 11 lines · Andrew Rybchenko
Quoted 8 lines · Stephen Hemminger
Quoted 4 lines · On Tue, 12 Oct 2021 21:39:26 +0200 David Marchand <[email protected]>…
If we do not enforce valid flags are passed by an application, this application might face issues in the future when we add more flags.
Signed-off-by David Marchand <[email protected]>Acked-by Andrew Rybchenko <[email protected]>
Acked-by Ray Kinsella <[email protected]>
Applied, thanks.
Signature · 1 line
David Marchand
Quoted 8 lines · David Marchand
If we do not enforce valid flags are passed by an application, this application might face issues in the future when we add more flags.
Signed-off-by David Marchand <[email protected]>--- app/test/test_memzone.c | 24 ++++++++++++++++++++++++ lib/eal/common/eal_common_memzone.c | 17 +++++++++++++++++ 2 files changed, 41 insertions(+)
Acked-by Ray Kinsella <[email protected]>