* [PATCH 1/3] drm/amdgpu: drm/amdkfd: split amdgpu_mn_register
@ 2021-03-02 11:33 Nirmoy Das
2021-03-02 11:33 ` [PATCH 2/3] drm/amdgpu: introduce kfd user flag for amdgpu_bo Nirmoy Das
2021-03-02 11:33 ` [PATCH 3/3] drm/amdgpu: drm/amdkfd: add amdgpu_kfd_bo struct Nirmoy Das
0 siblings, 2 replies; 8+ messages in thread
From: Nirmoy Das @ 2021-03-02 11:33 UTC (permalink / raw)
To: Christian.Koenig, Felix.Kuehling; +Cc: Nirmoy Das, amd-gfx
Split amdgpu_mn_register() into two functions to avoid unnecessary
bo->kfd_bo check.
Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
---
.../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(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 99ad4e1d0896..89d0e4f7c6a8 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -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);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c
index 828b5167ff12..1da67cf812b1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c
@@ -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
*
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.h
index a292238f75eb..565ee5a0a3ad 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.h
@@ -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
--
2.30.1
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/3] drm/amdgpu: introduce kfd user flag for amdgpu_bo
2021-03-02 11:33 [PATCH 1/3] drm/amdgpu: drm/amdkfd: split amdgpu_mn_register Nirmoy Das
@ 2021-03-02 11:33 ` Nirmoy Das
2021-03-02 12:40 ` Christian König
2021-03-02 11:33 ` [PATCH 3/3] drm/amdgpu: drm/amdkfd: add amdgpu_kfd_bo struct Nirmoy Das
1 sibling, 1 reply; 8+ messages in thread
From: Nirmoy Das @ 2021-03-02 11:33 UTC (permalink / raw)
To: Christian.Koenig, Felix.Kuehling; +Cc: Nirmoy Das, amd-gfx
Introduce a new flag for amdgpu_bo->flags to identify if
a BO is created by KFD.
Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
---
.../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(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 89d0e4f7c6a8..57798707cd5f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -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);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index 8e9b8a6e6ef0..97d19f6b572d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -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;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index 0bd22ed1dacf..5ebce6d6784a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -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. */
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
index 8cd96c9330dd..665ee0015f06 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
@@ -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,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 7b2db779f313..d36b1932db78 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -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))
diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h
index 8b832f7458f2..f7157bd8a1f0 100644
--- a/include/uapi/drm/amdgpu_drm.h
+++ b/include/uapi/drm/amdgpu_drm.h
@@ -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;
--
2.30.1
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 2/3] drm/amdgpu: introduce kfd user flag for amdgpu_bo
2021-03-02 11:33 ` [PATCH 2/3] drm/amdgpu: introduce kfd user flag for amdgpu_bo Nirmoy Das
@ 2021-03-02 12:40 ` Christian König
2021-03-02 13:01 ` Nirmoy
0 siblings, 1 reply; 8+ messages in thread
From: Christian König @ 2021-03-02 12:40 UTC (permalink / raw)
To: Nirmoy Das, Felix.Kuehling; +Cc: amd-gfx
Am 02.03.21 um 12:33 schrieb Nirmoy Das:
> Introduce a new flag for amdgpu_bo->flags to identify if
> a BO is created by KFD.
>
> Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
> ---
> .../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(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> index 89d0e4f7c6a8..57798707cd5f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> @@ -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);
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> index 8e9b8a6e6ef0..97d19f6b572d 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> @@ -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.
>
> return -EINVAL;
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> index 0bd22ed1dacf..5ebce6d6784a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> @@ -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. */
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> index 8cd96c9330dd..665ee0015f06 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> @@ -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,
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> index 7b2db779f313..d36b1932db78 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> @@ -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))
> diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h
> index 8b832f7458f2..f7157bd8a1f0 100644
> --- a/include/uapi/drm/amdgpu_drm.h
> +++ b/include/uapi/drm/amdgpu_drm.h
> @@ -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;
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/3] drm/amdgpu: introduce kfd user flag for amdgpu_bo
2021-03-02 12:40 ` Christian König
@ 2021-03-02 13:01 ` Nirmoy
2021-03-02 13:06 ` Christian König
0 siblings, 1 reply; 8+ messages in thread
From: Nirmoy @ 2021-03-02 13:01 UTC (permalink / raw)
To: Christian König, Nirmoy Das, Felix.Kuehling; +Cc: amd-gfx
On 3/2/21 1:40 PM, Christian König wrote:
>
>
> Am 02.03.21 um 12:33 schrieb Nirmoy Das:
>> Introduce a new flag for amdgpu_bo->flags to identify if
>> a BO is created by KFD.
>>
>> Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
>> ---
>> .../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(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
>> index 89d0e4f7c6a8..57798707cd5f 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
>> @@ -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);
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
>> index 8e9b8a6e6ef0..97d19f6b572d 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
>> @@ -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?
Ok, I will rename it to AMDGPU_GEM_KFD which sounds much better.
Thanks,
Nirmoy
>
>
> Christian.
>
>> return -EINVAL;
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>> index 0bd22ed1dacf..5ebce6d6784a 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>> @@ -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. */
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
>> index 8cd96c9330dd..665ee0015f06 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
>> @@ -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,
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>> index 7b2db779f313..d36b1932db78 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>> @@ -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))
>> diff --git a/include/uapi/drm/amdgpu_drm.h
>> b/include/uapi/drm/amdgpu_drm.h
>> index 8b832f7458f2..f7157bd8a1f0 100644
>> --- a/include/uapi/drm/amdgpu_drm.h
>> +++ b/include/uapi/drm/amdgpu_drm.h
>> @@ -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;
>
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/3] drm/amdgpu: introduce kfd user flag for amdgpu_bo
2021-03-02 13:01 ` Nirmoy
@ 2021-03-02 13:06 ` Christian König
2021-03-02 13:36 ` Nirmoy
0 siblings, 1 reply; 8+ messages in thread
From: Christian König @ 2021-03-02 13:06 UTC (permalink / raw)
To: Nirmoy, Nirmoy Das, Felix.Kuehling; +Cc: amd-gfx
Am 02.03.21 um 14:01 schrieb Nirmoy:
>
> On 3/2/21 1:40 PM, Christian König wrote:
>>
>>
>> Am 02.03.21 um 12:33 schrieb Nirmoy Das:
>>> Introduce a new flag for amdgpu_bo->flags to identify if
>>> a BO is created by KFD.
>>>
>>> Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
>>> ---
>>> .../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(-)
>>>
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
>>> index 89d0e4f7c6a8..57798707cd5f 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
>>> @@ -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);
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
>>> index 8e9b8a6e6ef0..97d19f6b572d 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
>>> @@ -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?
>
> Ok, I will rename it to AMDGPU_GEM_KFD which sounds much better.
No. When you want to use those flags you should probably call this
AMDGPU_GEM_CREATE_KFD.
Christian.
>
>
> Thanks,
>
> Nirmoy
>
>>
>>
>> Christian.
>>
>>> return -EINVAL;
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>>> index 0bd22ed1dacf..5ebce6d6784a 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>>> @@ -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. */
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
>>> index 8cd96c9330dd..665ee0015f06 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
>>> @@ -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,
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>>> index 7b2db779f313..d36b1932db78 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>>> @@ -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))
>>> diff --git a/include/uapi/drm/amdgpu_drm.h
>>> b/include/uapi/drm/amdgpu_drm.h
>>> index 8b832f7458f2..f7157bd8a1f0 100644
>>> --- a/include/uapi/drm/amdgpu_drm.h
>>> +++ b/include/uapi/drm/amdgpu_drm.h
>>> @@ -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;
>>
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/3] drm/amdgpu: introduce kfd user flag for amdgpu_bo
2021-03-02 13:06 ` Christian König
@ 2021-03-02 13:36 ` Nirmoy
0 siblings, 0 replies; 8+ messages in thread
From: Nirmoy @ 2021-03-02 13:36 UTC (permalink / raw)
To: Christian König, Nirmoy Das, Felix.Kuehling; +Cc: amd-gfx
On 3/2/21 2:06 PM, Christian König wrote:
> Am 02.03.21 um 14:01 schrieb Nirmoy:
>>
>> On 3/2/21 1:40 PM, Christian König wrote:
>>>
>>>
>>> Am 02.03.21 um 12:33 schrieb Nirmoy Das:
>>>> Introduce a new flag for amdgpu_bo->flags to identify if
>>>> a BO is created by KFD.
>>>>
>>>> Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
>>>> ---
>>>> .../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(-)
>>>>
>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
>>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
>>>> index 89d0e4f7c6a8..57798707cd5f 100644
>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
>>>> @@ -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);
>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
>>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
>>>> index 8e9b8a6e6ef0..97d19f6b572d 100644
>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
>>>> @@ -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?
>>
>> Ok, I will rename it to AMDGPU_GEM_KFD which sounds much better.
>
> No. When you want to use those flags you should probably call this
> AMDGPU_GEM_CREATE_KFD.
Ah I see.
Nirmoy
>
> Christian.
>
>>
>>
>> Thanks,
>>
>> Nirmoy
>>
>>>
>>>
>>> Christian.
>>>
>>>> return -EINVAL;
>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>>>> index 0bd22ed1dacf..5ebce6d6784a 100644
>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>>>> @@ -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. */
>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
>>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
>>>> index 8cd96c9330dd..665ee0015f06 100644
>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
>>>> @@ -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,
>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>>>> index 7b2db779f313..d36b1932db78 100644
>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
>>>> @@ -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))
>>>> diff --git a/include/uapi/drm/amdgpu_drm.h
>>>> b/include/uapi/drm/amdgpu_drm.h
>>>> index 8b832f7458f2..f7157bd8a1f0 100644
>>>> --- a/include/uapi/drm/amdgpu_drm.h
>>>> +++ b/include/uapi/drm/amdgpu_drm.h
>>>> @@ -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;
>>>
>
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 3/3] drm/amdgpu: drm/amdkfd: add amdgpu_kfd_bo struct
2021-03-02 11:33 [PATCH 1/3] drm/amdgpu: drm/amdkfd: split amdgpu_mn_register Nirmoy Das
2021-03-02 11:33 ` [PATCH 2/3] drm/amdgpu: introduce kfd user flag for amdgpu_bo Nirmoy Das
@ 2021-03-02 11:33 ` Nirmoy Das
1 sibling, 0 replies; 8+ messages in thread
From: Nirmoy Das @ 2021-03-02 11:33 UTC (permalink / raw)
To: Christian.Koenig, Felix.Kuehling; +Cc: Nirmoy Das, amd-gfx
Implement 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.
Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
---
.../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(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 57798707cd5f..1f52ae4de609 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -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:
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c
index 1da67cf812b1..eaaf4940abcb 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c
@@ -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;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index 5ebce6d6784a..af40eb869995 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -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
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
index 665ee0015f06..fa98a1fe2574 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
@@ -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);
--
2.30.1
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 1/3] drm/amdgpu: drm/amdkfd: split amdgpu_mn_register
@ 2021-03-03 9:25 Nirmoy Das
0 siblings, 0 replies; 8+ messages in thread
From: Nirmoy Das @ 2021-03-03 9:25 UTC (permalink / raw)
To: Christian.Koenig, Felix.Kuehling; +Cc: Nirmoy Das, amd-gfx
Split amdgpu_mn_register() into two functions to avoid unnecessary
bo->kfd_bo check.
Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
---
.../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(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 99ad4e1d0896..89d0e4f7c6a8 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -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);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c
index 828b5167ff12..1da67cf812b1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c
@@ -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
*
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.h
index a292238f75eb..565ee5a0a3ad 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mn.h
@@ -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
--
2.30.1
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-03-03 9:26 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-02 11:33 [PATCH 1/3] drm/amdgpu: drm/amdkfd: split amdgpu_mn_register Nirmoy Das
2021-03-02 11:33 ` [PATCH 2/3] drm/amdgpu: introduce kfd user flag for amdgpu_bo Nirmoy Das
2021-03-02 12:40 ` Christian König
2021-03-02 13:01 ` Nirmoy
2021-03-02 13:06 ` Christian König
2021-03-02 13:36 ` Nirmoy
2021-03-02 11:33 ` [PATCH 3/3] drm/amdgpu: drm/amdkfd: add amdgpu_kfd_bo struct Nirmoy Das
2021-03-03 9:25 [PATCH 1/3] drm/amdgpu: drm/amdkfd: split amdgpu_mn_register Nirmoy Das
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.