DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] memzone: enforce valid flags when reserving
@ 2021-10-12 19:39 David Marchand
  2021-10-12 20:14 ` Stephen Hemminger
  2021-10-13  9:00 ` Kinsella, Ray
  0 siblings, 2 replies; 5+ messages in thread
From: David Marchand @ 2021-10-12 19:39 UTC (permalink / raw)
  To: dev; +Cc: mdr, thomas, Anatoly Burakov

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 <david.marchand@redhat.com>
---
 app/test/test_memzone.c             | 24 ++++++++++++++++++++++++
 lib/eal/common/eal_common_memzone.c | 17 +++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/app/test/test_memzone.c b/app/test/test_memzone.c
index 27b8b52fcd..6350e0f29b 100644
--- a/app/test/test_memzone.c
+++ b/app/test/test_memzone.c
@@ -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;
diff --git a/lib/eal/common/eal_common_memzone.c b/lib/eal/common/eal_common_memzone.c
index 7c21aa921e..ecde9441ee 100644
--- a/lib/eal/common/eal_common_memzone.c
+++ b/lib/eal/common/eal_common_memzone.c
@@ -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.
 	 */
-- 
2.23.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [dpdk-dev] [PATCH] memzone: enforce valid flags when reserving
  2021-10-12 19:39 [dpdk-dev] [PATCH] memzone: enforce valid flags when reserving David Marchand
@ 2021-10-12 20:14 ` Stephen Hemminger
  2021-10-13  8:47   ` Andrew Rybchenko
  2021-10-13  9:00 ` Kinsella, Ray
  1 sibling, 1 reply; 5+ messages in thread
From: Stephen Hemminger @ 2021-10-12 20:14 UTC (permalink / raw)
  To: David Marchand; +Cc: dev, mdr, thomas, Anatoly Burakov

On Tue, 12 Oct 2021 21:39:26 +0200
David Marchand <david.marchand@redhat.com> wrote:

> 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 <david.marchand@redhat.com>

Acked-by: Stephen Hemminger <stephen@networkplumber.org>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [dpdk-dev] [PATCH] memzone: enforce valid flags when reserving
  2021-10-12 20:14 ` Stephen Hemminger
@ 2021-10-13  8:47   ` Andrew Rybchenko
  2021-10-15  8:27     ` David Marchand
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Rybchenko @ 2021-10-13  8:47 UTC (permalink / raw)
  To: Stephen Hemminger, David Marchand; +Cc: dev, mdr, thomas, Anatoly Burakov

On 10/12/21 11:14 PM, Stephen Hemminger wrote:
> On Tue, 12 Oct 2021 21:39:26 +0200
> David Marchand <david.marchand@redhat.com> wrote:
> 
>> 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 <david.marchand@redhat.com>
> 
> Acked-by: Stephen Hemminger <stephen@networkplumber.org>
> 

Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [dpdk-dev] [PATCH] memzone: enforce valid flags when reserving
  2021-10-12 19:39 [dpdk-dev] [PATCH] memzone: enforce valid flags when reserving David Marchand
  2021-10-12 20:14 ` Stephen Hemminger
@ 2021-10-13  9:00 ` Kinsella, Ray
  1 sibling, 0 replies; 5+ messages in thread
From: Kinsella, Ray @ 2021-10-13  9:00 UTC (permalink / raw)
  To: David Marchand, dev; +Cc: thomas, Anatoly Burakov



On 12/10/2021 20:39, David Marchand wrote:
> 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 <david.marchand@redhat.com>
> ---
>  app/test/test_memzone.c             | 24 ++++++++++++++++++++++++
>  lib/eal/common/eal_common_memzone.c | 17 +++++++++++++++++
>  2 files changed, 41 insertions(+)

Acked-by: Ray Kinsella <mdr@ashroe.eu>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [dpdk-dev] [PATCH] memzone: enforce valid flags when reserving
  2021-10-13  8:47   ` Andrew Rybchenko
@ 2021-10-15  8:27     ` David Marchand
  0 siblings, 0 replies; 5+ messages in thread
From: David Marchand @ 2021-10-15  8:27 UTC (permalink / raw)
  To: David Marchand
  Cc: Andrew Rybchenko, Stephen Hemminger, dev, Ray Kinsella,
	Thomas Monjalon, Anatoly Burakov

On Wed, Oct 13, 2021 at 10:47 AM Andrew Rybchenko
<andrew.rybchenko@oktetlabs.ru> wrote:
>
> On 10/12/21 11:14 PM, Stephen Hemminger wrote:
> > On Tue, 12 Oct 2021 21:39:26 +0200
> > David Marchand <david.marchand@redhat.com> wrote:
> >
> >> 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 <david.marchand@redhat.com>
> > Acked-by: Stephen Hemminger <stephen@networkplumber.org>
> Acked-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Acked-by: Ray Kinsella <mdr@ashroe.eu>

Applied, thanks.


-- 
David Marchand


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-10-15  8:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-12 19:39 [dpdk-dev] [PATCH] memzone: enforce valid flags when reserving David Marchand
2021-10-12 20:14 ` Stephen Hemminger
2021-10-13  8:47   ` Andrew Rybchenko
2021-10-15  8:27     ` David Marchand
2021-10-13  9:00 ` Kinsella, Ray

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).