Skip to content

Commit 58e6fc2

Browse files
PhilipYangAalexdeucher
authored andcommitted
drm/amdkfd: Fix kfd process ref leaking when userptr unmapping
kfd_lookup_process_by_pid hold the kfd process reference to ensure it doesn't get destroyed while sending the segfault event to user space. Calling kfd_lookup_process_by_pid as function parameter leaks the kfd process refcount and miss the NULL pointer check if app process is already destroyed. Fixes: 2d274bf ("amd/amdkfd: Trigger segfault for early userptr unmmapping") Signed-off-by: Philip Yang <Philip.Yang@amd.com> Reviewed-by: Harish Kasiviswanathan <Harish.Kasiviswanathan@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent 0c67342 commit 58e6fc2

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2586,12 +2586,17 @@ static int update_invalid_user_pages(struct amdkfd_process_info *process_info,
25862586
* from the KFD, trigger a segmentation fault in VM debug mode.
25872587
*/
25882588
if (amdgpu_ttm_adev(bo->tbo.bdev)->debug_vm_userptr) {
2589+
struct kfd_process *p;
2590+
25892591
pr_err("Pid %d unmapped memory before destroying userptr at GPU addr 0x%llx\n",
25902592
pid_nr(process_info->pid), mem->va);
25912593

25922594
// Send GPU VM fault to user space
2593-
kfd_signal_vm_fault_event_with_userptr(kfd_lookup_process_by_pid(process_info->pid),
2594-
mem->va);
2595+
p = kfd_lookup_process_by_pid(process_info->pid);
2596+
if (p) {
2597+
kfd_signal_vm_fault_event_with_userptr(p, mem->va);
2598+
kfd_unref_process(p);
2599+
}
25952600
}
25962601

25972602
ret = 0;

0 commit comments

Comments
 (0)