Skip to contentSkip to conversation

drm/amdkfd: fix units when unmapping a PROT_NONE VMA from GPUs

PATCH In review Perry Yuan 2 participants 2 messages Nov 9 – Nov 20

Subsystems (3)
lore
Share & tools
lore

Perry Yuan

author
#0 lore raw

PATCH 1/1 drm/amdkfd: fix units when unmapping a PROT_NONE VMA from GPUs

In svm_range_validate_and_map(), start and end are byte addresses while prange->start and prange->last are page numbers. Mixing them makes e >= s false in practice, so a VMA without VM_READ is never unmapped from the GPUs. The bounds also covered the whole request instead of the current VMA.

Use the page numbers of the current VMA, [addr, next).

Fixes 0ed704d058ce ("drm/amdkfd: Handle lack of READ permissions in SVM mapping")
---
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2 -2
index 876476046926..968ad471ae85 100644
@@ -1857,8 +1857,8 @@ static int svm_range_validate_and_map(struct mm_struct *mm,
 				svm_range_lock(prange);
 				if (vma->vm_flags & VM_WRITE)
 					pr_debug("VM_WRITE without VM_READ is not supported");
-				s = max(start, prange->start);
-				e = min(end, prange->last);
+				s = max(addr >> PAGE_SHIFT, prange->start);
+				e = min((next >> PAGE_SHIFT) - 1, prange->last);
 				if (e >= s)
 					r = svm_range_unmap_from_gpus(prange, s, e,
 						       prange->bitmap_mapped,
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw

Public

This patch is:

-----Original Message-----
From: Yuan, Perry <[email protected]>
Sent: Monday, November 9, 2026 2:21 PM
To: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; [email protected]
Cc: Zhang, Yifan <[email protected]>; Yuan, Perry <[email protected]>
Subject: [PATCH] drm/amdkfd: fix units when unmapping a PROT_NONE VMA from GPUs

In svm_range_validate_and_map(), start and end are byte addresses while prange->start and prange->last are page numbers. Mixing them makes e >= s false in practice, so a VMA without VM_READ is never unmapped from the GPUs. The bounds also covered the whole request instead of the current VMA.

Use the page numbers of the current VMA, [addr, next).

Fixes 0ed704d058ce ("drm/amdkfd: Handle lack of READ permissions in SVM mapping")
---
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2 -2
index 876476046926..968ad471ae85 100644
@@ -1857,8 +1857,8 @@ static int svm_range_validate_and_map(struct mm_struct *mm,
                                svm_range_lock(prange);
                                if (vma->vm_flags & VM_WRITE)
                                        pr_debug("VM_WRITE without VM_READ is not supported");
-                               s = max(start, prange->start);
-                               e = min(end, prange->last);
+                               s = max(addr >> PAGE_SHIFT, prange->start);
+                               e = min((next >> PAGE_SHIFT) - 1, prange->last);
                                if (e >= s)
                                        r = svm_range_unmap_from_gpus(prange, s, e,
                                                       prange->bitmap_mapped,

--
2.34.1