From patchwork Sat Apr 17 17:14:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slava Ovsiienko X-Patchwork-Id: 91714 X-Patchwork-Delegate: rasland@nvidia.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 06531A0562; Sat, 17 Apr 2021 19:14:24 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4E0C0161C57; Sat, 17 Apr 2021 19:14:22 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by mails.dpdk.org (Postfix) with ESMTP id E156B161B73 for ; Sat, 17 Apr 2021 19:14:19 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE1 (envelope-from viacheslavo@nvidia.com) with SMTP; 17 Apr 2021 20:14:16 +0300 Received: from nvidia.com (pegasus11.mtr.labs.mlnx [10.210.16.104]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 13HHEFYq003638; Sat, 17 Apr 2021 20:14:15 +0300 From: Viacheslav Ovsiienko To: dev@dpdk.org Cc: stable@dpdk.org, rasland@nvidia.com, matan@nvidia.com, orika@nvidia.com Date: Sat, 17 Apr 2021 20:14:14 +0300 Message-Id: <20210417171414.6117-1-viacheslavo@nvidia.com> X-Mailer: git-send-email 2.18.1 Subject: [dpdk-dev] [PATCH] net/mlx4: fix buffer leakage on device close X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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: a2ce2121c01c ("net/mlx4: separate Tx configuration functions") Cc: stable@dpdk.org Signed-off-by: Viacheslav Ovsiienko --- drivers/net/mlx4/mlx4_rxtx.c | 4 ---- drivers/net/mlx4/mlx4_txq.c | 19 +++++++++---------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/drivers/net/mlx4/mlx4_rxtx.c b/drivers/net/mlx4/mlx4_rxtx.c index adc1c9bf81..ecf08f53cf 100644 --- a/drivers/net/mlx4/mlx4_rxtx.c +++ b/drivers/net/mlx4/mlx4_rxtx.c @@ -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; diff --git a/drivers/net/mlx4/mlx4_txq.c b/drivers/net/mlx4/mlx4_txq.c index 31ab308050..2df26842fb 100644 --- a/drivers/net/mlx4/mlx4_txq.c +++ b/drivers/net/mlx4/mlx4_txq.c @@ -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; }