Article View: linux.kernel.netdev
Article #27104[PATCH net v6 1/2] xsk: Do not free ZC Rx buffer when the Rx ring is full
From: Maciej Fijalkowski
Date: Fri, 04 Dec 2026 19:39
Date: Fri, 04 Dec 2026 19:39
158 lines
15387 bytes
15387 bytes
From: Marcin Knap <marcin.knap@vecima.com>
When an XDP program redirects a zero-copy buffer to an XSK and the
socket's Rx ring is full, xsk_rcv_zc() frees the buffer and returns
-ENOBUFS to xdp_do_redirect().
A failed xdp_do_redirect() leaves the buffer owned by the caller, so
the driver releases it as well. That is harmless when the driver frees
it right away, as i40e, ice, igc, stmmac, idpf and most others do:
xp_free() ignores a buffer that is already on the pool free list. It
breaks when the driver releases or uses the buffer later, after it may
have been reallocated:
- mlx5e treats the failure as XDP_DROP and releases the buffer when
the Rx WQE is refilled. By then the buffer can be in use for another
Rx descriptor, so an in-use buffer goes back on the free list and the
same UMEM frame is later handed to user space twice. With striding
RQ this also ended in a NULL pointer dereference in
mlx5e_post_rx_wqes().
- ixgbe keeps the buffer in the ring on its need_wakeup -ENOBUFS
(XDP_EXIT) path and runs XDP on it again on the next poll.
- dpaa2 hands the buffer back to its hardware pool while it is also on
the pool free list.
- octeontx2 returns false on a failed redirect, so the caller goes on
to build an skb from the freed buffer.
Leave the buffer with the caller on both the single-buffer and the
multi-buffer -ENOBUFS paths, as xsk_rcv() and xsk_rcv_check() already
do. Make the drivers that relied on the core freeing the buffer free
it themselves:
- i40e and ice consume the descriptor on XDP_EXIT without freeing it.
- gve DQO counts the redirect error without freeing the buffer.
- octeontx2 now frees the buffer and reports it as consumed.
This covers redirects to an XSKMAP. A zero-copy buffer redirected to a
devmap, a cpumap or an ifindex is copied by
xdp_convert_zc_to_xdp_frame(), which frees it before
__xdp_do_redirect_frame() can still fail. The driver then releases it
a second time, and the copied page leaks. That path is not changed
here and is fixed separately in xdp_do_redirect().
Seen on Mellanox ConnectX-6 DX MT2892 (FW 22.47.1026) with AF_XDP
zero-copy on 7.3.0-rc6 when the user-space consumer could not keep up
with the Rx ring. With this change no duplicate frames were seen with
striding RQ on or off.
Fixes: 269009893146 ("xsk: recycle buffer in case Rx queue was full")
Signed-off-by: Marcin Knap <marcin.knap@vecima.com>
Reviewed-by: Björn Töpel <bjorn@kernel.org>
Reviewed-by: Jason Xing <kerneljasonxing@gmail.com>
Reviewed-by: Nitin Shetty J <nshettyj@marvell.com>
Tested-by: Jerome Tollet <jtollet@cisco.com>
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
drivers/net/ethernet/google/gve/gve_rx_dqo.c | 4 +++-
drivers/net/ethernet/intel/i40e/i40e_xsk.c | 1 +
drivers/net/ethernet/intel/ice/ice_xsk.c | 1 +
.../ethernet/marvell/octeontx2/nic/otx2_txrx.c | 3 ++-
net/xdp/xsk.c | 15 +++------------
5 files changed, 10 insertions(+), 14 deletions(-)
diff --git a/drivers/net/ethernet/google/gve/gve_rx_dqo.c b/drivers/net/ethernet/google/gve/gve_rx_dqo.c
index b4dbfb1ba39b..349b42d60fc2 100644
--- a/drivers/net/ethernet/google/gve/gve_rx_dqo.c
+++ b/drivers/net/ethernet/google/gve/gve_rx_dqo.c
@@ -687,8 +687,10 @@ static void gve_xsk_done_dqo(struct gve_priv *priv, struct gve_rx_ring *rx,
goto err;
break;
case XDP_REDIRECT:
- if (unlikely(xdp_do_redirect(priv->dev, xdp, xprog)))
+ if (unlikely(xdp_do_redirect(priv->dev, xdp, xprog))) {
+ xsk_buff_free(xdp);
goto err;
+ }
break;
}
diff --git a/drivers/net/ethernet/intel/i40e/i40e_xsk.c b/drivers/net/ethernet/intel/i40e/i40e_xsk.c
index 5f5f33b2a097..8760a493767c 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_xsk.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_xsk.c
@@ -356,6 +356,7 @@ static void i40e_handle_xdp_result_zc(struct i40e_ring *rx_ring,
return;
if (xdp_res == I40E_XDP_EXIT) {
+ xsk_buff_free(xdp_buff);
*failure = true;
return;
}
diff --git a/drivers/net/ethernet/intel/ice/ice_xsk.c b/drivers/net/ethernet/intel/ice/ice_xsk.c
index 0c1ce3e86a45..6e53387818a7 100644
--- a/drivers/net/ethernet/intel/ice/ice_xsk.c
+++ b/drivers/net/ethernet/intel/ice/ice_xsk.c
@@ -646,6 +646,7 @@ int ice_clean_rx_irq_zc(struct ice_rx_ring *rx_ring,
if (likely(xdp_res & (ICE_XDP_TX | ICE_XDP_REDIR))) {
xdp_xmit |= xdp_res;
} else if (xdp_res == ICE_XDP_EXIT) {
+ xsk_buff_free(first);
failure = true;
first = NULL;
break;
diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c
index 90af9b9044aa..6d10c132f61c 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c
@@ -1555,7 +1555,8 @@ static bool otx2_xdp_rcv_pkt_handler(struct otx2_nic *pfvf,
*need_xdp_flush = true;
return true;
}
- return false;
+ xsk_buff_free(xsk_buff);
+ return true;
}
err = xdp_do_redirect(pfvf->netdev, &xdp, prog);
diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index 48a835e53518..933a13a19a78 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -224,21 +224,15 @@ static int xsk_rcv_zc(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len)
struct list_head *xskb_list;
u32 contd = 0;
u32 num_desc;
- int err;
- if (likely(!frags)) {
- err = __xsk_rcv_zc(xs, xskb, len, contd);
- if (err)
- goto err;
- return 0;
- }
+ if (likely(!frags))
+ return __xsk_rcv_zc(xs, xskb, len, contd);
contd = XDP_PKT_CONTD;
num_desc = xdp_get_shared_info_from_buff(xdp)->nr_frags + 1;
if (xskq_prod_nb_free(xs->rx, num_desc) < num_desc) {
xs->rx_queue_full++;
- err = -ENOBUFS;
- goto err;
+ return -ENOBUFS;
}
xdp_buff_clear_frags_flag(xdp);
@@ -253,9 +247,6 @@ static int xsk_rcv_zc(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len)
}
return 0;
-err:
- xsk_buff_free(xdp);
- return err;
}
static void *xsk_copy_xdp_start(struct xdp_buff *from)
--
2.43.0
Technical Details
Message-ID:
<20261204193929.1168874-2-maciej.fijalkowski@intel.com>Path:
mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377587-linux-kernel-netdev=dewy.ruReferences:
<20261204193929.1168874-1-maciej.fijalkowski@intel.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377587-linux-kernel-netdev=dewy.ru From: maciej.fijalkowski@intel.com (Maciej Fijalkowski) Newsgroups: linux.kernel.netdev Subject: [PATCH net v6 1/2] xsk: Do not free ZC Rx buffer when the Rx ring is full Date: Fri, 4 Dec 2026 20:39:28 +0100 Organization: Usenet Network Message-ID: <20261204193929.1168874-2-maciej.fijalkowski@intel.com> References: <20261204193929.1168874-1-maciej.fijalkowski@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2847148"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:uOXPmlppSmgkDVkQx+tGSkWJ3VA= sha256:GID0NKLPEOhSgTV/Gb1zN2/zAnnWb6MSCJe8B5l8tDQ= sha1:3cUxHzSEPVLhnv1H8VrvQlTCwoY= sha256:6RliCIqdlbzLlvop0jfnf/zKAC9OVQKw9wtORGezGIc= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id C86B1117C8E; Fri, 4 Dec 2026 22:40:30 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.54 X-Spam-Status: No, score=-3.54 tagged_above=-9999 required=6.31 tests=[DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.001, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=intel.com X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id d8FZ3srAnh5h; Fri, 4 Dec 2026 22:40:23 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-377587-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=intel.com X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id DE0A4117C0E; Fri, 4 Dec 2026 22:40:08 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id DD96A27D79; Fri, 4 Dec 2026 19:40:05 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796413204; b=gqJ2dzLb2SfgCH1hcAvS645rY97JlwT38Kp7inOZjQkM4f0kb+64QqfrMW118ejbrEsD rdkICFYLXDhVaGYsdLecFhilxgu3m/fEa8wtD4wSv68MqrkWmHkKyhWl9xuJedhIk4SdL kf6h51IcOmGTrSXgA/Alk3MDh2BWd0dwd+oSv8eBjUixS6KFg6wf/BSucoAr0XwwYAXJy uUQLPlq2yqHjj7qOd+QEMSUwiXf9jZmTVSUJTfPltJGXrXqeq4UEKypuQMWtKqiQC4Ktp 2iYai1ja0UHsmaWAE7lqNWpgmz+VRoqv8JMHRS0qceQ8Xq5stdPpe+3tTFOavcgFfBg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796413204; h=X-Original-To:Received:DMARC-Filter:DKIM-Signature: X-CSE-ConnectionGUID:X-CSE-MsgGUID:X-IronPort-AV:X-IronPort-AV: Received:X-CSE-ConnectionGUID:X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV: Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=RUQY13NsF5n/+QkjgCbxyY2J+p1RW7F9Nf0m2wyPc4Q=; b=u8/9FDHxh95/tVkbm6/WmaqNG74+4IEdo5BR6nTaTWKQDbSZa3GDsIjUgr0kvNFR/Vv4 rK/pcpsCfNSroqc+p615C4NymyZZVQ49D2qLNyVeHNiMV85YbE5ClfJRdl207e+xsAc/5 2bB2xgOTrXjWkrDo61I2XkYM+rkduUTSXrz5NskTGu6pkWSw39mWp+13fiVoncsHnI0BY +yNKo2DebchP5qRbFhXlo5y6QgfChjt23LDYC1yyTU4+UOOHWS/D19WvtGqxgKik6/hZ6 Q4QxDeHYJVDAEdBlvqmH+OHAM+sdTWtr86u7kpDamGkOWZOT/dHQ/R9e79LckAI6NLg== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=mKNsZyNJ; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 54DF1606A6BB; Fri, 4 Dec 2026 19:40:04 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=mKNsZyNJ X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.8 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796413203; b=cAVzqaZJTMRBOyocYhHqhdO1gB76k2mIfFPIEcmE3Vt0WCaBm0hjVlsXksmmFJym3Liy zDq93AVzSyS90Y3sye4Q4o9FEsT2z8xyG9Tk8orn0PMD3HWB3+GmgYT8TDhhlLoW8Etyz zqjOa1R2jooScBzdmvmW6v9HmK1khFisYYkp0kLByt64RKaqP/pqvPvsrJO+SG+ZjfaVQ t1XPjSggCtwlFcnyQd2T0uJXtwvjnJzAHhs8vve8+6yepK2BHCOGyiK07/9PLp+QVAuKV 4E1pj9vIMtuB9YM0Q8hHT7g69Xwg1kBfkiUgiyXOEQ4yp1Nd8tA3VMpJOEzCgasJd5Q== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796413203; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject: Date:Message-Id:X-Mailer:In-Reply-To:References:MIME-Version: Content-Type:Content-Transfer-Encoding; bh=RUQY13NsF5n/+QkjgCbxyY2J+p1RW7F9Nf0m2wyPc4Q=; b=Tumrstk0Nc5c/UuN+l9p68qWl/9udAjj9ErU6EKcVeY/QfF+7Z/wT+O9MIwd8iiLTuV3 BKnMyDwp5dKMWW63cN4cfLvGvXJFTAfeRMefZlrO1AauPvB3+Y/zzGHwmX6ynC9Wmhg+I qIkxWntKRyU+UXAzLjMM6NnPrLQ4cUp5hTE/5xOG5c86pNu/xi9PuQuWELDJdAcfs/FyJ k0LxBiSBsthcIEGXeGJa6fL59Xx9kndgnjvWnCbxbw5CFlSSB+9O6aqICGg7asG4EB4ho 5T4OX9EOam5IJx1AG8ORZTlwnCCB6G5GI51dwD4l8oMNRkiysYgakTmrdE2fxt6CS3A== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=mKNsZyNJ; arc=none smtp.remote-ip=192.198.163.8 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5CF62606A6A1; Fri, 4 Dec 2026 19:40:02 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5CF62606A6A1 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796413202; x=1827949202; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RUQY13NsF5n/+QkjgCbxyY2J+p1RW7F9Nf0m2wyPc4Q=; b=mKNsZyNJ//dv7ZLEGpG07dFgSqGaHhx29To0AnpzkcssH0Ia3LmW+PJU bhuCxFuF97DusMPx80Z9JSAfouy00bMFYHjEJUeNEDiUa0Nnw3YqSc1oJ 3PzyUf4KoUfElttTYDiAD/NNBg9WlS9VJHAUWkl4eNJ81kkW5G9WYGeC/ PhtM6mi0O2zIzHf0VlOgwsPJPqnPsyVzYyOc9AuUdF9jIRt8VZbAEUHf2 dlgmJAvMl/x3k1HqxjxXdgnQOasyua4z142WLIt8midSqAnIs5TWuSEpS Kp6UYaBEOWXCpBHw3ff9LhNMt+kezX5Mu4Ml5Z3DC+yXzb+bPglQqSBON Q==; X-CSE-ConnectionGUID: Y3MmHOReTaKPyjt3ihN6jQ== X-CSE-MsgGUID: R9j1TCxiQmShEBceP+8YCw== X-IronPort-AV: E=McAfee;i="6800,10657,11986"; a="5290974" X-IronPort-AV: E=Sophos;i="6.29,79,1794902400"; d="scan'208";a="5290974" X-Received: from orviesa003.jf.intel.com ([10.64.159.143]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 11:40:01 -0800 X-CSE-ConnectionGUID: 8SXGvoP/Q+iFxSF1rqePIA== X-CSE-MsgGUID: W92BOJ5OTOqoZFiQS811mw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,79,1794902400"; d="scan'208";a="14021402" X-Received: from boxer.igk.intel.com ([10.102.20.173]) by orviesa003.jf.intel.com with ESMTP; 04 Dec 2026 11:39:56 -0800 X-Cc: bpf@vger.kernel.org, bjorn@kernel.org, kerneljasonxing@gmail.com, marcin.knap@vecima.com, joshwash@google.com, hramamurthy@google.com, sgoutham@marvell.com, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org, emil@etsalapatis.com, ihor.solodrai@linux.dev, toke@redhat.com, hangbin.liu@linux.dev X-Mailer: git-send-email 2.38.1 X-In-Reply-To: <20261204193929.1168874-1-maciej.fijalkowski@intel.com> X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list