* [PATCH net] net: mvneta: fix the Rx desc buffer DMA unmapping
@ 2018-09-19 13:29 Antoine Tenart
2018-09-20 4:25 ` David Miller
2018-09-20 10:14 ` [EXT] " Yelena Krivosheev
0 siblings, 2 replies; 6+ messages in thread
From: Antoine Tenart @ 2018-09-19 13:29 UTC (permalink / raw)
To: davem, yelena
Cc: Antoine Tenart, netdev, linux-kernel, thomas.petazzoni,
maxime.chevallier, gregory.clement, miquel.raynal, nadavh,
stefanc, ymarkman, mw
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")
Signed-off-by: Antoine Tenart <antoine.tenart@bootlin.com>
---
drivers/net/ethernet/marvell/mvneta.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/marvell/mvneta.c b/drivers/net/ethernet/marvell/mvneta.c
index bc80a678abc3..2db9708f2e24 100644
--- a/drivers/net/ethernet/marvell/mvneta.c
+++ b/drivers/net/ethernet/marvell/mvneta.c
@@ -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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net] net: mvneta: fix the Rx desc buffer DMA unmapping
2018-09-19 13:29 [PATCH net] net: mvneta: fix the Rx desc buffer DMA unmapping Antoine Tenart
@ 2018-09-20 4:25 ` David Miller
2018-09-20 10:14 ` [EXT] " Yelena Krivosheev
1 sibling, 0 replies; 6+ messages in thread
From: David Miller @ 2018-09-20 4:25 UTC (permalink / raw)
To: antoine.tenart
Cc: yelena, netdev, linux-kernel, thomas.petazzoni,
maxime.chevallier, gregory.clement, miquel.raynal, nadavh,
stefanc, ymarkman, mw
From: Antoine Tenart <antoine.tenart@bootlin.com>
Date: Wed, 19 Sep 2018 15:29:06 +0200
> 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")
> Signed-off-by: Antoine Tenart <antoine.tenart@bootlin.com>
Applied.
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [EXT] [PATCH net] net: mvneta: fix the Rx desc buffer DMA unmapping
2018-09-19 13:29 [PATCH net] net: mvneta: fix the Rx desc buffer DMA unmapping Antoine Tenart
2018-09-20 4:25 ` David Miller
@ 2018-09-20 10:14 ` Yelena Krivosheev
2018-09-20 11:20 ` Antoine Tenart
1 sibling, 1 reply; 6+ messages in thread
From: Yelena Krivosheev @ 2018-09-20 10:14 UTC (permalink / raw)
To: Antoine Tenart, davem
Cc: netdev, linux-kernel, thomas.petazzoni, maxime.chevallier,
gregory.clement, miquel.raynal, Nadav Haklai, Stefan Chulski,
Yan Markman, mw
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:antoine.tenart@bootlin.com]
Sent: Wednesday, September 19, 2018 4:29 PM
To: davem@davemloft.net; Yelena Krivosheev <yelena@marvell.com>
Cc: Antoine Tenart <antoine.tenart@bootlin.com>; netdev@vger.kernel.org; linux-kernel@vger.kernel.org; thomas.petazzoni@bootlin.com; maxime.chevallier@bootlin.com; gregory.clement@bootlin.com; miquel.raynal@bootlin.com; Nadav Haklai <nadavh@marvell.com>; Stefan Chulski <stefanc@marvell.com>; Yan Markman <ymarkman@marvell.com>; mw@semihalf.com
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")
Signed-off-by: Antoine Tenart <antoine.tenart@bootlin.com>
---
drivers/net/ethernet/marvell/mvneta.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/marvell/mvneta.c b/drivers/net/ethernet/marvell/mvneta.c
index bc80a678abc3..2db9708f2e24 100644
--- a/drivers/net/ethernet/marvell/mvneta.c
+++ b/drivers/net/ethernet/marvell/mvneta.c
@@ -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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [EXT] [PATCH net] net: mvneta: fix the Rx desc buffer DMA unmapping
2018-09-20 10:14 ` [EXT] " Yelena Krivosheev
@ 2018-09-20 11:20 ` Antoine Tenart
2018-09-20 14:59 ` Gregory CLEMENT
0 siblings, 1 reply; 6+ messages in thread
From: Antoine Tenart @ 2018-09-20 11:20 UTC (permalink / raw)
To: Yelena Krivosheev
Cc: Antoine Tenart, davem, netdev, linux-kernel, thomas.petazzoni,
maxime.chevallier, gregory.clement, miquel.raynal, Nadav Haklai,
Stefan Chulski, Yan Markman, mw
Hi Yelena,
On Thu, Sep 20, 2018 at 10:14:56AM +0000, Yelena Krivosheev wrote:
>
> 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
--
Antoine Ténart, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [EXT] [PATCH net] net: mvneta: fix the Rx desc buffer DMA unmapping
2018-09-20 11:20 ` Antoine Tenart
@ 2018-09-20 14:59 ` Gregory CLEMENT
2018-09-22 7:07 ` Yelena Krivosheev
0 siblings, 1 reply; 6+ messages in thread
From: Gregory CLEMENT @ 2018-09-20 14:59 UTC (permalink / raw)
To: Antoine Tenart
Cc: Yelena Krivosheev, davem, netdev, linux-kernel, thomas.petazzoni,
maxime.chevallier, miquel.raynal, Nadav Haklai, Stefan Chulski,
Yan Markman, mw
Hi Antoine,
On jeu., sept. 20 2018, Antoine Tenart <antoine.tenart@bootlin.com> wrote:
> Hi Yelena,
>
> On Thu, Sep 20, 2018 at 10:14:56AM +0000, Yelena Krivosheev wrote:
>>
>> 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!
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
>
> Antoine
>
> --
> Antoine Ténart, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com
--
Gregory Clement, Bootlin
Embedded Linux and Kernel engineering
http://bootlin.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [EXT] [PATCH net] net: mvneta: fix the Rx desc buffer DMA unmapping
2018-09-20 14:59 ` Gregory CLEMENT
@ 2018-09-22 7:07 ` Yelena Krivosheev
0 siblings, 0 replies; 6+ messages in thread
From: Yelena Krivosheev @ 2018-09-22 7:07 UTC (permalink / raw)
To: Gregory CLEMENT, Antoine Tenart
Cc: davem, netdev, linux-kernel, thomas.petazzoni, maxime.chevallier,
miquel.raynal, Nadav Haklai, Stefan Chulski, Yan Markman, mw
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:gregory.clement@bootlin.com]
Sent: Thursday, September 20, 2018 6:00 PM
To: Antoine Tenart <antoine.tenart@bootlin.com>
Cc: Yelena Krivosheev <yelena@marvell.com>; davem@davemloft.net; netdev@vger.kernel.org; linux-kernel@vger.kernel.org; thomas.petazzoni@bootlin.com; maxime.chevallier@bootlin.com; miquel.raynal@bootlin.com; Nadav Haklai <nadavh@marvell.com>; Stefan Chulski <stefanc@marvell.com>; Yan Markman <ymarkman@marvell.com>; mw@semihalf.com
Subject: Re: [EXT] [PATCH net] net: mvneta: fix the Rx desc buffer DMA unmapping
Hi Antoine,
On jeu., sept. 20 2018, Antoine Tenart <antoine.tenart@bootlin.com> wrote:
> Hi Yelena,
>
> On Thu, Sep 20, 2018 at 10:14:56AM +0000, Yelena Krivosheev wrote:
>>
>> 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!
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
>
> Antoine
>
> --
> Antoine Ténart, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com
--
Gregory Clement, Bootlin
Embedded Linux and Kernel engineering
http://bootlin.com
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-09-22 7:08 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-19 13:29 [PATCH net] net: mvneta: fix the Rx desc buffer DMA unmapping Antoine Tenart
2018-09-20 4:25 ` David Miller
2018-09-20 10:14 ` [EXT] " Yelena Krivosheev
2018-09-20 11:20 ` Antoine Tenart
2018-09-20 14:59 ` Gregory CLEMENT
2018-09-22 7:07 ` Yelena Krivosheev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).