Skip to content

Commit 7150850

Browse files
srishanmalexdeucher
authored andcommitted
drm/amdgpu: Fix fence put before wait in amdgpu_amdkfd_submit_ib
amdgpu_amdkfd_submit_ib() submits a GPU job and gets a fence from amdgpu_ib_schedule(). This fence is used to wait for job completion. Currently, the code drops the fence reference using dma_fence_put() before calling dma_fence_wait(). If dma_fence_put() releases the last reference, the fence may be freed before dma_fence_wait() is called. This can lead to a use-after-free. Fix this by waiting on the fence first and releasing the reference only after dma_fence_wait() completes. Fixes the below: drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c:697 amdgpu_amdkfd_submit_ib() warn: passing freed memory 'f' (line 696) Fixes: 9ae55f0 ("drm/amdgpu: Follow up change to previous drm scheduler change.") Cc: Felix Kuehling <Felix.Kuehling@amd.com> Cc: Dan Carpenter <dan.carpenter@linaro.org> Cc: Christian König <christian.koenig@amd.com> Cc: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com> Reviewed-by: Christian König <christian.koenig@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> (cherry picked from commit 8b9e525)
1 parent 3e6dd28 commit 7150850

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,9 +692,9 @@ int amdgpu_amdkfd_submit_ib(struct amdgpu_device *adev,
692692
goto err_ib_sched;
693693
}
694694

695-
/* Drop the initial kref_init count (see drm_sched_main as example) */
696-
dma_fence_put(f);
697695
ret = dma_fence_wait(f, false);
696+
/* Drop the returned fence reference after the wait completes */
697+
dma_fence_put(f);
698698

699699
err_ib_sched:
700700
amdgpu_job_free(job);

0 commit comments

Comments
 (0)