Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/amdkfd: fix kgd_mem memory leak when importing dmabuf

The kgd_mem memory allocated in amdgpu_amdkfd_gpuvm_import_dmabuf()
is not freed properly.

Explicitly free it in amdgpu_amdkfd_gpuvm_free_memory_of_gpu()
under condition "mem->bo->kfd_bo != mem".

Suggested-by: Felix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: Lang Yu <Lang.Yu@amd.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Lang Yu and committed by
Alex Deucher
0dc204bc 3d2af401

+8
+8
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
··· 1775 1775 { 1776 1776 struct amdkfd_process_info *process_info = mem->process_info; 1777 1777 unsigned long bo_size = mem->bo->tbo.base.size; 1778 + bool use_release_notifier = (mem->bo->kfd_bo == mem); 1778 1779 struct kfd_mem_attachment *entry, *tmp; 1779 1780 struct bo_vm_reservation_context ctx; 1780 1781 struct ttm_validate_buffer *bo_list_entry; ··· 1866 1865 * this needs to be the last call here. 1867 1866 */ 1868 1867 drm_gem_object_put(&mem->bo->tbo.base); 1868 + 1869 + /* 1870 + * For kgd_mem allocated in amdgpu_amdkfd_gpuvm_import_dmabuf(), 1871 + * explicitly free it here. 1872 + */ 1873 + if (!use_release_notifier) 1874 + kfree(mem); 1869 1875 1870 1876 return ret; 1871 1877 }