From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6D68EA046B for ; Tue, 23 Jul 2019 03:03:41 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 5E5171BFC6; Tue, 23 Jul 2019 03:03:41 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id BBA2F1BFB3 for ; Tue, 23 Jul 2019 03:03:39 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE2 (envelope-from yskoh@mellanox.com) with ESMTPS (AES256-SHA encrypted); 23 Jul 2019 04:03:37 +0300 Received: from scfae-sc-2.mti.labs.mlnx (scfae-sc-2.mti.labs.mlnx [10.101.0.96]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x6N11Hg4026580; Tue, 23 Jul 2019 04:03:36 +0300 From: Yongseok Koh To: Shahed Shaikh Cc: dpdk stable Date: Mon, 22 Jul 2019 18:00:45 -0700 Message-Id: <20190723010115.6446-78-yskoh@mellanox.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190723010115.6446-1-yskoh@mellanox.com> References: <20190723010115.6446-1-yskoh@mellanox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-stable] patch 'net/bnx2x: fix memory leak' has been queued to LTS release 17.11.7 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" Hi, FYI, your patch has been queued to LTS release 17.11.7 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objection by 07/27/19. So please shout if anyone has objection. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Thanks. Yongseok --- >From 7ddff92e2127b203d2f1f025e4ba6720fe9bc4e0 Mon Sep 17 00:00:00 2001 From: Shahed Shaikh Date: Thu, 11 Apr 2019 18:47:38 -0700 Subject: [PATCH] net/bnx2x: fix memory leak [ upstream commit 68ed0742256dde2335cb1f6560ef94e7b29febed ] We allocate DMA memory but never free after using it. Add function to free DMA memory. Fixes: b5bf7719221d ("bnx2x: driver support routines") Signed-off-by: Shahed Shaikh --- drivers/net/bnx2x/bnx2x.c | 15 +++++++++++++++ drivers/net/bnx2x/bnx2x.h | 3 ++- drivers/net/bnx2x/ecore_sp.h | 17 +++++++++-------- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/drivers/net/bnx2x/bnx2x.c b/drivers/net/bnx2x/bnx2x.c index 2beac31389..5e53782e94 100644 --- a/drivers/net/bnx2x/bnx2x.c +++ b/drivers/net/bnx2x/bnx2x.c @@ -189,6 +189,7 @@ bnx2x_dma_alloc(struct bnx2x_softc *sc, size_t size, struct bnx2x_dma *dma, } dma->paddr = (uint64_t) z->iova; dma->vaddr = z->addr; + dma->mzone = (const void *)z; PMD_DRV_LOG(DEBUG, sc, "%s: virt=%p phys=%" PRIx64, msg, dma->vaddr, dma->paddr); @@ -196,6 +197,19 @@ bnx2x_dma_alloc(struct bnx2x_softc *sc, size_t size, struct bnx2x_dma *dma, return 0; } +void bnx2x_dma_free(struct bnx2x_dma *dma) +{ + if (dma->mzone == NULL) + return; + + rte_memzone_free((const struct rte_memzone *)dma->mzone); + dma->sc = NULL; + dma->paddr = 0; + dma->vaddr = NULL; + dma->nseg = 0; + dma->mzone = NULL; +} + static int bnx2x_acquire_hw_lock(struct bnx2x_softc *sc, uint32_t resource) { uint32_t lock_status; @@ -2442,6 +2456,7 @@ static int bnx2x_alloc_mem(struct bnx2x_softc *sc) static void bnx2x_free_fw_stats_mem(struct bnx2x_softc *sc) { + bnx2x_dma_free(&sc->fw_stats_dma); sc->fw_stats_num = 0; sc->fw_stats_req_size = 0; diff --git a/drivers/net/bnx2x/bnx2x.h b/drivers/net/bnx2x/bnx2x.h index 2ec7a45c61..88f788a35f 100644 --- a/drivers/net/bnx2x/bnx2x.h +++ b/drivers/net/bnx2x/bnx2x.h @@ -321,6 +321,7 @@ struct bnx2x_dma { rte_iova_t paddr; void *vaddr; int nseg; + const void *mzone; char msg[RTE_MEMZONE_NAMESIZE - 6]; }; @@ -1752,7 +1753,7 @@ int bnx2x_cmpxchg(volatile int *addr, int old, int new); int bnx2x_dma_alloc(struct bnx2x_softc *sc, size_t size, struct bnx2x_dma *dma, const char *msg, uint32_t align); - +void bnx2x_dma_free(struct bnx2x_dma *dma); uint32_t bnx2x_dmae_opcode_add_comp(uint32_t opcode, uint8_t comp_type); uint32_t bnx2x_dmae_opcode_clr_src_reset(uint32_t opcode); uint32_t bnx2x_dmae_opcode(struct bnx2x_softc *sc, uint8_t src_type, diff --git a/drivers/net/bnx2x/ecore_sp.h b/drivers/net/bnx2x/ecore_sp.h index 7e52245a27..6b179898c4 100644 --- a/drivers/net/bnx2x/ecore_sp.h +++ b/drivers/net/bnx2x/ecore_sp.h @@ -153,14 +153,15 @@ typedef rte_spinlock_t ECORE_MUTEX_SPIN; } \ } while (0) -#define ECORE_ILT_FREE(x, y, size) \ - do { \ - if (x) { \ - rte_free(x); \ - x = NULL; \ - y = 0; \ - } \ - } while (0) +#define ECORE_ILT_FREE(x, y, size) \ + do { \ + if (x) { \ + bnx2x_dma_free((struct bnx2x_dma *)x); \ + rte_free(x); \ + x = NULL; \ + y = 0; \ + } \ + } while (0) #define ECORE_IS_VALID_ETHER_ADDR(_mac) TRUE -- 2.21.0 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2019-07-22 17:55:10.661523890 -0700 +++ 0078-net-bnx2x-fix-memory-leak.patch 2019-07-22 17:55:06.309475000 -0700 @@ -1,13 +1,14 @@ -From 68ed0742256dde2335cb1f6560ef94e7b29febed Mon Sep 17 00:00:00 2001 +From 7ddff92e2127b203d2f1f025e4ba6720fe9bc4e0 Mon Sep 17 00:00:00 2001 From: Shahed Shaikh Date: Thu, 11 Apr 2019 18:47:38 -0700 Subject: [PATCH] net/bnx2x: fix memory leak +[ upstream commit 68ed0742256dde2335cb1f6560ef94e7b29febed ] + We allocate DMA memory but never free after using it. Add function to free DMA memory. Fixes: b5bf7719221d ("bnx2x: driver support routines") -Cc: stable@dpdk.org Signed-off-by: Shahed Shaikh --- @@ -17,10 +18,10 @@ 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/drivers/net/bnx2x/bnx2x.c b/drivers/net/bnx2x/bnx2x.c -index ab092e23f0..298bc414a7 100644 +index 2beac31389..5e53782e94 100644 --- a/drivers/net/bnx2x/bnx2x.c +++ b/drivers/net/bnx2x/bnx2x.c -@@ -185,6 +185,7 @@ bnx2x_dma_alloc(struct bnx2x_softc *sc, size_t size, struct bnx2x_dma *dma, +@@ -189,6 +189,7 @@ bnx2x_dma_alloc(struct bnx2x_softc *sc, size_t size, struct bnx2x_dma *dma, } dma->paddr = (uint64_t) z->iova; dma->vaddr = z->addr; @@ -28,7 +29,7 @@ PMD_DRV_LOG(DEBUG, sc, "%s: virt=%p phys=%" PRIx64, msg, dma->vaddr, dma->paddr); -@@ -192,6 +193,19 @@ bnx2x_dma_alloc(struct bnx2x_softc *sc, size_t size, struct bnx2x_dma *dma, +@@ -196,6 +197,19 @@ bnx2x_dma_alloc(struct bnx2x_softc *sc, size_t size, struct bnx2x_dma *dma, return 0; } @@ -48,7 +49,7 @@ static int bnx2x_acquire_hw_lock(struct bnx2x_softc *sc, uint32_t resource) { uint32_t lock_status; -@@ -2436,6 +2450,7 @@ static int bnx2x_alloc_mem(struct bnx2x_softc *sc) +@@ -2442,6 +2456,7 @@ static int bnx2x_alloc_mem(struct bnx2x_softc *sc) static void bnx2x_free_fw_stats_mem(struct bnx2x_softc *sc) { @@ -57,10 +58,10 @@ sc->fw_stats_req_size = 0; diff --git a/drivers/net/bnx2x/bnx2x.h b/drivers/net/bnx2x/bnx2x.h -index 32a12294b1..9e82a89311 100644 +index 2ec7a45c61..88f788a35f 100644 --- a/drivers/net/bnx2x/bnx2x.h +++ b/drivers/net/bnx2x/bnx2x.h -@@ -319,6 +319,7 @@ struct bnx2x_dma { +@@ -321,6 +321,7 @@ struct bnx2x_dma { rte_iova_t paddr; void *vaddr; int nseg; @@ -68,7 +69,7 @@ char msg[RTE_MEMZONE_NAMESIZE - 6]; }; -@@ -1753,7 +1754,7 @@ int bnx2x_cmpxchg(volatile int *addr, int old, int new); +@@ -1752,7 +1753,7 @@ int bnx2x_cmpxchg(volatile int *addr, int old, int new); int bnx2x_dma_alloc(struct bnx2x_softc *sc, size_t size, struct bnx2x_dma *dma, const char *msg, uint32_t align); @@ -78,10 +79,10 @@ uint32_t bnx2x_dmae_opcode_clr_src_reset(uint32_t opcode); uint32_t bnx2x_dmae_opcode(struct bnx2x_softc *sc, uint8_t src_type, diff --git a/drivers/net/bnx2x/ecore_sp.h b/drivers/net/bnx2x/ecore_sp.h -index f295bf5af5..7126097db6 100644 +index 7e52245a27..6b179898c4 100644 --- a/drivers/net/bnx2x/ecore_sp.h +++ b/drivers/net/bnx2x/ecore_sp.h -@@ -151,14 +151,15 @@ typedef rte_spinlock_t ECORE_MUTEX_SPIN; +@@ -153,14 +153,15 @@ typedef rte_spinlock_t ECORE_MUTEX_SPIN; } \ } while (0)