🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #27491

Re: [PATCH net v6 1/2] xsk: Do not free ZC Rx buffer when the Rx ring is full

#27491
From: netdev-bot+sashiko
Date: Sat, 05 Dec 2026 19:42
237 lines
16537 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 (1) · High: 1 (1) · Medium: 0 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] The patch relies on ixgbe's XDP_EXIT retry path to handle the
  retained buffer correctly, but that retry reuses stale xdp_buff state.
- [Low] The commit message lists the drivers that break because
  xsk_rcv_zc() freed the buffer on -ENOBUFS, and names ixgbe as the one…

Pre-existing issues:
- [Critical] In otx2_xdp_rcv_pkt_handler(), the non-XSK (page pool)
  XDP_REDIRECT failure path releases the receive page and then returns…
- [High] In otx2_xdp_rcv_pkt_handler(), when pool->xsk_pool is set, the
  code runs the program on xsk_buff and does `goto handle_xdp_verdict`…

--

xsk: Do not free ZC Rx buffer when the Rx ring is full

This patch stops xsk_rcv_zc() from freeing the zero-copy buffer when
the XSK Rx ring is full. The buffer now stays with the driver that
called xdp_do_redirect(). It also updates i40e, ice, gve DQO and
octeontx2, which relied on the core freeing the buffer, so that they
free it themselves.

> 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:

[ ... ]

> - 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.

[Severity: Low]
Should igb be listed next to ixgbe here? igb_run_xdp_zc() returns
IGB_XDP_EXIT on -ENOBUFS when need_wakeup is enabled.
igb_clean_rx_irq_zc() then handles it the same way ixgbe does:

drivers/net/ethernet/intel/igb/igb_xsk.c:igb_clean_rx_irq_zc() {
    ...
			} else if (xdp_res == IGB_XDP_EXIT) {
				failure = true;
				break;
    ...
}

ntc is not advanced and rx_buffer_info_zc[ntc] is not cleared, so the
same xdp_buff goes through XDP again on the next poll. Before this
patch, that buffer was already on the pool free list.

The core change in xsk_rcv_zc() fixes igb without any driver change.
The changelog doesn't say so, though, and it suggests igb is one of
"most others" that free the buffer right away. Could igb be added to
the list of affected drivers?

[ ... ]

> diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c
> index 90af9b9044aa0..6d10c132f61cb 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;
>  		}

[Severity: High]
This is a pre-existing issue, but this patch is fixing the XSK verdict
handling in otx2_xdp_rcv_pkt_handler(). What happens with XDP_TX and
XDP_PASS on the XSK path?

The XSK branch jumps to the verdict without initializing the local
struct xdp_buff xdp:

	if (pool->xsk_pool) {
		xsk_buff = pool->xdp[--cq->rbpool->xdp_top];
		...
		xsk_buff->data_end = xsk_buff->data + cqe->sg.seg_size;
		act = bpf_prog_run_xdp(prog, xsk_buff);
		goto handle_xdp_verdict;
	}

The verdict cases still use xdp, though:

	case XDP_PASS:
		*metasize = xdp.data - xdp.data_meta;
		break;
	case XDP_TX:
		...
		xdpf = xdp_convert_buff_to_frame(&xdp);

xdp_convert_buff_to_frame() dereferences xdp->rxq->mem.type
immediately. xdp.rxq is uninitialized stack memory, or NULL with
INIT_STACK_ALL_ZERO.

Can an XDP_TX verdict on an AF_XDP zero-copy queue oops in NAPI
context here? xsk_buff is also never converted or released on that
path.

For XDP_PASS, metasize comes from uninitialized stack memory, and the
caller passes it to skb_metadata_set().

>  
>  		err = xdp_do_redirect(pfvf->netdev, &xdp, prog);

[Severity: Critical]
This isn't a bug introduced by this patch, but the non-XSK branch just
below seems to have the same problem the commit message describes for
octeontx2 ("returns false on a failed redirect, so the caller goes on
to build an skb from the freed buffer"):

		err = xdp_do_redirect(pfvf->netdev, &xdp, prog);
		if (!err) {
			*need_xdp_flush = true;
			return true;
		}

		otx2_dma_unmap_page(pfvf, iova, pfvf->rbsize,
				    DMA_FROM_DEVICE);
		xdpf = xdp_convert_buff_to_frame(&xdp);
		xdp_return_frame(xdpf);
		break;
	...
	return false;

The page is unmapped and returned through xdp_return_frame(), and then
the function returns false. otx2_rcv_pkt_handler() treats false as
XDP_PASS:

	if (pfvf->xdp_prog)
		if (otx2_xdp_rcv_pkt_handler(pfvf, pfvf->xdp_prog, cqe, cq,
					     &metasize, need_xdp_flush))
			return;

	skb = napi_get_frags(napi);
	...
			if (otx2_skb_add_frag(pfvf, skb, *seg_addr,
					      seg_size[seg], parse, cq->cq_idx))
				cq->pool_ptrs++;

Does this attach the already freed page to an skb and pass it to GRO?
cq->pool_ptrs also gets incremented a second time.

This looks reachable whenever __xdp_do_redirect_frame() fails, for
example when a devmap or ifindex target is down or has no
ndo_xdp_xmit.

Should this branch also return true after releasing the page? The
later patch in this series doesn't touch this driver either.

> diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
> index 48a835e535188..933a13a19a781 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);

[Severity: High]
Now that the buffer stays with the driver, ixgbe's XDP_EXIT retry
becomes the normal path whenever the XSK Rx ring is full. Does that
retry start from a clean xdp_buff?

drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c:ixgbe_clean_rx_irq_zc() {
    ...
		bi->xdp->data_end = bi->xdp->data + size;
		xsk_buff_dma_sync_for_cpu(bi->xdp);
		xdp_res = ixgbe_run_xdp_zc(adapter, rx_ring, bi->xdp);

		if (likely(xdp_res & (IXGBE_XDP_TX | IXGBE_XDP_REDIR))) {
			xdp_xmit |= xdp_res;
		} else if (xdp_res == IXGBE_XDP_EXIT) {
			failure = true;
			break;
    ...
}

On the next poll only data_end is recomputed. data and data_meta keep
whatever the previous program run left in them. igb resets them with
xsk_buff_set_size().

Suppose the program calls bpf_xdp_adjust_head() with a positive offset
N before redirecting. data then moves forward by N on every retry, and
data_end moves with it, so this check in bpf_xdp_adjust_head() keeps
passing:

	if (unlikely(data < data_start ||
		     data > xdp->data_end - ETH_HLEN))
		return -EINVAL;

After a single retry, user space would get the packet shifted by N
bytes, with N trailing bytes the hardware never wrote.

If the Rx ring stays full for enough polls, can [data, data_end) move
past the end of the UMEM chunk? The program could then read and write
the neighbouring chunk.

When the redirect finally succeeds, in aligned mode xp_get_handle()
takes the descriptor address from xskb->xdp.data - pool->addrs. That
address could then point into another chunk, so the same frame would
be handed to user space twice.

Would ixgbe need an xsk_buff_set_size() style reset before it runs XDP
again, as igb does? The later patch in this series ("xdp: Do not free
ZC buffer when a frame redirect fails") doesn't seem to touch ixgbe.

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204193929.1168874-1-maciej.fijalkowski%40intel.com
Technical Details
Message-ID: <179649976273.3148.10281043057398500708@kernel.org>
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-378114-linux-kernel-netdev=dewy.ru
References: <20261204193929.1168874-2-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-378114-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v6 1/2] xsk: Do not free ZC Rx buffer when the Rx ring is full
Date: Sat, 05 Dec 2026 19:42:42 +0000
Organization: Usenet Network
Message-ID: <179649976273.3148.10281043057398500708@kernel.org>
References: <20261204193929.1168874-2-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="3107420"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:pd26gCccQF3T21gl86/YIb/F2e8= sha256:UCQn56/cTdQ8LLNCbi1jgEpCee8SymfdAbs/tgaY2ck=
	sha1:VWhTxD36WfvbhWMTkaoj6SWEIKE= sha256:1/lKpfHbtl9RI54DsF/OQPHqN0TY5K10WPjmKm3Uv1A=
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 41106117E9C; Sat,  5 Dec 2026 22:43:09 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.639
X-Spam-Status: No, score=-3.639 tagged_above=-9999 required=6.31
	tests=[DKIMWL_WL_HIGH=-0.14, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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=kernel.org
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 iSoMDXQhrbHr;
	Sat,  5 Dec 2026 22:43:06 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-378114-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 2DCB4117EA0; Sat,  5 Dec 2026 22:42:55 +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 F1BE228C1A; Sat,  5 Dec 2026 19:42:53 +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=1796499773;
	b=1vQsdqVQ/3arb2Ecn8VAxV9LjIeLngYFF9UeY0il5mihosPgI7TyJoMPNl7O3yfXogt2
	 JiZgzPU1IvCjLVTH7g8fL/cYrQChQNxE50ZzAhAg/9+dFSjUsZL8cT1ZV28vDR1X5fy2e
	 H+CXzYM+Cn7VJ1D2yLgUydfgBAKPFKpGNGYvt7IwAEJEF0H8yWHB3DmzuyD0wcv3Irzdp
	 iB5ZXe04H3acO6pD6TZ7rLFNtE1IX/Ll41iowsW2NHP3dIFbjk2SHvT6t4F91dr5Sp6Av
	 Gel3yiOinKTSOxOWrNFMMesNRVBsDV52GaYdEDQ/S047vbj596k1mwutp+LCMycVn4Q==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796499773;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=RvBMYokT53hJt1IyOs1/zaFqFhmt/4sE8O/9qvytI3A=;
	b=CQaPApXKrwU1DatjIG3xDhj7wCWXjHs57FwD+K5X5PCYeBFJ7zDsvh0QjMzhJE9snsYK
	 FOyfb3AzYH1yLQkWpfeR4+ZuDWPPPG2I5SohC7V4MadZvCFD17ehJMkYkMMxlTe+XWAqe
	 ZhRfVm8zWKXstkazDMB2MJ0B0stzFIoWVzEZMY17V1d94+v+J4TcP1/HeYDl6DkM5h0R1
	 oPI/Vn1qzzQzrZuJGxM+zsdqydgH2Bw2gLetS/6DH+Ea007pKs3KbrSjlVuxkmYd3zNs8
	 ynzNR79qrYcoQqnfYiXIxoJp8G0IRumPJmv/qI2FUOqqvEGU1vqu4hPqZhW/I+PWokQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NXMIn+eC;
	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 1B324606A33E;
	Sat,  5 Dec 2026 19:42:53 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NXMIn+eC
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796499765;
	b=gMxWXEz4uVYICBnercTcxTEg4rUYcXX0/bxsALAOkgwCtOXr1ywvoc81rllZLX/54n3A
	 U5z2M4PqgUY1EQ52jkkxxa/scHtktCjng2eUFPPluhnAuScr+w/vq8ajqKTaEsPGIioJ5
	 cS7RH7y+ivTvJSMEDGOd8WMsCOpZkulDZWqoWxsaSB4n1XJz3ZnRoc2ofnnGONs1/Y/wO
	 m3pb+dKcvfudHw8NPes/ECi6YSBW1242CcTCV2t7aWc0KBWkxA+yIMHmYc9Z6YslBNuvL
	 /d6kIx6Gfk7bNea24CJFFMKsYGzGF8UQXSSJpOVyMy64CpeoHspsjPiuC7FEh2k79Uw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796499765;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=RvBMYokT53hJt1IyOs1/zaFqFhmt/4sE8O/9qvytI3A=;
	b=hb39mF9YO+DWdz75WekO/GqUyaRt3mHWQjULn4XCDtioOxxIhp4jY4RIyITybNBfVJM7
	 nZGcAFh1zqkehS6mtMtjEm2Zo2pF4Z3pRHieAaYdXd9GplM70J8OQM74CWsPCiJbMB76M
	 XSy+e6kZmcN90t1ZE4hbS5aMf4tTjjzTf6BOKV3KSouQp95KKR0iwLKyTX6Qkdxo3teSx
	 dZXyRjThSGLPiApety8kA/jYwzWWELCpYvy16/ZwZP7RN/uDjOqEl/cZUDWr4b4yjc5op
	 AckMc8tsfWmeprzFq4Ubc0BB9NTvE5P542FhetCgr3MIB8elFpaOjGqi+0ALJK9Ecbg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NXMIn+eC;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 303DC606A31F;
	Sat,  5 Dec 2026 19:42:44 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2CB891F0092B;
	Sat,  5 Dec 2026 19:42:43 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796499764;
	bh=RvBMYokT53hJt1IyOs1/zaFqFhmt/4sE8O/9qvytI3A=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=NXMIn+eCHW2HoWemPRRwypIhQ3aFHxiXl7oItFLm77JbaK//bxqWei0Q0DYrMOsYy
	 WCQOIHNqIKyOLm1pH5XHkgnb2OmgXT/CfbmUoVUMB56E23o19Hs10/HBkhflRURq05
	 euWIQ4sze1LzjGtAmX54fAKGq9F9CJlxksVBdwjjKzpFPfUtBs00aeRh8W82d6VpWN
	 079faepAu69WcuSajGbN5g7NfUvKllbtwRFKOndX/EyMGV/phI8zNqF5LY00FAAohM
	 rQB3gxHZzeSkCpLCfmWyb//Vsn9HnLssX90OpxzQt+aayXaq2Hbm2Uo+8M6b1UrX2n
	 KV4EeGURYlvUA==
X-Cc: netdev@vger.kernel.org, kuba@kernel.org, pabeni@redhat.com,
 magnus.karlsson@intel.com, sdf@fomichev.me, ast@kernel.org,
 daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com,
 jtollet@cisco.com, willemb@google.com, andrii@kernel.org, eddyz87@gmail.com,
 memxor@gmail.com, 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-In-Reply-To: <20261204193929.1168874-2-maciej.fijalkowski@intel.com>
X-sashiko-severity: High
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