From: Felix Kuehling <felix.kuehling@amd.com>
To: "Rafael Mendonca" <rafaelmendsr@gmail.com>,
"Alex Deucher" <alexander.deucher@amd.com>,
"Christian König" <christian.koenig@amd.com>,
"Pan, Xinhui" <Xinhui.Pan@amd.com>,
"David Airlie" <airlied@gmail.com>,
"Daniel Vetter" <daniel@ffwll.ch>,
"Ramesh Errabolu" <Ramesh.Errabolu@amd.com>,
"Oak Zeng" <Oak.Zeng@amd.com>
Cc: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] drm/amdkfd: Fix memory leak in kfd_mem_dmamap_userptr()
Date: Wed, 19 Oct 2022 15:24:20 -0400 [thread overview]
Message-ID: <ad11c2f2-abe9-5483-addd-15b0c1328fab@amd.com> (raw)
In-Reply-To: <20221018012751.887460-1-rafaelmendsr@gmail.com>
On 2022-10-17 21:27, Rafael Mendonca wrote:
> If the number of pages from the userptr BO differs from the SG BO then the
> allocated memory for the SG table doesn't get freed before returning
> -EINVAL, which may lead to a memory leak in some error paths. Fix this by
> checking the number of pages before allocating memory for the SG table.
>
> Fixes: 264fb4d332f5 ("drm/amdgpu: Add multi-GPU DMA mapping helpers")
> Signed-off-by: Rafael Mendonca <rafaelmendsr@gmail.com>
Thank you for catching this. The patch is
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
I submitted it to our amd-staging-drm-next branch.
Regards,
Felix
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> index 978d3970b5cc..84f44f7e4111 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> @@ -510,13 +510,13 @@ kfd_mem_dmamap_userptr(struct kgd_mem *mem,
> struct ttm_tt *ttm = bo->tbo.ttm;
> int ret;
>
> + if (WARN_ON(ttm->num_pages != src_ttm->num_pages))
> + return -EINVAL;
> +
> ttm->sg = kmalloc(sizeof(*ttm->sg), GFP_KERNEL);
> if (unlikely(!ttm->sg))
> return -ENOMEM;
>
> - if (WARN_ON(ttm->num_pages != src_ttm->num_pages))
> - return -EINVAL;
> -
> /* Same sequence as in amdgpu_ttm_tt_pin_userptr */
> ret = sg_alloc_table_from_pages(ttm->sg, src_ttm->pages,
> ttm->num_pages, 0,
prev parent reply other threads:[~2022-10-19 19:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-18 1:27 [PATCH] drm/amdkfd: Fix memory leak in kfd_mem_dmamap_userptr() Rafael Mendonca
2022-10-19 19:24 ` Felix Kuehling [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=ad11c2f2-abe9-5483-addd-15b0c1328fab@amd.com \
--to=felix.kuehling@amd.com \
--cc=Oak.Zeng@amd.com \
--cc=Ramesh.Errabolu@amd.com \
--cc=Xinhui.Pan@amd.com \
--cc=airlied@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafaelmendsr@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;
as well as URLs for NNTP newsgroup(s).