From: Zhu Lingshan <lingshan.zhu@amd.com>
To: <Alexander.Deucher@amd.com>, <Felix.Kuehling@amd.com>
Cc: <amd-gfx@lists.freedesktop.org>, Zhu Lingshan <lingshan.zhu@amd.com>
Subject: [PATCH] amdkfd: don't give a GPU access to SVM ranges when no VM
Date: Mon, 23 Nov 2026 17:42:29 +0800 [thread overview]
Message-ID: <20261123094229.12597-1-lingshan.zhu@amd.com> (raw)
If a kfd process does not perform ACQUIRE VM for its
kfd_process_device, the VM of the pdd is NULL.
This commit fails svm_range_check_attr() with -EINVAL,
before it changes anything when VM is null of a pdd.
When XNACK is enabled, this commit does not give GPUs that
have not acquired a VM default access to new svm ranges.
Signed-off-by: Zhu Lingshan <lingshan.zhu@amd.com>
---
drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
index 7401b7fdcb57..6e42b358ad59 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);
+ }
+ }
+ }
svm_range_set_default_attributes(svms, &prange->preferred_loc,
&prange->prefetch_loc,
@@ -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;
--
2.53.0
next reply other threads:[~2026-11-23 9:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 9:42 Zhu Lingshan [this message]
2026-11-23 10:04 ` [PATCH] amdkfd: don't give a GPU access to SVM ranges when no VM sashiko-bot
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=20261123094229.12597-1-lingshan.zhu@amd.com \
--to=lingshan.zhu@amd.com \
--cc=Alexander.Deucher@amd.com \
--cc=Felix.Kuehling@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
/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.