AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/amdgpu: reject CS on a VM that KFD has acquired
@ 2026-11-30 21:23 Yongqiang Sun
  2026-11-30 21:41 ` sashiko-bot
  0 siblings, 1 reply; 3+ messages in thread
From: Yongqiang Sun @ 2026-11-30 21:23 UTC (permalink / raw)
  To: amd-gfx; +Cc: Yongqiang Sun

KFD's userptr and SVM notifiers stop KFD queues only. On the eviction
path they leave the GPU page tables valid, so a DRM_IOCTL_AMDGPU_CS
job on the acquired VM can keep writing through a translation after
the memory is gone. Jobs submitted before ACQUIRE_VM are already
waited for in init_kfd_vm().

Refuse later submissions with -EPERM.

Signed-off-by: Yongqiang Sun <Yongqiang.Sun@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index 71e2b83faa12b..a0f4a0e779c38 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -1147,6 +1147,16 @@ static int amdgpu_cs_vm_handling(struct amdgpu_cs_parser *p)
 	if (!amdgpu_vm_ready(vm))
 		return -EINVAL;
 
+	/*
+	 * KFD acquired this VM. Its notifiers stop KFD queues only, and for
+	 * an eviction they leave the page tables valid, so a kernel-queue job
+	 * submitted here can keep using translations after the memory is gone.
+	 * Jobs submitted before the acquire are already waited for in
+	 * init_kfd_vm().
+	 */
+	if (vm->is_compute_context)
+		return -EPERM;
+
 	r = amdgpu_vm_clear_freed(adev, vm, NULL);
 	if (r)
 		return r;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread
* [PATCH] drm/amdgpu: reject CS on a VM that KFD has acquired
@ 2026-12-01  1:19 Yongqiang Sun
  0 siblings, 0 replies; 3+ messages in thread
From: Yongqiang Sun @ 2026-12-01  1:19 UTC (permalink / raw)
  To: amd-gfx; +Cc: Yongqiang Sun

KFD's userptr and SVM notifiers stop KFD queues only. On the eviction
path they leave the GPU page tables valid, so a DRM_IOCTL_AMDGPU_CS
job on the acquired VM can keep writing through a translation after
the memory is gone. Jobs submitted before ACQUIRE_VM are already
waited for in init_kfd_vm().

Refuse later submissions with -EPERM before validating buffers,
so the rejection does not move backing store or leave the KFD VM
with stale page tables.

Signed-off-by: Yongqiang Sun <Yongqiang.Sun@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index 71e2b83faa12b..0360ed53659a5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -964,6 +964,20 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
 		}
 	}
 
+	/*
+	 * KFD acquired this VM. Its notifiers stop KFD queues only, and for
+	 * an eviction they leave the page tables valid, so a kernel-queue job
+	 * submitted here can keep using translations after the memory is gone.
+	 * Jobs submitted before the acquire are already waited for in
+	 * init_kfd_vm(). Reject before vm_validate or ttm_bo_validate moves
+	 * anything: a later failure would leave the KFD VM with new backing
+	 * store and stale page tables.
+	 */
+	if (vm->is_compute_context) {
+		r = -EPERM;
+		goto out_free_user_pages;
+	}
+
 	amdgpu_bo_list_for_each_userptr_entry(e, list) {
 		struct mm_struct *usermm;
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-01  1:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 21:23 [PATCH] drm/amdgpu: reject CS on a VM that KFD has acquired Yongqiang Sun
2026-11-30 21:41 ` sashiko-bot
  -- strict thread matches above, loose matches on Subject: below --
2026-12-01  1:19 Yongqiang Sun

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox