patch 'net/af_xdp: fix shared UMEM refcount corruption' has been queued to stable release 25.11.5

Kevin Traynor ktraynor at redhat.com
Thu Dec 3 13:59:29 CET 2026


Hi,

FYI, your patch has been queued to stable release 25.11.5

Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 12/08/26. So please
shout if anyone has objections.

Also note that after the patch there's a diff of the upstream commit vs the
patch applied to the branch. This will indicate if there was any rebasing
needed to apply to the stable branch. If there were code changes for rebasing
(ie: not only metadata diffs), please double check that the rebase was
correctly done.

Queued patches are on a temporary branch at:
https://github.com/kevintraynor/dpdk-stable

This queued commit can be viewed at:
https://github.com/kevintraynor/dpdk-stable/commit/86005f6ca4c78b5a9bbf6a17ae98b7bf42c02986

Thanks.

Kevin

---
>From 86005f6ca4c78b5a9bbf6a17ae98b7bf42c02986 Mon Sep 17 00:00:00 2001
From: Sandeep Penigalapati <sandeep.penigalapati at intel.com>
Date: Thu, 20 Aug 2026 22:16:07 -0400
Subject: [PATCH] net/af_xdp: fix shared UMEM refcount corruption

[ upstream commit 53cdbf06bca6c02cf1e4cc31f42f4691734059fc ]

Shared UMEM is meant to be shared by a limited number of sockets,
governed by the mempool size (max_xsks). When the UMEM was already at
capacity (refcnt >= max_xsks), xdp_umem_configure() returned the UMEM
without incrementing its refcount, so the extra socket used it
unaccounted for.

This missing reference has two consequences. During queue setup the
fill-queue reservation is chosen from the refcount, so the sharing
socket reserves into its own uninitialised fill queue and crashes. At
close, the under-counted refcount reaches zero while the UMEM is still
in use, freeing it early and causing a use-after-free.

Reject sharing once the UMEM is at capacity by returning NULL. The
error is propagated from xsk_configure(), so Rx queue setup fails
cleanly with -ENOMEM. This applies the per-mempool socket limit that
shared UMEM was always intended to respect.

Harden the failure path this makes reachable:
- clear rxq->umem and its paired txq->umem when xsk_configure() fails,
  and skip queues whose UMEM is not yet set in get_shared_umem(), so a
  later scan over the same mempool cannot dereference a NULL or
  dangling UMEM;
- free the fill-queue mbufs that were allocated but not yet handed to
  the fill queue when a sharing socket fails to bind, so it no longer
  leaks a burst of mbufs back out of the shared mempool;
- propagate the map-insert failures in xsk_configure() instead of
  returning success, so a failed xsks_map update no longer leaves the
  caller using a deleted socket;
- continue past, rather than stop at, a failed queue in eth_dev_close()
  so later successful queues and their UMEM references are still freed;
- clamp max_xsks to UINT8_MAX so the cap stays within the uint8_t
  refcount.

Also correct the UMEM refcount memory ordering: release on the shared
increment and acquire-release on the final decrement, so the thread that
drops the last reference observes all prior users' writes before it
frees the UMEM.

Document the shared mempool sizing requirement (4096 mbufs per socket).

Note: on stable branches this is a behaviour change. Shared-UMEM setups
that previously appeared to start, until the fill-queue crash or the
use-after-free at close, now fail cleanly at Rx queue setup with
-ENOMEM.

Fixes: 74b46340e2d4 ("net/af_xdp: support shared UMEM")

Signed-off-by: Sandeep Penigalapati <sandeep.penigalapati at intel.com>
---
 doc/guides/nics/af_xdp.rst          |  5 +++
 drivers/net/af_xdp/rte_eth_af_xdp.c | 64 +++++++++++++++++++++++------
 2 files changed, 57 insertions(+), 12 deletions(-)

diff --git a/doc/guides/nics/af_xdp.rst b/doc/guides/nics/af_xdp.rst
index 57dc3b6918..a9e257af23 100644
--- a/doc/guides/nics/af_xdp.rst
+++ b/doc/guides/nics/af_xdp.rst
@@ -100,4 +100,9 @@ configured like so:
     --vdev net_af_xdp1,iface=ens786f2,shared_umem=1
 
+The shared mempool must be large enough for every AF_XDP socket sharing the UMEM.
+Each socket needs 4096 mbufs for its fill queue,
+so ``N`` sockets need at least ``4096 * N`` mbufs.
+Rx queue setup fails if the mempool is too small to add another socket to the UMEM.
+
 xdp_prog
 ~~~~~~~~
diff --git a/drivers/net/af_xdp/rte_eth_af_xdp.c b/drivers/net/af_xdp/rte_eth_af_xdp.c
index 54bd095c92..c5e5239d6e 100644
--- a/drivers/net/af_xdp/rte_eth_af_xdp.c
+++ b/drivers/net/af_xdp/rte_eth_af_xdp.c
@@ -1065,10 +1065,11 @@ eth_dev_close(struct rte_eth_dev *dev)
 	for (i = 0; i < internals->queue_cnt; i++) {
 		rxq = &internals->rx_queues[i];
+		/* Skip queues where eth_rx_queue_setup() was never called or failed. */
 		if (rxq->umem == NULL)
-			break;
+			continue;
 		xsk_socket__delete(rxq->xsk);
 
 		if (rte_atomic_fetch_sub_explicit(&rxq->umem->refcnt, 1,
-				rte_memory_order_acquire) - 1 == 0)
+				rte_memory_order_acq_rel) - 1 == 0)
 			xdp_umem_destroy(rxq->umem);
 	}
@@ -1157,4 +1158,7 @@ get_shared_umem(struct pkt_rx_queue *rxq, const char *ifname,
 					goto out;
 				}
+				/* A failed setup leaves mb_pool set with no umem. */
+				if (list_rxq->umem == NULL)
+					continue;
 				if (rte_atomic_load_explicit(&internals->rx_queues[i].umem->refcnt,
 						    rte_memory_order_acquire)) {
@@ -1191,10 +1195,27 @@ xsk_umem_info *xdp_umem_configure(struct pmd_internals *internals,
 			return NULL;
 
-		if (umem != NULL &&
-			rte_atomic_load_explicit(&umem->refcnt, rte_memory_order_acquire) <
-					umem->max_xsks) {
+		if (umem != NULL) {
+			/* Reject sharing once the UMEM is at capacity. */
+			if (rte_atomic_load_explicit(&umem->refcnt,
+					rte_memory_order_acquire) >= umem->max_xsks) {
+				if (umem->max_xsks == 0)
+					AF_XDP_LOG_LINE(ERR,
+						"%s,qid%i: mempool %s has %u mbufs, "
+						"need at least %u to share UMEM",
+						internals->if_name, rxq->xsk_queue_idx,
+						umem->mb_pool->name,
+						umem->mb_pool->populated_size,
+						ETH_AF_XDP_NUM_BUFFERS);
+				else
+					AF_XDP_LOG_LINE(ERR,
+						"%s,qid%i: UMEM %s already at max %u sockets",
+						internals->if_name, rxq->xsk_queue_idx,
+						umem->mb_pool->name, umem->max_xsks);
+				return NULL;
+			}
+
 			AF_XDP_LOG_LINE(INFO, "%s,qid%i sharing UMEM",
 					internals->if_name, rxq->xsk_queue_idx);
-			rte_atomic_fetch_add_explicit(&umem->refcnt, 1, rte_memory_order_acquire);
+			rte_atomic_fetch_add_explicit(&umem->refcnt, 1, rte_memory_order_release);
 		}
 	}
@@ -1242,6 +1263,8 @@ xsk_umem_info *xdp_umem_configure(struct pmd_internals *internals,
 
 		if (internals->shared_umem) {
-			umem->max_xsks = mb_pool->populated_size /
-						ETH_AF_XDP_NUM_BUFFERS;
+			/* refcnt is uint8_t, so the cap cannot exceed UINT8_MAX. */
+			umem->max_xsks = RTE_MIN(mb_pool->populated_size /
+						ETH_AF_XDP_NUM_BUFFERS,
+						(uint32_t)UINT8_MAX);
 			AF_XDP_LOG_LINE(INFO, "Max xsks for UMEM %s: %u",
 						mb_pool->name, umem->max_xsks);
@@ -1687,8 +1710,11 @@ xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
 	struct rte_mbuf *fq_bufs[reserve_size];
 	bool reserve_before;
+	bool free_fq_bufs = false;
 
 	rxq->umem = xdp_umem_configure(internals, rxq);
-	if (rxq->umem == NULL)
+	if (rxq->umem == NULL) {
+		txq->umem = NULL;
 		return -ENOMEM;
+	}
 	txq->umem = rxq->umem;
 	reserve_before = rte_atomic_load_explicit(&rxq->umem->refcnt,
@@ -1701,4 +1727,5 @@ xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
 		goto out_umem;
 	}
+	free_fq_bufs = true;
 #endif
 
@@ -1706,4 +1733,5 @@ xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
 	if (reserve_before) {
 		ret = reserve_fill_queue(rxq->umem, reserve_size, fq_bufs, &rxq->fq);
+		free_fq_bufs = false;
 		if (ret) {
 			AF_XDP_LOG_LINE(ERR, "Failed to reserve fill queue.");
@@ -1762,4 +1790,5 @@ xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
 		/* reserve fill queue of queues sharing UMEM */
 		ret = reserve_fill_queue(rxq->umem, reserve_size, fq_bufs, &rxq->fq);
+		free_fq_bufs = false;
 		if (ret) {
 			AF_XDP_LOG_LINE(ERR, "Failed to reserve fill queue.");
@@ -1777,4 +1806,5 @@ xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
 		if (err) {
 			AF_XDP_LOG_LINE(ERR, "Failed to insert xsk in map.");
+			ret = -EINVAL;
 			goto out_xsk;
 		}
@@ -1789,4 +1819,5 @@ xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
 			if (map_fd < 0) {
 				AF_XDP_LOG_LINE(ERR, "Failed to receive xskmap fd from AF_XDP Device Plugin");
+				ret = -EINVAL;
 				goto out_xsk;
 			}
@@ -1796,4 +1827,5 @@ xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
 			if (err < 0 || map_fd < 0) {
 				AF_XDP_LOG_LINE(ERR, "Failed to retrieve pinned map fd");
+				ret = -EINVAL;
 				goto out_xsk;
 			}
@@ -1803,4 +1835,5 @@ xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
 		if (err) {
 			AF_XDP_LOG_LINE(ERR, "Failed to insert xsk in map.");
+			ret = -EINVAL;
 			goto out_xsk;
 		}
@@ -1819,6 +1852,13 @@ out_xsk:
 	xsk_socket__delete(rxq->xsk);
 out_umem:
-	if (rte_atomic_fetch_sub_explicit(&rxq->umem->refcnt, 1, rte_memory_order_acquire) - 1 == 0)
+	/* Free fq_bufs that were allocated but never handed to the fill queue. */
+	if (free_fq_bufs)
+		rte_pktmbuf_free_bulk(fq_bufs, reserve_size);
+	if (rte_atomic_fetch_sub_explicit(&rxq->umem->refcnt, 1,
+			rte_memory_order_acq_rel) - 1 == 0)
 		xdp_umem_destroy(rxq->umem);
+	/* Drop dangling pointers so a later shared-UMEM scan skips this queue. */
+	rxq->umem = NULL;
+	txq->umem = NULL;
 
 	return ret;
@@ -1861,7 +1901,7 @@ eth_rx_queue_setup(struct rte_eth_dev *dev,
 	rxq->mb_pool = mb_pool;
 
-	if (xsk_configure(internals, rxq, nb_rx_desc)) {
+	ret = xsk_configure(internals, rxq, nb_rx_desc);
+	if (ret) {
 		AF_XDP_LOG_LINE(ERR, "Failed to configure xdp socket");
-		ret = -EINVAL;
 		goto err;
 	}
-- 
2.56.1

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2026-12-03 12:52:40.558264732 +0000
+++ 0043-net-af_xdp-fix-shared-UMEM-refcount-corruption.patch	2026-12-03 12:52:39.045019553 +0000
@@ -1 +1 @@
-From 53cdbf06bca6c02cf1e4cc31f42f4691734059fc Mon Sep 17 00:00:00 2001
+From 86005f6ca4c78b5a9bbf6a17ae98b7bf42c02986 Mon Sep 17 00:00:00 2001
@@ -5,0 +6,2 @@
+[ upstream commit 53cdbf06bca6c02cf1e4cc31f42f4691734059fc ]
+
@@ -52 +53,0 @@
-Cc: stable at dpdk.org
@@ -61 +62 @@
-index 3fb366dfdd..4d44746239 100644
+index 57dc3b6918..a9e257af23 100644
@@ -64 +65 @@
-@@ -103,4 +103,9 @@ configured like so:
+@@ -100,4 +100,9 @@ configured like so:
@@ -75 +76 @@
-index 52f7fc2cd5..9c99dcec20 100644
+index 54bd095c92..c5e5239d6e 100644
@@ -78 +79 @@
-@@ -1251,10 +1251,11 @@ eth_dev_close(struct rte_eth_dev *dev)
+@@ -1065,10 +1065,11 @@ eth_dev_close(struct rte_eth_dev *dev)
@@ -92 +93 @@
-@@ -1351,4 +1352,7 @@ get_shared_umem(struct pkt_rx_queue *rxq, const char *ifname,
+@@ -1157,4 +1158,7 @@ get_shared_umem(struct pkt_rx_queue *rxq, const char *ifname,
@@ -100 +101 @@
-@@ -1385,10 +1389,27 @@ xsk_umem_info *xdp_umem_configure(struct pmd_internals *internals,
+@@ -1191,10 +1195,27 @@ xsk_umem_info *xdp_umem_configure(struct pmd_internals *internals,
@@ -132 +133 @@
-@@ -1436,6 +1457,8 @@ xsk_umem_info *xdp_umem_configure(struct pmd_internals *internals,
+@@ -1242,6 +1263,8 @@ xsk_umem_info *xdp_umem_configure(struct pmd_internals *internals,
@@ -143 +144 @@
-@@ -1881,8 +1904,11 @@ xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
+@@ -1687,8 +1710,11 @@ xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
@@ -156 +157 @@
-@@ -1895,4 +1921,5 @@ xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
+@@ -1701,4 +1727,5 @@ xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
@@ -162 +163 @@
-@@ -1900,4 +1927,5 @@ xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
+@@ -1706,4 +1733,5 @@ xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
@@ -168 +169 @@
-@@ -1956,4 +1984,5 @@ xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
+@@ -1762,4 +1790,5 @@ xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
@@ -174 +175 @@
-@@ -1971,4 +2000,5 @@ xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
+@@ -1777,4 +1806,5 @@ xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
@@ -180 +181 @@
-@@ -1983,4 +2013,5 @@ xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
+@@ -1789,4 +1819,5 @@ xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
@@ -186 +187 @@
-@@ -1990,4 +2021,5 @@ xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
+@@ -1796,4 +1827,5 @@ xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
@@ -192 +193 @@
-@@ -1997,4 +2029,5 @@ xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
+@@ -1803,4 +1835,5 @@ xsk_configure(struct pmd_internals *internals, struct pkt_rx_queue *rxq,
@@ -198 +199 @@
-@@ -2013,6 +2046,13 @@ out_xsk:
+@@ -1819,6 +1852,13 @@ out_xsk:
@@ -213 +214 @@
-@@ -2055,7 +2095,7 @@ eth_rx_queue_setup(struct rte_eth_dev *dev,
+@@ -1861,7 +1901,7 @@ eth_rx_queue_setup(struct rte_eth_dev *dev,



More information about the stable mailing list