Re: [PATCH 6.6 055/156] bnxt_en: do not map packet buffers twice

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Dec 30, 2023 at 11:58:29AM +0000, Greg Kroah-Hartman wrote:
> 6.6-stable review patch.  If anyone has any objections, please let me know.
> 

No objections from me.

For reference I do have an implementation of this functionality to v6.1
if/when it should be added.   It is different as the bnxt_en driver did
not use the page pool to manage DMA mapping until v6.6.

The minimally disruptive patch to prevent this memory leak is below:

>From dc82f8b57e2692ec987628b53e6446ab9f4fa615 Mon Sep 17 00:00:00 2001
From: Andy Gospodarek <andrew.gospodarek@xxxxxxxxxxxx>
Date: Thu, 7 Dec 2023 16:23:21 -0500
Subject: [PATCH] bnxt_en: unmap frag buffers before returning page to pool

If pages are not unmapped before calling page_pool_recycle_direct they
will not be freed back to the pool.  This will lead to a memory leak and
messages like the following in dmesg:

[ 8229.436920] page_pool_release_retry() stalled pool shutdown 340 inflight 5437 sec

Fixes: a7559bc8c17c ("bnxt: support transmit and free of aggregation buffers")
Signed-off-by: Andy Gospodarek <andrew.gospodarek@xxxxxxxxxxxx>
---
 drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c
index aa56db138d6b..5b4548fad870 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c
@@ -80,6 +80,7 @@ struct bnxt_sw_tx_bd *bnxt_xmit_bd(struct bnxt *bp,
 			return NULL;
 
 		dma_unmap_addr_set(frag_tx_buf, mapping, frag_mapping);
+		dma_unmap_addr_set(frag_tx_buf, len, frag_len);
 
 		flags = frag_len << TX_BD_LEN_SHIFT;
 		txbd->tx_bd_len_flags_type = cpu_to_le32(flags);
@@ -154,8 +155,14 @@ void bnxt_tx_int_xdp(struct bnxt *bp, struct bnxt_napi *bnapi, int nr_pkts)
 
 			frags = tx_buf->nr_frags;
 			for (j = 0; j < frags; j++) {
+				struct pci_dev *pdev = bp->pdev;
+
 				tx_cons = NEXT_TX(tx_cons);
 				tx_buf = &txr->tx_buf_ring[tx_cons];
+				dma_unmap_single(&pdev->dev,
+						 dma_unmap_addr(tx_buf, mapping),
+						 dma_unmap_len(tx_buf, len),
+						 DMA_TO_DEVICE);
 				page_pool_recycle_direct(rxr->page_pool, tx_buf->page);
 			}
 		}

> 
> From: Andy Gospodarek <andrew.gospodarek@xxxxxxxxxxxx>
> 
> [ Upstream commit 23c93c3b6275a59f2a685f4a693944b53c31df4e ]
> 
> Remove double-mapping of DMA buffers as it can prevent page pool entries
> from being freed.  Mapping is managed by page pool infrastructure and
> was previously managed by the driver in __bnxt_alloc_rx_page before
> allowing the page pool infrastructure to manage it.
> 
> Fixes: 578fcfd26e2a ("bnxt_en: Let the page pool manage the DMA mapping")
> Reviewed-by: Somnath Kotur <somnath.kotur@xxxxxxxxxxxx>
> Signed-off-by: Andy Gospodarek <andrew.gospodarek@xxxxxxxxxxxx>
> Signed-off-by: Michael Chan <michael.chan@xxxxxxxxxxxx>
> Reviewed-by: David Wei <dw@xxxxxxxxxxx>
> Link: https://lore.kernel.org/r/20231214213138.98095-1-michael.chan@xxxxxxxxxxxx
> Signed-off-by: Jakub Kicinski <kuba@xxxxxxxxxx>
> Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
> ---
>  drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c | 11 ++---------
>  1 file changed, 2 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c
> index 96f5ca778c67d..8cb9a99154aad 100644
> --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c
> +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c
> @@ -59,7 +59,6 @@ struct bnxt_sw_tx_bd *bnxt_xmit_bd(struct bnxt *bp,
>  	for (i = 0; i < num_frags ; i++) {
>  		skb_frag_t *frag = &sinfo->frags[i];
>  		struct bnxt_sw_tx_bd *frag_tx_buf;
> -		struct pci_dev *pdev = bp->pdev;
>  		dma_addr_t frag_mapping;
>  		int frag_len;
>  
> @@ -73,16 +72,10 @@ struct bnxt_sw_tx_bd *bnxt_xmit_bd(struct bnxt *bp,
>  		txbd = &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)];
>  
>  		frag_len = skb_frag_size(frag);
> -		frag_mapping = skb_frag_dma_map(&pdev->dev, frag, 0,
> -						frag_len, DMA_TO_DEVICE);
> -
> -		if (unlikely(dma_mapping_error(&pdev->dev, frag_mapping)))
> -			return NULL;
> -
> -		dma_unmap_addr_set(frag_tx_buf, mapping, frag_mapping);
> -
>  		flags = frag_len << TX_BD_LEN_SHIFT;
>  		txbd->tx_bd_len_flags_type = cpu_to_le32(flags);
> +		frag_mapping = page_pool_get_dma_addr(skb_frag_page(frag)) +
> +			       skb_frag_off(frag);
>  		txbd->tx_bd_haddr = cpu_to_le64(frag_mapping);
>  
>  		len = frag_len;
> -- 
> 2.43.0
> 
> 
> 




[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux