From: "Björn Töpel" <bjorn@kernel.org>
To: Magnus Karlsson <magnus.karlsson@intel.com>,
Maciej Fijalkowski <maciej.fijalkowski@intel.com>,
Alexander Lobakin <aleksander.lobakin@intel.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Jesper Dangaard Brouer <hawk@kernel.org>,
John Fastabend <john.fastabend@gmail.com>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Willem de Bruijn <willemb@google.com>,
netdev@vger.kernel.org, bpf@vger.kernel.org
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>
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 [thread overview]
Message-ID: <20261130123737.125432-2-bjorn@kernel.org> (raw)
In-Reply-To: <20261130123737.125432-1-bjorn@kernel.org>
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
next prev parent reply other threads:[~2026-11-30 12:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 12:37 [PATCH net v2 0/4] xsk: Keep the shared info of zero-copy buffers in kernel memory Björn Töpel
2026-11-30 12:37 ` Björn Töpel [this message]
2026-11-30 12:37 ` [PATCH net v2 2/4] xdp: Size zero-copy skbs from the data, not the frame size Björn Töpel
2026-11-30 12:37 ` [PATCH net v2 3/4] intel: Copy the exact length of XSk packets to skbs Björn Töpel
2026-11-30 12:37 ` [PATCH net v2 4/4] xsk: Keep the shared info of zero-copy buffers in kernel memory Björn Töpel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261130123737.125432-2-bjorn@kernel.org \
--to=bjorn@kernel.org \
--cc=aleksander.lobakin@intel.com \
--cc=andrii@kernel.org \
--cc=anthony.l.nguyen@intel.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=clecigne@google.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=eddyz87@gmail.com \
--cc=edumazet@kernel.org \
--cc=emil@etsalapatis.com \
--cc=hawk@kernel.org \
--cc=horms@kernel.org \
--cc=ihor.solodrai@linux.dev \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kuba@kernel.org \
--cc=maciej.fijalkowski@intel.com \
--cc=magnus.karlsson@intel.com \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=przemyslaw.kitszel@intel.com \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=willemb@google.com \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox