Skip to content

Commit

Permalink
net/mlx4: fix buffer leakage on device close
Browse files Browse the repository at this point in the history
[ upstream commit b014c6b ]

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.

Fixes: a2ce212 ("net/mlx4: separate Tx configuration functions")

Signed-off-by: Viacheslav Ovsiienko <viacheslavo@nvidia.com>
  • Loading branch information
viacheslavo authored and steevenlee committed Jun 8, 2021
1 parent 0447574 commit 1c43f69
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
4 changes: 0 additions & 4 deletions drivers/net/mlx4/mlx4_rxtx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 9 additions & 10 deletions drivers/net/mlx4/mlx4_txq.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 1c43f69

Please sign in to comment.