From: sashiko-bot@kernel.org
To: "Yongqiang Sun" <Yongqiang.Sun@amd.com>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/amdgpu: reject CS on a VM that KFD has acquired
Date: Mon, 30 Nov 2026 21:41:34 +0000 [thread overview]
Message-ID: <sashiko-outbox-242027@kernel.org> (raw)
In-Reply-To: <20261130212328.2369114-1-Yongqiang.Sun@amd.com>
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
next prev parent reply other threads:[~2026-11-30 21:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-12-01 1:19 Yongqiang Sun
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-242027@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Yongqiang.Sun@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox