From: "Morten Brørup" <mb@smartsharesystems.com>
To: "Robert Sanford" <rsanford2@gmail.com>, <dev@dpdk.org>
Cc: <andrew.rybchenko@oktetlabs.ru>, <olivier.matz@6wind.com>,
"Robert Sanford" <rsanford@akamai.com>, <stable@dpdk.org>
Subject: RE: [PATCH v1 1/3] mempool: fix race between list walk and free
Date: Tue, 3 Nov 2026 14:54:52 +0100 [thread overview]
Message-ID: <98CBD80474FA8B44BF855DF32C47DC35F65AF4@smartserver.smartshare.dk> (raw)
In-Reply-To: <20261103011107.3658840-2-rsanford2@gmail.com>
> From: Robert Sanford [mailto:rsanford2@gmail.com]
> Sent: Tuesday, 3 November 2026 02.11
> To: dev@dpdk.org
> Cc: andrew.rybchenko@oktetlabs.ru; Morten Brørup;
> olivier.matz@6wind.com; Robert Sanford; stable@dpdk.org
> Subject: [PATCH v1 1/3] mempool: fix race between list walk and free
>
> From: Robert Sanford <rsanford@akamai.com>
>
> rte_mempool_walk(), rte_mempool_lookup() and rte_mempool_list_dump()
> traverse the mempool list holding only the mempool list lock.
> rte_mempool_create_empty() inserts into the list holding both the
> mempool list lock and the tailq lock, but rte_mempool_free() unlinks
> and frees the list entry holding only the tailq lock. So a mempool can
> be unlinked and freed, together with its list entry, while another
> thread is walking the list. The walker then reads freed memory. Since
> freed heap memory is zeroed, the walk callback is passed a NULL
> mempool, or rte_mempool_lookup() compares the name of one, and the
> process crashes.
>
> Take the mempool list lock in rte_mempool_free() as well, in the same
> order as rte_mempool_create_empty(). As a result, a rte_mempool_walk()
> callback must not free a mempool, as it already could not create one.
> Document this.
>
> Fixes: a3791ff0a3f8 ("mempool: introduce a function to free a pool")
> Cc: stable@dpdk.org
>
> Signed-off-by: Robert Sanford <rsanford@akamai.com>
> ---
> lib/mempool/rte_mempool.c | 8 ++++++++
> lib/mempool/rte_mempool.h | 3 +++
> 2 files changed, 11 insertions(+)
>
> diff --git a/lib/mempool/rte_mempool.c b/lib/mempool/rte_mempool.c
> index 069aabaa70..d9f339a3c2 100644
> --- a/lib/mempool/rte_mempool.c
> +++ b/lib/mempool/rte_mempool.c
> @@ -729,6 +729,13 @@ rte_mempool_free(struct rte_mempool *mp)
> return;
>
> mempool_list = RTE_TAILQ_CAST(rte_mempool_tailq.head,
> rte_mempool_list);
> + /*
> + * Take the mempool list lock as well, like
> rte_mempool_create_empty(),
> + * so that the entry is not unlinked and freed while
> + * rte_mempool_walk(), rte_mempool_lookup() or
> rte_mempool_list_dump()
> + * is traversing the list.
> + */
> + rte_mcfg_mempool_write_lock();
> rte_mcfg_tailq_write_lock();
> /* find out tailq entry */
> TAILQ_FOREACH(te, mempool_list, next) {
> @@ -741,6 +748,7 @@ rte_mempool_free(struct rte_mempool *mp)
> rte_free(te);
> }
> rte_mcfg_tailq_write_unlock();
> + rte_mcfg_mempool_write_unlock();
>
> mempool_event_callback_invoke(RTE_MEMPOOL_EVENT_DESTROY, mp);
> rte_mempool_trace_free(mp);
> diff --git a/lib/mempool/rte_mempool.h b/lib/mempool/rte_mempool.h
> index b34cd893b1..bd58d8a9d5 100644
> --- a/lib/mempool/rte_mempool.h
> +++ b/lib/mempool/rte_mempool.h
> @@ -1947,6 +1947,9 @@ uint32_t rte_mempool_calc_obj_size(uint32_t
> elt_size, uint32_t flags,
> /**
> * Walk list of all memory pools
> *
> + * The mempool list is locked while the iterator function runs, so the
> + * iterator function must not create or free a mempool.
> + *
> * @param func
> * Iterator function
> * @param arg
> --
> 2.34.1
Reviewed-by: Morten Brørup <mb@smartsharesystems.com>
Verified that rte_mempool_create_empty() takes the mcfg_mempool and mcfg_tailq locks in the same order as this patch.
next prev parent reply other threads:[~2026-11-03 13:54 UTC|newest]
Thread overview: 23+ 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 [this message]
2026-11-03 1:11 ` [PATCH v1 2/3] mempool: skip unpopulated pools in walk and dump Robert Sanford
2026-11-03 14:12 ` 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-12 15:43 ` [PATCH v4 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=98CBD80474FA8B44BF855DF32C47DC35F65AF4@smartserver.smartshare.dk \
--to=mb@smartsharesystems.com \
--cc=andrew.rybchenko@oktetlabs.ru \
--cc=dev@dpdk.org \
--cc=olivier.matz@6wind.com \
--cc=rsanford2@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox