Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
* [PATCH] Fix dma_unmap_sg() nents value
@ 2025-06-30  9:23 Thomas Fourier
  2025-07-01 10:48 ` Leon Romanovsky
  2025-07-02  9:24 ` Cheng Xu
  0 siblings, 2 replies; 3+ messages in thread
From: Thomas Fourier @ 2025-06-30  9:23 UTC (permalink / raw)
  Cc: Thomas Fourier, Cheng Xu, Kai Shen, Jason Gunthorpe,
	Leon Romanovsky, linux-rdma, linux-kernel

The dma_unmap_sg() functions should be called with the same nents as the
dma_map_sg(), not the value the map function returned.

Fixes: ed10435d3583 ("RDMA/erdma: Implement hierarchical MTT")
Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com>
---
 drivers/infiniband/hw/erdma/erdma_verbs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/infiniband/hw/erdma/erdma_verbs.c b/drivers/infiniband/hw/erdma/erdma_verbs.c
index af36a8d2df22..ec0ad4086066 100644
--- a/drivers/infiniband/hw/erdma/erdma_verbs.c
+++ b/drivers/infiniband/hw/erdma/erdma_verbs.c
@@ -629,7 +629,8 @@ static struct erdma_mtt *erdma_create_cont_mtt(struct erdma_dev *dev,
 static void erdma_destroy_mtt_buf_sg(struct erdma_dev *dev,
 				     struct erdma_mtt *mtt)
 {
-	dma_unmap_sg(&dev->pdev->dev, mtt->sglist, mtt->nsg, DMA_TO_DEVICE);
+	dma_unmap_sg(&dev->pdev->dev, mtt->sglist,
+		     DIV_ROUND_UP(mtt->size, PAGE_SIZE), DMA_TO_DEVICE);
 	vfree(mtt->sglist);
 }
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix dma_unmap_sg() nents value
  2025-06-30  9:23 [PATCH] Fix dma_unmap_sg() nents value Thomas Fourier
@ 2025-07-01 10:48 ` Leon Romanovsky
  2025-07-02  9:24 ` Cheng Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Leon Romanovsky @ 2025-07-01 10:48 UTC (permalink / raw)
  To: Thomas Fourier
  Cc: Cheng Xu, Kai Shen, Jason Gunthorpe, linux-rdma, linux-kernel


On Mon, 30 Jun 2025 11:23:46 +0200, Thomas Fourier wrote:
> The dma_unmap_sg() functions should be called with the same nents as the
> dma_map_sg(), not the value the map function returned.
> 
> 

Applied, thanks!

[1/1] Fix dma_unmap_sg() nents value
      https://git.kernel.org/rdma/rdma/c/4d67f2ac89a892

Best regards,
-- 
Leon Romanovsky <leon@kernel.org>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix dma_unmap_sg() nents value
  2025-06-30  9:23 [PATCH] Fix dma_unmap_sg() nents value Thomas Fourier
  2025-07-01 10:48 ` Leon Romanovsky
@ 2025-07-02  9:24 ` Cheng Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Cheng Xu @ 2025-07-02  9:24 UTC (permalink / raw)
  To: Thomas Fourier
  Cc: Kai Shen, Jason Gunthorpe, Leon Romanovsky, linux-rdma,
	linux-kernel



On 6/30/25 5:23 PM, Thomas Fourier wrote:
> The dma_unmap_sg() functions should be called with the same nents as the
> dma_map_sg(), not the value the map function returned.
> 
> Fixes: ed10435d3583 ("RDMA/erdma: Implement hierarchical MTT")
> Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com>
> ---
>  drivers/infiniband/hw/erdma/erdma_verbs.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 

Hi Thomas,

This patch is already accepted by Leon, and a late thanks to you.

Cheng Xu


> diff --git a/drivers/infiniband/hw/erdma/erdma_verbs.c b/drivers/infiniband/hw/erdma/erdma_verbs.c
> index af36a8d2df22..ec0ad4086066 100644
> --- a/drivers/infiniband/hw/erdma/erdma_verbs.c
> +++ b/drivers/infiniband/hw/erdma/erdma_verbs.c
> @@ -629,7 +629,8 @@ static struct erdma_mtt *erdma_create_cont_mtt(struct erdma_dev *dev,
>  static void erdma_destroy_mtt_buf_sg(struct erdma_dev *dev,
>  				     struct erdma_mtt *mtt)
>  {
> -	dma_unmap_sg(&dev->pdev->dev, mtt->sglist, mtt->nsg, DMA_TO_DEVICE);
> +	dma_unmap_sg(&dev->pdev->dev, mtt->sglist,
> +		     DIV_ROUND_UP(mtt->size, PAGE_SIZE), DMA_TO_DEVICE);
>  	vfree(mtt->sglist);
>  }
>  

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-07-02  9:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-30  9:23 [PATCH] Fix dma_unmap_sg() nents value Thomas Fourier
2025-07-01 10:48 ` Leon Romanovsky
2025-07-02  9:24 ` Cheng Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox