<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Reviewed-by: Alex Deucher <alexander.deucher@amd.com><br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> amd-gfx <amd-gfx-bounces@lists.freedesktop.org> on behalf of Kuehling, Felix <Felix.Kuehling@amd.com><br>
<b>Sent:</b> Friday, July 5, 2019 3:50 PM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org<br>
<b>Cc:</b> Yang, Philip; Kuehling, Felix<br>
<b>Subject:</b> [PATCH 1/1] drm/amdgpu: Prepare for hmm_range_register API change</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">From: Philip Yang <Philip.Yang@amd.com><br>
<br>
An upcoming change in the hmm_range_register API requires passing in<br>
a pointer to an hmm_mirror instead of mm_struct. To access the<br>
hmm_mirror we need pass bo instead of ttm to amdgpu_ttm_tt_get_user_pages<br>
because mirror is part of amdgpu_mn structure, which is accessible from bo.<br>
<br>
Signed-off-by: Philip Yang <Philip.Yang@amd.com><br>
Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com><br>
---<br>
.../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 5 +--<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 2 +-<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 3 +-<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c | 37 ----------------<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_mn.h | 44 ++++++++++++++++---<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 10 ++++-<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 5 ++-<br>
7 files changed, 55 insertions(+), 51 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c<br>
index 58cecfe57f8b..f5ecf28eb37c 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c<br>
@@ -503,7 +503,7 @@ static int init_user_pages(struct kgd_mem *mem, struct mm_struct *mm,<br>
goto out;<br>
}<br>
<br>
- ret = amdgpu_ttm_tt_get_user_pages(bo->tbo.ttm, bo->tbo.ttm->pages);<br>
+ ret = amdgpu_ttm_tt_get_user_pages(bo, bo->tbo.ttm->pages);<br>
if (ret) {<br>
pr_err("%s: Failed to get user pages: %d\n", __func__, ret);<br>
goto unregister_out;<br>
@@ -1728,8 +1728,7 @@ static int update_invalid_user_pages(struct amdkfd_process_info *process_info,<br>
bo = mem->bo;<br>
<br>
/* Get updated user pages */<br>
- ret = amdgpu_ttm_tt_get_user_pages(bo->tbo.ttm,<br>
- bo->tbo.ttm->pages);<br>
+ ret = amdgpu_ttm_tt_get_user_pages(bo, bo->tbo.ttm->pages);<br>
if (ret) {<br>
pr_debug("%s: Failed to get user pages: %d\n",<br>
__func__, ret);<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c<br>
index c25e1ebc76c3..c691df6f7a57 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c<br>
@@ -631,7 +631,7 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,<br>
return -ENOMEM;<br>
}<br>
<br>
- r = amdgpu_ttm_tt_get_user_pages(bo->tbo.ttm, e->user_pages);<br>
+ r = amdgpu_ttm_tt_get_user_pages(bo, e->user_pages);<br>
if (r) {<br>
kvfree(e->user_pages);<br>
e->user_pages = NULL;<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c<br>
index ed25a4e14404..2cead5a242d7 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c<br>
@@ -323,8 +323,7 @@ int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,<br>
}<br>
<br>
if (args->flags & AMDGPU_GEM_USERPTR_VALIDATE) {<br>
- r = amdgpu_ttm_tt_get_user_pages(bo->tbo.ttm,<br>
- bo->tbo.ttm->pages);<br>
+ r = amdgpu_ttm_tt_get_user_pages(bo, bo->tbo.ttm->pages);<br>
if (r)<br>
goto release_object;<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c<br>
index e0bb47ce570b..3971c201f320 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c<br>
@@ -45,48 +45,11 @@<br>
<br>
#include <linux/firmware.h><br>
#include <linux/module.h><br>
-#include <linux/hmm.h><br>
-#include <linux/interval_tree.h><br>
-#include <drm/drmP.h><br>
#include <drm/drm.h><br>
<br>
#include "amdgpu.h"<br>
#include "amdgpu_amdkfd.h"<br>
<br>
-/**<br>
- * struct amdgpu_mn<br>
- *<br>
- * @adev: amdgpu device pointer<br>
- * @mm: process address space<br>
- * @type: type of MMU notifier<br>
- * @work: destruction work item<br>
- * @node: hash table node to find structure by adev and mn<br>
- * @lock: rw semaphore protecting the notifier nodes<br>
- * @objects: interval tree containing amdgpu_mn_nodes<br>
- * @mirror: HMM mirror function support<br>
- *<br>
- * Data for each amdgpu device and process address space.<br>
- */<br>
-struct amdgpu_mn {<br>
- /* constant after initialisation */<br>
- struct amdgpu_device *adev;<br>
- struct mm_struct *mm;<br>
- enum amdgpu_mn_type type;<br>
-<br>
- /* only used on destruction */<br>
- struct work_struct work;<br>
-<br>
- /* protected by adev->mn_lock */<br>
- struct hlist_node node;<br>
-<br>
- /* objects protected by lock */<br>
- struct rw_semaphore lock;<br>
- struct rb_root_cached objects;<br>
-<br>
- /* HMM mirror */<br>
- struct hmm_mirror mirror;<br>
-};<br>
-<br>
/**<br>
* struct amdgpu_mn_node<br>
*<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.h<br>
index f5b67c63ed6b..281fd9fef662 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.h<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.h<br>
@@ -24,17 +24,51 @@<br>
#ifndef __AMDGPU_MN_H__<br>
#define __AMDGPU_MN_H__<br>
<br>
-/*<br>
- * HMM mirror<br>
- */<br>
-struct amdgpu_mn;<br>
-struct hmm_range;<br>
+#include <linux/types.h><br>
+#include <linux/hmm.h><br>
+#include <linux/rwsem.h><br>
+#include <linux/workqueue.h><br>
+#include <linux/interval_tree.h><br>
<br>
enum amdgpu_mn_type {<br>
AMDGPU_MN_TYPE_GFX,<br>
AMDGPU_MN_TYPE_HSA,<br>
};<br>
<br>
+/**<br>
+ * struct amdgpu_mn<br>
+ *<br>
+ * @adev: amdgpu device pointer<br>
+ * @mm: process address space<br>
+ * @type: type of MMU notifier<br>
+ * @work: destruction work item<br>
+ * @node: hash table node to find structure by adev and mn<br>
+ * @lock: rw semaphore protecting the notifier nodes<br>
+ * @objects: interval tree containing amdgpu_mn_nodes<br>
+ * @mirror: HMM mirror function support<br>
+ *<br>
+ * Data for each amdgpu device and process address space.<br>
+ */<br>
+struct amdgpu_mn {<br>
+ /* constant after initialisation */<br>
+ struct amdgpu_device *adev;<br>
+ struct mm_struct *mm;<br>
+ enum amdgpu_mn_type type;<br>
+<br>
+ /* only used on destruction */<br>
+ struct work_struct work;<br>
+<br>
+ /* protected by adev->mn_lock */<br>
+ struct hlist_node node;<br>
+<br>
+ /* objects protected by lock */<br>
+ struct rw_semaphore lock;<br>
+ struct rb_root_cached objects;<br>
+<br>
+ /* HMM mirror */<br>
+ struct hmm_mirror mirror;<br>
+};<br>
+<br>
#if defined(CONFIG_HMM_MIRROR)<br>
void amdgpu_mn_lock(struct amdgpu_mn *mn);<br>
void amdgpu_mn_unlock(struct amdgpu_mn *mn);<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c<br>
index 8225d6e05a55..5d85617886b3 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c<br>
@@ -726,8 +726,10 @@ struct amdgpu_ttm_tt {<br>
<br>
#define MAX_RETRY_HMM_RANGE_FAULT 16<br>
<br>
-int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages)<br>
+int amdgpu_ttm_tt_get_user_pages(struct amdgpu_bo *bo, struct page **pages)<br>
{<br>
+ struct hmm_mirror *mirror = bo->mn ? &bo->mn->mirror : NULL;<br>
+ struct ttm_tt *ttm = bo->tbo.ttm;<br>
struct amdgpu_ttm_tt *gtt = (void *)ttm;<br>
struct mm_struct *mm = gtt->usertask->mm;<br>
unsigned long start = gtt->userptr;<br>
@@ -741,6 +743,12 @@ int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages)<br>
if (!mm) /* Happens during process shutdown */<br>
return -ESRCH;<br>
<br>
+ if (unlikely(!mirror)) {<br>
+ DRM_DEBUG_DRIVER("Failed to get hmm_mirror\n");<br>
+ r = -EFAULT;<br>
+ goto out;<br>
+ }<br>
+<br>
vma = find_vma(mm, start);<br>
if (unlikely(!vma || start < vma->vm_start)) {<br>
r = -EFAULT;<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h<br>
index c2b7669004ba..caa76c693700 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h<br>
@@ -102,10 +102,11 @@ int amdgpu_ttm_alloc_gart(struct ttm_buffer_object *bo);<br>
int amdgpu_ttm_recover_gart(struct ttm_buffer_object *tbo);<br>
<br>
#if IS_ENABLED(CONFIG_DRM_AMDGPU_USERPTR)<br>
-int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages);<br>
+int amdgpu_ttm_tt_get_user_pages(struct amdgpu_bo *bo, struct page **pages);<br>
bool amdgpu_ttm_tt_get_user_pages_done(struct ttm_tt *ttm);<br>
#else<br>
-static inline int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages)<br>
+static inline int amdgpu_ttm_tt_get_user_pages(struct amdgpu_bo *bo,<br>
+ struct page **pages)<br>
{<br>
return -EPERM;<br>
}<br>
-- <br>
2.17.1<br>
<br>
_______________________________________________<br>
amd-gfx mailing list<br>
amd-gfx@lists.freedesktop.org<br>
<a href="https://lists.freedesktop.org/mailman/listinfo/amd-gfx">https://lists.freedesktop.org/mailman/listinfo/amd-gfx</a></div>
</span></font></div>
</body>
</html>