* [PATCH] amdkfd: don't give a GPU access to SVM ranges when no VM
@ 2026-11-23 9:42 Zhu Lingshan
2026-11-23 10:04 ` sashiko-bot
2026-11-23 16:25 ` Philip Yang
0 siblings, 2 replies; 3+ messages in thread
From: Zhu Lingshan @ 2026-11-23 9:42 UTC (permalink / raw)
To: Alexander.Deucher, Felix.Kuehling; +Cc: amd-gfx, Zhu Lingshan
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] amdkfd: don't give a GPU access to SVM ranges when no VM
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
2026-11-23 16:25 ` Philip Yang
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-23 10:04 UTC (permalink / raw)
To: Zhu Lingshan; +Cc: amd-gfx
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] amdkfd: don't give a GPU access to SVM ranges when no VM
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
@ 2026-11-23 16:25 ` Philip Yang
1 sibling, 0 replies; 3+ messages in thread
From: Philip Yang @ 2026-11-23 16:25 UTC (permalink / raw)
To: Zhu Lingshan, Alexander.Deucher, Felix.Kuehling; +Cc: amd-gfx
[-- Attachment #1: Type: text/plain, Size: 3184 bytes --]
On 2026-11-23 04:42, Zhu Lingshan wrote:
> 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);
> + }
> + }
> + }
I suspect this issue is caused by a low-level test application that
doesn’t initialize KFD through the Thunk.
Could we update svm_range_list_init() to check for drm_priv before
marking SVM as supported? With that check in place, this change and the
other related change below may no longer be necessary.
@@ -3468,7 +3468,8 @@ int svm_range_list_init(struct kfd_process *p)
spin_lock_init(&svms->deferred_list_lock);
for (i = 0; i < p->n_pdds; i++)
- if (KFD_IS_SVM_API_SUPPORTED(p->pdds[i]->dev->adev))
+ if (KFD_IS_SVM_API_SUPPORTED(p->pdds[i]->dev->adev) &&
+ p->pdds[i]->drm_priv)
bitmap_set(svms->bitmap_supported, i, 1);
/* Value of default granularity cannot exceed 0x1B, the
Regards,
Philip
>
> 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;
[-- Attachment #2: Type: text/html, Size: 4191 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-23 16:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2026-11-23 16:25 ` Philip Yang
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.