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 9B6E1A0C4B; Thu, 14 Oct 2021 21:29:34 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2877C40041; Thu, 14 Oct 2021 21:29:34 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mails.dpdk.org (Postfix) with ESMTP id C8C924003C for ; Thu, 14 Oct 2021 21:29:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634239772; 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: in-reply-to:in-reply-to:references:references; bh=r9Hgn/3dkdz4D1Al6oYbyHvDoNLhCLLGhlLh/9aX0Ko=; b=OzPZUYNMY0M3P4FO7w48WX2LA/DLYbDAzi+DK5WKT3PBnMVXzggNYS4XRdkGSR0NoGDpwq uAA6J6OKpcXCvcGyuov6JKzjVvBsSwJby7tTxlY0PBK8PbuRpp9G7tZrNhHfBFjxFOs9Yh jawJX3UXawpxjCk+JKklxzIAytb3HUo= 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-205-UgJ-7TBGMtOa7fkXUj2brA-1; Thu, 14 Oct 2021 15:29:29 -0400 X-MC-Unique: UgJ-7TBGMtOa7fkXUj2brA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 22672801AA7; Thu, 14 Oct 2021 19:29:27 +0000 (UTC) Received: from dmarchan.remote.csb (unknown [10.40.193.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id A9A0E5C232; Thu, 14 Oct 2021 19:29:23 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: dkozlyuk@oss.nvidia.com, thomas@monjalon.net, Andrew Rybchenko , Ray Kinsella , Olivier Matz Date: Thu, 14 Oct 2021 21:29:16 +0200 Message-Id: <20211014192916.15046-1-david.marchand@redhat.com> In-Reply-To: <20211012072848.17741-1-david.marchand@redhat.com> References: <20211012072848.17741-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 v2] mempool: enforce valid flags at creation 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 Reviewed-by: Andrew Rybchenko Acked-by: Ray Kinsella --- Changes since v1: - fixed checkpatch warning, - moved flags to validate them in the same order than parameters, --- app/test/test_mempool.c | 21 +++++++++++++++++++++ lib/mempool/rte_mempool.c | 13 +++++++++++++ lib/mempool/rte_mempool.h | 2 +- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/app/test/test_mempool.c b/app/test/test_mempool.c index 7675a3e605..66bc8d86b7 100644 --- a/app/test/test_mempool.c +++ b/app/test/test_mempool.c @@ -205,6 +205,24 @@ static int test_mempool_creation_with_exceeded_cache_size(void) return 0; } +static int test_mempool_creation_with_unknown_flag(void) +{ + struct rte_mempool *mp_cov; + + mp_cov = rte_mempool_create("test_mempool_unknown_flag", MEMPOOL_SIZE, + MEMPOOL_ELT_SIZE, 0, 0, + NULL, NULL, + NULL, NULL, + SOCKET_ID_ANY, MEMPOOL_F_NO_IOVA_CONTIG << 1); + + if (mp_cov != NULL) { + rte_mempool_free(mp_cov); + RET_ERR(); + } + + return 0; +} + static struct rte_mempool *mp_spsc; static rte_spinlock_t scsp_spinlock; static void *scsp_obj_table[MAX_KEEP]; @@ -635,6 +653,9 @@ test_mempool(void) if (test_mempool_creation_with_exceeded_cache_size() < 0) GOTO_ERR(ret, err); + if (test_mempool_creation_with_unknown_flag() < 0) + GOTO_ERR(ret, err); + if (test_mempool_same_name_twice_creation() < 0) GOTO_ERR(ret, err); diff --git a/lib/mempool/rte_mempool.c b/lib/mempool/rte_mempool.c index c5f859ae71..607419ccaf 100644 --- a/lib/mempool/rte_mempool.c +++ b/lib/mempool/rte_mempool.c @@ -777,6 +777,13 @@ rte_mempool_cache_free(struct rte_mempool_cache *cache) rte_free(cache); } +#define MEMPOOL_KNOWN_FLAGS (MEMPOOL_F_NO_SPREAD \ + | MEMPOOL_F_NO_CACHE_ALIGN \ + | MEMPOOL_F_SP_PUT \ + | MEMPOOL_F_SC_GET \ + | MEMPOOL_F_POOL_CREATED \ + | MEMPOOL_F_NO_IOVA_CONTIG \ + ) /* create an empty mempool */ struct rte_mempool * rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size, @@ -821,6 +828,12 @@ 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) { + rte_errno = EINVAL; + return NULL; + } + /* "no cache align" imply "no spread" */ if (flags & MEMPOOL_F_NO_CACHE_ALIGN) flags |= MEMPOOL_F_NO_SPREAD; diff --git a/lib/mempool/rte_mempool.h b/lib/mempool/rte_mempool.h index 04b14d7ae9..88bcbc51ef 100644 --- a/lib/mempool/rte_mempool.h +++ b/lib/mempool/rte_mempool.h @@ -991,7 +991,7 @@ typedef void (rte_mempool_ctor_t)(struct rte_mempool *, void *); * with rte_errno set appropriately. Possible rte_errno values include: * - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure * - E_RTE_SECONDARY - function was called from a secondary process instance - * - EINVAL - cache size provided is too large + * - EINVAL - cache size provided is too large or an unknown flag was passed * - ENOSPC - the maximum number of memzones has already been allocated * - EEXIST - a memzone with the same name already exists * - ENOMEM - no appropriate memory area found in which to create memzone -- 2.23.0