🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26875

Re: [PATCH net v3 1/4] libeth: xsk: Count each XDP_TX buffer on its own

#26875
From: netdev-bot+sashiko
Date: Fri, 04 Dec 2026 10:39
166 lines
14279 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 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 in-flight XDP_TX count uses opposite signs on the two sides,
  so this patch does not fix the count it is meant to fix.
- [Low] The commit message names two causes for the wrong XSk XDP_TX in-
  flight count: userspace rewriting the shared info in the UMEM, and a…

--

libeth: xsk: Count each XDP_TX buffer on its own

This commit changes libeth so that each XSk XDP_TX SQE counts one
completed buffer and its own byte length. It no longer reads the frame's
shared info at bulk flush time, because that shared info lives in the UMEM
and can change before the flush. The goal is to keep the idpf in-flight
XDP_TX count on XSk queues correct.

> libeth takes the number of buffers of an XSk XDP_TX frame from its
> shared info, and reports that many completed buffers to the driver. It
> reads the shared info when it flushes the bulk, not when it queues the
> frame. The shared info of a zero-copy buffer lives in the UMEM, which
> userspace may write at any time, so a rewritten count makes libeth
> report a wrong number.

[ ... ]

> Make libeth count each buffer on its own SQE. Head and fragments each
> count one completed buffer, and the head counts the packet. Stats stay
> the same for frames sent in full.
>
> Found by an AI agent while reviewing this code. Not triggered at
> runtime.

[Severity: Low]
This isn't a bug, but should the message mention another trigger? It needs
no userspace action and was reachable before this patch: a multi-buffer
XSk XDP_TX frame that is only partly sent when the XDPSQ ring is full.

libeth_xdp_tx_xmit_bulk() limits the send to the free ring space and only
counts what it wrote:

	n = min(n, prep(xdpsq, &sq));
	...
	if (sq.xdp_tx)
		*sq.xdp_tx += n;

__libeth_xdp_finalize_rx() then does the final flush with drop set:

	if (bq->count)
		flush_bulk(bq, flags | LIBETH_XDP_TX_DROP);

libeth_xdp_tx_exception() then drops the unsent tail through
libeth_xsk_tx_return_bulk(). That tail can include trailing frags of a
frame whose head was already sent.

Before this patch, the head SQE's nr_frags covered the whole frame
(1 + sinfo->nr_frags), and frag SQEs counted nothing. So the in-flight
count was off by the number of dropped frags.

The per-SQE counting in this patch also covers that case. The message only
hints at it with "Stats stay the same for frames sent in full". Bytes
reported for a partly sent frame also change, from the full frame size to
the sum of the buffers that were sent.

Could the message describe this path, since normal load can reach it?

