net/mlx4: fix buffer leakage on device close
PATCH 1/1 net/mlx4: fix buffer leakage on device close
The mlx4 PMD tracks the buffers (mbufs) for the packets being transmitted in the dedicated array named as "elts". The tx_burst routine frees the mbufs from this array once it needs to rearm the hardware descriptor and store the new mbuf, so it looks like as replacement mbuf pointer in the elts array.
On the device stop mlx4 PMD freed only the part of elts according tail and head pointers, leaking the rest of buffers, remained in the elts array.
--- drivers/net/mlx4/mlx4_rxtx.c | 4 ---- drivers/net/mlx4/mlx4_txq.c | 19 +++++++++---------- 2 files changed, 9 insertions(+), 14 deletions(-)
drivers/net/mlx4/mlx4_rxtx.c +0 -4
@@ -921,10 +921,6 @@ mlx4_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n)if (likely (elt->buf !=NULL )) {struct rte_mbuf *tmp = elt->buf; -#ifdef RTE_LIBRTE_MLX4_DEBUG -/* Poisoning. */ -memset (&elt->buf,0x66 ,sizeof (struct rte_mbuf *)); -#endif /* Faster than rte_pktmbuf_free(). */ do { struct rte_mbuf *next = tmp->next;
drivers/net/mlx4/mlx4_txq.c +9 -10
@@ -206,19 +206,18 @@ mlx4_tx_uar_uninit_secondary(struct rte_eth_dev *dev __rte_unused)static void mlx4_txq_free_elts (struct txq *txq) { -unsigned int elts_head = txq->elts_head; -unsigned int elts_tail = txq->elts_tail;struct txq_elt (*elts)[txq->elts_n] = txq->elts; -unsigned int elts_m = txq->elts_n -1 ; +unsigned int n = txq->elts_n; -DEBUG ("%p: freeing WRs" , (void *)txq); -while (elts_tail != elts_head) { -struct txq_elt *elt = &(*elts)[elts_tail++ & elts_m]; +DEBUG ("%p: freeing WRs, %u" , (void *)txq, n); +while (n--) { +struct txq_elt *elt = &(*elts)[n]; -MLX4_ASSERT (elt->buf !=NULL ); -rte_pktmbuf_free (elt->buf); - elt->buf =NULL ; - elt->wqe =NULL ; +if (elt->buf) { +rte_pktmbuf_free (elt->buf); + elt->buf =NULL ; + elt->wqe =NULL ; + } } txq->elts_tail = txq->elts_head; }
Signature · 1 line
2.18.1
Hi,
Quoted 13 lines
-----Original Message-----
From: Viacheslav Ovsiienko <[email protected]>
Sent: Saturday, April 17, 2021 8:14 PM
To: [email protected]
Cc: [email protected]; Raslan Darawsheh <[email protected]>; Matan Azrad <[email protected]>; Ori Kam <[email protected]>
Subject: [PATCH] net/mlx4: fix buffer leakage on device closeThe mlx4 PMD tracks the buffers (mbufs) for the packets being transmitted in the dedicated array named as "elts". The
tx_burstroutine frees the mbufs from this array once it needs to rearm the hardware descriptor and store the new mbuf, so it looks like as replacement mbuf pointer in the elts array.
Quoted 7 lines
On the device stop mlx4 PMD freed only the part of elts according tail and head pointers, leaking the rest of buffers, remained in the elts array.
Fixes a2ce2121c01c ("net/mlx4: separate Tx configuration functions")Signed-off-by Viacheslav Ovsiienko <[email protected]>
Patch applied to next-net-mlx,
Kindest regards,
Raslan Darawsheh