๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #27412

Re: [PATCH net v4 1/5] libeth: xdp: Count completed XDP_TX buffers up

#27412
From: netdev-bot+sashiko
Date: Sat, 05 Dec 2026 15:17
196 lines
15274 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 ยท High: 2 (1) ยท Medium: 0 ยท Low: 0

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] On an idpf XDPSQ that has an XSk pool, the frag descriptors of a
  non-XSk multi-buffer XDP_TX frame are counted as XSk xmit completions.
- [High] The restored in-flight counter still drifts for non-XSk XDP_TX
  frames that are only partly sent.

Pre-existing issues:
- [High] When an idpf XDPSQ is in XSk mode, it can still be cleaned by
  the non-XSk routine `idpf_xdpsq_complete()`.

--

libeth: xdp: Count completed XDP_TX buffers up

This patch changes __libeth_xdp_complete_tx() to add the completed
non-XSk-xmit buffers to cp->xdp_tx instead of subtracting them. With
that, idpf's in-flight XDP_TX counter can return to zero. It also updates
the struct libeth_cq_pp kernel-doc to say buffers rather than frames.

> diff --git a/include/net/libeth/xdp.h b/include/net/libeth/xdp.h
> index 898723ab62e81..38fcd3fdff70e 100644
> --- a/include/net/libeth/xdp.h
> +++ b/include/net/libeth/xdp.h
> @@ -1795,7 +1795,7 @@ __libeth_xdp_complete_tx(struct libeth_sqe *sqe, struct libeth_cq_pp *cp,
>  	case LIBETH_SQE_XDP_TX:
>  	case LIBETH_SQE_XDP_XMIT:
>  	case LIBETH_SQE_XSK_TX:
> -		cp->xdp_tx -= sqe->nr_frags;
> +		cp->xdp_tx += sqe->nr_frags;

[Severity: High]

The counter is exact now, but can idpf_xsksq_complete_slow() tell non-XSk
XDP_TX frags apart from XSk xmit descriptors?

A regular Rx queue picks its XDPSQ by CPU. __idpf_xdp_rxq_info_init() sets:

	rxq->xdpsqs = &vport->txqs[rsrc->xdp_txq_offset];

and __libeth_xdp_tx_init_bulk() then picks xdpsqs[libeth_xdpsq_id(num)].
So XDP_TX from a regular Rx queue whose NAPI runs on CPU k lands on XDPSQ k,
even when that queue is in XSk mode.

For a multi-buffer XDP_TX frame, libeth_xdp_tx_fill_buf() sets a type only
on the head SQE:

	if (!sinfo)
		return desc;

	sqe = &sq->sqes[i];
	sqe->type = LIBETH_SQE_XDP_TX;

The non-first frag SQEs stay LIBETH_SQE_EMPTY. In contrast, ndo_xdp_xmit
frags get LIBETH_SQE_XDP_XMIT_FRAG and XSk XDP_TX frags get
LIBETH_SQE_XSK_TX_FRAG.

idpf_xsksq_complete_slow() counts every EMPTY slot as an XSk completion:

		if (sqe->type)
			libeth_xdp_complete_tx(sqe, &cp);
		else
			xsk_frames++;

idpf_xsksq_complete() then passes that count to
xsk_tx_completed(xdpsq->pool, xsk_frames).

For a frame with m frags, would the XSk completion ring producer move m
entries past what was reserved? Userspace would then get completions for
XSk xmit descriptors the NIC is still reading. The commit message says this
outcome is removed.

The next patch in the series, "libeth: xsk: Count each XDP_TX buffer on its
own", only changes libeth_xsk_tx_fill_buf() and the XSK_TX completion
accounting. libeth_xdp_tx_fill_buf() is unchanged at the end of the series.

[Severity: High]

Can xdpsq->xdp_tx still drift when a non-XSk XDP_TX frame is only partly
sent?

On the send side, libeth_xdp_tx_xmit_bulk() counts only the descriptors it
actually placed:

	*sq.xdp_tx += n;

Here n can stop partway through a multi-buffer frame.

On the completion side, __libeth_xdp_tx_fill_stats() sets the head SQE's
nr_frags to the full frame:

	ue->nr_frags += us->nr_frags;

The line above returns that full count. idpf then does
xdpsq->xdp_tx -= cp.xdp_tx.

A frame can be sent short in at least two ways. First,
__libeth_xdp_finalize_rx() flushes with:

	flush_bulk(bq, flags | LIBETH_XDP_TX_DROP);

If the XDPSQ fills mid-frame, the head and some frags go out. Then
libeth_xdp_tx_exception()->libeth_xdp_tx_return_bulk() skips the unsent
frags without adjusting any counter:

		if (!(frm->len_fl & LIBETH_XDP_TX_FIRST))
			continue;

Second, libeth_xdp_tx_queue_bulk() breaks out of its frag loop when
flush_bulk(bq, 0) fails. That leaves a MULTI head in the bulk without its
remaining frags, so it is sent short later.

Each such event leaves the u32 xdpsq->xdp_tx lower by the number of missing
frags. On an XSk XDPSQ, could xdp_tx then read 0 while that many XDP_TX
buffers are still in flight? That would happen long before the 2^31 wrap
described in the commit message.

When that happens, idpf_xsksq_complete() takes the fast path:

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

This reports in-flight XDP_TX descriptors through xsk_tx_completed(). It
also skips their SQEs without freeing the page-pool buffers.

Before this patch the fast path never ran after the first XDP_TX, so the
drift had no effect. The next patch in the series switches only
LIBETH_SQE_XSK_TX / LIBETH_SQE_XSK_TX_FRAG to per-buffer counting. The
LIBETH_SQE_XDP_TX case still adds sqe->nr_frags at the end of the series.

[Severity: High]

This is a pre-existing issue and was not introduced by this patch. Can an
XSk-mode idpf XDPSQ be cleaned by idpf_xdpsq_complete() instead of
idpf_xsksq_complete()?

In struct idpf_tx_queue, dev and pool share a union:

	union {
		struct device *dev;
		struct xsk_buff_pool *pool;
	};

idpf_xsk_setup_txq() sets txq->pool = pool, so txq->dev then holds the pool
pointer.

idpf_xdp_xmit() passes &vport->txqs[xdp_txq_offset] to
libeth_xdp_xmit_do_bulk(), which picks a queue by CPU without checking XSK.
Regular-Rx XDP_TX goes through idpf_xdp_tx_flush_bulk, which uses the same
prep callback. idpf_xdp_tx_prep() then cleans with the non-XSk routine
whatever the queue mode:

	if (free < xdpsq->thresh)
		free += idpf_xdpsq_complete(xdpsq, xdpsq->thresh);

idpf_xdpsq_complete() builds:

	struct libeth_cq_pp cp = {
		.dev	= xdpsq->dev,

For completed LIBETH_SQE_XDP_XMIT and LIBETH_SQE_XDP_XMIT_FRAG SQEs,
__libeth_xdp_complete_tx() then calls:

		dma_unmap_page(cp->dev, dma_unmap_addr(sqe, dma),
			       dma_unmap_len(sqe, len), DMA_TO_DEVICE);

Does that hand a struct xsk_buff_pool to the DMA API as a struct device?
The DMA ops, IOMMU and swiotlb lookups would then read fields out of pool
memory.

In the same loop, XSk xmit SQEs are EMPTY. __libeth_xdp_complete_tx()
returns early for them, and next_to_clean moves past them, but
xsk_tx_completed() is never called. Would the completion ring entries
reserved for those frames be lost?

idpf_xsksq_complete() follows the intended rules: it uses
xdpsq->pool->dev and reports EMPTY slots. No patch in this series changes
idpf_xdp_tx_prep(), idpf_xdpsq_complete() or idpf_xdp_xmit().

>  
>  		cp->xss->packets++;
>  		cp->xss->bytes += sqe->bytes;

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204142030.626820-1-bjorn%40kernel.org
Technical Details
Message-ID: <179648385109.3146.5021762353826565156@kernel.org>
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-378034-linux-kernel-netdev=dewy.ru
References: <20261204142030.626820-2-bjorn@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-378034-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v4 1/5] libeth: xdp: Count completed XDP_TX buffers up
Date: Sat, 05 Dec 2026 15:17:31 +0000
Organization: Usenet Network
Message-ID: <179648385109.3146.5021762353826565156@kernel.org>
References: <20261204142030.626820-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="3055109"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:TSVAa6IBUFj9E1aPuiFv1Uem/hA= sha256:68F61PXyOqFXPoTDc2omSimFOaQBuG1bJ2cSZLl8S+c=
	sha1:AMp3BqnFaXCdk2TgMAsWh6whZ2A= sha256:bznr55CpVfK/4PqZC7rRKIj9mfmsg8SXd4vsR5PBpqs=
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 C463A117E50; Sat,  5 Dec 2026 18:17:53 +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=[DCC_REPUT_70_89=0.1, 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] 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 01n-LW1fP5cq;
	Sat,  5 Dec 2026 18:17: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-378034-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 0C08C117E4D; Sat,  5 Dec 2026 18:17:39 +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 169D42BBCD; Sat,  5 Dec 2026 15:17:35 +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=1796483854;
	b=rOBKLAvK+YehgNozLHmOem+IObolY48vpMDvKw8OfMMhYqv/j429xi5A0Rwuob9DyyhD
	 V5+HHLByomYnSx3neTcP4jqQlV+9nT3cpupQYP6whepSizNllHAZ11p//PNtZM86VQghq
	 Jiyd1PfZqxTI5SELAbnQMzV2C759EKmD6B5z7KmHCoZZrUcEg08iL94cNaHG19UjZ9Isy
	 B7MqF5Gfa/6Nn/VVlnIAEk6tM2VIPROcm1FGMwTsBQyIdsjBOdTb5dkGmqsds9mIFWj2v
	 P/Nxuy40EeK5xnwxMENznK4+BBoY31meVTYFAGh/tLRVlH3G8wsdI/AFZA+UQdGRc/g==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796483854;
	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=bnE5qquqS7Pv3MDSCJobyu9X9Nhbpq8gJ1eAS7xaSuI=;
	b=R62cEIerbnoETVgCNdMr+Qe+pmXrTo+UtVf1cPPKm3OGpPxq8x88cDRWBeptSIi6DwA/
	 SZiN5jg3TNW7xhYrmefTkZvQmS6bmQ8khCjaskg/kSaBEZNmqZ4akWyz0u1YrjAlhXHgR
	 thbnQ6qBe+FSmXuSiHReEELazKrbaMa0G4JjwGgXVru83rfXD0FRyCyxuoCh6pt/DorhN
	 XpGKeUds8larNCTWJZSIBRWH17fUST+RYTR2Z9Z7YmzLZTxotrCMsYqkqlm/I7MsCCwN3
	 rzptHOnloFaBUa65uF6wql5Fn+zC7JLPdWcQKet5ew7pgJQ7IhPCQq3rOOKvfG3bdqA==
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=Md+xzacc;
	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 B92D4606A339;
	Sat,  5 Dec 2026 15:17:34 +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=Md+xzacc
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=1796483853;
	b=wTxG4yDQ29EfC8/0XBKdmIpMkGm3GNojiAgpDgq5nR1coQCvce3LRuaJWYG7b1stW4jb
	 KIfRO3OOgCLW7VJA9sKTMYJzQPfahwSpzqzX914HgEom2SCBGK+MCHYGLYE4tcZg1vYcF
	 35QeO83A4e2j4cQmW2/VYgQioGAxXXfOGWL/2qMgQEu47RkvzI6OK6KmdLdRTmXWEHwgG
	 WR6iq4uH2LTgcK67scyab98081Bz67A2YoquATC8DTGuy6NcQOKBHvkTriRB7R69wPvlU
	 RLyrTdgqIbWGqz5uUfOB4t+UX3ZyoG4EJIybQPqxc9eisZZn4KWOhMz/RKjahIhHxyA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796483853;
	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=bnE5qquqS7Pv3MDSCJobyu9X9Nhbpq8gJ1eAS7xaSuI=;
	b=R/mb2/vLZem7/1nKeNDI6jOVIOBQOoAsoSfLQInmkz+cOJr72iBWi3Iflqm3ojdLbfSt
	 xHtsHQBPkCpGxLWVEZigA3qorDZQBK0Ba3fof5nzrgIk3FkIXVmxoYtF4l3qJlSbyeEuV
	 F0NqpRzlW6k3Zff7tM2PeoIrtNAfFJqUbx06RNmcoU6nlcKh84nmd29grIzzGndaiInEe
	 Lm43IINBuKkcFU0lLeNqtTUHoHdCuy8QgCLVtGOkTGCR3QAQEXIaJlanNMq5Vsk7Cz1AT
	 WTq2lOEWDSKRMjgcbrS04va8X+x1RdsycYV5tiADTUaTkpo1eejfpMdiySLPN8uP2Vg==
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=Md+xzacc;
	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 D854D606A322;
	Sat,  5 Dec 2026 15:17:33 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9999E1F0092B;
	Sat,  5 Dec 2026 15:17:31 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796483853;
	bh=bnE5qquqS7Pv3MDSCJobyu9X9Nhbpq8gJ1eAS7xaSuI=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=Md+xzaccqjLZ9Eyk3uRixSyYdCq6+I5IR03CcM66xq5UkwRJF8ZEVDB7qJCUNsAvq
	 Kd9Z4I/KlDZLa+He+d8Oawt4WHp8xh4xGUxmv6FtJcTWh4uDpEwkcafI94l/gEHchq
	 I+5SE70ybeB4B1zzPtWptQuMSJnIv1wf7de8A7Wa5TsNib4Py2+nvBfKpEiTn82u06
	 8p1AlUK7vLFOi7LIB2wwYVEvHDHFe+00ozJA7/+Ab46w+aloIwf7XjrHIJm5dFugr/
	 OmUCNsD+vjVV5Lkrcswnow0sd2FIYuWtJHWh6hDAkjiBAGDWOfmhqks1BX3OCv6t8D
	 ILLSHaN+kSV2w==
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, michal.kubiak@intel.com
X-In-Reply-To: <20261204142030.626820-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