From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9E5A5A0C4C; Tue, 12 Oct 2021 21:39:57 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 874F641120; Tue, 12 Oct 2021 21:39:57 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id AB6AB4111C for ; Tue, 12 Oct 2021 21:39:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634067595; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=1xPZAG8X7PS9DxWz+X9Jd66YYvTU8vJJg8+0/iY1rCo=; b=iVvDeLOWYOTh+KoZ5az8Rdqn2YpS2n4osHs7BD5X0HGEiEMauAUDG2lNM5CJavmPaxN03C 7qbiqURZXqltFccBj7xVaCqNB6AsQhTw2I8iby3ro3MpvTmUnmsm/CsPAn2UY9Z9Hk843V ct/3dY1sxqxuFzZEBfjhNo7I6qDimRY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-174-eYnOVhzHMB-ePME7gaOitQ-1; Tue, 12 Oct 2021 15:39:53 -0400 X-MC-Unique: eYnOVhzHMB-ePME7gaOitQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CB1B4801ADA; Tue, 12 Oct 2021 19:39:52 +0000 (UTC) Received: from dmarchan.remote.csb (unknown [10.40.192.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF17E60CC9; Tue, 12 Oct 2021 19:39:50 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: mdr@ashroe.eu, thomas@monjalon.net, Anatoly Burakov Date: Tue, 12 Oct 2021 21:39:26 +0200 Message-Id: <20211012193927.21838-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david.marchand@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Subject: [dpdk-dev] [PATCH] memzone: enforce valid flags when reserving X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- 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