> diff --git a/include/net/libeth/xdp.h b/include/net/libeth/xdp.h
> index 898723ab62e81..66a3c4ec9967e 100644
> --- a/include/net/libeth/xdp.h
> +++ b/include/net/libeth/xdp.h
> @@ -1794,12 +1794,19 @@ __libeth_xdp_complete_tx(struct libeth_sqe *sqe, struct libeth_cq_pp *cp,
>  	switch (type) {
>  	case LIBETH_SQE_XDP_TX:
>  	case LIBETH_SQE_XDP_XMIT:
> -	case LIBETH_SQE_XSK_TX:
>  		cp->xdp_tx -= sqe->nr_frags;
>
>  		cp->xss->packets++;
>  		cp->xss->bytes += sqe->bytes;
>  		break;
> +	case LIBETH_SQE_XSK_TX:
> +		cp->xss->packets++;
> +		fallthrough;
> +	case LIBETH_SQE_XSK_TX_FRAG:
> +		/* One buffer per SQE, see libeth_xsk_tx_fill_buf() */
> +		cp->xdp_tx--;

[Severity: High]
Does this decrement move the idpf in-flight count the wrong way?

cp.xdp_tx is a u32, and idpf starts it at 0 because its initializer does
not set the field. idpf then expects a positive count of completed
buffers:

drivers/net/ethernet/intel/idpf/xsk.c:idpf_xsksq_complete_slow() {
	struct libeth_cq_pp cp = {
		.dev	= xdpsq->pool->dev,
		.bq	= &bq,
		.xss	= &ss,
		.napi	= true,
	};
    ...
	xdpsq->xdp_tx -= cp.xdp_tx;
}

idpf_xdpsq_complete() in idpf/xdp.c works the same way. The kernel-doc
for struct libeth_cq_pp also describes @xdp_tx as "number of XDP-not-XSk
frames processed".

After k XSk XDP_TX completions, cp.xdp_tx is 2^32 - k. The subtraction in
idpf therefore adds k to xdpsq->xdp_tx. The send side in
libeth_xdp_tx_xmit_bulk() also adds to it:

	if (sq.xdp_tx)
		*sq.xdp_tx += n;

So the count goes up by two for each XDP_TX buffer and does not get back
to 0.

Would that stop idpf_xsksq_complete() from ever taking its fast path
again?

	if (likely(!xdpsq->xdp_tx)) {
		...
		xsk_frames = done_frames;

		goto finalize;
	}

After about 2^31 XDP_TX buffers the u32 can wrap to exactly 0 while
XDP_TX SQEs are still in flight. In that case, can those SQEs be reported
through xsk_tx_completed() as XSk xmit frames? libeth_xdp_complete_tx()
would never be called for them.

Their UMEM buffers would not be freed. The SQEs would keep
LIBETH_SQE_XSK_TX as their type and a stale xsk pointer. That seems to be
the same "idpf may then complete XDP_TX buffers as XSk xmit frames" result
the commit message says this patch prevents.

The existing cp->xdp_tx -= sqe->nr_frags for LIBETH_SQE_XDP_TX and
LIBETH_SQE_XDP_XMIT uses the same sign, and the new branch copies it.

Should this fix change the sign on one side, either in the libeth
completion code or in the idpf consumers? No later patch in the series
appears to touch include/net/libeth/ or drivers/net/ethernet/intel/idpf/.

> +		cp->xss->bytes += sqe->bytes;
> +		break;
>  	default:
>  		break;
>  	}

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203095647.3448925-1-bjorn%40kernel.org
Technical Details
Message-ID: <179638077454.3146.35797073950689629@kernel.org>
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377253-linux-kernel-netdev=dewy.ru
References: <20261203095647.3448925-2-bjorn@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377253-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v3 1/4] libeth: xsk: Count each XDP_TX buffer on its own
Date: Fri, 04 Dec 2026 10:39:34 +0000
Organization: Usenet Network
Message-ID: <179638077454.3146.35797073950689629@kernel.org>
References: <20261203095647.3448925-2-bjorn@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2742374"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:tABDHHSyg73B9Q9oR5kOJQpO2mM= sha256:69visREcz8O6iF2hvkZMaNB+iAHbeF/UJBCRduiSW7Y=
	sha1:S5BJ6t5S628JOcNyxpKyUQSN9aY= sha256:Lx7jjTyyb2kJLrVc/KzP2RYqt2lHsdo2GsEXDwLVBDE=
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 2D390117B87; Fri,  4 Dec 2026 13:40:05 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.541
X-Spam-Status: No, score=-3.541 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.142, 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 Z3xdY2gJ3SYy;
	Fri,  4 Dec 2026 13:40:02 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-377253-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 9F444117BA5; Fri,  4 Dec 2026 13:39:53 +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 6371F32853; Fri,  4 Dec 2026 10:39:45 +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=1796380782;
	b=x8qk3mfuVS+VMtwrirafYklQBTW4eYRhlzHndke4BO5kcDpDOGphup3B2nHm1iLeNk1z
	 XQHIGTBd5QofJqeYb/v8ncWz/vQmBjbM/oj1nbJpRW26ChWPvbKxMJC6twfSl58z0Nrpq
	 FRRSso8cKh89kcxEzCHSDHugw6OrnJvGyz4p2AhoeZMNP7dmewAofa4so+qDLo5BNh3h9
	 1Xie1oQqbPdH8yka0QpQ8fGppkqVen1Og1Y0Pkm19bzSJfake4xNN/HmUA+Fi61R8sAMG
	 YpbR1OsU1ePK6eAbAYJfKZaxYO9qRU0gUEm0V7ZqsoWqShPRuKTRDCd2zZkE5R6wudQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796380782;
	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=01GPd3po7dauFBY70VCg6ZoG1f2PpPQfMizTEnfy6zc=;
	b=1LKGa5wTjn+H0v2rJUSckSH88OOl9mhUcrrFxwjauum1kAcMhVeDFJyewRoC2i1KD8bC
	 iQtmaK70dyfanKSkvstclsJfKpfRv0LQKlBYOEkfqXcv9lgGCC3wa77Yitt38MMUTumgw
	 SGnLN3ChNWv4CslxfpcMGMaxvhbG0y8UttANbe1aDngC07Mof6V1NbwAS6PI7x6yXsI1h
	 +GpkEHOJbFUYJwO8I+L2+Xt4aFdOZmZRhhD+MiBaMoq5EAUuGLPjdJeXBvpsbtKCUqeK2
	 D1KAyDe0mkrbzwBu9XdtL7pu61oLS9DmgaiI/L3i3EkhkcyXhwtKWYi/hLCtrEKyCEQ==
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=Oy+ILzf4;
	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 C1427606A684;
	Fri,  4 Dec 2026 10:39:42 +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=Oy+ILzf4
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=1796380776;
	b=C3kmOZZp+ATZ+bYEL7l2fb6LzEOPRkNfq5yGU0ZhVE/ifrZFtXvHbR3isRMpxIq0RD9D
	 RtR2fkPBgSWE1lNYR4IoluS6tHP+5KeuMeMdCpg/boAbTLixXB60uB45mLrHUDfIW6u7o
	 fQ4/swyaSt+KpCc21aycbGqKZcIYL9SzC2hUQoLOG65+EeGbgEsYeYgnn/Lgdn3P3XdUl
	 hMOCoPUehL5DsjSoNzr9WIWBGw6SIobhhbxBwnhHCA+/JjDe7i8l3d+ACYZ8jTmdJf3JU
	 O0FRntabXvjXPqXs/ZfWw3DR2cOx3wNJ5lFIQiGDEm9Wy7qLbma+Qn+NjNBtdIjd3IQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796380776;
	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=01GPd3po7dauFBY70VCg6ZoG1f2PpPQfMizTEnfy6zc=;
	b=sPHf/AG4vx8XxAA7liTGqvlutTaIaL/8v5VpB6m1tHpOeunKtH4v9mLrEiukcCxEa+HH
	 sx/I4R6pbZlisFDmU6OsSeCE73aOPJGfgzjL7MFNVFnrKrdu1WimBP+WjXZnuoiLcSfOQ
	 DYyA1gDMrQegAcuJDKrFQOBt4ByLxrYHCNrn6GVYpcasLySn23ZvqMZs/MhGIh/fj+AxJ
	 bkwD8gq4LFuukJuqoS3/dKyyUYVFKSKiOh8Tv7Gdl6202SlRe6kM+Ro0JVEZfz2vZQpKF
	 /SZJnmDpdvoS3Av5ZCAPQdEGXKdhEEWJCIPnXbtSthbIB/VHf3GkBDKkJ4CNz8plBdw==
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=Oy+ILzf4;
	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 DDC75606A32D;
	Fri,  4 Dec 2026 10:39:36 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01B411F000CE;
	Fri,  4 Dec 2026 10:39:34 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796380776;
	bh=01GPd3po7dauFBY70VCg6ZoG1f2PpPQfMizTEnfy6zc=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=Oy+ILzf4XJiJcj1m9DFdFGOgA9RBskLZg3p5ogGXD9z3KTPhnQRP0N8hNMTYUwnfj
	 UR0DE4vVWBPncCsCJ0uh3/h6icOUmGxz3fK1CV58Lreefs5sfoblbL1mIQgFrKhjZC
	 6qD1CBe8R7qx11EAwlinxRVjcZxLbfiOBc/YglO2MbKFMm5fQG02KQrKgrGDRMUgih
	 glCapiw09FF/fSLYzGUk5SsRuCmiT3a+CP3SlseqwTXJgtPAz5nQByLOJX56gPM5nr
	 eNfAVTwTt70WkZJs//kILfiYHeYnga3J/UOochzKY9UiPFA1pEZqnej9VNIYMivtc+
	 VhGu2ukiHvSOQ==
X-Cc: magnus.karlsson@intel.com, maciej.fijalkowski@intel.com,
 aleksander.lobakin@intel.com, ast@kernel.org, daniel@iogearbox.net,
 hawk@kernel.org, john.fastabend@gmail.com, andrii@kernel.org,
 eddyz87@gmail.com, memxor@gmail.com, davem@davemloft.net, edumazet@kernel.org,
 kuba@kernel.org, pabeni@redhat.com, willemb@google.com, andrew+netdev@lunn.ch,
 anthony.l.nguyen@intel.com, przemyslaw.kitszel@intel.com,
 netdev@vger.kernel.org, bpf@vger.kernel.org, horms@kernel.org,
 sdf@fomichev.me, martin.lau@linux.dev, song@kernel.org,
 yonghong.song@linux.dev, jolsa@kernel.org, emil@etsalapatis.com,
 ihor.solodrai@linux.dev, intel-wired-lan@lists.osuosl.org,
 clecigne@google.com, michal.swiatkowski@linux.intel.com,
 sriram.yagnaraman@ericsson.com, kurt@linutronix.de
X-In-Reply-To: <20261203095647.3448925-2-bjorn@kernel.org>
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