Skip to contentSkip to conversation

drm/amdgpu: Prepare for hmm_range_register API change

PATCH In review Kuehling, Felix 2 participants 2 messages Jul 5, 2019 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: Prepare for hmm_range_register API change

From: Philip Yang <[email protected]>

An upcoming change in the hmm_range_register API requires passing in a pointer to an hmm_mirror instead of mm_struct. To access the hmm_mirror we need pass bo instead of ttm to amdgpu_ttm_tt_get_user_pages because mirror is part of amdgpu_mn structure, which is accessible from bo.

---
 .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  |  5 +--
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c        |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c       |  3 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c        | 37 ----------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_mn.h        | 44 ++++++++++++++++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c       | 10 ++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h       |  5 ++-
 7 files changed, 55 insertions(+), 51 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +2 -3
index 58cecfe57f8b..f5ecf28eb37c 100644
@@ -503,7 +503,7 @@ static int init_user_pages(struct kgd_mem *mem, struct mm_struct *mm,
 		goto out;
 	}
 
-	ret = amdgpu_ttm_tt_get_user_pages(bo->tbo.ttm, bo->tbo.ttm->pages);
+	ret = amdgpu_ttm_tt_get_user_pages(bo, bo->tbo.ttm->pages);
 	if (ret) {
 		pr_err("%s: Failed to get user pages: %d\n", __func__, ret);
 		goto unregister_out;
@@ -1728,8 +1728,7 @@ static int update_invalid_user_pages(struct amdkfd_process_info *process_info,
 		bo = mem->bo;
 
 		/* Get updated user pages */
-		ret = amdgpu_ttm_tt_get_user_pages(bo->tbo.ttm,
-						   bo->tbo.ttm->pages);
+		ret = amdgpu_ttm_tt_get_user_pages(bo, bo->tbo.ttm->pages);
 		if (ret) {
 			pr_debug("%s: Failed to get user pages: %d\n",
 				__func__, ret);
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 -1
index c25e1ebc76c3..c691df6f7a57 100644
@@ -631,7 +631,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
 			return -ENOMEM;
 		}
 
-		r = amdgpu_ttm_tt_get_user_pages(bo->tbo.ttm, e->user_pages);
+		r = amdgpu_ttm_tt_get_user_pages(bo, e->user_pages);
 		if (r) {
 			kvfree(e->user_pages);
 			e->user_pages = NULL;
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1 -2
index ed25a4e14404..2cead5a242d7 100644
@@ -323,8 +323,7 @@ int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
 	}
 
 	if (args->flags & AMDGPU_GEM_USERPTR_VALIDATE) {
-		r = amdgpu_ttm_tt_get_user_pages(bo->tbo.ttm,
-						 bo->tbo.ttm->pages);
+		r = amdgpu_ttm_tt_get_user_pages(bo, bo->tbo.ttm->pages);
 		if (r)
 			goto release_object;
 
drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c +0 -37
index e0bb47ce570b..3971c201f320 100644
@@ -45,48 +45,11 @@
 
 #include <linux/firmware.h>
 #include <linux/module.h>
-#include <linux/hmm.h>
-#include <linux/interval_tree.h>
-#include <drm/drmP.h>
 #include <drm/drm.h>
 
 #include "amdgpu.h"
 #include "amdgpu_amdkfd.h"
 
-/**
- * struct amdgpu_mn
- *
- * @adev: amdgpu device pointer
- * @mm: process address space
- * @type: type of MMU notifier
- * @work: destruction work item
- * @node: hash table node to find structure by adev and mn
- * @lock: rw semaphore protecting the notifier nodes
- * @objects: interval tree containing amdgpu_mn_nodes
- * @mirror: HMM mirror function support
- *
- * Data for each amdgpu device and process address space.
- */
-struct amdgpu_mn {
-	/* constant after initialisation */
-	struct amdgpu_device	*adev;
-	struct mm_struct	*mm;
-	enum amdgpu_mn_type	type;
-
-	/* only used on destruction */
-	struct work_struct	work;
-
-	/* protected by adev->mn_lock */
-	struct hlist_node	node;
-
-	/* objects protected by lock */
-	struct rw_semaphore	lock;
-	struct rb_root_cached	objects;
-
-	/* HMM mirror */
-	struct hmm_mirror	mirror;
-};
-
 /**
  * struct amdgpu_mn_node
  *
drivers/gpu/drm/amd/amdgpu/amdgpu_mn.h +39 -5

56 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +9 -1
index 8225d6e05a55..5d85617886b3 100644
@@ -726,8 +726,10 @@ struct amdgpu_ttm_tt {
 
 #define MAX_RETRY_HMM_RANGE_FAULT	16
 
-int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages)
+int amdgpu_ttm_tt_get_user_pages(struct amdgpu_bo *bo, struct page **pages)
 {
+	struct hmm_mirror *mirror = bo->mn ? &bo->mn->mirror : NULL;
+	struct ttm_tt *ttm = bo->tbo.ttm;
 	struct amdgpu_ttm_tt *gtt = (void *)ttm;
 	struct mm_struct *mm = gtt->usertask->mm;
 	unsigned long start = gtt->userptr;
@@ -741,6 +743,12 @@ int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages)
 	if (!mm) /* Happens during process shutdown */
 		return -ESRCH;
 
+	if (unlikely(!mirror)) {
+		DRM_DEBUG_DRIVER("Failed to get hmm_mirror\n");
+		r = -EFAULT;
+		goto out;
+	}
+
 	vma = find_vma(mm, start);
 	if (unlikely(!vma || start < vma->vm_start)) {
 		r = -EFAULT;
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +3 -2
index c2b7669004ba..caa76c693700 100644
@@ -102,10 +102,11 @@ int amdgpu_ttm_alloc_gart(struct ttm_buffer_object *bo);
 int amdgpu_ttm_recover_gart(struct ttm_buffer_object *tbo);
 
 #if IS_ENABLED(CONFIG_DRM_AMDGPU_USERPTR)
-int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages);
+int amdgpu_ttm_tt_get_user_pages(struct amdgpu_bo *bo, struct page **pages);
 bool amdgpu_ttm_tt_get_user_pages_done(struct ttm_tt *ttm);
 #else
-static inline int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages)
+static inline int amdgpu_ttm_tt_get_user_pages(struct amdgpu_bo *bo,
+					       struct page **pages)
 {
 	return -EPERM;
 }
Signature · 6 lines
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 20190705195010.7569-1-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org

Reviewed-by
#2 lore raw

________________________________
From: amd-gfx <amd-gfx-bounces-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org> on behalf of Kuehling, Felix <[email protected]>
Sent: Friday, July 5, 2019 3:50 PM
To: [email protected]
Cc: Yang, Philip; Kuehling, Felix
Subject: [PATCH 1/1] drm/amdgpu: Prepare for hmm_range_register API change

From: Philip Yang <[email protected]>

An upcoming change in the hmm_range_register API requires passing in a pointer to an hmm_mirror instead of mm_struct. To access the hmm_mirror we need pass bo instead of ttm to amdgpu_ttm_tt_get_user_pages because mirror is part of amdgpu_mn structure, which is accessible from bo.

---
 .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  |  5 +--
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c        |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c       |  3 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c        | 37 ----------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_mn.h        | 44 ++++++++++++++++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c       | 10 ++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h       |  5 ++-
 7 files changed, 55 insertions(+), 51 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +2 -3
index 58cecfe57f8b..f5ecf28eb37c 100644
@@ -503,7 +503,7 @@ static int init_user_pages(struct kgd_mem *mem, struct mm_struct *mm,
                 goto out;
         }
 
-       ret = amdgpu_ttm_tt_get_user_pages(bo->tbo.ttm, bo->tbo.ttm->pages);
+       ret = amdgpu_ttm_tt_get_user_pages(bo, bo->tbo.ttm->pages);
         if (ret) {
                 pr_err("%s: Failed to get user pages: %d\n", __func__, ret);
                 goto unregister_out;
@@ -1728,8 +1728,7 @@ static int update_invalid_user_pages(struct amdkfd_process_info *process_info,
                 bo = mem->bo;
 
                 /* Get updated user pages */
-               ret = amdgpu_ttm_tt_get_user_pages(bo->tbo.ttm,
-                                                  bo->tbo.ttm->pages);
+               ret = amdgpu_ttm_tt_get_user_pages(bo, bo->tbo.ttm->pages);
                 if (ret) {
                         pr_debug("%s: Failed to get user pages: %d\n",
                                 __func__, ret);
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 -1
index c25e1ebc76c3..c691df6f7a57 100644
@@ -631,7 +631,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
                         return -ENOMEM;
                 }
 
-               r = amdgpu_ttm_tt_get_user_pages(bo->tbo.ttm, e->user_pages);
+               r = amdgpu_ttm_tt_get_user_pages(bo, e->user_pages);
                 if (r) {
                         kvfree(e->user_pages);
                         e->user_pages = NULL;
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1 -2
index ed25a4e14404..2cead5a242d7 100644
@@ -323,8 +323,7 @@ int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
         }
 
         if (args->flags & AMDGPU_GEM_USERPTR_VALIDATE) {
-               r = amdgpu_ttm_tt_get_user_pages(bo->tbo.ttm,
-                                                bo->tbo.ttm->pages);
+               r = amdgpu_ttm_tt_get_user_pages(bo, bo->tbo.ttm->pages);
                 if (r)
                         goto release_object;
 
drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c +0 -37
index e0bb47ce570b..3971c201f320 100644
@@ -45,48 +45,11 @@
 
 #include <linux/firmware.h>
 #include <linux/module.h>
-#include <linux/hmm.h>
-#include <linux/interval_tree.h>
-#include <drm/drmP.h>
 #include <drm/drm.h>
 
 #include "amdgpu.h"
 #include "amdgpu_amdkfd.h"
 
-/**
- * struct amdgpu_mn
- *
- * @adev: amdgpu device pointer
- * @mm: process address space
- * @type: type of MMU notifier
- * @work: destruction work item
- * @node: hash table node to find structure by adev and mn
- * @lock: rw semaphore protecting the notifier nodes
- * @objects: interval tree containing amdgpu_mn_nodes
- * @mirror: HMM mirror function support
- *
- * Data for each amdgpu device and process address space.
- */
-struct amdgpu_mn {
-       /* constant after initialisation */
-       struct amdgpu_device    *adev;
-       struct mm_struct        *mm;
-       enum amdgpu_mn_type     type;
-
-       /* only used on destruction */
-       struct work_struct      work;
-
-       /* protected by adev->mn_lock */
-       struct hlist_node       node;
-
-       /* objects protected by lock */
-       struct rw_semaphore     lock;
-       struct rb_root_cached   objects;
-
-       /* HMM mirror */
-       struct hmm_mirror       mirror;
-};
-
 /**
  * struct amdgpu_mn_node
  *
drivers/gpu/drm/amd/amdgpu/amdgpu_mn.h +39 -5

56 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +9 -1
index 8225d6e05a55..5d85617886b3 100644
@@ -726,8 +726,10 @@ struct amdgpu_ttm_tt {
 
 #define MAX_RETRY_HMM_RANGE_FAULT       16
 
-int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages)
+int amdgpu_ttm_tt_get_user_pages(struct amdgpu_bo *bo, struct page **pages)
 {
+       struct hmm_mirror *mirror = bo->mn ? &bo->mn->mirror : NULL;
+       struct ttm_tt *ttm = bo->tbo.ttm;
         struct amdgpu_ttm_tt *gtt = (void *)ttm;
         struct mm_struct *mm = gtt->usertask->mm;
         unsigned long start = gtt->userptr;
@@ -741,6 +743,12 @@ int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages)
         if (!mm) /* Happens during process shutdown */
                 return -ESRCH;
 
+       if (unlikely(!mirror)) {
+               DRM_DEBUG_DRIVER("Failed to get hmm_mirror\n");
+               r = -EFAULT;
+               goto out;
+       }
+
         vma = find_vma(mm, start);
         if (unlikely(!vma || start < vma->vm_start)) {
                 r = -EFAULT;
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +3 -2
index c2b7669004ba..caa76c693700 100644
@@ -102,10 +102,11 @@ int amdgpu_ttm_alloc_gart(struct ttm_buffer_object *bo);
 int amdgpu_ttm_recover_gart(struct ttm_buffer_object *tbo);
 
 #if IS_ENABLED(CONFIG_DRM_AMDGPU_USERPTR)
-int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages);
+int amdgpu_ttm_tt_get_user_pages(struct amdgpu_bo *bo, struct page **pages);
 bool amdgpu_ttm_tt_get_user_pages_done(struct ttm_tt *ttm);
 #else
-static inline int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages)
+static inline int amdgpu_ttm_tt_get_user_pages(struct amdgpu_bo *bo,
+                                              struct page **pages)
 {
         return -EPERM;
 }

--
2.17.1

_______________________________________________
amd-gfx mailing list [email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx