drm/amdgpu: use HMM mirror callback to replace mmu notifier (v2)
Subsystems (2)
PATCH 1/1 drm/amdgpu: use HMM mirror callback to replace mmu notifier (v2)
Replace our MMU notifier with hmm_mirror_ops.sync_cpu_device_pagetables callback. Enable CONFIG_HMM and CONFIG_HMM_MIRROR as a dependency in DRM_AMDGPU_USERPTR Kconfig.
It supports both KFD userptr and gfx userptr paths.
This depends on several HMM patchset from Jérôme Glisse queued for upstream. See
http://172.27.226.38/root/kernel_amd/commits/hmm-dev-v01 (for AMD intranet)
--- drivers/gpu/drm/amd/amdgpu/Kconfig | 6 +-- drivers/gpu/drm/amd/amdgpu/Makefile | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c | 78 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.h | 41 +++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c | 50 ++++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_mn.h | 7 +++ 6 files changed, 178 insertions(+), 5 deletions(-) create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.h
drivers/gpu/drm/amd/amdgpu/Kconfig +3 -3
@@ -26,10 +26,10 @@ config DRM_AMDGPU_CIK config DRM_AMDGPU_USERPTR bool "Always enable userptr write support" depends on DRM_AMDGPU - select MMU_NOTIFIER + select HMM_MIRROR help - This option selects CONFIG_MMU_NOTIFIER if it isn't already - selected to enabled full userptr support. + This option selects CONFIG_HMM and CONFIG_HMM_MIRROR if it + isn't already selected to enabled full userptr support. config DRM_AMDGPU_GART_DEBUGFS bool "Allow GART access through debugfs"
drivers/gpu/drm/amd/amdgpu/Makefile +1 -0
@@ -172,6 +172,7 @@ amdgpu-$(CONFIG_COMPAT) += amdgpu_ioc32.o amdgpu-$(CONFIG_VGA_SWITCHEROO) += amdgpu_atpx_handler.o amdgpu-$(CONFIG_ACPI) += amdgpu_acpi.o amdgpu-$(CONFIG_MMU_NOTIFIER) += amdgpu_mn.o +amdgpu-$(CONFIG_HMM) += amdgpu_hmm.o include $(FULL_AMD_PATH)/powerplay/Makefile
drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c new file +78 -0
78 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.h new file +41 -0
41 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c +48 -2
91 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_mn.h +7 -0
@@ -28,6 +28,7 @@* MMU Notifier */ struct amdgpu_mn ; +struct hmm_mirror ;enum amdgpu_mn_type {AMDGPU_MN_TYPE_GFX ,
@@ -41,6 +42,12 @@ struct amdgpu_mn *amdgpu_mn_get(struct amdgpu_device *adev, enum amdgpu_mn_type type);int amdgpu_mn_register (struct amdgpu_bo *bo,unsigned long addr);void amdgpu_mn_unregister (struct amdgpu_bo *bo); +int amdgpu_mn_invalidate_range (struct hmm_mirror *mirror, +struct mm_struct *mm, +unsigned long start, +unsigned long end, +bool blockable); +void amdgpu_hmm_mn_release (struct hmm_mirror *mirror);#else static inline void amdgpu_mn_lock (struct amdgpu_mn *mn) {}static inline void amdgpu_mn_unlock (struct amdgpu_mn *mn) {}
Signature · 6 lines
2.7.4 _______________________________________________ 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): 1536789749-17213-1-git-send-email-Philip.Yang-5C7GfCeVMHo@public.gmane.org
Am 13.09.2018 um 00:02 schrieb Philip Yang:
Quoted 12 lines
Replace our MMU notifier with hmm_mirror_ops.sync_cpu_device_pagetables callback. Enable
CONFIG_HMMandCONFIG_HMM_MIRRORas a dependency inDRM_AMDGPU_USERPTRKconfig.It supports both KFD userptr and gfx userptr paths.
This depends on several HMM patchset from Jérôme Glisse queued for upstream. See
http://172.27.226.38/root/kernel_amd/commits/hmm-dev-v01 (for AMD intranet)Change-Id Ie62c3c5e3c5b8521ab3b438d1eff2aa2a003835eSigned-off-by Philip Yang <[email protected]>
Quoted 7 lines
--- drivers/gpu/drm/amd/amdgpu/Kconfig | 6 +-- drivers/gpu/drm/amd/amdgpu/Makefile | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c | 78 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.h | 41 +++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c | 50 ++++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_mn.h | 7 +++
Please either fully merge amdgpu_mn.* into amdgpu_hmm.* or the other way around.
Additional to that you should add documentation to all newly added functions.
Regards,
Christian.
Quoted 281 lines
6 files changed, 178 insertions(+), 5 deletions(-)create mode 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.ccreate mode 100644drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.hdrivers/gpu/drm/amd/amdgpu/Kconfig +3
-3@@ -26,10 +26,10 @@ config DRM_AMDGPU_CIK config DRM_AMDGPU_USERPTR bool "Always enable userptr write support" depends on DRM_AMDGPU - select MMU_NOTIFIER + select HMM_MIRROR help - This option selects CONFIG_MMU_NOTIFIER if it isn't already - selected to enabled full userptr support. + This option selects CONFIG_HMM and CONFIG_HMM_MIRROR if it + isn't already selected to enabled full userptr support. config DRM_AMDGPU_GART_DEBUGFS bool "Allow GART access through debugfs"drivers/gpu/drm/amd/amdgpu/Makefile +1
-0@@ -172,6 +172,7 @@ amdgpu-$(CONFIG_COMPAT) += amdgpu_ioc32.o amdgpu-$(CONFIG_VGA_SWITCHEROO) += amdgpu_atpx_handler.o amdgpu-$(CONFIG_ACPI) += amdgpu_acpi.o amdgpu-$(CONFIG_MMU_NOTIFIER) += amdgpu_mn.o +amdgpu-$(CONFIG_HMM) += amdgpu_hmm.o include $(FULL_AMD_PATH)/powerplay/Makefiledrivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c new file +78
-0@@ -0,0 +1,78 @@ +/* +* Copyright 2018 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include <linux/mutex.h> +#include <linux/slab.h> +#include <linux/notifier.h> +#include <linux/compat.h> +#include <linux/mman.h> +#include <linux/hmm.h> +#include <asm/page.h> +#include "amdgpu.h" +#include "amdgpu_mn.h" + +static void amdgpu_hmm_release (struct hmm_mirror *mirror) +{ +pr_debug ("mirror=%p\n" , mirror); +amdgpu_hmm_mn_release (mirror); +} + +static int amdgpu_hmm_sync_cpu_device_pagetables (struct hmm_mirror *mirror, +const struct hmm_update *update) +{ +struct hmm *hmm; +struct mm_struct *mm; +unsigned long start; +unsigned long end; + + start = update->start; + end = update->end; + +pr_debug ("mirror %p start %lx end %lx\n" , mirror, start, end); + + hmm = mirror->hmm; + mm = *(struct mm_struct **)hmm; + +return amdgpu_mn_invalidate_range (mirror, mm, start, end, + update->blockable); +} + +static struct hmm_mirror_ops amdgpu_hmm_mirror_ops = { + .sync_cpu_device_pagetables = amdgpu_hmm_sync_cpu_device_pagetables, + .release = amdgpu_hmm_release +}; + +int amdgpu_hmm_register (struct hmm_mirror *mirror,struct mm_struct *mm) +{ +pr_debug ("mirror=%p\n" , mirror); + + mirror->ops = &amdgpu_hmm_mirror_ops; + +return hmm_mirror_register (mirror, mm); +} + +void amdgpu_hmm_unregister (struct hmm_mirror *mirror) +{ +pr_debug ("mirror=%p\n" , mirror); + +hmm_mirror_unregister (mirror); +}drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.h new file +41
-0@@ -0,0 +1,41 @@ +/* +* Copyright 2018 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifndef __AMDGPU_HMM_H__ +#define __AMDGPU_HMM_H__ + +#include <linux/mm.h> +#include <linux/hmm.h> + +#if IS_ENABLED (CONFIG_HMM ) + +int amdgpu_hmm_register (struct hmm_mirror *mirror,struct mm_struct *mm); +void amdgpu_hmm_unregister (struct hmm_mirror *mirror); + +#else + +#define amdgpu_hmm_register (x, y) (0) +#define amdgpu_hmm_unregister (x) + +#endif + +#endif drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c +48
-2@@ -47,11 +47,13 @@#include <linux/module.h> #include <linux/mmu_notifier.h> #include <linux/interval_tree.h> +#include <linux/hmm.h> #include <drm/drmP.h> #include <drm/drm.h> #include "amdgpu.h" #include "amdgpu_amdkfd.h" +#include "amdgpu_hmm.h" /** * struct amdgpu_mn @@ -66,6 +68,7 @@* @objects: interval tree containing amdgpu_mn_nodes * @read_lock: mutex for recursive locking of @lock * @recursion: depth of recursion +* @hmm_mirror: HMM mirror function support * * Data for each amdgpu device and process address space. */ @@ -87,6 +90,9 @@ struct amdgpu_mn {struct rb_root_cached objects;struct mutex read_lock;atomic_t recursion; + +/* HMM mirror */ +struct hmm_mirror hmm_mirror; };/** @@ -129,7 +135,9 @@ static void amdgpu_mn_destroy(struct work_struct *work) }up_write (&amn->lock);mutex_unlock (&adev->mn_lock); -mmu_notifier_unregister_no_release (&amn->mn, amn->mm); + +amdgpu_hmm_unregister (&amn->hmm_mirror); +kfree (amn); }@@ -372,6 +380,44 @@ static const struct mmu_notifier_ops amdgpu_mn_ops[] = {*/ #define AMDGPU_MN_KEY (mm, type) ((unsigned long)(mm) + (type)) +void amdgpu_hmm_mn_release (struct hmm_mirror *mirror) +{ +struct amdgpu_mn *amn; + + amn = container_of(mirror, struct amdgpu_mn, hmm_mirror); + +amdgpu_mn_release (&amn->mn, amn->mm); +} + +int amdgpu_mn_invalidate_range (struct hmm_mirror *mirror, +struct mm_struct *mm, +unsigned long start, +unsigned long end, +bool blockable) + +{ +unsigned long key; +struct amdgpu_mn *amn; +int r =0 ; + + amn = container_of(mirror, struct amdgpu_mn, hmm_mirror); + key =AMDGPU_MN_KEY (mm, amn->type); + +hash_for_each_possible (amn->adev->mn_hash, amn, node, key) +if (AMDGPU_MN_KEY (amn->mm, amn->type) == key) { + r = amn->mn.ops->invalidate_range_start (&amn->mn, mm, + start, end, blockable); + amn->mn.ops->invalidate_range_end (&amn->mn, mm, + start, end); +if (r) { +DRM_ERROR ("failed to invalidate %lx\n" , start); +break ; + } + } + +return r; +} +/** * amdgpu_mn_get - create notifier context * @@ -413,7 +459,7 @@ struct amdgpu_mn *amdgpu_mn_get(struct amdgpu_device *adev,mutex_init (&amn->read_lock);atomic_set (&amn->recursion,0 ); - r =__mmu_notifier_register (&amn->mn, mm); + r =amdgpu_hmm_register (&amn->hmm_mirror, mm);if (r) goto free_amn;drivers/gpu/drm/amd/amdgpu/amdgpu_mn.h +1
-0@@ -28,6 +28,7 @@* MMU Notifier */ struct amdgpu_mn ; +struct hmm_mirror ;enum amdgpu_mn_type {AMDGPU_MN_TYPE_GFX ,@@ -41,6 +42,12 @@ struct amdgpu_mn *amdgpu_mn_get(struct amdgpu_device *adev, enum amdgpu_mn_type type);int amdgpu_mn_register (struct amdgpu_bo *bo,unsigned long addr);
drivers/gpu/drm/amd/amdgpu/amdgpu_mn.h struct amdgpu_mn *amdgpu_mn_get(struct amdgpu_device *adev, · line 53
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_mn.h +6
-0void amdgpu_mn_unregister (struct amdgpu_bo *bo); +int amdgpu_mn_invalidate_range (struct hmm_mirror *mirror, +struct mm_struct *mm, +unsigned long start, +unsigned long end, +bool blockable); +void amdgpu_hmm_mn_release (struct hmm_mirror *mirror);#else static inline void amdgpu_mn_lock (struct amdgpu_mn *mn) {}static inline void amdgpu_mn_unlock (struct amdgpu_mn *mn) {}
_______________________________________________
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): 08ed8e11-902e-7b23-b797-0e655104ed72-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Quoted 22 lines · Christian König
Am 13.09.2018 um 00:02 schrieb Philip Yang:
Quoted 12 lines
Replace our MMU notifier with hmm_mirror_ops.sync_cpu_device_pagetables callback. Enable
CONFIG_HMMandCONFIG_HMM_MIRRORas a dependency inDRM_AMDGPU_USERPTRKconfig.It supports both KFD userptr and gfx userptr paths.
This depends on several HMM patchset from Jérôme Glisse queued for upstream. See
http://172.27.226.38/root/kernel_amd/commits/hmm-dev-v01 (for AMD intranet)Change-Id Ie62c3c5e3c5b8521ab3b438d1eff2aa2a003835eSigned-off-by Philip Yang <[email protected]>Quoted 8 lines
---
drivers/gpu/drm/amd/amdgpu/Kconfig | 6 +-- drivers/gpu/drm/amd/amdgpu/Makefile | 1 +drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c| 78
+++++++++++++++++++++++++++++++++
drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.h| 41 +++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c | 50 ++++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_mn.h | 7 +++
Quoted 2 lines
Please either fully merge amdgpu_mn.* into amdgpu_hmm.* or the other way around.
Agree, I will merge hmm changes and future hmm changes into amdgpu_mn.*. This will make things simpler.
Quoted 2 lines
Additional to that you should add documentation to all newly added functions.
I will submit new version v3 for review.
Regards,
Philip
Quoted 306 lines
Regards,
Christian.Quoted 303 lines
6 files changed, 178 insertions(+), 5 deletions(-)create mode 100644
drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.ccreate mode 100644drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.hdrivers/gpu/drm/amd/amdgpu/Kconfig +0
-0@@ -26,10 +26,10 @@ config DRM_AMDGPU_CIKconfig
DRM_AMDGPU_USERPTR
bool "Always enable userptr write support" depends onDRM_AMDGPU
- selectMMU_NOTIFIER
+ selectHMM_MIRROR
help
- This option selectsCONFIG_MMU_NOTIFIERif it isn't already - selected to enabled full userptr support.
+ This option selectsCONFIG_HMMandCONFIG_HMM_MIRRORif it + isn't already selected to enabled full userptr support. configDRM_AMDGPU_GART_DEBUGFS
bool "Allow GART access through debugfs"drivers/gpu/drm/amd/amdgpu/Makefile +0
-0@@ -172,6 +172,7 @@ amdgpu-$(CONFIG_COMPAT) += amdgpu_ioc32.oamdgpu-$(CONFIG_VGA_SWITCHEROO) += amdgpu_atpx_handler.o
amdgpu-$(CONFIG_ACPI) += amdgpu_acpi.o
amdgpu-$(CONFIG_MMU_NOTIFIER) += amdgpu_mn.o
+amdgpu-$(CONFIG_HMM) += amdgpu_hmm.o
include $(FULL_AMD_PATH)/powerplay/Makefile
diff --gita/drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.cnew file mode 100644
index 0000000..6c506f6drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c new file +4
-0@@ -0,0 +1,78 @@ +/* +* Copyright 2018 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c new file +18
-0+ +#include <linux/mutex.h> +#include <linux/slab.h> +#include <linux/notifier.h> +#include <linux/compat.h> +#include <linux/mman.h> +#include <linux/hmm.h> +#include <asm/page.h> +#include "amdgpu.h" +#include "amdgpu_mn.h" + +static void amdgpu_hmm_release (struct hmm_mirror *mirror) +{ + pr_debug("mirror=%p\n", mirror); + amdgpu_hmm_mn_release(mirror); +} + +static int amdgpu_hmm_sync_cpu_device_pagetables(struct hmm_mirror*mirror,
+ const structhmm_update*update)drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c new file +20
-0+{ + struct hmm *hmm; + struct mm_struct *mm; + unsigned long start; + unsigned long end; + + start = update->start; + end = update->end; + + pr_debug("mirror %p start %lx end %lx\n", mirror, start, end); + + hmm = mirror->hmm; + mm = *(struct mm_struct **)hmm; + + return amdgpu_mn_invalidate_range(mirror, mm, start, end, + update->blockable); +} + +static struct hmm_mirror_ops amdgpu_hmm_mirror_ops = { + .sync_cpu_device_pagetables =
amdgpu_hmm_sync_cpu_device_pagetables,
+ .release =amdgpu_hmm_releasedrivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c new file +3
-0+}; + +int amdgpu_hmm_register(struct hmm_mirror *mirror, struct mm_struct*mm)
drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c new file +14
-0+{ + pr_debug("mirror=%p\n", mirror); + + mirror->ops = &amdgpu_hmm_mirror_ops; + + return hmm_mirror_register(mirror, mm); +} + +void amdgpu_hmm_unregister (struct hmm_mirror *mirror) +{ + pr_debug("mirror=%p\n", mirror); + + hmm_mirror_unregister(mirror); +}drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.h new file +4
-0@@ -0,0 +1,41 @@ +/* +* Copyright 2018 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.h new file +10
-0+ +#ifndef __AMDGPU_HMM_H__ +#define __AMDGPU_HMM_H__ + +#include <linux/mm.h> +#include <linux/hmm.h> + +#if IS_ENABLED (CONFIG_HMM ) + +int amdgpu_hmm_register(struct hmm_mirror *mirror, struct mm_struct*mm);
drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.h new file +10
-0+void amdgpu_hmm_unregister (struct hmm_mirror *mirror); + +#else + +#define amdgpu_hmm_register (x, y) (0) +#define amdgpu_hmm_unregister (x) + +#endif + +#endif drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c +9
-1@@ -47,11 +47,13 @@ #include <linux/module.h> #include <linux/mmu_notifier.h> #include <linux/interval_tree.h> +#include <linux/hmm.h> #include <drm/drmP.h> #include <drm/drm.h> #include "amdgpu.h" #include "amdgpu_amdkfd.h" +#include "amdgpu_hmm.h" /*** struct amdgpu_mn @@ -66,6 +68,7 @@* @objects: interval tree containing amdgpu_mn_nodes * @read_lock: mutex for recursive locking of @lock * @recursion: depth of recursion +* @hmm_mirror: HMM mirror function support * * Data for each amdgpu device and process address space. */ @@ -87,6 +90,9 @@ struct amdgpu_mn { struct rb_root_cached objects; struct mutex read_lock; atomic_t recursion; + + /* HMM mirror */ + struct hmm_mirror hmm_mirror; }; /**@@ -129,7 +135,9 @@ static void amdgpu_mn_destroy(struct work_struct *work) } up_write(&amn->lock); mutex_unlock(&adev->mn_lock); - mmu_notifier_unregister_no_release(&amn->mn, amn->mm); + + amdgpu_hmm_unregister(&amn->hmm_mirror); + kfree(amn); }@@ -372,6 +380,44 @@ static const struct
mmu_notifier_opsamdgpu_mn_ops[] = { */
#defineAMDGPU_MN_KEY(mm, type)((unsigned long)(mm) + (type)) +voidamdgpu_hmm_mn_release(struct hmm_mirror *mirror)drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c +37
-0+{ + struct amdgpu_mn *amn; + + amn = container_of(mirror, struct amdgpu_mn, hmm_mirror); + + amdgpu_mn_release(&amn->mn, amn->mm); +} + +int amdgpu_mn_invalidate_range (struct hmm_mirror *mirror, + struct mm_struct *mm, + unsigned long start, + unsigned long end, + bool blockable) + +{ + unsigned long key; + struct amdgpu_mn *amn; + int r = 0; + + amn = container_of(mirror, struct amdgpu_mn, hmm_mirror); + key = AMDGPU_MN_KEY(mm, amn->type); + + hash_for_each_possible(amn->adev->mn_hash, amn, node, key) + if (AMDGPU_MN_KEY(amn->mm, amn->type) == key) { + r = amn->mn.ops->invalidate_range_start(&amn->mn, mm, + start, end, blockable); + amn->mn.ops->invalidate_range_end (&amn->mn, mm, + start, end); + if (r) { + DRM_ERROR("failed to invalidate %lx\n", start); + break; + } + } + + return r; +} +/**
*amdgpu_mn_get- create notifier context
*drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c +1
-0@@ -413,7 +459,7 @@ struct amdgpu_mn *amdgpu_mn_get(structamdgpu_device *adev, mutex_init(&amn->read_lock); atomic_set(&amn->recursion, 0); - r = __mmu_notifier_register(&amn->mn, mm); + r = amdgpu_hmm_register(&amn->hmm_mirror, mm); if (r) goto free_amn;diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.hb/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.hindex eb0f432..e7781db 100644drivers/gpu/drm/amd/amdgpu/amdgpu_mn.h +2
-0@@ -28,6 +28,7 @@* MMU Notifier */ struct amdgpu_mn; +struct hmm_mirror ; enum amdgpu_mn_type { AMDGPU_MN_TYPE_GFX,@@ -41,6 +42,12 @@ struct amdgpu_mn *amdgpu_mn_get(struct amdgpu_device *adev, enum amdgpu_mn_type type); int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr); void amdgpu_mn_unregister(struct amdgpu_bo *bo); +int amdgpu_mn_invalidate_range(struct hmm_mirror *mirror,
Quoted 9 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_mn.h +5
-0+ struct mm_struct *mm, + unsigned long start, + unsigned long end, + bool blockable); +void amdgpu_hmm_mn_release (struct hmm_mirror *mirror); #else static inline void amdgpu_mn_lock(struct amdgpu_mn *mn) {}static inline void
amdgpu_mn_unlock(struct amdgpu_mn *mn){}
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx