From: Felix Kuehling <felix.kuehling@amd.com>
To: xinhui pan <xinhui.pan@amd.com>, amd-gfx@lists.freedesktop.org
Cc: alexander.deucher@amd.com, christian.koenig@amd.com
Subject: Re: [PATCH] drm/amdgpu: Fix double free of dmabuf
Date: Fri, 19 Nov 2021 18:22:24 -0500 [thread overview]
Message-ID: <37c9343b-6865-b63d-c674-b8ad602bd44d@amd.com> (raw)
In-Reply-To: <20211119101725.66619-1-xinhui.pan@amd.com>
On 2021-11-19 5:17 a.m., xinhui pan wrote:
> amdgpu_amdkfd_gpuvm_free_memory_of_gpu drop dmabuf reference increased in
> amdgpu_gem_prime_export.
> amdgpu_bo_destroy drop dmabuf reference increased in
> amdgpu_gem_prime_import.
OK. This was not obvious at all. The get_dma_buf in
amdgpu_gem_prime_import could use a comment that it's balanced by the
dma_buf_put in drm_prime_gem_destroy, which gets called from
amdgpu_bo_destroy for any bo that has a bo->tbo.base.import_attach.
I confirmed the bug and tested the fix by running the following test on
a 2-GPU system
HSA_USERPTR_FOR_PAGED_MEM=0 run_kfdtest.sh
--gtest_filter=KFDMemoryTest.MMBench
>
> So remove this extra dma_buf_put to avoid double free.
>
> Signed-off-by: xinhui pan <xinhui.pan@amd.com>
Tested-by: Felix Kuehling <Felix.Kuehling@amd.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 6 ------
> 1 file changed, 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> index 6c6d5d994b5d..0f68d28e002e 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> @@ -665,12 +665,6 @@ kfd_mem_attach_dmabuf(struct amdgpu_device *adev, struct kgd_mem *mem,
> if (IS_ERR(gobj))
> return PTR_ERR(gobj);
>
> - /* Import takes an extra reference on the dmabuf. Drop it now to
> - * avoid leaking it. We only need the one reference in
> - * kgd_mem->dmabuf.
> - */
> - dma_buf_put(mem->dmabuf);
> -
> *bo = gem_to_amdgpu_bo(gobj);
> (*bo)->flags |= AMDGPU_GEM_CREATE_PREEMPTIBLE;
> (*bo)->parent = amdgpu_bo_ref(mem->bo);
prev parent reply other threads:[~2021-11-19 23:22 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-19 10:17 [PATCH] drm/amdgpu: Fix double free of dmabuf xinhui pan
2021-11-19 10:52 ` Christian König
2021-11-19 16:16 ` Felix Kuehling
2021-11-19 23:22 ` 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=37c9343b-6865-b63d-c674-b8ad602bd44d@amd.com \
--to=felix.kuehling@amd.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=xinhui.pan@amd.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