Skip to content

Commit 6b61a54

Browse files
hkasivisalexdeucher
authored andcommitted
drm/amdgpu: Fix double deletion of validate_list
If amdgpu_amdkfd_gpuvm_free_memory_of_gpu() fails after kgd_mem is removed from validate_list, the mem handle still lingers in the KFD idr. This means when process is terminated, kfd_process_free_outstanding_kfd_bos() will call amdgpu_amdkfd_gpuvm_free_memory_of_gpu() again resulting in double deletion. To avoid this - (a) Check if list is empty before deleting it (b) Rearragne amdgpu_amdkfd_gpuvm_free_memory_of_gpu() such that it can be safely called again if it returns failure the first time. Signed-off-by: Harish Kasiviswanathan <[email protected]> Reviewed-by: Philip Yang <[email protected]> Signed-off-by: Alex Deucher <[email protected]> (cherry picked from commit 6ba6034)
1 parent 8496244 commit 6b61a54

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,21 +1920,21 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(
19201920

19211921
/* Make sure restore workers don't access the BO any more */
19221922
mutex_lock(&process_info->lock);
1923-
list_del(&mem->validate_list);
1923+
if (!list_empty(&mem->validate_list))
1924+
list_del_init(&mem->validate_list);
19241925
mutex_unlock(&process_info->lock);
19251926

1927+
ret = reserve_bo_and_cond_vms(mem, NULL, BO_VM_ALL, &ctx);
1928+
if (unlikely(ret))
1929+
return ret;
1930+
19261931
/* Cleanup user pages and MMU notifiers */
19271932
if (amdgpu_ttm_tt_get_usermm(mem->bo->tbo.ttm)) {
19281933
amdgpu_hmm_unregister(mem->bo);
1929-
mutex_lock(&process_info->notifier_lock);
19301934
amdgpu_hmm_range_free(mem->range);
1931-
mutex_unlock(&process_info->notifier_lock);
1935+
mem->range = NULL;
19321936
}
19331937

1934-
ret = reserve_bo_and_cond_vms(mem, NULL, BO_VM_ALL, &ctx);
1935-
if (unlikely(ret))
1936-
return ret;
1937-
19381938
amdgpu_amdkfd_remove_eviction_fence(mem->bo,
19391939
process_info->eviction_fence);
19401940
pr_debug("Release VA 0x%llx - 0x%llx\n", mem->va,

0 commit comments

Comments
 (0)