* [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
* Re: [PATCH] drm/amdgpu: reject CS on a VM that KFD has acquired
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
0 siblings, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-30 21:41 UTC (permalink / raw)
To: Yongqiang Sun, amd-gfx
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/amdgpu: late vm->is_compute_context check in
amdgpu_cs_vm_handling()
--
commit 217554c6af3d7136df0f66880e6fb5b7119d400b
Author: Yongqiang Sun <Yongqiang.Sun@amd.com>
drm/amdgpu: reject CS on a VM that KFD has acquired
This commit rejects DRM_IOCTL_AMDGPU_CS command submissions with -EPERM
in amdgpu_cs_vm_handling() when the VM has been acquired by KFD.
> 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;
[Severity: High]
Does checking vm->is_compute_context in amdgpu_cs_vm_handling() happen too
late, after amdgpu_cs_parser_bos() has already migrated BOs and mutated the
KFD VM state without updating its page tables?
Before amdgpu_cs_ioctl() reaches amdgpu_cs_vm_handling(),
amdgpu_cs_parser_bos() locks the VM and runs:
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c:amdgpu_cs_parser_bos() {
...
r = amdgpu_vm_validate(p->adev, &fpriv->vm, NULL,
amdgpu_cs_bo_validate, p);
if (r) {
drm_err(adev_to_drm(p->adev), "amdgpu_vm_validate() failed.\n");
goto out_free_user_pages;
}
drm_exec_for_each_locked_object(&p->exec, obj) {
r = amdgpu_cs_bo_validate(p, gem_to_amdgpu_bo(obj));
if (unlikely(r))
goto out_free_user_pages;
}
...
}
amdgpu_vm_validate() moves evicted page table BOs to needs_update and
clears vm->evicting = false, and amdgpu_cs_bo_validate() validates every
locked BO (including vm->root.bo and mapped BOs in p->bo_list) into
bo->preferred_domains. When a BO or page table in a fallback domain such
as GTT is migrated to VRAM and amdgpu_cs_vm_handling() then returns -EPERM
before amdgpu_vm_bo_update(), amdgpu_vm_handle_moved() and
amdgpu_vm_update_pdes() run, the old TTM resource is freed while the live
KFD compute VM is left with unupdated PDEs/PTEs (and a stale
vm->pd_phys_addr if vm->root.bo moved) and vm->evicting cleared.
Checking fpriv->vm.is_compute_context in amdgpu_cs_parser_bos() right after
drm_exec_until_all_locked(&p->exec) locks the VM PD would reject the
submission before any VM or BO state is modified.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130212328.2369114-1-Yongqiang.Sun@amd.com?part=1
^ permalink raw reply [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