dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Lizhi Hou <lizhi.hou@amd.com>
To: Jackie Liu <liu.yun@linux.dev>, <mamin506@gmail.com>
Cc: <dri-devel@lists.freedesktop.org>
Subject: Re: [PATCH 1/2] accel/amdxdna: fix memory leak in amdxdna_iommu_alloc() when iommu_map() fails
Date: Wed, 3 Jun 2026 09:29:12 -0700	[thread overview]
Message-ID: <9af8e500-d5ca-cc15-05b2-4a5cbf703410@amd.com> (raw)
In-Reply-To: <20260603013543.94835-1-liu.yun@linux.dev>

Hi Jackie,

Thanks for providing the patch. This is a known bug and the fix is on 
the way.

https://gitlab.freedesktop.org/drm/misc/kernel/-/commit/432fafdc9a3122a7bee5b2bfd23dcf2dc262a3d7

Lizhi

On 6/2/26 18:35, Jackie Liu wrote:
> From: Jackie Liu <liuyun01@kylinos.cn>
>
> When iommu_map() fails in amdxdna_iommu_alloc(), the code jumps to
> the 'free_iova' label which only frees the IOVA allocation. The
> physical pages allocated by __get_free_pages() are not freed, causing
> a memory leak.
>
> Add a 'free_pages' intermediate label to properly release the pages
> before freeing the IOVA, matching the cleanup order in
> amdxdna_iommu_free().
>
> Fixes: ece3e8980907 ("accel/amdxdna: Allow forcing IOVA-based DMA via module parameter")
> Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
> ---
>   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..af67e059d599 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_pages;
>   
>   	return cpu_addr;
>   
> +free_pages:
> +	free_pages((unsigned long)cpu_addr, get_order(size));
>   free_iova:
>   	__free_iova(&xdna->iovad, iova);
>   	return ERR_PTR(ret);

      parent reply	other threads:[~2026-06-03 16:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-03  1:35 [PATCH 1/2] accel/amdxdna: fix memory leak in amdxdna_iommu_alloc() when iommu_map() fails Jackie Liu
2026-06-03  1:35 ` [PATCH 2/2] accel/amdxdna: fix error code being silently swallowed in hwctx status queries Jackie Liu
2026-06-03 16:52   ` Lizhi Hou
2026-06-03 16:29 ` Lizhi Hou [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9af8e500-d5ca-cc15-05b2-4a5cbf703410@amd.com \
    --to=lizhi.hou@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=liu.yun@linux.dev \
    --cc=mamin506@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox