Skip to contentSkip to conversation

net: mvneta: fix the Rx desc buffer DMA unmapping

PATCH Applied Antoine Tenart 4 participants 6 messages Sep 19, 2018 – Sep 22, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: mvneta: fix the Rx desc buffer DMA unmapping

With CONFIG_DMA_API_DEBUG enabled we now get a warning when using the mvneta driver:

mvneta d0030000.ethernet: DMA-API: device driver frees DMA memory with wrong function [device address=0x000000001165b000] [size=4096 bytes] [mapped as page] [unmapped as single]

This is because when using the s/w buffer management, the Rx descriptor buffer is mapped with dma_map_page but unmapped with dma_unmap_single. This patch fixes this by using the right unmapping function.

Fixes 562e2f467e71 ("net: mvneta: Improve the buffer allocation method for SWBM")
---
 drivers/net/ethernet/marvell/mvneta.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/marvell/mvneta.c +2 -2
index bc80a678abc3..2db9708f2e24 100644
@@ -2008,8 +2008,8 @@ static int mvneta_rx_swbm(struct napi_struct *napi,
 				skb_add_rx_frag(rxq->skb, frag_num, page,
 						frag_offset, frag_size,
 						PAGE_SIZE);
-				dma_unmap_single(dev->dev.parent, phys_addr,
-						 PAGE_SIZE, DMA_FROM_DEVICE);
+				dma_unmap_page(dev->dev.parent, phys_addr,
+					       PAGE_SIZE, DMA_FROM_DEVICE);
 				rxq->left_size -= frag_size;
 			}
 		} else {
Signature · 1 line
2.17.1
maintainer Applied
#1 lore raw

From: Antoine Tenart <[email protected]>
Date: Wed, 19 Sep 2018 15:29:06 +0200

Quoted 7 lines

With CONFIG_DMA_API_DEBUG enabled we now get a warning when using the mvneta driver:

mvneta d0030000.ethernet: DMA-API: device driver frees DMA memory with wrong function [device address=0x000000001165b000] [size=4096 bytes] [mapped as page] [unmapped as single]

Quoted 6 lines

This is because when using the s/w buffer management, the Rx descriptor buffer is mapped with dma_map_page but unmapped with dma_unmap_single. This patch fixes this by using the right unmapping function.

Fixes 562e2f467e71 ("net: mvneta: Improve the buffer allocation method for SWBM")

Applied.

#2 lore raw
In reply to Antoine Tenart

Hi Antoine.

Good point.
Please, check and fix all cases of dma_unmap_single() usage. See mvneta_rxq_drop_pkts()
...

		if (!data || !(rx_desc->buf_phys_addr))
			continue;
		dma_unmap_single(pp->dev->dev.parent, rx_desc->buf_phys_addr,
				 MVNETA_RX_BUF_SIZE(pp->pkt_size), DMA_FROM_DEVICE);
		__free_page(data);

...

Thanks.
Yelena

-----Original Message-----
From: Antoine Tenart [mailto:[email protected]]
Sent: Wednesday, September 19, 2018 4:29 PM
To: [email protected]; Yelena Krivosheev <[email protected]>
Cc: Antoine Tenart <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Nadav Haklai <[email protected]>; Stefan Chulski <[email protected]>; Yan Markman <[email protected]>; [email protected]
Subject: [EXT] [PATCH net] net: mvneta: fix the Rx desc buffer DMA unmapping

External Email

----------------------------------------------------------------------
With CONFIG_DMA_API_DEBUG enabled we now get a warning when using the mvneta driver:

mvneta d0030000.ethernet: DMA-API: device driver frees DMA memory with wrong function [device address=0x000000001165b000] [size=4096 bytes] [mapped as page] [unmapped as single]

This is because when using the s/w buffer management, the Rx descriptor buffer is mapped with dma_map_page but unmapped with dma_unmap_single. This patch fixes this by using the right unmapping function.

Fixes 562e2f467e71 ("net: mvneta: Improve the buffer allocation method for SWBM")
---
 drivers/net/ethernet/marvell/mvneta.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/marvell/mvneta.c +2 -2
index bc80a678abc3..2db9708f2e24 100644
@@ -2008,8 +2008,8 @@ static int mvneta_rx_swbm(struct napi_struct *napi,
 				skb_add_rx_frag(rxq->skb, frag_num, page,
 						frag_offset, frag_size,
 						PAGE_SIZE);
-				dma_unmap_single(dev->dev.parent, phys_addr,
-						 PAGE_SIZE, DMA_FROM_DEVICE);
+				dma_unmap_page(dev->dev.parent, phys_addr,
+					       PAGE_SIZE, DMA_FROM_DEVICE);
 				rxq->left_size -= frag_size;
 			}
 		} else {

--
2.17.1

#3 lore raw

Hi Yelena,

Quoted 10 lines · Yelena Krivosheev

Please, check and fix all cases of dma_unmap_single() usage. See mvneta_rxq_drop_pkts()
...

		if (!data || !(rx_desc->buf_phys_addr))
			continue;
		dma_unmap_single(pp->dev->dev.parent, rx_desc->buf_phys_addr,
				 MVNETA_RX_BUF_SIZE(pp->pkt_size), DMA_FROM_DEVICE);
		__free_page(data);

...

I had a look at the one reported by CONFIG_DMA_API_DEBUG, and at DMA unmapping calls using PAGE_SIZE. As you pointed out there might be others parts, thanks!

Antoine

Signature · 3 lines
Antoine Ténart, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#4 lore raw

Hi Antoine,

Quoted 14 lines · Antoine Tenart

Hi Yelena,

Quoted 10 lines · Yelena Krivosheev

Please, check and fix all cases of dma_unmap_single() usage. See mvneta_rxq_drop_pkts()
...

		if (!data || !(rx_desc->buf_phys_addr))
			continue;
		dma_unmap_single(pp->dev->dev.parent, rx_desc->buf_phys_addr,
				 MVNETA_RX_BUF_SIZE(pp->pkt_size), DMA_FROM_DEVICE);
		__free_page(data);

...

Quoted 3 lines

I had a look at the one reported by CONFIG_DMA_API_DEBUG, and at DMA unmapping calls using PAGE_SIZE. As you pointed out there might be others parts, thanks!

Actually Jisheng had submitted a similar patch few weeks ago and as I pointed at this time, the dma_unmap in mvneta_rxq_drop_pkts can be called when the allocation is done in with HWBM in this case which use a dma_map_single.

I though that in this case using dma_map_single is the things to do even if in the SWBM case it is less optimal.

Gregory

Quoted 7 lines

Antoine

Signature · 3 lines
Antoine Ténart, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Signature · 3 lines
Gregory Clement, Bootlin
Embedded Linux and Kernel engineering
http://bootlin.com
#5 lore raw

Hi Gregory.

I want to clarify static mvneta_rxq_drop_pkts():

static void mvneta_rxq_drop_pkts(struct mvneta_port *pp,
struct mvneta_rx_queue *rxq)

{
	int rx_done, i;

	rx_done = mvneta_rxq_busy_desc_num_get(pp, rxq);
	if (rx_done)
		mvneta_rxq_desc_num_update(pp, rxq, rx_done, rx_done);

	if (pp->bm_priv) { <---------------------------- this is case for HWBM
		for (i = 0; i < rx_done; i++) {
			struct mvneta_rx_desc *rx_desc =
						  mvneta_rxq_next_desc_get(rxq);
			u8 pool_id = MVNETA_RX_GET_BM_POOL_ID(rx_desc);
			struct mvneta_bm_pool *bm_pool;

			bm_pool = &pp->bm_priv->bm_pools[pool_id];
			/* Return dropped buffer to the pool */
			mvneta_bm_pool_put_bp(pp->bm_priv, bm_pool,
					      rx_desc->buf_phys_addr);
		}
		return;
	}

<-------- this is case for SWBM only

	for (i = 0; i < rxq->size; i++) {
		struct mvneta_rx_desc *rx_desc = rxq->descs + i;
		void *data = rxq->buf_virt_addr[i];

		if (!data || !(rx_desc->buf_phys_addr))
			continue;
		dma_unmap_single(pp->dev->dev.parent, rx_desc->buf_phys_addr,
				 MVNETA_RX_BUF_SIZE(pp->pkt_size), DMA_FROM_DEVICE);
		__free_page(data);
	}
}

So I suggest to fix dma_unmap_single() call too.

Thanks.
Yelena

-----Original Message-----
From: Gregory CLEMENT [mailto:[email protected]]
Sent: Thursday, September 20, 2018 6:00 PM
To: Antoine Tenart <[email protected]>
Cc: Yelena Krivosheev <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Nadav Haklai <[email protected]>; Stefan Chulski <[email protected]>; Yan Markman <[email protected]>; [email protected]
Subject: Re: [EXT] [PATCH net] net: mvneta: fix the Rx desc buffer DMA unmapping

Hi Antoine,

Quoted 14 lines · Antoine Tenart

Hi Yelena,

Quoted 10 lines · Yelena Krivosheev

Please, check and fix all cases of dma_unmap_single() usage. See mvneta_rxq_drop_pkts()
...

		if (!data || !(rx_desc->buf_phys_addr))
			continue;
		dma_unmap_single(pp->dev->dev.parent, rx_desc->buf_phys_addr,
				 MVNETA_RX_BUF_SIZE(pp->pkt_size), DMA_FROM_DEVICE);
		__free_page(data);

...

Quoted 3 lines

I had a look at the one reported by CONFIG_DMA_API_DEBUG, and at DMA unmapping calls using PAGE_SIZE. As you pointed out there might be others parts, thanks!

Actually Jisheng had submitted a similar patch few weeks ago and as I pointed at this time, the dma_unmap in mvneta_rxq_drop_pkts can be called when the allocation is done in with HWBM in this case which use a dma_map_single.

I though that in this case using dma_map_single is the things to do even if in the SWBM case it is less optimal.

Gregory

Quoted 7 lines

Antoine

--
Antoine Ténart, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

--
Gregory Clement, Bootlin
Embedded Linux and Kernel engineering
http://bootlin.com