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 ABB07A0C43; Mon, 18 Oct 2021 10:26:51 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8EDD940141; Mon, 18 Oct 2021 10:26:51 +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 4CB8C4003C for ; Mon, 18 Oct 2021 10:26:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634545609; 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=yWCWrYwo6aagjSxnvjy7c+55QZTqafRcp1A1xkDO2C0=; b=JxlLDm2iW6GOJm5FEJB4koHtM6pHECLZ+ivuWa1kIT9ZcPCzATqf270oJRjHkj/cFfj5fX Kf9frO2PnhyjX2/yQs+XAVehL/y5RCvrARXo52EaPzk0ru+nMnQyTZgY0NYyscfwLCaYES OfbOEWx29kd3dWXgBX1FvWQPAMbmq70= 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-555-kMH_y5_KOEuhP_cLqE88SQ-1; Mon, 18 Oct 2021 04:26:46 -0400 X-MC-Unique: kMH_y5_KOEuhP_cLqE88SQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0EB3D1018720; Mon, 18 Oct 2021 08:26:45 +0000 (UTC) Received: from dmarchan.remote.csb (unknown [10.40.193.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2DBAB10023AB; Mon, 18 Oct 2021 08:26:41 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: Dmitry Kozlyuk , Olivier Matz , Andrew Rybchenko , Ray Kinsella , Stephen Hemminger Date: Mon, 18 Oct 2021 10:26:35 +0200 Message-Id: <20211018082635.2054-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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] mempool: accept user flags only 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" As reported by Dmitry, 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. Other internal flags 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 --- app/test/test_mempool.c | 8 ++++---- lib/mempool/rte_mempool.c | 11 ++--------- lib/mempool/rte_mempool.h | 9 +++++++++ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/app/test/test_mempool.c b/app/test/test_mempool.c index 66bc8d86b7..ba05742f76 100644 --- a/app/test/test_mempool.c +++ b/app/test/test_mempool.c @@ -205,15 +205,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, MEMPOOL_F_NO_IOVA_CONTIG << 1); + SOCKET_ID_ANY, ~MEMPOOL_VALID_USER_FLAGS); if (mp_cov != NULL) { rte_mempool_free(mp_cov); @@ -653,7 +653,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 607419ccaf..7f92d79c89 100644 --- a/lib/mempool/rte_mempool.c +++ b/lib/mempool/rte_mempool.c @@ -777,13 +777,6 @@ 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, @@ -828,8 +821,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 & ~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 88bcbc51ef..d2bf2843f7 100644 --- a/lib/mempool/rte_mempool.h +++ b/lib/mempool/rte_mempool.h @@ -258,6 +258,15 @@ struct rte_mempool { #define MEMPOOL_F_POOL_CREATED 0x0010 /**< Internal: pool is created. */ #define MEMPOOL_F_NO_IOVA_CONTIG 0x0020 /**< Don't need IOVA contiguous objs. */ +/** + * This macro lists all the mempool flags an application may request. + */ +#define MEMPOOL_VALID_USER_FLAGS (MEMPOOL_F_NO_SPREAD \ + | MEMPOOL_F_NO_CACHE_ALIGN \ + | MEMPOOL_F_SP_PUT \ + | MEMPOOL_F_SC_GET \ + | MEMPOOL_F_NO_IOVA_CONTIG \ + ) /** * @internal When debug is enabled, store some statistics. * -- 2.23.0