From: sashiko-bot@kernel.org
To: "Zhu Lingshan" <lingshan.zhu@amd.com>
Cc: amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH] amdkfd: don't give a GPU access to SVM ranges when no VM
Date: Mon, 23 Nov 2026 10:04:04 +0000 [thread overview]
Message-ID: <sashiko-outbox-229024@kernel.org> (raw)
In-Reply-To: <20261123094229.12597-1-lingshan.zhu@amd.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] drm/amdkfd: missing drm_priv check for location attrs in
svm_range_check_attr()
- [Medium] drm/amdkfd: svm_range_get_attr() reports default access for
VM-less GPUs
--
commit c034a8aa5ef1d29d58a7b5188aa7d91ba73e78a9
Author: Zhu Lingshan <lingshan.zhu@amd.com>
amdkfd: don't give a GPU access to SVM ranges when no VM
This commit prevents GPUs whose kfd_process_device has not acquired a VM
from receiving default access to new SVM ranges when XNACK is enabled, and
rejects setting SVM access attributes for such GPUs in
svm_range_check_attr().
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
> index a571fda5c713a..042ac8081f082 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
> @@ -339,6 +339,7 @@ svm_range *svm_range_new(struct svm_range_list *svms, uint64_t start,
> uint64_t size = last - start + 1;
> struct svm_range *prange;
> struct kfd_process *p;
> + int i;
>
> prange = kzalloc_obj(*prange);
> if (!prange)
> @@ -367,9 +368,17 @@ svm_range *svm_range_new(struct svm_range_list *svms, uint64_t start,
> mutex_init(&prange->migrate_mutex);
> mutex_init(&prange->lock);
>
> - if (p->xnack_enabled)
> + if (p->xnack_enabled) {
> bitmap_copy(prange->bitmap_access, svms->bitmap_supported,
> MAX_GPU_INSTANCE);
> + for_each_set_bit(i, svms->bitmap_supported, p->n_pdds) {
> + if (!p->pdds[i]->drm_priv) {
> + pr_debug("GPU %d has no VM acquired, skip mapping SVM range [0x%llx 0x%llx] to it\n",
> + p->pdds[i]->user_gpu_id, start, last);
> + clear_bit(i, prange->bitmap_access);
> + }
> + }
> + }
[Severity: Medium]
Should svm_range_get_attr() also clear bits for GPUs with
!p->pdds[i]->drm_priv when reporting default attributes for an
unregistered range?
drivers/gpu/drm/amd/amdkfd/kfd_svm.c:svm_range_get_attr() {
...
node = interval_tree_iter_first(&svms->objects, start, last);
if (!node) {
pr_debug("range attrs not found return default values\n");
svm_range_set_default_attributes(svms, &location, &prefetch_loc,
&granularity, &flags_and);
flags_or = flags_and;
if (p->xnack_enabled)
bitmap_copy(bitmap_access, svms->bitmap_supported,
MAX_GPU_INSTANCE);
...
}
When p->xnack_enabled is true and an address range is not yet in
svms->objects, KFD_IOCTL_SVM_OP_GET_ATTR still copies
svms->bitmap_supported into bitmap_access without excluding GPUs where
drm_priv is NULL. It then reports KFD_IOCTL_SVM_ATTR_ACCESS for those
GPUs, contradicting the default bitmap_access initialized by
svm_range_new() and causing a subsequent KFD_IOCTL_SVM_OP_SET_ATTR with
the queried attributes to fail with -EINVAL in svm_range_check_attr().
> @@ -722,6 +731,13 @@ svm_range_check_attr(struct kfd_process *p,
> break;
> case KFD_IOCTL_SVM_ATTR_ACCESS:
> case KFD_IOCTL_SVM_ATTR_ACCESS_IN_PLACE:
> + gpuidx = kfd_process_gpuidx_from_gpuid(p, val);
> + if (gpuidx >= 0 && !p->pdds[gpuidx]->drm_priv) {
> + pr_debug("GPU %d has no VM acquired, so SVM does not work on it, please acquire VM for it first\n",
> + val);
> + return -EINVAL;
> + }
> + break;
> case KFD_IOCTL_SVM_ATTR_NO_ACCESS:
> gpuidx = kfd_process_gpuidx_from_gpuid(p, val);
> break;
[Severity: High]
Does svm_range_check_attr() also need to reject GPUs with
!p->pdds[gpuidx]->drm_priv for KFD_IOCTL_SVM_ATTR_PREFERRED_LOC and
KFD_IOCTL_SVM_ATTR_PREFETCH_LOC?
Because the drm_priv check is only performed for ACCESS and
ACCESS_IN_PLACE, a process that has acquired a VM on one GPU can pass
another GPU whose pdd->drm_priv is NULL as PREFETCH_LOC or PREFERRED_LOC.
svm_range_set_attr() -> svm_range_trigger_migration() ->
svm_migrate_to_vram() will then allocate a VRAM BO and migrate pages via
SDMA onto an unacquired GPU that has not gone through
kfd_bind_process_to_device().
When p->xnack_enabled is true and the range is later validated for another
GPU, svm_range_validate_and_map() only adds prange->actual_loc to
ctx->bitmap if test_bit(gpuidx, prange->bitmap_access) is set. Since
svm_range_new() cleared the unacquired GPU's bit in prange->bitmap_access,
actual_loc is omitted from ctx->bitmap and owner is not cleared to NULL,
causing amdgpu_hmm_range_get_pages() -> hmm_range_fault() to fault on the
unacquired GPU's device-private pages while svm_migrate_to_ram() skips
migration because p->svms.faulting_task == current.
Checking !p->pdds[gpuidx]->drm_priv after the switch alongside the
existing gpuidx validation would cover all GPU-targeted attributes.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123094229.12597-1-lingshan.zhu@amd.com?part=1
next prev parent reply other threads:[~2026-11-23 10:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 9:42 [PATCH] amdkfd: don't give a GPU access to SVM ranges when no VM Zhu Lingshan
2026-11-23 10:04 ` sashiko-bot [this message]
2026-11-23 16:25 ` Philip Yang
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-229024@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=amd-gfx@lists.freedesktop.org \
--cc=lingshan.zhu@amd.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.