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 <alek…@intel.com>
Signed-off-by: Björn Töpel <bjo…@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