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")
Signed-off-by: Perry Yuan <[email protected]>
---
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
index 876476046926..968ad471ae85 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
@@ -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

Reply via email to