🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #8922

Re: [PATCH bpf v2] xsk: Do not free ZC Rx buffer when the Rx ring is full

#8922
From: Björn Töpel
Date: Fri, 30 Oct 2026 13:37
64 lines
10882 bytes
Marcin Knap via B4 Relay <devnull+marcin.knap.vecima.com@kernel.org>
writes:

> 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, and
> most drivers rely on that: mlx5e treats the failure as XDP_DROP and
> releases the buffer when the Rx WQE is refilled, while i40e, ice,
> ixgbe, igb, igc, stmmac, idpf and others free it themselves. The
> buffer is therefore freed twice. It gets reused for another Rx
> descriptor, the second free puts an in-use buffer back on the pool
> free list, and the same UMEM frame is later handed to user space
> twice. ixgbe and igb keep the buffer in the ring on their need_wakeup
> -ENOBUFS (XDP_EXIT) path and run it through XDP again on the next poll,
> after the core has freed it.
>
> 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. A few drivers relied on the core freeing the buffer, so make them
> free it:
>
> - i40e and ice consume the descriptor on XDP_EXIT without freeing it.
> - gve DQO counts the redirect error without freeing the buffer.
> - octeontx2 returns false on a failed redirect, so the caller goes on
>   to build an skb from the already freed buffer. Free the buffer and
>   report it as consumed instead.
>
> 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>
> ---
> Tested on mlx5 (ConnectX-6 DX) in zero-copy single-buffer mode.
> The i40e and ice changes and the multi-buffer path are build-tested
> only, as I don't have that hardware available.
> ---
> Changes in v2:
> - Also free the buffer on zero-copy redirect failure in gve DQO and
>   octeontx2, which relied on the core freeing it (AI review).
> - Audited the remaining zero-copy drivers against Björn's table.
>   ixgbe and igb no longer run XDP on a freed buffer after
>   XDP_EXIT; making them drop and consume the descriptor (R2) is
>   left for a follow-up unless you prefer it in this patch.
> - Rebased on current bpf.
> - Link to v1: https://patch.msgid.link/20261019-xsk-zc-rx-double-free-v1-1-2aa19f6628fb@vecima.com

Thank you for catching, and cleaning up the drivers.

I can follow-up with the documentation [1], or if you respin, feel free
to add it yourself.

Reviewed-by: Björn Töpel <bjorn@kernel.org>


[1] https://gist.github.com/fb-bjorn/d6835c49650bc3433b427a9c9708fbe2
Technical Details
Message-ID: <87jymz48e0.fsf@all.your.base.are.belong.to.us>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-353782-linux-kernel-netdev=dewy.ru
References: <20261030-xsk-zc-rx-double-free-v2-1-cf01d4a9f3f7@vecima.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-353782-linux-kernel-netdev=dewy.ru
From: bjorn@kernel.org (Björn Töpel)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH bpf v2] xsk: Do not free ZC Rx buffer when the Rx ring
 is full
Date: Fri, 30 Oct 2026 14:37:11 +0100
Organization: Usenet Network
Message-ID: <87jymz48e0.fsf@all.your.base.are.belong.to.us>
References: <20261030-xsk-zc-rx-double-free-v2-1-cf01d4a9f3f7@vecima.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="2245068"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:zF0qRDqUJ58V+dvFSOMTZtHh3DI= sha256:hICuSOUdxoieGHMXSIs7+OapCtmctMd1m2IruvsvwkU=
	sha1:Gnel4Q9/+CXIkt/s79eHhuR4/PU= sha256:DjL2n/gKjWkJtln8sxrnKSXAGx9UmTZpc0giHCx9GA4=
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 CFFCB125C95; Fri, 30 Oct 2026 16:39:54 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, 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 LyCsdyhWe8Nj;
	Fri, 30 Oct 2026 16:39:50 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-353782-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 70508125C91; Fri, 30 Oct 2026 16:39:41 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id B028D2C235; Fri, 30 Oct 2026 13:37:22 +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=1793367442;
	b=HUDVlmmS8IQRBRLPo8iF5KrsWmcbQYoD8Fpd8lrpAD/9JzlvtwoPHtauF9gZZO743STq
	 JWmWj1hKliEdqfFiJ9w7tZpi7XBMBKvqsAxORCYtLBr7pMfg8zMNUidi+dypcl6c7+I2A
	 WvnLaY2WC1pLdsMDNa3NtDq9kt1a7CEErThHFGmNw/yrAC7R0xVX6ADgNpVqA3ugWZ0Pz
	 HRWo7LV0RZbDi4FajLIhboaaVs9TUiuvilsa7FUWfS4EL5YgyvrbWAlGch1J+hb5Ymo0V
	 OjyEPScYfBYa/fJ3NNTaKhYPOzazgB6ZUj/G1bTZPgPNWmd0X8/g3ki0ANGmW3XKcwA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793367442;
	h=X-Original-To:Received:Received:DKIM-Signature:From:To:Cc:Subject:
	 In-Reply-To:References:Date:Message-ID:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding;
	bh=8tJ3mHvsCbcK0uC2z5FiKSUzFDveTQLdd2jjhlDidfw=;
	b=OYE/0f5IF588PgBbOtgRoGvuqQx7mRyrAV8sqiBjF8YIrlUc/sO6v3ro7TA6rKoo8UCf
	 KTcQ4s1slM4raXruwg4bvEfFw5EMib//XrhjngizrV8djIjFcTknWAEMm67Um1CKkkN4w
	 47ZBGZALq+LsTwU7pViK2JLniq+04ZnR1R73ium7apIQKlGGQgKkdrAiRwlObfEB3oIG/
	 6oVqW/XBwiJEawPwTIXZKFuBDDeAEvNfcAMUbg3/WBEKhIkMknBg7axWueq6Faq4SoCEq
	 65TnebEd01bl1PXuLRuJBNcddZSBuunCRm3dIFJR5HQYzx5S5bbDbW2NCrCr4+bTgjw==
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=gNgiXmC1;
	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 0A616606A323;
	Fri, 30 Oct 2026 13:37:22 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=gNgiXmC1
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=1793367436;
	b=Pn22/D0gU4/OX1RWK2G/+AA1GB0RUlC2VKAZasH0ShnL5Fv0dbBa+JmBvGglDxaZ3K3E
	 hVsY3YR6m4/nLyB3UA4zwrWfmRM4Xblbks2waguQvTaandIJrZiAx1eggRAC8KsiWdlfV
	 qfdmSVva++Z38YXSXG2VJHwoEX1ica5h3qgUS9iUDIvNlfrHp5vS600tWyqUNbJ/8GGYU
	 nFw7udRe2dDfflG1jNEhcp2Xx+ihcEXuupZwFZ3yKG26smT8nPwtrofJk0P7RsVWAxJWO
	 451e/jfQZMDDHvULXckCNp64WT/p6/MtWLNYYsNtzGlA8tRg/+qlI2YrToo9b+IM+eg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793367436;
	h=Received:DKIM-Signature:From:To:Cc:Subject:In-Reply-To:References:
	 Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding;
	bh=8tJ3mHvsCbcK0uC2z5FiKSUzFDveTQLdd2jjhlDidfw=;
	b=A+E5JpqGeAgrWxQ4DmqdOdmUqIFuOPr7+drp3yeOWweuxNDgzTpEfjNrISakdWHZWp7l
	 WXDI19Z47WthgziNXLrszdmFotoReWP4IdKg8gsycPsa4hCVkqlBhnHYeDPr5Ux0ZC5BK
	 bOl/h28kDq7gyTkFxJQhWBvhAGLE1N5SfRYz8ljuIzD74UrV6r5SW1GRFouKTc0sKuGxA
	 7UOEvb4PvNdAmywxI3rMBInv/Smtl150Ci5h+hdXAHqrqHMDuYZDotPP8APZOdhNjzdiv
	 TdrBDv/EwmvkSMsRc+O7mvfnfNRG4Yx3G/DK5wAuosIwdEX7yXuTv571BRDl2i5JIpA==
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=gNgiXmC1;
	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 B0A2F606A31A;
	Fri, 30 Oct 2026 13:37:15 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id EED6A1F00A02;
	Fri, 30 Oct 2026 13:37:14 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1793367435;
	bh=8tJ3mHvsCbcK0uC2z5FiKSUzFDveTQLdd2jjhlDidfw=;
	h=From:To:Cc:Subject:In-Reply-To:References:Date;
	b=gNgiXmC1hJbmntbn8phJg0ee50nGdaXjCJiFZtfcwCb84nlmG2+I+G+swfz1cbYwA
	 mY70cuTfDvF9VNaKUyVrakM6NBJiqWEIGKYaMwvHjmZ8tmc8Ysz/j4uBRznu8hRT/I
	 yN+BnVieh5JO7BlbF2r/8BXu/3H84N0fyGavQlBlcQ0RGHLqG0nWL03rxTQ/AU2rZU
	 QQDVFy4ogb/lpeX7tmDxNJCLMsHGEdkqw1oYI/6W66inTlQnbxY1OE5C9U9OPbyk8I
	 TCxIi/nnjTP0BRsxVDY274yuz+Jp43YGCHVJkJ1h4+j+kXRmcE+IB2cjxwVFvPnSVV
	 3UlzcFxZ75wPA==
X-Cc: intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org,
 linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Marcin Knap
 <marcin.knap@vecima.com>, Joshua Washington <joshwash@google.com>,
 Harshitha Ramamurthy <hramamurthy@google.com>, Sunil Goutham
 <sgoutham@marvell.com>, Geetha sowjanya <gakula@marvell.com>, Ratheesh
 Kannoth <rkannoth@marvell.com>, Subbaraya Sundeep <sbhatta@marvell.com>,
 Bharat Bhushan <bbhushan2@marvell.com>
X-In-Reply-To: <20261030-xsk-zc-rx-double-free-v2-1-cf01d4a9f3f7@vecima.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