DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net/mlx5: fix mbuf corruption in vectorized MPRQ Rx
@ 2026-11-26 14:28 Gavin Hu
  2026-11-26 15:42 ` Dariusz Sosnowski
  0 siblings, 1 reply; 2+ messages in thread
From: Gavin Hu @ 2026-11-26 14:28 UTC (permalink / raw)
  To: dev
  Cc: stable, Dariusz Sosnowski, Viacheslav Ovsiienko, Bing Zhao,
	Ori Kam, Suanming Mou, Matan Azrad, Alexander Kozyrev

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@dpdk.org

Signed-off-by: Gavin Hu <gahu@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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] net/mlx5: fix mbuf corruption in vectorized MPRQ Rx
  2026-11-26 14:28 [PATCH] net/mlx5: fix mbuf corruption in vectorized MPRQ Rx Gavin Hu
@ 2026-11-26 15:42 ` Dariusz Sosnowski
  0 siblings, 0 replies; 2+ messages in thread
From: Dariusz Sosnowski @ 2026-11-26 15:42 UTC (permalink / raw)
  To: Gavin Hu
  Cc: dev, stable, Viacheslav Ovsiienko, Bing Zhao, Ori Kam,
	Suanming Mou, Matan Azrad, Alexander Kozyrev

On Thu, Nov 26, 2026 at 04:28:24PM +0200, Gavin Hu wrote:
> 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@dpdk.org
> 
> Signed-off-by: Gavin Hu <gahu@nvidia.com>

Acked-by: Dariusz Sosnowski <dsosnowski@nvidia.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-26 15:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 14:28 [PATCH] net/mlx5: fix mbuf corruption in vectorized MPRQ Rx Gavin Hu
2026-11-26 15:42 ` Dariusz Sosnowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox