From: Al Viro <viro@zeniv.linux.org.uk>
To: viro@zeniv.linux.org.uk
Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-fsdevel@vger.kernel.org
Subject: [PATCH 2/4] amdgpu: fix a race in kfd_mem_export_dmabuf()
Date: Mon, 12 Aug 2024 07:59:04 +0100 [thread overview]
Message-ID: <20240812065906.241398-2-viro@zeniv.linux.org.uk> (raw)
In-Reply-To: <20240812065906.241398-1-viro@zeniv.linux.org.uk>
Using drm_gem_prime_handle_to_fd() to set dmabuf up and insert it into
descriptor table, only to have it looked up by file descriptor and
remove it from descriptor table is not just too convoluted - it's
racy; another thread might have modified the descriptor table while
we'd been going through that song and dance.
Switch kfd_mem_export_dmabuf() to using drm_gem_prime_handle_to_dmabuf()
and leave the descriptor table alone...
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 11672bfe4fad..bc5401de2948 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -25,7 +25,6 @@
#include <linux/pagemap.h>
#include <linux/sched/mm.h>
#include <linux/sched/task.h>
-#include <linux/fdtable.h>
#include <drm/ttm/ttm_tt.h>
#include <drm/drm_exec.h>
@@ -818,18 +817,13 @@ static int kfd_mem_export_dmabuf(struct kgd_mem *mem)
if (!mem->dmabuf) {
struct amdgpu_device *bo_adev;
struct dma_buf *dmabuf;
- int r, fd;
bo_adev = amdgpu_ttm_adev(mem->bo->tbo.bdev);
- r = drm_gem_prime_handle_to_fd(&bo_adev->ddev, bo_adev->kfd.client.file,
+ dmabuf = drm_gem_prime_handle_to_dmabuf(&bo_adev->ddev, bo_adev->kfd.client.file,
mem->gem_handle,
mem->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_WRITABLE ?
- DRM_RDWR : 0, &fd);
- if (r)
- return r;
- dmabuf = dma_buf_get(fd);
- close_fd(fd);
- if (WARN_ON_ONCE(IS_ERR(dmabuf)))
+ DRM_RDWR : 0);
+ if (IS_ERR(dmabuf))
return PTR_ERR(dmabuf);
mem->dmabuf = dmabuf;
}
--
2.39.2
next prev parent reply other threads:[~2024-08-12 7:31 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-12 6:56 [PATCHES] [drm] file descriptor fixes Al Viro
2024-08-12 6:59 ` [PATCH 1/4] new helper: drm_gem_prime_handle_to_dmabuf() Al Viro
2024-08-12 6:59 ` Al Viro [this message]
2024-08-14 22:15 ` [PATCH 2/4] amdgpu: fix a race in kfd_mem_export_dmabuf() Felix Kuehling
2024-08-22 0:29 ` Al Viro
2024-08-22 18:02 ` Alex Deucher
2024-08-12 6:59 ` [PATCH 3/4] amdkfd CRIU fixes Al Viro
2024-08-12 6:59 ` [PATCH 4/4] amdgpu: get rid of bogus includes of fdtable.h Al Viro
2024-08-22 14:41 ` [PATCH 1/4] new helper: drm_gem_prime_handle_to_dmabuf() Thomas Zimmermann
2024-08-22 15:20 ` Al Viro
2024-08-23 1:57 ` Al Viro
2024-08-23 7:21 ` Thomas Zimmermann
2024-08-23 7:53 ` Al Viro
2024-09-10 16:36 ` Alex Deucher
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=20240812065906.241398-2-viro@zeniv.linux.org.uk \
--to=viro@zeniv.linux.org.uk \
--cc=amd-gfx@lists.freedesktop.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-fsdevel@vger.kernel.org \
/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