drm/amdgpu: Fix the EPERM error when get user pages
Subsystems (3)
PATCH v2 1/1 drm/amdgpu: Fix the EPERM error when get user pages
Check and pass the readonly flags when set amdgpu_ttm_tt flags
for readonly ptr pages. Otherwise, there is EPERM error returned
during the KFDExceptionTest.PermissionFaultUserPointer test on
ploaris10.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +8 -1
@@ -1036,10 +1036,17 @@ static int init_user_pages(struct kgd_mem *mem, uint64_t user_addr,struct ttm_operation_ctx ctx = { true, false };struct hmm_range *range;int ret =0 ; +uint32_t tt_flags =0 ;mutex_lock (&process_info->lock); - ret =amdgpu_ttm_tt_set_userptr (&bo->tbo, user_addr,0 ); +if (!(mem->alloc_flags &KFD_IOC_ALLOC_MEM_FLAGS_WRITABLE )) + tt_flags |=AMDGPU_GEM_USERPTR_READONLY ; +else + tt_flags =0 ; + + + ret =amdgpu_ttm_tt_set_userptr (&bo->tbo, user_addr, tt_flags);if (ret) {pr_err ("%s: Failed to set userptr: %d\n" , __func__, ret); goto out;
Signature · 1 line
2.34.1
Felix Kuehling
maintainerQuoted 7 lines · Ma Jun
Check and pass the readonly flags when set
amdgpu_ttm_ttflagsfor readonly ptr pages. Otherwise, there is EPERM error returned
during the KFDExceptionTest.PermissionFaultUserPointer test on
ploaris10.
I remember you asked me about this maybe 2 weeks ago. I'm still not sure how your test is supposed to work correctly. Someone needs to decide whether to set KFD_IOC_ALLOC_MEM_FLAGS_WRITABLE when registering the userptr. How does this happen? I think you need some code that checks that the VMA is read-only and then clears the WRITABLE flag from mem->alloc_flags. But I don't see that anywhere. I don't think we ever added proper support for read-only userptrs in KFD. Your patch is a partial fix at best, and I don't see how this helps.
Two more nit-picks inline.
Quoted 13 lines
Signed-off-by Ma Jun <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0
-0@@ -1036,10 +1036,17 @@ static int init_user_pages(struct kgd_mem *mem, uint64_t user_addr,struct ttm_operation_ctx ctx = { true, false };struct hmm_range *range;
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c static int init_user_pages(struct kgd_mem *mem, uint64_t user_addr, · line 1046
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +5
-1int ret =0 ; +uint32_t tt_flags =0 ;mutex_lock (&process_info->lock); - ret =amdgpu_ttm_tt_set_userptr (&bo->tbo, user_addr,0 ); +if (!(mem->alloc_flags &KFD_IOC_ALLOC_MEM_FLAGS_WRITABLE )) + tt_flags |=AMDGPU_GEM_USERPTR_READONLY ; +else + tt_flags =0 ;
This else-branch is unnecessary because you initialized tt_flags to 0 above.
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c static int init_user_pages(struct kgd_mem *mem, uint64_t user_addr, · line 1048
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +2
-0+ +
Double blank lines. One is enough.
Regards,
Felix
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1
-0+ ret =amdgpu_ttm_tt_set_userptr (&bo->tbo, user_addr, tt_flags);if (ret) {pr_err ("%s: Failed to set userptr: %d\n" , __func__, ret); goto out;