ntb_perf: pass correct struct device to dma_alloc_coherent
PATCH 1/1 ntb_perf: pass correct struct device to dma_alloc_coherent
From: Sanjay R Mehta <[email protected]>
Currently, ntb->dev is passed to dma_alloc_coherent and dma_free_coherent calls. The returned dma_addr_t is the CPU physical address. This works fine as long as IOMMU is disabled. But when IOMMU is enabled, we need to make sure that IOVA is returned for dma_addr_t. So the correct way to achieve this is by changing the first parameter of dma_alloc_coherent() as ntb->pdev->dev instead.
--- drivers/ntb/test/ntb_perf.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/ntb/test/ntb_perf.c +4 -3
@@ -559,7 +559,7 @@ static void perf_free_inbuf(struct perf_peer *peer)return ; (void )ntb_mw_clear_trans (peer->perf->ntb, peer->pidx, peer->gidx); -dma_free_coherent (&peer->perf->ntb->dev, peer->inbuf_size, +dma_free_coherent (&peer->perf->ntb->pdev->dev, peer->inbuf_size, peer->inbuf, peer->inbuf_xlat); peer->inbuf =NULL ; }
@@ -588,8 +588,9 @@ static int perf_setup_inbuf(struct perf_peer *peer)perf_free_inbuf (peer); - peer->inbuf =dma_alloc_coherent (&perf->ntb->dev, peer->inbuf_size, - &peer->inbuf_xlat,GFP_KERNEL ); + peer->inbuf =dma_alloc_coherent (&perf->ntb->pdev->dev, + peer->inbuf_size, &peer->inbuf_xlat, +GFP_KERNEL );if (!peer->inbuf) {dev_err (&perf->ntb->dev,"Failed to alloc inbuf of %pa\n" , &peer->inbuf_size);
Signature · 1 line
2.7.4
Quoted 11 lines · Sanjay R Mehta
From: Sanjay R Mehta <[email protected]>
Currently,
ntb->devis passed todma_alloc_coherentanddma_free_coherentcalls. The returneddma_addr_tis the CPU physical address. This works fine as long as IOMMU is disabled. But when IOMMU is enabled, we need to make sure that IOVA is returned fordma_addr_t. So the correct way to achieve this is by changing the first parameter ofdma_alloc_coherent()asntb->pdev->devinstead.
Quoted 2 lines
Fixes 5648e56 ("NTB: ntb_perf: Add full multi-port NTB API support")Signed-off-by Sanjay R Mehta <[email protected]>
Yes, I did the same thing as one of the patches in my fix-up series that never got merged. See [1].
Hopefully you can make better progress than I did.
While you're at it I think it's worth doing the same thing in ntb_tool as well as removing the dma_coerce_mask_and_coherent() calls that are in the NTB drivers which are meaningless once we get back to using the correct DMA device.
Thanks,
Logan
[1] https://lore.kernel.org/lkml/[email protected]/
Quoted 30 lines
--- drivers/ntb/test/ntb_perf.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/ntb/test/ntb_perf.c +4
-3@@ -559,7 +559,7 @@ static void perf_free_inbuf(struct perf_peer *peer)return ; (void )ntb_mw_clear_trans (peer->perf->ntb, peer->pidx, peer->gidx); -dma_free_coherent (&peer->perf->ntb->dev, peer->inbuf_size, +dma_free_coherent (&peer->perf->ntb->pdev->dev, peer->inbuf_size, peer->inbuf, peer->inbuf_xlat); peer->inbuf =NULL ; }@@ -588,8 +588,9 @@ static int perf_setup_inbuf(struct perf_peer *peer)perf_free_inbuf (peer); - peer->inbuf =dma_alloc_coherent (&perf->ntb->dev, peer->inbuf_size, - &peer->inbuf_xlat,GFP_KERNEL ); + peer->inbuf =dma_alloc_coherent (&perf->ntb->pdev->dev, + peer->inbuf_size, &peer->inbuf_xlat, +GFP_KERNEL );if (!peer->inbuf) {dev_err (&perf->ntb->dev,"Failed to alloc inbuf of %pa\n" , &peer->inbuf_size);
Quoted 19 lines · Logan Gunthorpe
[CAUTION: External Email]
Quoted 11 lines · Sanjay R Mehta
From: Sanjay R Mehta <[email protected]>
Currently,
ntb->devis passed todma_alloc_coherentanddma_free_coherentcalls. The returneddma_addr_tis the CPU physical address. This works fine as long as IOMMU is disabled. But when IOMMU is enabled, we need to make sure that IOVA is returned fordma_addr_t. So the correct way to achieve this is by changing the first parameter ofdma_alloc_coherent()asntb->pdev->devinstead.Quoted 2 lines
Fixes 5648e56 ("NTB: ntb_perf: Add full multi-port NTB API support")Signed-off-by Sanjay R Mehta <[email protected]>Yes, I did the same thing as one of the patches in my fix-up series that never got merged. See [1].
Quoted 6 lines
Hopefully you can make better progress than I did.
While you're at it I think it's worth doing the same thing in
ntb_toolas well as removing thedma_coerce_mask_and_coherent()calls that are in the NTB drivers which are meaningless once we get back to using the correct DMA device.
Yes, What you said make sense. I will address your comment in the next version of patch, but I will break them down into two separate patches.
Quoted 37 lines
Thanks,
Logan
Quoted 30 lines
--- drivers/ntb/test/ntb_perf.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/ntb/test/ntb_perf.c +4
-3@@ -559,7 +559,7 @@ static void perf_free_inbuf(struct perf_peer *peer)return ; (void )ntb_mw_clear_trans (peer->perf->ntb, peer->pidx, peer->gidx); -dma_free_coherent (&peer->perf->ntb->dev, peer->inbuf_size, +dma_free_coherent (&peer->perf->ntb->pdev->dev, peer->inbuf_size, peer->inbuf, peer->inbuf_xlat); peer->inbuf =NULL ; }@@ -588,8 +588,9 @@ static int perf_setup_inbuf(struct perf_peer *peer)perf_free_inbuf (peer); - peer->inbuf =dma_alloc_coherent (&perf->ntb->dev, peer->inbuf_size, - &peer->inbuf_xlat,GFP_KERNEL ); + peer->inbuf =dma_alloc_coherent (&perf->ntb->pdev->dev, + peer->inbuf_size, &peer->inbuf_xlat, +GFP_KERNEL );if (!peer->inbuf) {dev_err (&perf->ntb->dev,"Failed to alloc inbuf of %pa\n" , &peer->inbuf_size);