All of lore.kernel.org
 help / color / mirror / Atom feed
From: Robert Sanford <rsanford2@gmail.com>
To: dev@dpdk.org
Cc: andrew.rybchenko@oktetlabs.ru, mb@smartsharesystems.com,
	olivier.matz@6wind.com, Robert Sanford <rsanford@akamai.com>,
	stable@dpdk.org
Subject: [PATCH v1 2/3] mempool: skip unpopulated pools in walk and dump
Date: Mon,  2 Nov 2026 20:11:06 -0500	[thread overview]
Message-ID: <20261103011107.3658840-3-rsanford2@gmail.com> (raw)
In-Reply-To: <20261103011107.3658840-1-rsanford2@gmail.com>

From: Robert Sanford <rsanford@akamai.com>

rte_mempool_create_empty() adds a mempool to the mempool list before
the mempool has a store. The store is allocated, and
RTE_MEMPOOL_F_POOL_CREATED is set, by the first populate call. In
between, rte_mempool_walk() passes the mempool to its callback, and
rte_mempool_list_dump() calls rte_mempool_dump() on it, which reads
the number of objects in the store. With the ring driver this
dereferences a NULL ring, and the process crashes.

Skip mempools that do not have RTE_MEMPOOL_F_POOL_CREATED set in
rte_mempool_walk() and rte_mempool_list_dump(), and document it. The
populating thread sets the flag without holding a lock, so add a
release fence before setting it and an acquire fence after checking
it. A walker that sees the flag then also sees the store.

rte_mempool_lookup() is unchanged. It does not access the store, and
callers may look up a mempool that is not populated yet.

Fixes: 449c49b93a6b ("mempool: support handler operations")
Cc: stable@dpdk.org

Signed-off-by: Robert Sanford <rsanford@akamai.com>
---
 lib/mempool/rte_mempool.c | 20 +++++++++++++++++++-
 lib/mempool/rte_mempool.h |  3 +++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/lib/mempool/rte_mempool.c b/lib/mempool/rte_mempool.c
index d9f339a3c2..7c4d4697c7 100644
--- a/lib/mempool/rte_mempool.c
+++ b/lib/mempool/rte_mempool.c
@@ -304,6 +304,12 @@ mempool_ops_alloc_once(struct rte_mempool *mp)
 		ret = rte_mempool_ops_alloc(mp);
 		if (ret != 0)
 			return ret;
+		/*
+		 * rte_mempool_walk() and rte_mempool_list_dump() access the
+		 * store of pools with this flag set. Make the store visible
+		 * before the flag.
+		 */
+		rte_atomic_thread_fence(rte_memory_order_release);
 		mp->flags |= RTE_MEMPOOL_F_POOL_CREATED;
 	}
 	return 0;
@@ -1412,6 +1418,11 @@ rte_mempool_list_dump(FILE *f)
 
 	TAILQ_FOREACH(te, mempool_list, next) {
 		mp = (struct rte_mempool *) te->data;
+		/* skip mempools that are not populated yet */
+		if ((mp->flags & RTE_MEMPOOL_F_POOL_CREATED) == 0)
+			continue;
+		/* pairs with the release fence in mempool_ops_alloc_once() */
+		rte_atomic_thread_fence(rte_memory_order_acquire);
 		rte_mempool_dump(f, mp);
 	}
 
