[PATCH] net/mlx5: fix mbuf corruption in vectorized MPRQ Rx

Gavin Hu gahu at nvidia.com
Thu Nov 26 15:28:24 CET 2026


rxq_burst_mprq_v() caps the packets it handles by the number of
replenished mbufs:

	pkts_n = RTE_MIN(pkts_n, rxq->elts_ci - rxq->rq_pi);

That cap bounds rxq_cq_process_v() and the mbufs returned to the
application, but not the compressed CQE session handled at the
"decompress" label. rxq_cq_decompress_v() takes the session length
from the title CQE and always writes all of it into elts[].

For SPRQ this cannot overrun: the elts mbufs are the buffers posted to
the RQ, so the HW never completes more packets than there are mbufs.
MPRQ posts strides instead. The HW keeps completing packets no matter
how many elts the SW managed to replenish, so the session length is
unrelated to the number of available elts.

Once the mbuf pool runs dry, unzipping therefore walks past the
MLX5_VPMD_DESCS_PER_LOOP fake_mbuf guards placed at elts_ci and reaches
the slots beyond them, which still hold mbufs already handed to the
application. It overwrites their rearm_data and rx_descriptor_fields1.
rearm_data covers ol_flags, so the victim loses RTE_MBUF_F_EXTERNAL
while buf_addr and shinfo keep pointing at the MPRQ stride: the mbuf
now claims to be direct, but its buffer lives in stride memory. The lost
RTE_MBUF_F_EXTERNAL flag triggers incorrect mbuf handling later in the
application, when the mbuf is attached to another one.

Compute the session length from the title CQE before unzipping, the
same way rxq_cq_decompress_v() does, and leave the session in the CQ
until it fits entirely in the available elts. The CQ consumer index is
not advanced, so the session is retried on a later burst once
replenishment succeeds.

Fixes: 0f20acbf5eda ("net/mlx5: implement vectorized MPRQ burst")
Cc: stable at dpdk.org

Signed-off-by: Gavin Hu <gahu at nvidia.com>
---
 drivers/net/mlx5/mlx5_rxtx_vec.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/net/mlx5/mlx5_rxtx_vec.c b/drivers/net/mlx5/mlx5_rxtx_vec.c
index 228ff2bfcb..c86d1f9f7e 100644
--- a/drivers/net/mlx5/mlx5_rxtx_vec.c
+++ b/drivers/net/mlx5/mlx5_rxtx_vec.c
@@ -561,7 +561,22 @@ rxq_burst_mprq_v(struct mlx5_rxq_data *rxq, struct rte_mbuf **pkts,
 decompress:
 	/* Decompress the last CQE if compressed. */
 	if (comp_idx < MLX5_VPMD_DESCS_PER_LOOP) {
+		volatile struct mlx5_cqe *tcqe = &cq[nocmp_n];
+		uint32_t mcqe_n;
+
 		MLX5_ASSERT(comp_idx == (nocmp_n % MLX5_VPMD_DESCS_PER_LOOP));
+		/*
+		 * MPRQ HW completes packets regardless of how many elts were
+		 * replenished, and unzipping always writes the whole session.
+		 * Leave the session in the CQ until it fits.
+		 */
+		mcqe_n = rxq->cqe_comp_layout ?
+			 (MLX5_CQE_NUM_MINIS(tcqe->op_own) + 1U) :
+			 rte_be_to_cpu_32(tcqe->byte_cnt);
+		if (unlikely(mcqe_n > rxq->elts_ci - rxq->rq_pi)) {
+			*no_cq = !rcvd_pkt;
+			return rcvd_pkt;
+		}
 		rxq->decompressed = rxq_cq_decompress_v(rxq, &cq[nocmp_n],
 							&elts[nocmp_n], false);
 		/* Return more packets if needed. */
-- 
2.27.0



More information about the stable mailing list