All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Kozlyuk <dkozlyuk@oss.nvidia.com>
To: <dev@dpdk.org>
Cc: Olivier Matz <olivier.matz@6wind.com>,
	Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Subject: [dpdk-dev] [PATCH v2] mempool: fix non-IO flag inference
Date: Sat, 23 Oct 2021 00:09:19 +0300	[thread overview]
Message-ID: <20211022210920.207732-1-dkozlyuk@nvidia.com> (raw)
In-Reply-To: <20211022075937.52983-1-dkozlyuk@nvidia.com>

When mempool had been created with RTE_MEMPOOL_F_NO_IOVA_CONTIG flag
but later populated with valid IOVA, RTE_MEMPOOL_F_NON_IO was unset,
while it should be kept. The unit test did not catch this
because rte_mempool_populate_default() it used was populating
with RTE_BAD_IOVA.

Keep setting RTE_MEMPOOL_NON_IO at an empty mempool creation
and add an assert for it in the unit test (remove the separate case).
Do not reset the flag if RTE_MEMPOOL_F_ON_IOVA_CONTIG is set.

Fixes: 11541c5c81dd ("mempool: add non-IO flag")

Signed-off-by: Dmitry Kozlyuk <dkozlyuk@nvidia.com>
---
v2: IOVA mode has nothing to do with populating the mempool,
    so logic related to it is removed and the unit test simplified.

 app/test/test_mempool.c   | 45 +++++++++++++++++----------------------
 lib/mempool/rte_mempool.c |  4 ++--
 2 files changed, 22 insertions(+), 27 deletions(-)

