All of lore.kernel.org
 help / color / mirror / Atom feed
* [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

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.