drm/amdgpu: drm/amdkfd: split amdgpu_mn_register
Subsystems (4)
PATCH 1/3 drm/amdgpu: drm/amdkfd: split amdgpu_mn_register
Split amdgpu_mn_register() into two functions to avoid unnecessary bo->kfd_bo check.
--- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c | 21 +++++++++++++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_mn.h | 8 +++++++ 3 files changed, 26 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1 -1
@@ -571,7 +571,7 @@ static int init_user_pages(struct kgd_mem *mem, uint64_t user_addr) goto out; } - ret =amdgpu_mn_register (bo, user_addr); + ret =amdgpu_mn_register_hsa (bo, user_addr);if (ret) {pr_err ("%s: Failed to register MMU notifier: %d\n" , __func__, ret);
drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c +17 -4
@@ -132,15 +132,28 @@ static const struct mmu_interval_notifier_ops amdgpu_mn_hsa_ops = {*/ int amdgpu_mn_register (struct amdgpu_bo *bo,unsigned long addr) { -if (bo->kfd_bo) -return mmu_interval_notifier_insert (&bo->notifier, current->mm, - addr,amdgpu_bo_size (bo), - &amdgpu_mn_hsa_ops);return mmu_interval_notifier_insert (&bo->notifier, current->mm, addr,amdgpu_bo_size (bo), &amdgpu_mn_gfx_ops); } +/** +* amdgpu_mn_register_hsa - register a BO for notifier updates +* +* @bo: amdgpu buffer object +* @addr: userptr addr we should monitor +* +* Registers a mmu_notifier for the given kfd BO at the specified address. +* Returns 0 on success, -ERRNO if anything goes wrong. +*/ + +int amdgpu_mn_register_hsa (struct amdgpu_bo *bo,unsigned long addr) +{ +return mmu_interval_notifier_insert (&bo->notifier, current->mm, addr, +amdgpu_bo_size (bo), + &amdgpu_mn_hsa_ops); +} +/** * amdgpu_mn_unregister - unregister a BO for notifier updates *
drivers/gpu/drm/amd/amdgpu/amdgpu_mn.h +8 -0
@@ -32,6 +32,7 @@#if defined(CONFIG_HMM_MIRROR )int amdgpu_mn_register (struct amdgpu_bo *bo,unsigned long addr); +int amdgpu_mn_register_hsa (struct amdgpu_bo *bo,unsigned long addr);void amdgpu_mn_unregister (struct amdgpu_bo *bo);#else static inline int amdgpu_mn_register (struct amdgpu_bo *bo,unsigned long addr)
@@ -40,6 +41,13 @@ static inline int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr) "add CONFIG_ZONE_DEVICE=y in config file to fix this\n"); return -ENODEV; } + +static inline int amdgpu_mn_register_hsa (struct amdgpu_bo *bo,unsigned long addr) +{ +DRM_WARN_ONCE ("HMM_MIRROR kernel config option is not enabled, " +"add CONFIG_ZONE_DEVICE=y in config file to fix this\n" ); +return -ENODEV ; +}static inline void amdgpu_mn_unregister (struct amdgpu_bo *bo) {}#endif
Signature · 6 lines
2.30.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 2/3 drm/amdgpu: introduce kfd user flag for amdgpu_bo
Introduce a new flag for amdgpu_bo->flags to identify if a BO is created by KFD.
--- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 48 ++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 3 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +- include/uapi/drm/amdgpu_drm.h | 5 ++ 6 files changed, 59 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1 -1
@@ -1227,7 +1227,7 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu( bp.flags = alloc_flags; bp.type = bo_type; bp.resv =NULL ; - ret =amdgpu_bo_create (adev, &bp, &bo); + ret =amdgpu_kfd_bo_create (adev, &bp, &bo);if (ret) {pr_debug ("Failed to create BO on domain %s. ret %d\n" ,domain_string (alloc_domain), ret);
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -1
@@ -234,7 +234,8 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,AMDGPU_GEM_CREATE_VRAM_CLEARED |AMDGPU_GEM_CREATE_VM_ALWAYS_VALID |AMDGPU_GEM_CREATE_EXPLICIT_SYNC | - AMDGPU_GEM_CREATE_ENCRYPTED)) +AMDGPU_GEM_CREATE_ENCRYPTED | + AMDGPU_GEM_USER_KFD)) return -EINVAL;
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +47 -1
60 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +3 -0
@@ -245,6 +245,9 @@ void amdgpu_bo_placement_from_domain(struct amdgpu_bo *abo, u32 domain);int amdgpu_bo_create (struct amdgpu_device *adev,struct amdgpu_bo_param *bp,struct amdgpu_bo **bo_ptr); +int amdgpu_kfd_bo_create (struct amdgpu_device *adev, +struct amdgpu_bo_param *bp, +struct amdgpu_bo **bo_ptr); int amdgpu_bo_create_reserved(struct amdgpu_device *adev, unsigned long size, int align, u32 domain, struct amdgpu_bo **bo_ptr,
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -1
@@ -164,7 +164,7 @@ static int amdgpu_verify_access(struct ttm_buffer_object *bo, struct file *filp)* Don't verify access for KFD BOs. They don't have a GEM * object associated with them. */ -if (abo->kfd_bo) +if (abo->flags &AMDGPU_GEM_USER_KFD )return 0 ;if (amdgpu_ttm_tt_get_usermm (bo->ttm))
include/uapi/drm/amdgpu_drm.h +5 -0
@@ -142,6 +142,11 @@ extern "C" {*/ #define AMDGPU_GEM_CREATE_ENCRYPTED (1 << 10) +/* Flag that the allocating BO's user is KFD. It should never be used by +* user space applications +*/ +#define AMDGPU_GEM_USER_KFD (1 << 20) +struct drm_amdgpu_gem_create_in {/** the requested memory size */ __u64 bo_size;
Signature · 6 lines
2.30.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Christian König
maintainerRe: [PATCH 2/3] drm/amdgpu: introduce kfd user flag for amdgpu_bo
Am 02.03.21 um 12:33 schrieb Nirmoy Das:
Quoted 31 lines
Introduce a new flag for
amdgpu_bo->flagsto identify if a BO is created by KFD.Signed-off-by Nirmoy Das <[email protected]>--- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 48 ++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 3 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +- include/uapi/drm/amdgpu_drm.h | 5 ++ 6 files changed, 59 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1
-1@@ -1227,7 +1227,7 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu( bp.flags = alloc_flags; bp.type = bo_type; bp.resv =NULL ; - ret =amdgpu_bo_create (adev, &bp, &bo); + ret =amdgpu_kfd_bo_create (adev, &bp, &bo);if (ret) {pr_debug ("Failed to create BO on domain %s. ret %d\n" ,domain_string (alloc_domain), ret);drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data, · line 238
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2
-1@@ -234,7 +234,8 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,AMDGPU_GEM_CREATE_VRAM_CLEARED |AMDGPU_GEM_CREATE_VM_ALWAYS_VALID |AMDGPU_GEM_CREATE_EXPLICIT_SYNC | - AMDGPU_GEM_CREATE_ENCRYPTED)) +AMDGPU_GEM_CREATE_ENCRYPTED | + AMDGPU_GEM_USER_KFD))
Please stick with the naming here. And why _USER_KFD and not just _KFD?
Christian.
Quoted 102 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0
-0return -EINVAL ;drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +47
-1@@ -697,6 +697,52 @@ int amdgpu_bo_create(struct amdgpu_device *adev,return r; } +/** +* amdgpu_kfd_bo_create - create an &amdgpu_bo buffer object with kfd user flag +* @adev: amdgpu device object +* @bp: parameters to be used for the buffer object +* @bo_ptr: pointer to the buffer object pointer +* +* Creates an &amdgpu_bo buffer object; and if requested, also creates a +* shadow object. +* Shadow object is used to backup the original buffer object, and is always +* in GTT. +* +* Returns: +* 0 for success or a negative error code on failure. +*/ + +int amdgpu_kfd_bo_create (struct amdgpu_device *adev, +struct amdgpu_bo_param *bp, +struct amdgpu_bo **bo_ptr) +{ +u64 flags = bp->flags; +int r; + + bp->flags = bp->flags & ~AMDGPU_GEM_CREATE_SHADOW ; + bp->flags = bp->flags |AMDGPU_GEM_USER_KFD ; + r =amdgpu_bo_do_create (adev, bp, bo_ptr); +if (r) +return r; + +if ((flags &AMDGPU_GEM_CREATE_SHADOW ) && !(adev->flags &AMD_IS_APU )) { +if (!bp->resv) +WARN_ON (dma_resv_lock ((*bo_ptr)->tbo.base.resv, +NULL )); + + r =amdgpu_bo_create_shadow (adev, bp->size, *bo_ptr); + +if (!bp->resv) +dma_resv_unlock ((*bo_ptr)->tbo.base.resv); + +if (r) +amdgpu_bo_unref (bo_ptr); + } + +return r; +} + +/** * amdgpu_bo_validate - validate an &amdgpu_bo buffer object * @bo: pointer to the buffer object @@ -1309,7 +1355,7 @@ void amdgpu_bo_release_notify(struct ttm_buffer_object *bo) abo =ttm_to_amdgpu_bo (bo); -if (abo->kfd_bo) +if (abo->flags &AMDGPU_GEM_USER_KFD )amdgpu_amdkfd_unreserve_memory_limit (abo);/* We only remove the fence if the resv has individualized. */ drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +3
-0@@ -245,6 +245,9 @@ void amdgpu_bo_placement_from_domain(struct amdgpu_bo *abo, u32 domain);int amdgpu_bo_create (struct amdgpu_device *adev,struct amdgpu_bo_param *bp,struct amdgpu_bo **bo_ptr); +int amdgpu_kfd_bo_create (struct amdgpu_device *adev, +struct amdgpu_bo_param *bp, +struct amdgpu_bo **bo_ptr); int amdgpu_bo_create_reserved(struct amdgpu_device *adev, unsigned long size, int align, u32 domain, struct amdgpu_bo **bo_ptr,drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1
-1@@ -164,7 +164,7 @@ static int amdgpu_verify_access(struct ttm_buffer_object *bo, struct file *filp)* Don't verify access for KFD BOs. They don't have a GEM * object associated with them. */ -if (abo->kfd_bo) +if (abo->flags &AMDGPU_GEM_USER_KFD )return 0 ;if (amdgpu_ttm_tt_get_usermm (bo->ttm))include/uapi/drm/amdgpu_drm.h +0
-0@@ -142,6 +142,11 @@ extern "C" {*/
include/uapi/drm/amdgpu_drm.h extern "C" { · line 152
Quoted 10 lines
include/uapi/drm/amdgpu_drm.h +5
-0#define AMDGPU_GEM_CREATE_ENCRYPTED (1 << 10) +/* Flag that the allocating BO's user is KFD. It should never be used by +* user space applications +*/ +#define AMDGPU_GEM_USER_KFD (1 << 20) +struct drm_amdgpu_gem_create_in {/** the requested memory size */ __u64 bo_size;
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH 2/3] drm/amdgpu: introduce kfd user flag for amdgpu_bo
Quoted 35 lines · Christian König
Am 02.03.21 um 12:33 schrieb Nirmoy Das:
Quoted 32 lines
Introduce a new flag for
amdgpu_bo->flagsto identify if a BO is created by KFD.Signed-off-by Nirmoy Das <[email protected]>---
.../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 48 ++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 3 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +- include/uapi/drm/amdgpu_drm.h | 5 ++6 files changed, 59 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1
-1@@ -1227,7 +1227,7 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu( bp.flags = alloc_flags; bp.type = bo_type; bp.resv = NULL; - ret = amdgpu_bo_create(adev, &bp, &bo); + ret = amdgpu_kfd_bo_create(adev, &bp, &bo); if (ret) { pr_debug("Failed to create BO on domain %s. ret %d\n", domain_string(alloc_domain), ret);drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0
-0@@ -234,7 +234,8 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
Quoted 8 lines
Quoted 6 lines
AMDGPU_GEM_CREATE_VRAM_CLEARED|AMDGPU_GEM_CREATE_VM_ALWAYS_VALID|AMDGPU_GEM_CREATE_EXPLICIT_SYNC| -AMDGPU_GEM_CREATE_ENCRYPTED)) +AMDGPU_GEM_CREATE_ENCRYPTED| +AMDGPU_GEM_USER_KFD))Please stick with the naming here. And why
_USER_KFDand not just_KFD?
Ok, I will rename it to AMDGPU_GEM_KFD which sounds much better.
Thanks,
Nirmoy
Quoted 107 lines
Christian.
Quoted 103 lines
return
-EINVAL;
diff --gita/drivers/gpu/drm/amd/amdgpu/amdgpu_object.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_object.cindex0bd22ed1dacf..5ebce6d6784a100644drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0@@ -697,6 +697,52 @@ int amdgpu_bo_create(struct amdgpu_device *adev, return r; }+/**
+ *amdgpu_kfd_bo_create- create an&amdgpu_bobuffer object with kfd user flag
+ * @adev: amdgpu device object
+ * @bp: parameters to be used for the buffer object
+ * @bo_ptr: pointer to the buffer object pointer
+ *
+ * Creates an&amdgpu_bobuffer object; and if requested, also creates a
+ * shadow object.
+ * Shadow object is used to backup the original buffer object, and is always
+ * in GTT.
+ *
+ * Returns:
+ * 0 for success or a negative error code on failure.
+ */drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +15
-0+ +int amdgpu_kfd_bo_create (struct amdgpu_device *adev, + struct amdgpu_bo_param *bp, + struct amdgpu_bo **bo_ptr) +{ + u64 flags = bp->flags; + int r; + + bp->flags = bp->flags & ~AMDGPU_GEM_CREATE_SHADOW; + bp->flags = bp->flags | AMDGPU_GEM_USER_KFD; + r = amdgpu_bo_do_create(adev, bp, bo_ptr); + if (r) + return r; + + if ((flags & AMDGPU_GEM_CREATE_SHADOW) && !(adev->flags &
AMD_IS_APU)) {
+ if (!bp->resv)
+ WARN_ON(dma_resv_lock((*bo_ptr)->tbo.base.resv, + NULL));drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +14
-0+ + r = amdgpu_bo_create_shadow(adev, bp->size, *bo_ptr); + + if (!bp->resv) + dma_resv_unlock((*bo_ptr)->tbo.base.resv); + + if (r) + amdgpu_bo_unref(bo_ptr); + } + + return r; +} + +/**
*amdgpu_bo_validate- validate an&amdgpu_bobuffer object
* @bo: pointer to the buffer objectdrivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1
-0@@ -1309,7 +1355,7 @@ void amdgpu_bo_release_notify(struct ttm_buffer_object *bo) abo = ttm_to_amdgpu_bo(bo); - if (abo->kfd_bo) + if (abo->flags & AMDGPU_GEM_USER_KFD) amdgpu_amdkfd_unreserve_memory_limit(abo); /* We only remove the fence if the resv has individualized. */drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +3
-0@@ -245,6 +245,9 @@ void amdgpu_bo_placement_from_domain(struct amdgpu_bo *abo, u32 domain); int amdgpu_bo_create(struct amdgpu_device *adev, struct amdgpu_bo_param *bp, struct amdgpu_bo **bo_ptr); +int amdgpu_kfd_bo_create (struct amdgpu_device *adev, + struct amdgpu_bo_param *bp, + struct amdgpu_bo **bo_ptr); int amdgpu_bo_create_reserved(struct amdgpu_device *adev, unsigned long size, int align,u32 domain, struct
amdgpu_bo**bo_ptr,drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1
-1@@ -164,7 +164,7 @@ static int amdgpu_verify_access(structttm_buffer_object *bo, struct file *filp) * Don't verify access for KFD BOs. They don't have a GEM * object associated with them. */ - if (abo->kfd_bo) + if (abo->flags & AMDGPU_GEM_USER_KFD) return 0; if (amdgpu_ttm_tt_get_usermm(bo->ttm))include/uapi/drm/amdgpu_drm.h +0
-0@@ -142,6 +142,11 @@ extern "C" {*/ #define AMDGPU_GEM_CREATE_ENCRYPTED (1 << 10)
Quoted 9 lines
Quoted 8 lines
+/* Flag that the allocating BO's user is KFD. It should never be used by
+ * user space applications
+ */include/uapi/drm/amdgpu_drm.h +2
-0+#define AMDGPU_GEM_USER_KFD (1 << 20) +struct drm_amdgpu_gem_create_in {
/** the requested memory size */
__u64bo_size;
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Christian König
maintainerRe: [PATCH 2/3] drm/amdgpu: introduce kfd user flag for amdgpu_bo
Am 02.03.21 um 14:01 schrieb Nirmoy:
Quoted 47 lines · Christian König
Quoted 36 lines
Am 02.03.21 um 12:33 schrieb Nirmoy Das:
Quoted 33 lines
Introduce a new flag for
amdgpu_bo->flagsto identify if a BO is created by KFD.Signed-off-by Nirmoy Das <[email protected]>---
.../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 48
++++++++++++++++++-
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 3 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +- include/uapi/drm/amdgpu_drm.h | 5 ++6 files changed, 59 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1
-1@@ -1227,7 +1227,7 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu( bp.flags = alloc_flags; bp.type = bo_type; bp.resv = NULL; - ret = amdgpu_bo_create(adev, &bp, &bo); + ret = amdgpu_kfd_bo_create(adev, &bp, &bo); if (ret) { pr_debug("Failed to create BO on domain %s. ret %d\n", domain_string(alloc_domain), ret);drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0
-0@@ -234,7 +234,8 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,Quoted 8 lines
Quoted 6 lines
AMDGPU_GEM_CREATE_VRAM_CLEARED|AMDGPU_GEM_CREATE_VM_ALWAYS_VALID|AMDGPU_GEM_CREATE_EXPLICIT_SYNC| -AMDGPU_GEM_CREATE_ENCRYPTED)) +AMDGPU_GEM_CREATE_ENCRYPTED| +AMDGPU_GEM_USER_KFD))Please stick with the naming here. And why
_USER_KFDand not just_KFD?
Quoted 1 line
Ok, I will rename it to
AMDGPU_GEM_KFDwhich sounds much better.
No. When you want to use those flags you should probably call this AMDGPU_GEM_CREATE_KFD.
Christian.
Quoted 122 lines
Thanks,
Nirmoy
Quoted 116 lines
Christian.
Quoted 111 lines
return
-EINVAL;
diff --gita/drivers/gpu/drm/amd/amdgpu/amdgpu_object.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_object.cindex0bd22ed1dacf..5ebce6d6784a100644drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0@@ -697,6 +697,52 @@ int amdgpu_bo_create(struct amdgpu_device *adev, return r; }+/**
+ *amdgpu_kfd_bo_create- create an&amdgpu_bobuffer object with kfd user flag
+ * @adev: amdgpu device object
+ * @bp: parameters to be used for the buffer object
+ * @bo_ptr: pointer to the buffer object pointer
+ *
+ * Creates an&amdgpu_bobuffer object; and if requested, also creates a
+ * shadow object.
+ * Shadow object is used to backup the original buffer object, and is always
+ * in GTT.
+ *
+ * Returns:
+ * 0 for success or a negative error code on failure.
+ */drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +15
-0+ +int amdgpu_kfd_bo_create (struct amdgpu_device *adev, + struct amdgpu_bo_param *bp, + struct amdgpu_bo **bo_ptr) +{ + u64 flags = bp->flags; + int r; + + bp->flags = bp->flags & ~AMDGPU_GEM_CREATE_SHADOW; + bp->flags = bp->flags | AMDGPU_GEM_USER_KFD; + r = amdgpu_bo_do_create(adev, bp, bo_ptr); + if (r) + return r; + + if ((flags & AMDGPU_GEM_CREATE_SHADOW) && !(adev->flags &
AMD_IS_APU)) {
+ if (!bp->resv)
+ WARN_ON(dma_resv_lock((*bo_ptr)->tbo.base.resv,
+ NULL));drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +14
-0+ + r = amdgpu_bo_create_shadow(adev, bp->size, *bo_ptr); + + if (!bp->resv) + dma_resv_unlock((*bo_ptr)->tbo.base.resv); + + if (r) + amdgpu_bo_unref(bo_ptr); + } + + return r; +} + +/**
*amdgpu_bo_validate- validate an&amdgpu_bobuffer object
* @bo: pointer to the buffer objectdrivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1
-0@@ -1309,7 +1355,7 @@ void amdgpu_bo_release_notify(struct ttm_buffer_object *bo) abo = ttm_to_amdgpu_bo(bo); - if (abo->kfd_bo) + if (abo->flags & AMDGPU_GEM_USER_KFD) amdgpu_amdkfd_unreserve_memory_limit(abo); /* We only remove the fence if the resv has individualized. */drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +3
-0@@ -245,6 +245,9 @@ void amdgpu_bo_placement_from_domain(struct amdgpu_bo *abo, u32 domain); int amdgpu_bo_create(struct amdgpu_device *adev, struct amdgpu_bo_param *bp, struct amdgpu_bo **bo_ptr); +int amdgpu_kfd_bo_create (struct amdgpu_device *adev, + struct amdgpu_bo_param *bp, + struct amdgpu_bo **bo_ptr); int amdgpu_bo_create_reserved(struct amdgpu_device *adev, unsigned long size, int align,u32 domain, struct
amdgpu_bo**bo_ptr,drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1
-1@@ -164,7 +164,7 @@ static int amdgpu_verify_access(structttm_buffer_object *bo, struct file *filp) * Don't verify access for KFD BOs. They don't have a GEM * object associated with them. */ - if (abo->kfd_bo) + if (abo->flags & AMDGPU_GEM_USER_KFD) return 0; if (amdgpu_ttm_tt_get_usermm(bo->ttm))include/uapi/drm/amdgpu_drm.h +0
-0@@ -142,6 +142,11 @@ extern "C" {*/ #define AMDGPU_GEM_CREATE_ENCRYPTED (1 << 10)+/* Flag that the allocating BO's user is KFD. It should never be used by
+ * user space applications
+ */include/uapi/drm/amdgpu_drm.h +2
-0+#define AMDGPU_GEM_USER_KFD (1 << 20) +struct drm_amdgpu_gem_create_in {
/** the requested memory size */
__u64bo_size;
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH 2/3] drm/amdgpu: introduce kfd user flag for amdgpu_bo
Quoted 48 lines · Christian König
Am 02.03.21 um 14:01 schrieb Nirmoy:
Quoted 47 lines · Christian König
Quoted 44 lines
Am 02.03.21 um 12:33 schrieb Nirmoy Das:
Quoted 33 lines
Introduce a new flag for
amdgpu_bo->flagsto identify if a BO is created by KFD.Signed-off-by Nirmoy Das <[email protected]>---
.../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 48
++++++++++++++++++-
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 3 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +- include/uapi/drm/amdgpu_drm.h | 5 ++6 files changed, 59 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1
-1@@ -1227,7 +1227,7 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu( bp.flags = alloc_flags; bp.type = bo_type; bp.resv = NULL; - ret = amdgpu_bo_create(adev, &bp, &bo); + ret = amdgpu_kfd_bo_create(adev, &bp, &bo); if (ret) { pr_debug("Failed to create BO on domain %s. ret %d\n", domain_string(alloc_domain), ret);drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0
-0@@ -234,7 +234,8 @@ int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,Quoted 6 lines
AMDGPU_GEM_CREATE_VRAM_CLEARED|AMDGPU_GEM_CREATE_VM_ALWAYS_VALID|AMDGPU_GEM_CREATE_EXPLICIT_SYNC| -AMDGPU_GEM_CREATE_ENCRYPTED)) +AMDGPU_GEM_CREATE_ENCRYPTED| +AMDGPU_GEM_USER_KFD))Please stick with the naming here. And why
_USER_KFDand not just_KFD?
Quoted 3 lines
Quoted 1 line
Ok, I will rename it to
AMDGPU_GEM_KFDwhich sounds much better.No. When you want to use those flags you should probably call this
AMDGPU_GEM_CREATE_KFD.
Ah I see.
Nirmoy
Quoted 126 lines
Christian.
Quoted 122 lines
Thanks,
Nirmoy
Quoted 116 lines
Christian.
Quoted 111 lines
return
-EINVAL;
diff --gita/drivers/gpu/drm/amd/amdgpu/amdgpu_object.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_object.cindex0bd22ed1dacf..5ebce6d6784a100644drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0@@ -697,6 +697,52 @@ int amdgpu_bo_create(struct amdgpu_device *adev, return r; }+/**
+ *amdgpu_kfd_bo_create- create an&amdgpu_bobuffer object with kfd user flag
+ * @adev: amdgpu device object
+ * @bp: parameters to be used for the buffer object
+ * @bo_ptr: pointer to the buffer object pointer
+ *
+ * Creates an&amdgpu_bobuffer object; and if requested, also creates a
+ * shadow object.
+ * Shadow object is used to backup the original buffer object, and is always
+ * in GTT.
+ *
+ * Returns:
+ * 0 for success or a negative error code on failure.
+ */drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +15
-0+ +int amdgpu_kfd_bo_create (struct amdgpu_device *adev, + struct amdgpu_bo_param *bp, + struct amdgpu_bo **bo_ptr) +{ + u64 flags = bp->flags; + int r; + + bp->flags = bp->flags & ~AMDGPU_GEM_CREATE_SHADOW; + bp->flags = bp->flags | AMDGPU_GEM_USER_KFD; + r = amdgpu_bo_do_create(adev, bp, bo_ptr); + if (r) + return r; + + if ((flags & AMDGPU_GEM_CREATE_SHADOW) && !(adev->flags &
AMD_IS_APU)) {
+ if (!bp->resv)
+ WARN_ON(dma_resv_lock((*bo_ptr)->tbo.base.resv,
+ NULL));drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +14
-0+ + r = amdgpu_bo_create_shadow(adev, bp->size, *bo_ptr); + + if (!bp->resv) + dma_resv_unlock((*bo_ptr)->tbo.base.resv); + + if (r) + amdgpu_bo_unref(bo_ptr); + } + + return r; +} + +/**
*amdgpu_bo_validate- validate an&amdgpu_bobuffer object
* @bo: pointer to the buffer objectdrivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1
-0@@ -1309,7 +1355,7 @@ void amdgpu_bo_release_notify(struct ttm_buffer_object *bo) abo = ttm_to_amdgpu_bo(bo); - if (abo->kfd_bo) + if (abo->flags & AMDGPU_GEM_USER_KFD) amdgpu_amdkfd_unreserve_memory_limit(abo); /* We only remove the fence if the resv has individualized. */drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +3
-0@@ -245,6 +245,9 @@ void amdgpu_bo_placement_from_domain(struct amdgpu_bo *abo, u32 domain); int amdgpu_bo_create(struct amdgpu_device *adev, struct amdgpu_bo_param *bp, struct amdgpu_bo **bo_ptr); +int amdgpu_kfd_bo_create (struct amdgpu_device *adev, + struct amdgpu_bo_param *bp, + struct amdgpu_bo **bo_ptr); int amdgpu_bo_create_reserved(struct amdgpu_device *adev, unsigned long size, int align,u32 domain, struct
amdgpu_bo**bo_ptr,drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1
-1@@ -164,7 +164,7 @@ static int amdgpu_verify_access(structttm_buffer_object *bo, struct file *filp) * Don't verify access for KFD BOs. They don't have a GEM * object associated with them. */ - if (abo->kfd_bo) + if (abo->flags & AMDGPU_GEM_USER_KFD) return 0; if (amdgpu_ttm_tt_get_usermm(bo->ttm))include/uapi/drm/amdgpu_drm.h +0
-0@@ -142,6 +142,11 @@ extern "C" {*/ #define AMDGPU_GEM_CREATE_ENCRYPTED (1 << 10)+/* Flag that the allocating BO's user is KFD. It should never be used by
+ * user space applications
+ */include/uapi/drm/amdgpu_drm.h +2
-0+#define AMDGPU_GEM_USER_KFD (1 << 20) +struct drm_amdgpu_gem_create_in {
/** the requested memory size */
__u64bo_size;
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 3/3 drm/amdgpu: drm/amdkfd: add amdgpu_kfd_bo struct
In reply to Nirmoy DasImplement a new struct based on amdgpu_bo base class for BOs created by kfd device so that kfd related memeber of amdgpu_bo can be moved there.
--- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 10 ++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 32 ++++++++++++++----- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 8 ++++- 4 files changed, 40 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +7 -3
@@ -1152,6 +1152,7 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(struct sg_table *sg =NULL ;uint64_t user_addr =0 ;struct amdgpu_bo *bo; +struct amdgpu_kfd_bo *kbo;struct amdgpu_bo_param bp;u32 domain, alloc_domain;u64 alloc_flags;
@@ -1227,17 +1228,20 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu( bp.flags = alloc_flags; bp.type = bo_type; bp.resv =NULL ; - ret =amdgpu_kfd_bo_create (adev, &bp, &bo); + ret =amdgpu_kfd_bo_create (adev, &bp, &kbo);if (ret) {pr_debug ("Failed to create BO on domain %s. ret %d\n" ,domain_string (alloc_domain), ret); goto err_bo_create; } + + bo = &kbo->bo;if (bo_type == ttm_bo_type_sg) { bo->tbo.sg = sg; bo->tbo.ttm->sg = sg; } - bo->kfd_bo = *mem; + + kbo->kfd_bo = *mem; (*mem)->bo = bo;if (user_addr) bo->flags |=AMDGPU_AMDKFD_USERPTR_BO ;
@@ -1261,7 +1265,7 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu( allocate_init_user_pages_failed:remove_kgd_mem_from_kfd_bo_list (*mem, avm->process_info); -amdgpu_bo_unref (&bo); +amdgpu_kfd_bo_unref (&kbo);/* Don't unreserve system mem limit twice */ goto err_reserve_limit; err_bo_create:
drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c +2 -1
@@ -102,6 +102,7 @@ static bool amdgpu_mn_invalidate_hsa(struct mmu_interval_notifier *mni, unsigned long cur_seq) { struct amdgpu_bo *bo = container_of(mni, struct amdgpu_bo, notifier); + struct amdgpu_kfd_bo *kbo = container_of(bo, struct amdgpu_kfd_bo, bo);struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev);if (!mmu_notifier_range_blockable (range))
@@ -111,7 +112,7 @@ static bool amdgpu_mn_invalidate_hsa(struct mmu_interval_notifier *mni,mmu_interval_set_seq (mni, cur_seq); -amdgpu_amdkfd_evict_userptr (bo->kfd_bo, bo->notifier.mm); +amdgpu_amdkfd_evict_userptr (kbo->kfd_bo, bo->notifier.mm);mutex_unlock (&adev->notifier_lock);return true;
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +24 -8
@@ -551,8 +551,10 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev, acc_size =ttm_bo_dma_acc_size (&adev->mman.bdev, size,sizeof (struct amdgpu_bo )); +if (bp->bo_ptr_size <sizeof (struct amdgpu_bo )) + bp->bo_ptr_size =sizeof (struct amdgpu_bo ); - bo =kzalloc (sizeof (struct amdgpu_bo ),GFP_KERNEL ); + bo =kzalloc (bp->bo_ptr_size,GFP_KERNEL );if (bo ==NULL )return -ENOMEM ;drm_gem_private_object_init (adev_to_drm (adev), &bo->tbo.base, size);
@@ -714,35 +716,37 @@ int amdgpu_bo_create(struct amdgpu_device *adev,int amdgpu_kfd_bo_create (struct amdgpu_device *adev,struct amdgpu_bo_param *bp, -struct amdgpu_bo **bo_ptr) +struct amdgpu_kfd_bo **kfd_bo_ptr) { +struct amdgpu_bo *bo_ptr;u64 flags = bp->flags;int r; bp->flags = bp->flags & ~AMDGPU_GEM_CREATE_SHADOW ; bp->flags = bp->flags |AMDGPU_GEM_USER_KFD ; - r =amdgpu_bo_do_create (adev, bp, bo_ptr); + bp->bo_ptr_size =sizeof (struct amdgpu_kfd_bo ); + r =amdgpu_bo_do_create (adev, bp, &bo_ptr);if (r)return r; + *kfd_bo_ptr = (struct amdgpu_kfd_bo *)bo_ptr;if ((flags &AMDGPU_GEM_CREATE_SHADOW ) && !(adev->flags &AMD_IS_APU )) {if (!bp->resv) -WARN_ON (dma_resv_lock ((*bo_ptr)->tbo.base.resv, +WARN_ON (dma_resv_lock ((*kfd_bo_ptr)->bo.tbo.base.resv,NULL )); - r =amdgpu_bo_create_shadow (adev, bp->size, *bo_ptr); + r =amdgpu_bo_create_shadow (adev, bp->size, &(*kfd_bo_ptr)->bo);if (!bp->resv) -dma_resv_unlock ((*bo_ptr)->tbo.base.resv); +dma_resv_unlock ((*kfd_bo_ptr)->bo.tbo.base.resv);if (r) -amdgpu_bo_unref (bo_ptr); +amdgpu_kfd_bo_unref (kfd_bo_ptr); }return r; } -/** * amdgpu_bo_validate - validate an &amdgpu_bo buffer object * @bo: pointer to the buffer object
@@ -910,6 +914,18 @@ void amdgpu_bo_unref(struct amdgpu_bo **bo) *bo =NULL ; } +void amdgpu_kfd_bo_unref (struct amdgpu_kfd_bo **kbo) +{ +struct ttm_buffer_object *tbo; + +if ((*kbo) ==NULL ) +return ; + + tbo = &((*kbo)->bo.tbo); +ttm_bo_put (tbo); + *kbo =NULL ; +} +/** * amdgpu_bo_pin_restricted - pin an &amdgpu_bo buffer object * @bo: &amdgpu_bo buffer object to be pinned
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +7 -1
@@ -43,6 +43,8 @@ struct amdgpu_bo_param {u32 domain;u32 preferred_domain;u64 flags; +/* size of a subclass using amdgpu_bo as base class */ +u32 bo_ptr_size;enum ttm_bo_type type;bool no_wait_gpu;struct dma_resv *resv;
@@ -109,7 +111,10 @@ struct amdgpu_bo {#endif struct list_head shadow_list; +}; +struct amdgpu_kfd_bo { +struct amdgpu_bo bo;struct kgd_mem *kfd_bo; };
@@ -247,7 +252,7 @@ int amdgpu_bo_create(struct amdgpu_device *adev, struct amdgpu_bo **bo_ptr);int amdgpu_kfd_bo_create (struct amdgpu_device *adev,struct amdgpu_bo_param *bp, -struct amdgpu_bo **bo_ptr); +struct amdgpu_kfd_bo **bo_ptr); int amdgpu_bo_create_reserved(struct amdgpu_device *adev, unsigned long size, int align, u32 domain, struct amdgpu_bo **bo_ptr,
@@ -266,6 +271,7 @@ void *amdgpu_bo_kptr(struct amdgpu_bo *bo);void amdgpu_bo_kunmap (struct amdgpu_bo *bo);struct amdgpu_bo *amdgpu_bo_ref (struct amdgpu_bo *bo);void amdgpu_bo_unref (struct amdgpu_bo **bo); +void amdgpu_kfd_bo_unref (struct amdgpu_kfd_bo **kbo);int amdgpu_bo_pin (struct amdgpu_bo *bo,u32 domain);int amdgpu_bo_pin_restricted (struct amdgpu_bo *bo,u32 domain,u64 min_offset,u64 max_offset);
Signature · 6 lines
2.30.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx