Skip to content

Commit 60f6112

Browse files
PhilipYangAgregkh
authored andcommitted
drm/amdkfd: Fix kfd process ref leaking when userptr unmapping
[ Upstream commit 58e6fc2 ] 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 <[email protected]> Reviewed-by: Harish Kasiviswanathan <[email protected]> Signed-off-by: Alex Deucher <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 842e6c4 commit 60f6112

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
@@ -2583,12 +2583,17 @@ static int update_invalid_user_pages(struct amdkfd_process_info *process_info,
25832583
* from the KFD, trigger a segmentation fault in VM debug mode.
25842584
*/
25852585
if (amdgpu_ttm_adev(bo->tbo.bdev)->debug_vm_userptr) {
2586+
struct kfd_process *p;
2587+
25862588
pr_err("Pid %d unmapped memory before destroying userptr at GPU addr 0x%llx\n",
25872589
pid_nr(process_info->pid), mem->va);
25882590

25892591
// Send GPU VM fault to user space
2590-
kfd_signal_vm_fault_event_with_userptr(kfd_lookup_process_by_pid(process_info->pid),
2591-
mem->va);
2592+
p = kfd_lookup_process_by_pid(process_info->pid);
2593+
if (p) {
2594+
kfd_signal_vm_fault_event_with_userptr(p, mem->va);
2595+
kfd_unref_process(p);
2596+
}
25922597
}
25932598

25942599
ret = 0;

0 commit comments

Comments
 (0)