public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] accel/amdxdna: Fix memory leak in amdxdna_iommu_alloc()
@ 2026-04-16 13:37 Felix Gu
  2026-04-16 15:24 ` Lizhi Hou
  2026-04-16 15:58 ` Lizhi Hou
  0 siblings, 2 replies; 3+ messages in thread
From: Felix Gu @ 2026-04-16 13:37 UTC (permalink / raw)
  To: Min Ma, Lizhi Hou, Oded Gabbay, Mario Limonciello (AMD)
  Cc: dri-devel, linux-kernel, Felix Gu

In amdxdna_iommu_alloc(), if iommu_map() fails after successfully
allocating both iova and cpu_addr, the code jumps to free_iova
which only frees the iova, leaking the allocated pages.

Fixes: ece3e8980907 ("accel/amdxdna: Allow forcing IOVA-based DMA via module parameter")
Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
 drivers/accel/amdxdna/amdxdna_iommu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/accel/amdxdna/amdxdna_iommu.c b/drivers/accel/amdxdna/amdxdna_iommu.c
index 4626434d4180..a2e8d8ac0901 100644
--- a/drivers/accel/amdxdna/amdxdna_iommu.c
+++ b/drivers/accel/amdxdna/amdxdna_iommu.c
@@ -110,10 +110,12 @@ void *amdxdna_iommu_alloc(struct amdxdna_dev *xdna, size_t size, dma_addr_t *dma
 			iova_align(&xdna->iovad, size),
 			IOMMU_READ | IOMMU_WRITE, GFP_KERNEL);
 	if (ret)
-		goto free_iova;
+		goto free_cpu_addr;
 
 	return cpu_addr;
 
+free_cpu_addr:
+	free_pages((unsigned long)cpu_addr, get_order(size));
 free_iova:
 	__free_iova(&xdna->iovad, iova);
 	return ERR_PTR(ret);

---
base-commit: 936c21068d7ade00325e40d82bfd2f3f29d9f659
change-id: 20260416-amdxdna-f46d045130aa

Best regards,
-- 
Felix Gu <ustc.gu@gmail.com>


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

* Re: [PATCH] accel/amdxdna: Fix memory leak in amdxdna_iommu_alloc()
  2026-04-16 13:37 [PATCH] accel/amdxdna: Fix memory leak in amdxdna_iommu_alloc() Felix Gu
@ 2026-04-16 15:24 ` Lizhi Hou
  2026-04-16 15:58 ` Lizhi Hou
  1 sibling, 0 replies; 3+ messages in thread
From: Lizhi Hou @ 2026-04-16 15:24 UTC (permalink / raw)
  To: Felix Gu, Min Ma, Oded Gabbay, Mario Limonciello (AMD)
  Cc: dri-devel, linux-kernel


On 4/16/26 06:37, Felix Gu wrote:
> In amdxdna_iommu_alloc(), if iommu_map() fails after successfully
> allocating both iova and cpu_addr, the code jumps to free_iova
> which only frees the iova, leaking the allocated pages.
>
> Fixes: ece3e8980907 ("accel/amdxdna: Allow forcing IOVA-based DMA via module parameter")
> Signed-off-by: Felix Gu <ustc.gu@gmail.com>
> ---
>   drivers/accel/amdxdna/amdxdna_iommu.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/accel/amdxdna/amdxdna_iommu.c b/drivers/accel/amdxdna/amdxdna_iommu.c
> index 4626434d4180..a2e8d8ac0901 100644
> --- a/drivers/accel/amdxdna/amdxdna_iommu.c
> +++ b/drivers/accel/amdxdna/amdxdna_iommu.c
> @@ -110,10 +110,12 @@ void *amdxdna_iommu_alloc(struct amdxdna_dev *xdna, size_t size, dma_addr_t *dma
>                          iova_align(&xdna->iovad, size),
>                          IOMMU_READ | IOMMU_WRITE, GFP_KERNEL);
>          if (ret)
> -               goto free_iova;
> +               goto free_cpu_addr;
>
>          return cpu_addr;
>
> +free_cpu_addr:
> +       free_pages((unsigned long)cpu_addr, get_order(size));
Reviewed-by: Lizhi Hou <lizhi.hou@amd.com>
>   free_iova:
>          __free_iova(&xdna->iovad, iova);
>          return ERR_PTR(ret);
>
> ---
> base-commit: 936c21068d7ade00325e40d82bfd2f3f29d9f659
> change-id: 20260416-amdxdna-f46d045130aa
>
> Best regards,
> --
> Felix Gu <ustc.gu@gmail.com>
>

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

* Re: [PATCH] accel/amdxdna: Fix memory leak in amdxdna_iommu_alloc()
  2026-04-16 13:37 [PATCH] accel/amdxdna: Fix memory leak in amdxdna_iommu_alloc() Felix Gu
  2026-04-16 15:24 ` Lizhi Hou
@ 2026-04-16 15:58 ` Lizhi Hou
  1 sibling, 0 replies; 3+ messages in thread
From: Lizhi Hou @ 2026-04-16 15:58 UTC (permalink / raw)
  To: Felix Gu, Min Ma, Oded Gabbay, Mario Limonciello (AMD)
  Cc: dri-devel, linux-kernel

Applied to drm-misc-next

On 4/16/26 06:37, Felix Gu wrote:
> [You don't often get email from ustc.gu@gmail.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> In amdxdna_iommu_alloc(), if iommu_map() fails after successfully
> allocating both iova and cpu_addr, the code jumps to free_iova
> which only frees the iova, leaking the allocated pages.
>
> Fixes: ece3e8980907 ("accel/amdxdna: Allow forcing IOVA-based DMA via module parameter")
> Signed-off-by: Felix Gu <ustc.gu@gmail.com>
> ---
>   drivers/accel/amdxdna/amdxdna_iommu.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/accel/amdxdna/amdxdna_iommu.c b/drivers/accel/amdxdna/amdxdna_iommu.c
> index 4626434d4180..a2e8d8ac0901 100644
> --- a/drivers/accel/amdxdna/amdxdna_iommu.c
> +++ b/drivers/accel/amdxdna/amdxdna_iommu.c
> @@ -110,10 +110,12 @@ void *amdxdna_iommu_alloc(struct amdxdna_dev *xdna, size_t size, dma_addr_t *dma
>                          iova_align(&xdna->iovad, size),
>                          IOMMU_READ | IOMMU_WRITE, GFP_KERNEL);
>          if (ret)
> -               goto free_iova;
> +               goto free_cpu_addr;
>
>          return cpu_addr;
>
> +free_cpu_addr:
> +       free_pages((unsigned long)cpu_addr, get_order(size));
>   free_iova:
>          __free_iova(&xdna->iovad, iova);
>          return ERR_PTR(ret);
>
> ---
> base-commit: 936c21068d7ade00325e40d82bfd2f3f29d9f659
> change-id: 20260416-amdxdna-f46d045130aa
>
> Best regards,
> --
> Felix Gu <ustc.gu@gmail.com>
>

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

end of thread, other threads:[~2026-04-16 15:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-16 13:37 [PATCH] accel/amdxdna: Fix memory leak in amdxdna_iommu_alloc() Felix Gu
2026-04-16 15:24 ` Lizhi Hou
2026-04-16 15:58 ` Lizhi Hou

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