Skip to contentSkip to conversation

drm/amdgpu: Fix the EPERM error when get user pages

PATCH Superseded Ma Jun 3 participants 3 messages May 15, 2023 – May 16, 2023

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ma Jun

author
#0 lore raw

PATCH 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
index d426333e865a..85d1087439c0 100644
@@ -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
#1 lore raw

[AMD Official Use Only - General]

Quoted 29 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Ma Jun
Sent: Monday, May 15, 2023 2:14 AM
To: [email protected]
Cc: Sierra Guiza, Alejandro (Alex) <[email protected]>; Ma, Jun <[email protected]>; Kuehling, Felix <[email protected]>; Koenig, Christian <[email protected]>
Subject: [PATCH] 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 +0 -0
index d426333e865a..85d1087439c0 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c static int init_user_pages(struct kgd_mem · line 1044

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +2 -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))

Space between the if and (. E.g., if (

Alex

Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +6 -0
+		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;
--
2.34.1

#2 lore raw
Quoted 37 lines · Alexander

[AMD Official Use Only - General]

Quoted 35 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Ma Jun
Sent: Monday, May 15, 2023 2:14 AM
To: [email protected]
Cc: Sierra Guiza, Alejandro (Alex) <[email protected]>; Ma, Jun <[email protected]>; Kuehling, Felix <[email protected]>; Koenig, Christian <[email protected]>
Subject: [PATCH] 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 +1 -0
index d426333e865a..85d1087439c0 100644
@@ -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;
 
Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c static int init_user_pages(struct kgd_mem *mem, uint64_t user_addr, · line 1043

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1 -1
 	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))

Space between the if and (. E.g., if (

Thanks, will fix in next version.

Regards,
Ma Jun

Quoted 14 lines

Alex

Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +6 -0
+		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;
--
2.34.1