libeth reads the shared info of an XSk XDP_TX frame when it flushes
the bulk, not when it queues the frame. The fragment count it finds
there decides how many completions idpf reports to the XSk pool.
The shared info of a zero-copy buffer lives in the UMEM, which
userspace may write at any time, so a rewritten count makes idpf
report the wrong number of completions. Once the next patch moves the
shared info into the buffer pool, the next multi-buffer frame of the
same poll can overwrite it before the flush.
Count each buffer on its own SQE. Head and fragments each take one off
the in-flight count, and the head counts the packet. Stats do not
change.
Found by code inspection.
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 | 3 ++-
include/net/libeth/xdp.h | 9 ++++++++-
include/net/libeth/xsk.h | 6 ++++--
3 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/include/net/libeth/tx.h b/include/net/libeth/tx.h
index c3db5c6f1641..25cad5566436 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,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;
}
base-commit: 28a371228d4eb4857cc31eeb1a0d7d01e9c3ea2f
--
2.56.1