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>,
Andrew Lunn <andrew+netdev@lunn.ch>,
Tony Nguyen <anthony.l.nguyen@intel.com>,
Przemek Kitszel <przemyslaw.kitszel@intel.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>,
intel-wired-lan@lists.osuosl.org,
"Clément Lecigne" <clecigne@google.com>,
"Michal Swiatkowski" <michal.swiatkowski@linux.intel.com>,
"Sriram Yagnaraman" <sriram.yagnaraman@ericsson.com>,
"Kurt Kanzenbach" <kurt@linutronix.de>,
"Michal Kubiak" <michal.kubiak@intel.com>
Subject: [PATCH net v4 2/5] libeth: xsk: Count each XDP_TX buffer on its own
Date: Fri, 4 Dec 2026 15:20:22 +0100 [thread overview]
Message-ID: <20261204142030.626820-3-bjorn@kernel.org> (raw)
In-Reply-To: <20261204142030.626820-1-bjorn@kernel.org>
libeth counts the completed buffers of an XSk XDP_TX frame from its
shared info, which it reads at the bulk flush, not when it queues the
frame. A zero-copy buffer keeps its shared info in the UMEM, which
userspace may write at any time. Once the last patch of this series
moves it into the buffer pool, the next multi-buffer frame of the poll
can overwrite it first.
It also goes wrong without userspace. When the XDPSQ fills up inside a
multi-buffer frame, libeth sends the first buffers, drops the rest,
and still reports the whole frame.
That breaks the in-flight XDP_TX count 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, and the packet on the
head. A partly sent frame now counts the bytes of the buffers sent.
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")
Acked-by: Alexander Lobakin <aleksander.lobakin@intel.com>
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 622c26059cb9..21c7fd7803df 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 38fcd3fdff70..12284ed9fb48 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.53.1
next prev parent reply other threads:[~2026-12-04 14:20 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 14:20 [PATCH net v4 0/5] xsk: Keep the shared info of zero-copy buffers in kernel memory Björn Töpel
2026-12-04 14:20 ` [PATCH net v4 1/5] libeth: xdp: Count completed XDP_TX buffers up Björn Töpel
2026-12-04 14:20 ` Björn Töpel [this message]
2026-12-04 14:20 ` [PATCH net v4 3/5] xdp: Size zero-copy skbs from the data, not the frame size Björn Töpel
2026-12-04 14:20 ` [PATCH net v4 4/5] intel: Copy the exact length of XSk packets to skbs Björn Töpel
2026-12-04 14:20 ` [PATCH net v4 5/5] 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=20261204142030.626820-3-bjorn@kernel.org \
--to=bjorn@kernel.org \
--cc=aleksander.lobakin@intel.com \
--cc=andrew+netdev@lunn.ch \
--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=kurt@linutronix.de \
--cc=maciej.fijalkowski@intel.com \
--cc=magnus.karlsson@intel.com \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=michal.kubiak@intel.com \
--cc=michal.swiatkowski@linux.intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=przemyslaw.kitszel@intel.com \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=sriram.yagnaraman@ericsson.com \
--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