🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24609

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

#24609
From: Björn Töpel
Date: Mon, 30 Nov 2026 12:37
107 lines
12013 bytes
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. Once the last patch of this series moves the
shared info into the buffer pool, the next multi-buffer frame of the
same poll can overwrite it before the flush.

A wrong number breaks the in-flight count of XDP_TX buffers that idpf
keeps on its XSk queues, and idpf may then complete XDP_TX buffers as
XSk xmit frames.

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.

Fixes: b3ad8450b4dc ("libeth: xsk: add XSk XDP_TX sending helpers")
Signed-off-by: Björn Töpel <bjorn@kernel.org>
---
 include/net/libeth/tx.h  | 8 +++++---
 include/net/libeth/xdp.h | 9 ++++++++-
 include/net/libeth/xsk.h | 6 ++++--
 3 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/include/net/libeth/tx.h b/include/net/libeth/tx.h
index c3db5c6f1641..a8cf03c8be71 100644
--- a/include/net/libeth/tx.h
+++ b/include/net/libeth/tx.h
@@ -22,7 +22,8 @@
  * @LIBETH_SQE_XDP_XMIT: &xdp_frame, unmap and xdp_return_frame_bulk(), stats
  * @LIBETH_SQE_XDP_XMIT_FRAG: &xdp_frame frag, only unmap DMA
  * @LIBETH_SQE_XSK_TX: &libeth_xdp_buff on XSk queue, xsk_buff_free(), stats
- * @LIBETH_SQE_XSK_TX_FRAG: &libeth_xdp_buff frag on XSk queue, xsk_buff_free()
+ * @LIBETH_SQE_XSK_TX_FRAG: &libeth_xdp_buff frag on XSk queue, xsk_buff_free(),
+ *			    stats
  */
 enum libeth_sqe_type {
 	LIBETH_SQE_EMPTY		= 0U,
@@ -50,9 +51,10 @@ enum libeth_sqe_type {
  * @xsk: XSk Rx frame from XDP_TX action
  * @dma: DMA address to unmap
  * @len: length of the mapped region to unmap
- * @nr_frags: number of frags in the frame this buffer belongs to
+ * @nr_frags: number of frags in the frame this buffer belongs to, not for XSk
  * @packets: number of physical packets sent for this frame
- * @bytes: number of physical bytes sent for this frame
+ * @bytes: number of physical bytes sent for this frame, or for this buffer
+ *	   on XSk
  * @priv: driver-private scratchpad
  */
 struct libeth_sqe {
diff --git a/include/net/libeth/xdp.h b/include/net/libeth/xdp.h
index 898723ab62e8..66a3c4ec9967 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--;
+		cp->xss->bytes += sqe->bytes;
+		break;
 	default:
 		break;
 	}
diff --git a/include/net/libeth/xsk.h b/include/net/libeth/xsk.h
index 249b1c740788..2cd4252a3445 100644
--- a/include/net/libeth/xsk.h
+++ b/include/net/libeth/xsk.h
@@ -129,6 +129,10 @@ libeth_xsk_tx_fill_buf(struct libeth_xdp_tx_frame frm, u32 i,
 
 	sqe = &sq->sqes[i];
 	sqe->xsk = xdp;
+	/* Count each buffer on its own SQE. The shared info of the frame
+	 * may change before the bulk is flushed.
+	 */
+	sqe->bytes = desc.len;
 
 	if (!(desc.flags & LIBETH_XDP_TX_FIRST)) {
 		sqe->type = LIBETH_SQE_XSK_TX_FRAG;
@@ -136,8 +140,6 @@ libeth_xsk_tx_fill_buf(struct libeth_xdp_tx_frame frm, u32 i,
 	}
 
 	sqe->type = LIBETH_SQE_XSK_TX;
-	libeth_xdp_tx_fill_stats(sqe, &desc,
-				 xdp_get_shared_info_from_buff(&xdp->base));
 
 	return desc;
 }
-- 
2.56.1
Technical Details
Message-ID: <20261130123737.125432-2-bjorn@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374171-linux-kernel-netdev=dewy.ru
References: <20261130123737.125432-1-bjorn@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374171-linux-kernel-netdev=dewy.ru
From: bjorn@kernel.org (Björn Töpel)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v2 1/4] libeth: xsk: Count each XDP_TX buffer on its own
Date: Mon, 30 Nov 2026 13:37:32 +0100
Organization: Usenet Network
Message-ID: <20261130123737.125432-2-bjorn@kernel.org>
References: <20261130123737.125432-1-bjorn@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1424809"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:p7+GITxVpLFuBg6QthGGG25iZaQ= sha256:l2y6jC+54a2L5nHgxFfFkayFNHvlwTZlzMhxSErTDS4=
	sha1:EFw3uJ3rPbUhi8jIwWN8R0EzTdc= sha256:X1JbTp2cJkm9hKjPcFGhxmYURbrY/95VTa2sWn8GOwE=
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 7052B125FE4; Mon, 30 Nov 2026 15:38:08 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 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] 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 7_GRJbgdnJt0;
	Mon, 30 Nov 2026 15:38:05 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-374171-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 D77A9125FE2; Mon, 30 Nov 2026 15:37:56 +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 B48332D9C8; Mon, 30 Nov 2026 12:37: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=1796042273;
	b=DBgLgYBC7CXhSAUkRXkrgqhrwyZHzqrqByo5bM7SKH62fsvvSxy/aJLUols88rbuKc5p
	 iXC/RAvUKr8QwY7M1BYdGHBKijOM2toEdt4tVFEghwBejBoNVBEXyAgj8x6EEfurtdAAo
	 bMIdtS4Ug9ALitqGBA5pAt7q+IhXU3mF4hI3pwnkkai2bQjUHeDnKEqaaOqnqeMWV6OwE
	 i55h2bZs0LnsMTil+ROI2QCwd7953uYNfDhhT3bybRSmQ2cXLsQB3qgktuuLnsEPBqoDo
	 HJ6UA6Wlo45kuMM7GBI9HhdJim7rBtIDuqpO8IQcfVT3kiff8BfKLtL6ibHB8d217KA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796042273;
	h=X-Original-To:Received:Received:DKIM-Signature: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=IqUnybaBKLXaG+PAN/2isXsn5ciPicC+Ck/+NBew9+E=;
	b=u0vM9RKAZO7iN+zxcXJip8F2X/1AL3/lfZwz1nuediwdbhRWSnWziyaJhEoOY5ouYKWv
	 MYL+vosx+Ggh+wB07gFWiWkE0SWxBAjNyAxnNGL2tm0La/yGmPaixccTskPMY3EgDpo5z
	 N/Yk5RKHQHxAdHVKa5g+7ppFwhaO1HklmbDS4N772euxPwZjvVmqXLVEpFXKoPHCbiAgJ
	 3yyIxfX7ECHqPLSbnsCryQ33WkUYP8Wc6IodDuKlTSfB5oagBMeABUFvwo4MR8hLi07Ns
	 94GYY/6ShLMlC9plUjMy+c1O5MBUgETVlZkq6FosZBPcsPNshKFPWRhAtJ9wm6YZftw==
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=BwVypcLh;
	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 5A96F606A32C;
	Mon, 30 Nov 2026 12:37: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=BwVypcLh
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=1796042272;
	b=eRNCc930qE6c4QSGlL+huQxinBEJFQyS6wu4KkC/s8ecsDGAa0NPys7Nmu2H/eA3iCrr
	 3PoggWzK6f6TvaWMimeLKfYzmCSB+n+OQ/TyOnDT1TFEF5/q0VAOOCbC27b9eN9d0iQ8a
	 2QxDy6bRptvvFLyz0D6NryOxLlmEjcC2ARuzm7NyWc3OzCuT2lVjv5OOx1JFsv8teIhwT
	 3H17seQ5mWx8UlNDEwstqgUf4f6IeihpItnTthswEZ7vRn09U7eFlUFPDTlAgyU2Abyok
	 IJK5lkJu31dsmkXoFBN7rROBr7aJRzFIEb5J+ustgN2KSBHUv5S21D8C1KhSbkg/ZeQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796042272;
	h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer:
	 In-Reply-To:References:MIME-Version:Content-Type:
	 Content-Transfer-Encoding;
	bh=IqUnybaBKLXaG+PAN/2isXsn5ciPicC+Ck/+NBew9+E=;
	b=WtXigPJ/UErwu1nT/Atb9D9hbaYgI1jf8vjPLHdFugUazgGDLoiM0Slmou/+uwNtwMi6
	 W9yLlgIFdJtYC2Oirpdgk5f7e/9bqxT1pOyEnIR5L0q3BZAL/eAkBr3e27JGto8doJpZI
	 IjvbDe5jYkveM6HJbJQjpG+s9V4mq0se9MaY2VQxB558zC7Ihh67cfBBF/uIRAYtzZ+33
	 obBnM8nDt1uKKXCbT1Q50WaRbtWDKTHEGr7p/rDf9xKcZpja+HITi+DDpKc9CMgr3Jrkb
	 L05PUXiEdVQVzX+fm77Biu5iYwYJXx4M/Nib4wPsJjYVmOQcoMaRcVb0rBeVN+ak0Hg==
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=BwVypcLh;
	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 790CA606A31C;
	Mon, 30 Nov 2026 12:37:52 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67B0D1F00896;
	Mon, 30 Nov 2026 12:37:46 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796042272;
	bh=IqUnybaBKLXaG+PAN/2isXsn5ciPicC+Ck/+NBew9+E=;
	h=From:To:Cc:Subject:Date:In-Reply-To:References;
	b=BwVypcLhyQr0D/otHe+OzCJTSlCHG/yjA7cXaxSIxQ2wgvjgXsMIA/uHXkJwFXGdj
	 WOdj/42zQIZidvRUovSiQjdm66Ra83yq0KUo8GdbYx6jX1lb0IIrvVnbU5klOw89Ry
	 rmL+5qpW0Uih4hS8vA6oQxF08ftyTDNdr2CUAl6G1ZX7WrQJCgZhBC7q+PAUaVH9fb
	 paiq9FPgu63RWzjBWJZbAPnWAhM8dT/IuD7NQqg49nIVlYTq1QsYZCCkB7viikvWtJ
	 9hEKL2MgsiZ59yK1nUgbapPYCj62uwEJc4SRs0HiqKavbX+srd5lM7pEHkheF9IYJE
	 e0qRboFTX0cHg==
X-Cc: Björn Töpel <bjorn@kernel.org>,
	Simon Horman <horms@kernel.org>,
	Stanislav Fomichev <sdf@fomichev.me>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	Jiri Olsa <jolsa@kernel.org>,
	Emil Tsalapatis <emil@etsalapatis.com>,
	Ihor Solodrai <ihor.solodrai@linux.dev>,
	Tony Nguyen <anthony.l.nguyen@intel.com>,
	Przemek Kitszel <przemyslaw.kitszel@intel.com>,
	intel-wired-lan@lists.osuosl.org,
	Clément Lecigne <clecigne@google.com>
X-Mailer: git-send-email 2.56.1
X-In-Reply-To: <20261130123737.125432-1-bjorn@kernel.org>
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