@@ -1460,7 +1471,14 @@ void rte_mempool_walk(void (*func)(struct rte_mempool *, void *),
 	rte_mcfg_mempool_read_lock();
 
 	RTE_TAILQ_FOREACH_SAFE(te, mempool_list, next, tmp_te) {
-		(*func)((struct rte_mempool *) te->data, arg);
+		struct rte_mempool *mp = (struct rte_mempool *) te->data;
+
+		/* skip mempools that are not populated yet */
+		if ((mp->flags & RTE_MEMPOOL_F_POOL_CREATED) == 0)
+			continue;
+		/* pairs with the release fence in mempool_ops_alloc_once() */
+		rte_atomic_thread_fence(rte_memory_order_acquire);
+		(*func)(mp, arg);
 	}
 
 	rte_mcfg_mempool_read_unlock();
diff --git a/lib/mempool/rte_mempool.h b/lib/mempool/rte_mempool.h
index bd58d8a9d5..7782768a2d 100644
--- a/lib/mempool/rte_mempool.h
+++ b/lib/mempool/rte_mempool.h
@@ -1907,6 +1907,8 @@ static inline void *rte_mempool_get_priv(struct rte_mempool *mp)
 /**
  * Dump the status of all mempools on the console
  *
+ * Mempools that are not populated yet are skipped.
+ *
  * @param f
  *   A pointer to a file for output
  */
@@ -1949,6 +1951,7 @@ uint32_t rte_mempool_calc_obj_size(uint32_t elt_size, uint32_t flags,
  *
  * The mempool list is locked while the iterator function runs, so the
  * iterator function must not create or free a mempool.
+ * Mempools that are not populated yet are skipped.
  *
  * @param func
  *   Iterator function
-- 
2.34.1


  parent reply	other threads:[~2026-11-03  1:11 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03  1:11 [PATCH v1 0/3] mempool: fix races between list walk and create/free Robert Sanford
2026-11-03  1:11 ` [PATCH v1 1/3] mempool: fix race between list walk and free Robert Sanford
2026-11-03 13:54   ` Morten Brørup
2026-11-03  1:11 ` Robert Sanford [this message]
2026-11-03 14:12   ` [PATCH v1 2/3] mempool: skip unpopulated pools in walk and dump Morten Brørup
2026-11-03  1:11 ` [PATCH v1 3/3] test/mempool: add list walk race test Robert Sanford
2026-11-03 14:15   ` Morten Brørup
2026-11-03 17:35 ` [PATCH v2 0/3] mempool: fix races between list walk and create/free Robert Sanford
2026-11-03 17:35   ` [PATCH v2 1/3] mempool: fix race between list walk and free Robert Sanford
2026-11-03 17:35   ` [PATCH v2 2/3] mempool: fix dump of unpopulated pool Robert Sanford
2026-11-06  8:43     ` Morten Brørup
2026-11-06 18:43       ` Robert Sanford
2026-11-06 19:24         ` Morten Brørup
2026-11-03 17:35   ` [PATCH v2 3/3] test/mempool: add list walk race test Robert Sanford
2026-11-09 14:40   ` [PATCH v3 0/3] mempool: fix races between list walk and create/free Robert Sanford
2026-11-09 14:40     ` [PATCH v3 1/3] mempool: fix race between list walk and free Robert Sanford
2026-11-09 14:40     ` [PATCH v3 2/3] mempool: fix dump of unpopulated pool Robert Sanford
2026-11-09 14:40     ` [PATCH v3 3/3] test/mempool: add list walk race test Robert Sanford
2026-11-11 13:00       ` Morten Brørup
2026-11-12 15:43     ` [PATCH v4 0/3] mempool: fix races between list walk and create/free Robert Sanford
2026-11-12 15:43       ` [PATCH v4 1/3] mempool: fix race between list walk and free Robert Sanford
2026-11-12 15:43       ` [PATCH v4 2/3] mempool: fix dump of unpopulated pool Robert Sanford
2026-11-19 14:08         ` Thomas Monjalon
2026-11-19 14:18           ` Morten Brørup
2026-11-19 14:47             ` Thomas Monjalon
2026-11-19 19:27               ` Morten Brørup
2026-11-19 14:20           ` Morten Brørup
2026-11-12 15:43       ` [PATCH v4 3/3] test/mempool: add list walk race test Robert Sanford
2026-11-30 20:51       ` [PATCH v5 0/3] mempool: fix races between list walk and create/free Robert Sanford
2026-11-30 20:51         ` [PATCH v5 1/3] mempool: fix race between list walk and free Robert Sanford
2026-11-30 20:51         ` [PATCH v5 2/3] mempool: fix dump of unpopulated pool Robert Sanford
2026-12-01  0:06           ` Stephen Hemminger
2026-11-30 20:51         ` [PATCH v5 3/3] test/mempool: add list walk race test Robert Sanford

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=20261103011107.3658840-3-rsanford2@gmail.com \
    --to=rsanford2@gmail.com \
    --cc=andrew.rybchenko@oktetlabs.ru \
    --cc=dev@dpdk.org \
    --cc=mb@smartsharesystems.com \
    --cc=olivier.matz@6wind.com \
    --cc=rsanford@akamai.com \
    --cc=stable@dpdk.org \
    /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.