Skip to content

Commit 6c6ca71

Browse files
Al Viroalexdeucher
authored andcommitted
drm/amdgpu: fix a race in kfd_mem_export_dmabuf()
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... Reviewed-by: Felix Kuehling <[email protected]> Signed-off-by: Al Viro <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent b2d4da3 commit 6c6ca71

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <linux/pagemap.h>
2626
#include <linux/sched/mm.h>
2727
#include <linux/sched/task.h>
28-
#include <linux/fdtable.h>
2928
#include <drm/ttm/ttm_tt.h>
3029

3130
#include <drm/drm_exec.h>
@@ -818,18 +817,13 @@ static int kfd_mem_export_dmabuf(struct kgd_mem *mem)
818817
if (!mem->dmabuf) {
819818
struct amdgpu_device *bo_adev;
820819
struct dma_buf *dmabuf;
821-
int r, fd;
822820

823821
bo_adev = amdgpu_ttm_adev(mem->bo->tbo.bdev);
824-
r = drm_gem_prime_handle_to_fd(&bo_adev->ddev, bo_adev->kfd.client.file,
822+
dmabuf = drm_gem_prime_handle_to_dmabuf(&bo_adev->ddev, bo_adev->kfd.client.file,
825823
mem->gem_handle,
826824
mem->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_WRITABLE ?
827-
DRM_RDWR : 0, &fd);
828-
if (r)
829-
return r;
830-
dmabuf = dma_buf_get(fd);
831-
close_fd(fd);
832-
if (WARN_ON_ONCE(IS_ERR(dmabuf)))
825+
DRM_RDWR : 0);
826+
if (IS_ERR(dmabuf))
833827
return PTR_ERR(dmabuf);
834828
mem->dmabuf = dmabuf;
835829
}

0 commit comments

Comments
 (0)