diff --git a/app/test/test_mempool.c b/app/test/test_mempool.c
index 4f399b461d..4b0f6b0e7f 100644
--- a/app/test/test_mempool.c
+++ b/app/test/test_mempool.c
@@ -740,16 +740,31 @@ test_mempool_events_safety(void)
 static int
 test_mempool_flag_non_io_set_when_no_iova_contig_set(void)
 {
+	void *virt = NULL;
+	rte_iova_t iova;
+	size_t size = MEMPOOL_ELT_SIZE * 16;
 	struct rte_mempool *mp = NULL;
 	int ret;
 
+	virt = rte_malloc("test_mempool", size, rte_mem_page_size());
+	RTE_TEST_ASSERT_NOT_NULL(virt, "Cannot allocate memory");
+	iova = rte_mem_virt2iova(virt);
+	RTE_TEST_ASSERT_NOT_EQUAL(iova,  RTE_BAD_IOVA, "Cannot get IOVA");
 	mp = rte_mempool_create_empty("empty", MEMPOOL_SIZE,
 				      MEMPOOL_ELT_SIZE, 0, 0,
 				      SOCKET_ID_ANY, RTE_MEMPOOL_F_NO_IOVA_CONTIG);
 	RTE_TEST_ASSERT_NOT_NULL(mp, "Cannot create mempool: %s",
 				 rte_strerror(rte_errno));
 	rte_mempool_set_ops_byname(mp, rte_mbuf_best_mempool_ops(), NULL);
-	ret = rte_mempool_populate_default(mp);
+
+	RTE_TEST_ASSERT(mp->flags & RTE_MEMPOOL_F_NON_IO,
+			"NON_IO flag is not set on an empty mempool");
+
+	/*
+	 * Always use valid IOVA so that populate() has no other reason
+	 * to infer that the mempool cannot be used for IO.
+	 */
+	ret = rte_mempool_populate_iova(mp, virt, iova, size, NULL, NULL);
 	RTE_TEST_ASSERT(ret > 0, "Failed to populate mempool: %s",
 			rte_strerror(-ret));
 	RTE_TEST_ASSERT(mp->flags & RTE_MEMPOOL_F_NON_IO,
@@ -757,6 +772,7 @@ test_mempool_flag_non_io_set_when_no_iova_contig_set(void)
 	ret = TEST_SUCCESS;
 exit:
 	rte_mempool_free(mp);
+	rte_free(virt);
 	return ret;
 }
 
@@ -785,6 +801,9 @@ test_mempool_flag_non_io_unset_when_populated_with_valid_iova(void)
 	RTE_TEST_ASSERT_NOT_NULL(mp, "Cannot create mempool: %s",
 				 rte_strerror(rte_errno));
 
+	RTE_TEST_ASSERT(mp->flags & RTE_MEMPOOL_F_NON_IO,
+			"NON_IO flag is not set on an empty mempool");
+
 	ret = rte_mempool_populate_iova(mp, RTE_PTR_ADD(virt, 1 * block_size),
 					RTE_BAD_IOVA, block_size, NULL, NULL);
 	RTE_TEST_ASSERT(ret > 0, "Failed to populate mempool: %s",
@@ -812,28 +831,6 @@ test_mempool_flag_non_io_unset_when_populated_with_valid_iova(void)
 	return ret;
 }
 
-static int
-test_mempool_flag_non_io_unset_by_default(void)
-{
-	struct rte_mempool *mp;
-	int ret;
-
-	mp = rte_mempool_create_empty("empty", MEMPOOL_SIZE,
-				      MEMPOOL_ELT_SIZE, 0, 0,
-				      SOCKET_ID_ANY, 0);
-	RTE_TEST_ASSERT_NOT_NULL(mp, "Cannot create mempool: %s",
-				 rte_strerror(rte_errno));
-	ret = rte_mempool_populate_default(mp);
-	RTE_TEST_ASSERT_EQUAL(ret, (int)mp->size, "Failed to populate mempool: %s",
-			      rte_strerror(-ret));
-	RTE_TEST_ASSERT(!(mp->flags & RTE_MEMPOOL_F_NON_IO),
-			"NON_IO flag is set by default");
-	ret = TEST_SUCCESS;
-exit:
-	rte_mempool_free(mp);
-	return ret;
-}
-
 #pragma pop_macro("RTE_TEST_TRACE_FAILURE")
 
 static int
@@ -1022,8 +1019,6 @@ test_mempool(void)
 		GOTO_ERR(ret, err);
 
 	/* test NON_IO flag inference */
-	if (test_mempool_flag_non_io_unset_by_default() < 0)
-		GOTO_ERR(ret, err);
 	if (test_mempool_flag_non_io_set_when_no_iova_contig_set() < 0)
 		GOTO_ERR(ret, err);
 	if (test_mempool_flag_non_io_unset_when_populated_with_valid_iova() < 0)
diff --git a/lib/mempool/rte_mempool.c b/lib/mempool/rte_mempool.c
index b75d26c82a..f66a561d05 100644
--- a/lib/mempool/rte_mempool.c
+++ b/lib/mempool/rte_mempool.c
@@ -372,8 +372,8 @@ rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr,
 	STAILQ_INSERT_TAIL(&mp->mem_list, memhdr, next);
 	mp->nb_mem_chunks++;
 
-	/* At least some objects in the pool can now be used for IO. */
-	if (iova != RTE_BAD_IOVA)
+	/* Check if at least some objects in the pool are now usable for IO. */
+	if (!(mp->flags & RTE_MEMPOOL_F_NO_IOVA_CONTIG) && iova != RTE_BAD_IOVA)
 		mp->flags &= ~RTE_MEMPOOL_F_NON_IO;
 
 	/* Report the mempool as ready only when fully populated. */
-- 
2.25.1


  reply	other threads:[~2021-10-22 21:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-22  7:59 [dpdk-dev] [PATCH] mempool: fix non-IO flag inference Dmitry Kozlyuk
2021-10-22 21:09 ` Dmitry Kozlyuk [this message]
2021-10-25 13:33   ` [dpdk-dev] [PATCH v2] " Olivier Matz
2021-10-25 15:01     ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211022210920.207732-1-dkozlyuk@nvidia.com \
    --to=dkozlyuk@oss.nvidia.com \
    --cc=andrew.rybchenko@oktetlabs.ru \
    --cc=dev@dpdk.org \
    --cc=olivier.matz@6wind.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.