When mapping an SVM range, svm_range_validate_and_map() faults the pages
with hmm_range_fault(), requesting write access unless the range is
read-only. It decides read-only from the VMA write permission alone, so
KFD_IOCTL_SVM_FLAG_GPU_RO is ignored and the range is faulted for write.

svm_range_get_pte_flags() already honors GPU_RO for the page table; honor
it for the fault too.

Signed-off-by: Junhua Shen <[email protected]>
---
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
index ed5e3318877b..1b94b3b6d069 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
@@ -1840,7 +1840,8 @@ static int svm_range_validate_and_map(struct mm_struct 
*mm,
 
                vma = vma_lookup(mm, addr);
                if (vma) {
-                       readonly = !(vma->vm_flags & VM_WRITE);
+                       readonly = !(vma->vm_flags & VM_WRITE) ||
+                                  (prange->flags & KFD_IOCTL_SVM_FLAG_GPU_RO);
 
                        next = min(vma->vm_end, end);
                        npages = (next - addr) >> PAGE_SHIFT;
-- 
2.53.0

Reply via email to