[PATCH] amd/amdkfd: Trigger segfault for early userptr unmmapping

Shane Xiao shane.xiao at amd.com
Wed Apr 23 09:50:36 UTC 2025


If applications unmap the memory before destroying the userptr, it needs
trigger a segfault to notify user space to correct the free sequence in
VM debug mode.

Signed-off-by: Shane Xiao <shane.xiao at amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index d2ec4130a316..259b38424b7f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -2559,6 +2559,16 @@ static int update_invalid_user_pages(struct amdkfd_process_info *process_info,
 			if (ret != -EFAULT)
 				return ret;
 
+			/* If applications unmaps memory before destroying the userptr
+			 * from the KFD, trigger a segmentation fault in VM debug mode.
+			 */
+			if (amdgpu_ttm_adev(bo->tbo.bdev)->debug_vm) {
+				amdgpu_ttm_tt_get_userptr(&bo->tbo, userptr);
+				pr_err("User space unmap memory before destroying a userptr that refers to it\n");
+				pr_err("The unmap userptr address is 0x%llx\n", userptr);
+				send_sig(SIGSEGV, get_pid_task(process_info->pid, PIDTYPE_PID), 0);
+			}
+
 			ret = 0;
 		}
 
-- 
2.25.1



More information about the amd-gfx mailing list