All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/7] drm/amdgpu: add amdgpu_bo_vm bo type
@ 2021-05-21 12:45 Nirmoy Das
  2021-05-21 12:45 ` [PATCH 2/7] drm/amdgpu: add a new identifier for amdgpu_bo Nirmoy Das
                   ` (6 more replies)
  0 siblings, 7 replies; 15+ messages in thread
From: Nirmoy Das @ 2021-05-21 12:45 UTC (permalink / raw)
  To: amd-gfx; +Cc: alexander.deucher, Nirmoy Das, Christian.Koenig

Add new BO subcalss that will be used by amdgpu vm code.

Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 32 ++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 10 +++++++
 2 files changed, 42 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index 745fcf3ea450..61b1edcb490a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -692,6 +692,38 @@ int amdgpu_bo_create_user(struct amdgpu_device *adev,
 	*ubo_ptr = to_amdgpu_bo_user(bo_ptr);
 	return r;
 }
+
+/**
+ * amdgpu_bo_create_vm - create an &amdgpu_bo_vm buffer object
+ * @adev: amdgpu device object
+ * @bp: parameters to be used for the buffer object
+ * @vmbo_ptr: pointer to the buffer object pointer
+ *
+ * Create a BO to be for GPUVM.
+ *
+ * Returns:
+ * 0 for success or a negative error code on failure.
+ */
+
+int amdgpu_bo_create_vm(struct amdgpu_device *adev,
+			struct amdgpu_bo_param *bp,
+			struct amdgpu_bo_vm **vmbo_ptr)
+{
+	struct amdgpu_bo *bo_ptr;
+	int r;
+
+	/* bo_ptr_size will be determined by the caller and it depends on
+	 * num of amdgpu_vm_pt entries.
+	 */
+	BUG_ON(bp->bo_ptr_size < sizeof(struct amdgpu_bo_vm));
+	r = amdgpu_bo_create(adev, bp, &bo_ptr);
+	if (r)
+		return r;
+
+	*vmbo_ptr = to_amdgpu_bo_vm(bo_ptr);
+	return r;
+}
+
 /**
  * amdgpu_bo_validate - validate an &amdgpu_bo buffer object
  * @bo: pointer to the buffer object
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
index 11480c5a2716..a7fbf5f7051e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
@@ -44,6 +44,7 @@
 #define AMDGPU_AMDKFD_CREATE_SVM_BO	(1ULL << 62)
 
 #define to_amdgpu_bo_user(abo) container_of((abo), struct amdgpu_bo_user, bo)
+#define to_amdgpu_bo_vm(abo) container_of((abo), struct amdgpu_bo_vm, bo)
 
 struct amdgpu_bo_param {
 	unsigned long			size;
@@ -125,6 +126,12 @@ struct amdgpu_bo_user {
 
 };
 
+struct amdgpu_bo_vm {
+	struct amdgpu_bo		bo;
+	struct amdgpu_bo		*shadow;
+	struct amdgpu_vm_pt             entries[];
+};
+
 static inline struct amdgpu_bo *ttm_to_amdgpu_bo(struct ttm_buffer_object *tbo)
 {
 	return container_of(tbo, struct amdgpu_bo, tbo);
@@ -272,6 +279,9 @@ int amdgpu_bo_create_kernel_at(struct amdgpu_device *adev,
 int amdgpu_bo_create_user(struct amdgpu_device *adev,
 			  struct amdgpu_bo_param *bp,
 			  struct amdgpu_bo_user **ubo_ptr);
+int amdgpu_bo_create_vm(struct amdgpu_device *adev,
+			struct amdgpu_bo_param *bp,
+			struct amdgpu_bo_vm **ubo_ptr);
 void amdgpu_bo_free_kernel(struct amdgpu_bo **bo, u64 *gpu_addr,
 			   void **cpu_addr);
 int amdgpu_bo_create_shadow(struct amdgpu_device *adev,
-- 
2.31.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 2/7] drm/amdgpu: add a new identifier for amdgpu_bo
  2021-05-21 12:45 [PATCH 1/7] drm/amdgpu: add amdgpu_bo_vm bo type Nirmoy Das
@ 2021-05-21 12:45 ` Nirmoy Das
  2021-05-21 12:58   ` Christian König
  2021-05-21 12:45 ` [PATCH 3/7] drm/amdgpu: use amdgpu_bo_vm for vm code Nirmoy Das
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 15+ messages in thread
From: Nirmoy Das @ 2021-05-21 12:45 UTC (permalink / raw)
  To: amd-gfx; +Cc: alexander.deucher, Nirmoy Das, Christian.Koenig

Add has_shadow to identify if a BO is shadowed.

Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 2 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 5 ++---
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index 61b1edcb490a..eb3ce33cbfff 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -619,6 +619,7 @@ int amdgpu_bo_create(struct amdgpu_device *adev,
 	}
 	if (!bp->resv)
 		amdgpu_bo_unreserve(bo);
+	bo->has_shadow = false;
 	*bo_ptr = bo;
 
 	trace_amdgpu_bo_create(bo);
@@ -657,6 +658,7 @@ int amdgpu_bo_create_shadow(struct amdgpu_device *adev,
 	r = amdgpu_bo_create(adev, &bp, &bo->shadow);
 	if (!r) {
 		bo->shadow->parent = amdgpu_bo_ref(bo);
+		bo->has_shadow = true;
 		mutex_lock(&adev->shadow_list_lock);
 		list_add_tail(&bo->shadow->shadow_list, &adev->shadow_list);
 		mutex_unlock(&adev->shadow_list_lock);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
index a7fbf5f7051e..3a0e6ca88563 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
@@ -104,9 +104,8 @@ struct amdgpu_bo {
 	struct amdgpu_vm_bo_base	*vm_bo;
 	/* Constant after initialization */
 	struct amdgpu_bo		*parent;
-	struct amdgpu_bo		*shadow;
-
-
+	struct amdgpu_bo                *shadow;
+	bool				has_shadow;
 
 #ifdef CONFIG_MMU_NOTIFIER
 	struct mmu_interval_notifier	notifier;
-- 
2.31.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 3/7] drm/amdgpu: use amdgpu_bo_vm for vm code
  2021-05-21 12:45 [PATCH 1/7] drm/amdgpu: add amdgpu_bo_vm bo type Nirmoy Das
  2021-05-21 12:45 ` [PATCH 2/7] drm/amdgpu: add a new identifier for amdgpu_bo Nirmoy Das
@ 2021-05-21 12:45 ` Nirmoy Das
  2021-05-21 12:45 ` [PATCH 4/7] drm/amdgpu: create shadow bo directly Nirmoy Das
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 15+ messages in thread
From: Nirmoy Das @ 2021-05-21 12:45 UTC (permalink / raw)
  To: amd-gfx; +Cc: alexander.deucher, Nirmoy Das, Christian.Koenig

Use amdgpu_bo_vm for BO for PT/PD.

Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 43 ++++++++++++++------------
 1 file changed, 24 insertions(+), 19 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 55991f393481..1ac0293e5123 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -863,9 +863,10 @@ static int amdgpu_vm_clear_bo(struct amdgpu_device *adev,
 static int amdgpu_vm_pt_create(struct amdgpu_device *adev,
 			       struct amdgpu_vm *vm,
 			       int level, bool immediate,
-			       struct amdgpu_bo **bo)
+			       struct amdgpu_bo_vm **vmbo)
 {
 	struct amdgpu_bo_param bp;
+	struct amdgpu_bo *bo;
 	int r;
 
 	memset(&bp, 0, sizeof(bp));
@@ -876,7 +877,7 @@ static int amdgpu_vm_pt_create(struct amdgpu_device *adev,
 	bp.domain = amdgpu_bo_get_preferred_pin_domain(adev, bp.domain);
 	bp.flags = AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS |
 		AMDGPU_GEM_CREATE_CPU_GTT_USWC;
-	bp.bo_ptr_size = sizeof(struct amdgpu_bo);
+	bp.bo_ptr_size = sizeof(struct amdgpu_bo_vm);
 	if (vm->use_cpu_for_update)
 		bp.flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
 
@@ -885,23 +886,24 @@ static int amdgpu_vm_pt_create(struct amdgpu_device *adev,
 	if (vm->root.base.bo)
 		bp.resv = vm->root.base.bo->tbo.base.resv;
 
-	r = amdgpu_bo_create(adev, &bp, bo);
+	r = amdgpu_bo_create_vm(adev, &bp, vmbo);
 	if (r)
 		return r;
 
+	bo = &(*vmbo)->bo;
 	if (vm->is_compute_context && (adev->flags & AMD_IS_APU))
 		return 0;
 
 	if (!bp.resv)
-		WARN_ON(dma_resv_lock((*bo)->tbo.base.resv,
+		WARN_ON(dma_resv_lock(bo->tbo.base.resv,
 				      NULL));
-	r = amdgpu_bo_create_shadow(adev, bp.size, *bo);
+	r = amdgpu_bo_create_shadow(adev, bp.size, bo);
 
 	if (!bp.resv)
-		dma_resv_unlock((*bo)->tbo.base.resv);
+		dma_resv_unlock(bo->tbo.base.resv);
 
 	if (r) {
-		amdgpu_bo_unref(bo);
+		amdgpu_bo_unref(&bo);
 		return r;
 	}
 
@@ -928,7 +930,8 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
 			       bool immediate)
 {
 	struct amdgpu_vm_pt *entry = cursor->entry;
-	struct amdgpu_bo *pt;
+	struct amdgpu_bo *pt_bo;
+	struct amdgpu_bo_vm *pt;
 	int r;
 
 	if (cursor->level < AMDGPU_VM_PTB && !entry->entries) {
@@ -952,18 +955,19 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
 	/* Keep a reference to the root directory to avoid
 	 * freeing them up in the wrong order.
 	 */
-	pt->parent = amdgpu_bo_ref(cursor->parent->base.bo);
-	amdgpu_vm_bo_base_init(&entry->base, vm, pt);
+	pt_bo = &pt->bo;
+	pt_bo->parent = amdgpu_bo_ref(cursor->parent->base.bo);
+	amdgpu_vm_bo_base_init(&entry->base, vm, pt_bo);
 
-	r = amdgpu_vm_clear_bo(adev, vm, pt, immediate);
+	r = amdgpu_vm_clear_bo(adev, vm, pt_bo, immediate);
 	if (r)
 		goto error_free_pt;
 
 	return 0;
 
 error_free_pt:
-	amdgpu_bo_unref(&pt->shadow);
-	amdgpu_bo_unref(&pt);
+	amdgpu_bo_unref(&pt_bo->shadow);
+	amdgpu_bo_unref(&pt_bo);
 	return r;
 }
 
@@ -2837,7 +2841,8 @@ long amdgpu_vm_wait_idle(struct amdgpu_vm *vm, long timeout)
  */
 int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, u32 pasid)
 {
-	struct amdgpu_bo *root;
+	struct amdgpu_bo *root_bo;
+	struct amdgpu_bo_vm *root;
 	int r, i;
 
 	vm->va = RB_ROOT_CACHED;
@@ -2891,18 +2896,18 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, u32 pasid)
 				false, &root);
 	if (r)
 		goto error_free_delayed;
-
-	r = amdgpu_bo_reserve(root, true);
+	root_bo = &root->bo;
+	r = amdgpu_bo_reserve(root_bo, true);
 	if (r)
 		goto error_free_root;
 
-	r = dma_resv_reserve_shared(root->tbo.base.resv, 1);
+	r = dma_resv_reserve_shared(root_bo->tbo.base.resv, 1);
 	if (r)
 		goto error_unreserve;
 
-	amdgpu_vm_bo_base_init(&vm->root.base, vm, root);
+	amdgpu_vm_bo_base_init(&vm->root.base, vm, root_bo);
 
-	r = amdgpu_vm_clear_bo(adev, vm, root, false);
+	r = amdgpu_vm_clear_bo(adev, vm, root_bo, false);
 	if (r)
 		goto error_unreserve;
 
-- 
2.31.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 4/7] drm/amdgpu: create shadow bo directly
  2021-05-21 12:45 [PATCH 1/7] drm/amdgpu: add amdgpu_bo_vm bo type Nirmoy Das
  2021-05-21 12:45 ` [PATCH 2/7] drm/amdgpu: add a new identifier for amdgpu_bo Nirmoy Das
  2021-05-21 12:45 ` [PATCH 3/7] drm/amdgpu: use amdgpu_bo_vm for vm code Nirmoy Das
@ 2021-05-21 12:45 ` Nirmoy Das
  2021-05-21 12:45 ` [PATCH 5/7] drm/amdgpu: switch to amdgpu_bo_vm's shadow Nirmoy Das
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 15+ messages in thread
From: Nirmoy Das @ 2021-05-21 12:45 UTC (permalink / raw)
  To: amd-gfx; +Cc: alexander.deucher, Nirmoy Das, Christian.Koenig

Shadow BOs are only needed by VM code so create it
directly within vm code.

Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 1ac0293e5123..cead68181197 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -867,6 +867,8 @@ static int amdgpu_vm_pt_create(struct amdgpu_device *adev,
 {
 	struct amdgpu_bo_param bp;
 	struct amdgpu_bo *bo;
+	struct amdgpu_bo *shadow_bo;
+	struct dma_resv *resv;
 	int r;
 
 	memset(&bp, 0, sizeof(bp));
@@ -897,9 +899,19 @@ static int amdgpu_vm_pt_create(struct amdgpu_device *adev,
 	if (!bp.resv)
 		WARN_ON(dma_resv_lock(bo->tbo.base.resv,
 				      NULL));
-	r = amdgpu_bo_create_shadow(adev, bp.size, bo);
+	resv = bp.resv;
+	memset(&bp, 0, sizeof(bp));
+	bp.size = amdgpu_vm_bo_size(adev, level);
+	bp.domain = AMDGPU_GEM_DOMAIN_GTT;
+	bp.flags = AMDGPU_GEM_CREATE_CPU_GTT_USWC;
+	bp.type = ttm_bo_type_kernel;
+	bp.resv = bo->tbo.base.resv;
+	bp.bo_ptr_size = sizeof(struct amdgpu_bo);
 
-	if (!bp.resv)
+	r = amdgpu_bo_create(adev, &bp, &shadow_bo);
+
+
+	if (!resv)
 		dma_resv_unlock(bo->tbo.base.resv);
 
 	if (r) {
@@ -907,6 +919,13 @@ static int amdgpu_vm_pt_create(struct amdgpu_device *adev,
 		return r;
 	}
 
+	shadow_bo->parent = amdgpu_bo_ref(bo);
+	bo->has_shadow = true;
+	mutex_lock(&adev->shadow_list_lock);
+	list_add_tail(&shadow_bo->shadow_list, &adev->shadow_list);
+	mutex_unlock(&adev->shadow_list_lock);
+	bo->shadow = shadow_bo;
+
 	return 0;
 }
 
-- 
2.31.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 5/7] drm/amdgpu: switch to amdgpu_bo_vm's shadow
  2021-05-21 12:45 [PATCH 1/7] drm/amdgpu: add amdgpu_bo_vm bo type Nirmoy Das
                   ` (2 preceding siblings ...)
  2021-05-21 12:45 ` [PATCH 4/7] drm/amdgpu: create shadow bo directly Nirmoy Das
@ 2021-05-21 12:45 ` Nirmoy Das
  2021-05-21 12:45 ` [PATCH 6/7] drm/amdgpu: remove unused code Nirmoy Das
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 15+ messages in thread
From: Nirmoy Das @ 2021-05-21 12:45 UTC (permalink / raw)
  To: amd-gfx; +Cc: alexander.deucher, Nirmoy Das, Christian.Koenig

Use shadow of amdgpu_bo_vm instead of the base class.

Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c      |  4 +--
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c      | 27 ++++++++++++---------
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c | 16 ++++++------
 3 files changed, 26 insertions(+), 21 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index 90136f9dedd6..46ccd43566e2 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -460,8 +460,8 @@ static int amdgpu_cs_validate(void *param, struct amdgpu_bo *bo)
 	if (r)
 		return r;
 
-	if (bo->shadow)
-		r = amdgpu_cs_bo_validate(p, bo->shadow);
+	if (bo->has_shadow)
+		r = amdgpu_cs_bo_validate(p, to_amdgpu_bo_vm(bo)->shadow);
 
 	return r;
 }
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index cead68181197..120e6b7a0286 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -658,9 +658,9 @@ void amdgpu_vm_move_to_lru_tail(struct amdgpu_device *adev,
 
 		ttm_bo_move_to_lru_tail(&bo->tbo, &bo->tbo.mem,
 					&vm->lru_bulk_move);
-		if (bo->shadow)
-			ttm_bo_move_to_lru_tail(&bo->shadow->tbo,
-						&bo->shadow->tbo.mem,
+		if (bo->has_shadow)
+			ttm_bo_move_to_lru_tail(&to_amdgpu_bo_vm(bo)->shadow->tbo,
+						&to_amdgpu_bo_vm(bo)->shadow->tbo.mem,
 						&vm->lru_bulk_move);
 	}
 	spin_unlock(&adev->mman.bdev.lru_lock);
@@ -788,8 +788,9 @@ static int amdgpu_vm_clear_bo(struct amdgpu_device *adev,
 	if (r)
 		return r;
 
-	if (bo->shadow) {
-		r = ttm_bo_validate(&bo->shadow->tbo, &bo->shadow->placement,
+	if (bo->has_shadow) {
+		r = ttm_bo_validate(&to_amdgpu_bo_vm(bo)->shadow->tbo,
+				    &to_amdgpu_bo_vm(bo)->shadow->placement,
 				    &ctx);
 		if (r)
 			return r;
@@ -924,7 +925,7 @@ static int amdgpu_vm_pt_create(struct amdgpu_device *adev,
 	mutex_lock(&adev->shadow_list_lock);
 	list_add_tail(&shadow_bo->shadow_list, &adev->shadow_list);
 	mutex_unlock(&adev->shadow_list_lock);
-	bo->shadow = shadow_bo;
+	(*vmbo)->shadow = shadow_bo;
 
 	return 0;
 }
@@ -985,7 +986,7 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
 	return 0;
 
 error_free_pt:
-	amdgpu_bo_unref(&pt_bo->shadow);
+	amdgpu_bo_unref(&pt->shadow);
 	amdgpu_bo_unref(&pt_bo);
 	return r;
 }
@@ -1000,7 +1001,8 @@ static void amdgpu_vm_free_table(struct amdgpu_vm_pt *entry)
 	if (entry->base.bo) {
 		entry->base.bo->vm_bo = NULL;
 		list_del(&entry->base.vm_status);
-		amdgpu_bo_unref(&entry->base.bo->shadow);
+		if (&entry->base.bo->has_shadow)
+			amdgpu_bo_unref(&to_amdgpu_bo_vm(entry->base.bo)->shadow);
 		amdgpu_bo_unref(&entry->base.bo);
 	}
 	kvfree(entry->entries);
@@ -2691,7 +2693,8 @@ void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,
 	struct amdgpu_vm_bo_base *bo_base;
 
 	/* shadow bo doesn't have bo base, its validation needs its parent */
-	if (bo->parent && bo->parent->shadow == bo)
+	if (bo->parent && bo->parent->has_shadow &&
+	    to_amdgpu_bo_vm(bo->parent)->shadow == bo)
 		bo = bo->parent;
 
 	for (bo_base = bo->vm_bo; bo_base; bo_base = bo_base->next) {
@@ -2953,8 +2956,8 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, u32 pasid)
 	amdgpu_bo_unreserve(vm->root.base.bo);
 
 error_free_root:
-	amdgpu_bo_unref(&vm->root.base.bo->shadow);
-	amdgpu_bo_unref(&vm->root.base.bo);
+	amdgpu_bo_unref(&root->shadow);
+	amdgpu_bo_unref(&root_bo);
 	vm->root.base.bo = NULL;
 
 error_free_delayed:
@@ -3096,7 +3099,7 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 	}
 
 	/* Free the shadow bo for compute VM */
-	amdgpu_bo_unref(&vm->root.base.bo->shadow);
+	amdgpu_bo_unref(&to_amdgpu_bo_vm(vm->root.base.bo)->shadow);
 
 	if (pasid)
 		vm->pasid = pasid;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c
index a83a646759c5..f92260594c72 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c
@@ -41,8 +41,8 @@ static int amdgpu_vm_sdma_map_table(struct amdgpu_bo *table)
 	if (r)
 		return r;
 
-	if (table->shadow)
-		r = amdgpu_ttm_alloc_gart(&table->shadow->tbo);
+	if (table->has_shadow)
+		r = amdgpu_ttm_alloc_gart(&to_amdgpu_bo_vm(table)->shadow->tbo);
 
 	return r;
 }
@@ -238,8 +238,9 @@ static int amdgpu_vm_sdma_update(struct amdgpu_vm_update_params *p,
 
 		if (!p->pages_addr) {
 			/* set page commands needed */
-			if (bo->shadow)
-				amdgpu_vm_sdma_set_ptes(p, bo->shadow, pe, addr,
+			if (bo->has_shadow)
+				amdgpu_vm_sdma_set_ptes(p, to_amdgpu_bo_vm(bo)->shadow,
+							pe, addr,
 							count, incr, flags);
 			amdgpu_vm_sdma_set_ptes(p, bo, pe, addr, count,
 						incr, flags);
@@ -248,7 +249,7 @@ static int amdgpu_vm_sdma_update(struct amdgpu_vm_update_params *p,
 
 		/* copy commands needed */
 		ndw -= p->adev->vm_manager.vm_pte_funcs->copy_pte_num_dw *
-			(bo->shadow ? 2 : 1);
+			(bo->has_shadow ? 2 : 1);
 
 		/* for padding */
 		ndw -= 7;
@@ -263,8 +264,9 @@ static int amdgpu_vm_sdma_update(struct amdgpu_vm_update_params *p,
 			pte[i] |= flags;
 		}
 
-		if (bo->shadow)
-			amdgpu_vm_sdma_copy_ptes(p, bo->shadow, pe, nptes);
+		if (bo->has_shadow)
+			amdgpu_vm_sdma_copy_ptes(p, to_amdgpu_bo_vm(bo)->shadow,
+						 pe, nptes);
 		amdgpu_vm_sdma_copy_ptes(p, bo, pe, nptes);
 
 		pe += nptes * 8;
-- 
2.31.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 6/7] drm/amdgpu: remove unused code
  2021-05-21 12:45 [PATCH 1/7] drm/amdgpu: add amdgpu_bo_vm bo type Nirmoy Das
                   ` (3 preceding siblings ...)
  2021-05-21 12:45 ` [PATCH 5/7] drm/amdgpu: switch to amdgpu_bo_vm's shadow Nirmoy Das
@ 2021-05-21 12:45 ` Nirmoy Das
  2021-05-21 12:45 ` [PATCH 7/7] drm/amdgpu: do not allocate entries separately Nirmoy Das
  2021-05-21 14:54 ` [PATCH 1/7] drm/amdgpu: add amdgpu_bo_vm bo type Alex Deucher
  6 siblings, 0 replies; 15+ messages in thread
From: Nirmoy Das @ 2021-05-21 12:45 UTC (permalink / raw)
  To: amd-gfx; +Cc: alexander.deucher, Nirmoy Das, Christian.Koenig

Remove unused code related to shadow BO.

Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 30 ----------------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  4 ---
 2 files changed, 34 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index eb3ce33cbfff..7308048bb7cc 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -637,36 +637,6 @@ int amdgpu_bo_create(struct amdgpu_device *adev,
 	return r;
 }
 
-int amdgpu_bo_create_shadow(struct amdgpu_device *adev,
-			    unsigned long size,
-			    struct amdgpu_bo *bo)
-{
-	struct amdgpu_bo_param bp;
-	int r;
-
-	if (bo->shadow)
-		return 0;
-
-	memset(&bp, 0, sizeof(bp));
-	bp.size = size;
-	bp.domain = AMDGPU_GEM_DOMAIN_GTT;
-	bp.flags = AMDGPU_GEM_CREATE_CPU_GTT_USWC;
-	bp.type = ttm_bo_type_kernel;
-	bp.resv = bo->tbo.base.resv;
-	bp.bo_ptr_size = sizeof(struct amdgpu_bo);
-
-	r = amdgpu_bo_create(adev, &bp, &bo->shadow);
-	if (!r) {
-		bo->shadow->parent = amdgpu_bo_ref(bo);
-		bo->has_shadow = true;
-		mutex_lock(&adev->shadow_list_lock);
-		list_add_tail(&bo->shadow->shadow_list, &adev->shadow_list);
-		mutex_unlock(&adev->shadow_list_lock);
-	}
-
-	return r;
-}
-
 /**
  * amdgpu_bo_create_user - create an &amdgpu_bo_user buffer object
  * @adev: amdgpu device object
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
index 3a0e6ca88563..df30dc7effda 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
@@ -104,7 +104,6 @@ struct amdgpu_bo {
 	struct amdgpu_vm_bo_base	*vm_bo;
 	/* Constant after initialization */
 	struct amdgpu_bo		*parent;
-	struct amdgpu_bo                *shadow;
 	bool				has_shadow;
 
 #ifdef CONFIG_MMU_NOTIFIER
@@ -283,9 +282,6 @@ int amdgpu_bo_create_vm(struct amdgpu_device *adev,
 			struct amdgpu_bo_vm **ubo_ptr);
 void amdgpu_bo_free_kernel(struct amdgpu_bo **bo, u64 *gpu_addr,
 			   void **cpu_addr);
-int amdgpu_bo_create_shadow(struct amdgpu_device *adev,
-			    unsigned long size,
-			    struct amdgpu_bo *bo);
 int amdgpu_bo_kmap(struct amdgpu_bo *bo, void **ptr);
 void *amdgpu_bo_kptr(struct amdgpu_bo *bo);
 void amdgpu_bo_kunmap(struct amdgpu_bo *bo);
-- 
2.31.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 7/7] drm/amdgpu: do not allocate entries separately
  2021-05-21 12:45 [PATCH 1/7] drm/amdgpu: add amdgpu_bo_vm bo type Nirmoy Das
                   ` (4 preceding siblings ...)
  2021-05-21 12:45 ` [PATCH 6/7] drm/amdgpu: remove unused code Nirmoy Das
@ 2021-05-21 12:45 ` Nirmoy Das
  2021-05-21 13:01   ` Christian König
  2021-05-21 14:54 ` [PATCH 1/7] drm/amdgpu: add amdgpu_bo_vm bo type Alex Deucher
  6 siblings, 1 reply; 15+ messages in thread
From: Nirmoy Das @ 2021-05-21 12:45 UTC (permalink / raw)
  To: amd-gfx; +Cc: alexander.deucher, Nirmoy Das, Christian.Koenig

Allocate PD/PT entries while allocating VM BOs and use that
instead of allocating those entries separately.

Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 31 ++++++++++++++------------
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 120e6b7a0286..4717f075a391 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -880,7 +880,12 @@ static int amdgpu_vm_pt_create(struct amdgpu_device *adev,
 	bp.domain = amdgpu_bo_get_preferred_pin_domain(adev, bp.domain);
 	bp.flags = AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS |
 		AMDGPU_GEM_CREATE_CPU_GTT_USWC;
-	bp.bo_ptr_size = sizeof(struct amdgpu_bo_vm);
+	if (level < AMDGPU_VM_PTB)
+		bp.bo_ptr_size = struct_size((*vmbo), entries,
+					     amdgpu_vm_num_entries(adev, level));
+	else
+		bp.bo_ptr_size = sizeof(struct amdgpu_bo_vm);
+
 	if (vm->use_cpu_for_update)
 		bp.flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
 
@@ -954,19 +959,14 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
 	struct amdgpu_bo_vm *pt;
 	int r;
 
-	if (cursor->level < AMDGPU_VM_PTB && !entry->entries) {
-		unsigned num_entries;
-
-		num_entries = amdgpu_vm_num_entries(adev, cursor->level);
-		entry->entries = kvmalloc_array(num_entries,
-						sizeof(*entry->entries),
-						GFP_KERNEL | __GFP_ZERO);
-		if (!entry->entries)
-			return -ENOMEM;
-	}
-
-	if (entry->base.bo)
+	if (entry->base.bo) {
+		if (cursor->level < AMDGPU_VM_PTB)
+			entry->entries =
+				to_amdgpu_bo_vm(entry->base.bo)->entries;
+		else
+			entry->entries = NULL;
 		return 0;
+	}
 
 	r = amdgpu_vm_pt_create(adev, vm, cursor->level, immediate, &pt);
 	if (r)
@@ -978,6 +978,10 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
 	pt_bo = &pt->bo;
 	pt_bo->parent = amdgpu_bo_ref(cursor->parent->base.bo);
 	amdgpu_vm_bo_base_init(&entry->base, vm, pt_bo);
+	if (cursor->level < AMDGPU_VM_PTB)
+		entry->entries = pt->entries;
+	else
+		entry->entries = NULL;
 
 	r = amdgpu_vm_clear_bo(adev, vm, pt_bo, immediate);
 	if (r)
@@ -1005,7 +1009,6 @@ static void amdgpu_vm_free_table(struct amdgpu_vm_pt *entry)
 			amdgpu_bo_unref(&to_amdgpu_bo_vm(entry->base.bo)->shadow);
 		amdgpu_bo_unref(&entry->base.bo);
 	}
-	kvfree(entry->entries);
 	entry->entries = NULL;
 }
 
-- 
2.31.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 2/7] drm/amdgpu: add a new identifier for amdgpu_bo
  2021-05-21 12:45 ` [PATCH 2/7] drm/amdgpu: add a new identifier for amdgpu_bo Nirmoy Das
@ 2021-05-21 12:58   ` Christian König
  2021-05-21 13:54     ` Nirmoy
  0 siblings, 1 reply; 15+ messages in thread
From: Christian König @ 2021-05-21 12:58 UTC (permalink / raw)
  To: Nirmoy Das, amd-gfx; +Cc: alexander.deucher

Am 21.05.21 um 14:45 schrieb Nirmoy Das:
> Add has_shadow to identify if a BO is shadowed.

Ok that is not going into the right direction.

Instead of identifying which BOs have a shadow we need to identify if 
this is a VM BO or not.

I think the first think you need to do is to move the shadow handling 
from amdgpu_cs_validate() into amdgpu_vm_validate_pt_bos().

And then do it only for ttm_bo_type_kernel BOs, cause those are the 
PD/PT BOs.

Regards,
Christian.

>
> Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 2 ++
>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 5 ++---
>   2 files changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> index 61b1edcb490a..eb3ce33cbfff 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> @@ -619,6 +619,7 @@ int amdgpu_bo_create(struct amdgpu_device *adev,
>   	}
>   	if (!bp->resv)
>   		amdgpu_bo_unreserve(bo);
> +	bo->has_shadow = false;
>   	*bo_ptr = bo;
>   
>   	trace_amdgpu_bo_create(bo);
> @@ -657,6 +658,7 @@ int amdgpu_bo_create_shadow(struct amdgpu_device *adev,
>   	r = amdgpu_bo_create(adev, &bp, &bo->shadow);
>   	if (!r) {
>   		bo->shadow->parent = amdgpu_bo_ref(bo);
> +		bo->has_shadow = true;
>   		mutex_lock(&adev->shadow_list_lock);
>   		list_add_tail(&bo->shadow->shadow_list, &adev->shadow_list);
>   		mutex_unlock(&adev->shadow_list_lock);
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> index a7fbf5f7051e..3a0e6ca88563 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> @@ -104,9 +104,8 @@ struct amdgpu_bo {
>   	struct amdgpu_vm_bo_base	*vm_bo;
>   	/* Constant after initialization */
>   	struct amdgpu_bo		*parent;
> -	struct amdgpu_bo		*shadow;
> -
> -
> +	struct amdgpu_bo                *shadow;
> +	bool				has_shadow;
>   
>   #ifdef CONFIG_MMU_NOTIFIER
>   	struct mmu_interval_notifier	notifier;

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 7/7] drm/amdgpu: do not allocate entries separately
  2021-05-21 12:45 ` [PATCH 7/7] drm/amdgpu: do not allocate entries separately Nirmoy Das
@ 2021-05-21 13:01   ` Christian König
  2021-05-21 14:04     ` Nirmoy
  0 siblings, 1 reply; 15+ messages in thread
From: Christian König @ 2021-05-21 13:01 UTC (permalink / raw)
  To: Nirmoy Das, amd-gfx; +Cc: alexander.deucher

Am 21.05.21 um 14:45 schrieb Nirmoy Das:
> Allocate PD/PT entries while allocating VM BOs and use that
> instead of allocating those entries separately.
>
> Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 31 ++++++++++++++------------
>   1 file changed, 17 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index 120e6b7a0286..4717f075a391 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -880,7 +880,12 @@ static int amdgpu_vm_pt_create(struct amdgpu_device *adev,
>   	bp.domain = amdgpu_bo_get_preferred_pin_domain(adev, bp.domain);
>   	bp.flags = AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS |
>   		AMDGPU_GEM_CREATE_CPU_GTT_USWC;
> -	bp.bo_ptr_size = sizeof(struct amdgpu_bo_vm);
> +	if (level < AMDGPU_VM_PTB)
> +		bp.bo_ptr_size = struct_size((*vmbo), entries,
> +					     amdgpu_vm_num_entries(adev, level));
> +	else
> +		bp.bo_ptr_size = sizeof(struct amdgpu_bo_vm);
> +

Rather do it like this here:

if (level < AMDGPU_VM_PTB)
     num_entries = amdgpu_vm_num_entries(...)
else
     num_entries = 0;

bp.bo_ptr_size = struct_size(....)

If we have that calculation more than once then it might make sense to 
unify it in a function, but I don't think so of hand.

Regards,
Christian.

>   	if (vm->use_cpu_for_update)
>   		bp.flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
>   
> @@ -954,19 +959,14 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
>   	struct amdgpu_bo_vm *pt;
>   	int r;
>   
> -	if (cursor->level < AMDGPU_VM_PTB && !entry->entries) {
> -		unsigned num_entries;
> -
> -		num_entries = amdgpu_vm_num_entries(adev, cursor->level);
> -		entry->entries = kvmalloc_array(num_entries,
> -						sizeof(*entry->entries),
> -						GFP_KERNEL | __GFP_ZERO);
> -		if (!entry->entries)
> -			return -ENOMEM;
> -	}
> -
> -	if (entry->base.bo)
> +	if (entry->base.bo) {
> +		if (cursor->level < AMDGPU_VM_PTB)
> +			entry->entries =
> +				to_amdgpu_bo_vm(entry->base.bo)->entries;
> +		else
> +			entry->entries = NULL;
>   		return 0;
> +	}
>   
>   	r = amdgpu_vm_pt_create(adev, vm, cursor->level, immediate, &pt);
>   	if (r)
> @@ -978,6 +978,10 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
>   	pt_bo = &pt->bo;
>   	pt_bo->parent = amdgpu_bo_ref(cursor->parent->base.bo);
>   	amdgpu_vm_bo_base_init(&entry->base, vm, pt_bo);
> +	if (cursor->level < AMDGPU_VM_PTB)
> +		entry->entries = pt->entries;
> +	else
> +		entry->entries = NULL;
>   
>   	r = amdgpu_vm_clear_bo(adev, vm, pt_bo, immediate);
>   	if (r)
> @@ -1005,7 +1009,6 @@ static void amdgpu_vm_free_table(struct amdgpu_vm_pt *entry)
>   			amdgpu_bo_unref(&to_amdgpu_bo_vm(entry->base.bo)->shadow);
>   		amdgpu_bo_unref(&entry->base.bo);
>   	}
> -	kvfree(entry->entries);
>   	entry->entries = NULL;
>   }
>   

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 2/7] drm/amdgpu: add a new identifier for amdgpu_bo
  2021-05-21 12:58   ` Christian König
@ 2021-05-21 13:54     ` Nirmoy
  0 siblings, 0 replies; 15+ messages in thread
From: Nirmoy @ 2021-05-21 13:54 UTC (permalink / raw)
  To: Christian König, Nirmoy Das, amd-gfx; +Cc: alexander.deucher


On 5/21/21 2:58 PM, Christian König wrote:
> Am 21.05.21 um 14:45 schrieb Nirmoy Das:
>> Add has_shadow to identify if a BO is shadowed.
>
> Ok that is not going into the right direction.


I was expecting this :) but wasn't sure how to handle it.

>
>
> Instead of identifying which BOs have a shadow we need to identify if 
> this is a VM BO or not.
>
> I think the first think you need to do is to move the shadow handling 
> from amdgpu_cs_validate() into amdgpu_vm_validate_pt_bos().
>
> And then do it only for ttm_bo_type_kernel BOs, cause those are the 
> PD/PT BOs.


Thanks, this sounds good.


Nirmoy

>
> Regards,
> Christian.
>
>>
>> Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
>> ---
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 2 ++
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 5 ++---
>>   2 files changed, 4 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c 
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>> index 61b1edcb490a..eb3ce33cbfff 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>> @@ -619,6 +619,7 @@ int amdgpu_bo_create(struct amdgpu_device *adev,
>>       }
>>       if (!bp->resv)
>>           amdgpu_bo_unreserve(bo);
>> +    bo->has_shadow = false;
>>       *bo_ptr = bo;
>>         trace_amdgpu_bo_create(bo);
>> @@ -657,6 +658,7 @@ int amdgpu_bo_create_shadow(struct amdgpu_device 
>> *adev,
>>       r = amdgpu_bo_create(adev, &bp, &bo->shadow);
>>       if (!r) {
>>           bo->shadow->parent = amdgpu_bo_ref(bo);
>> +        bo->has_shadow = true;
>>           mutex_lock(&adev->shadow_list_lock);
>>           list_add_tail(&bo->shadow->shadow_list, &adev->shadow_list);
>>           mutex_unlock(&adev->shadow_list_lock);
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h 
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
>> index a7fbf5f7051e..3a0e6ca88563 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
>> @@ -104,9 +104,8 @@ struct amdgpu_bo {
>>       struct amdgpu_vm_bo_base    *vm_bo;
>>       /* Constant after initialization */
>>       struct amdgpu_bo        *parent;
>> -    struct amdgpu_bo        *shadow;
>> -
>> -
>> +    struct amdgpu_bo                *shadow;
>> +    bool                has_shadow;
>>     #ifdef CONFIG_MMU_NOTIFIER
>>       struct mmu_interval_notifier    notifier;
>
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 7/7] drm/amdgpu: do not allocate entries separately
  2021-05-21 13:01   ` Christian König
@ 2021-05-21 14:04     ` Nirmoy
  0 siblings, 0 replies; 15+ messages in thread
From: Nirmoy @ 2021-05-21 14:04 UTC (permalink / raw)
  To: Christian König, Nirmoy Das, amd-gfx; +Cc: alexander.deucher


On 5/21/21 3:01 PM, Christian König wrote:
> Am 21.05.21 um 14:45 schrieb Nirmoy Das:
>> Allocate PD/PT entries while allocating VM BOs and use that
>> instead of allocating those entries separately.
>>
>> Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
>> ---
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 31 ++++++++++++++------------
>>   1 file changed, 17 insertions(+), 14 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c 
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>> index 120e6b7a0286..4717f075a391 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>> @@ -880,7 +880,12 @@ static int amdgpu_vm_pt_create(struct 
>> amdgpu_device *adev,
>>       bp.domain = amdgpu_bo_get_preferred_pin_domain(adev, bp.domain);
>>       bp.flags = AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS |
>>           AMDGPU_GEM_CREATE_CPU_GTT_USWC;
>> -    bp.bo_ptr_size = sizeof(struct amdgpu_bo_vm);
>> +    if (level < AMDGPU_VM_PTB)
>> +        bp.bo_ptr_size = struct_size((*vmbo), entries,
>> +                         amdgpu_vm_num_entries(adev, level));
>> +    else
>> +        bp.bo_ptr_size = sizeof(struct amdgpu_bo_vm);
>> +
>
> Rather do it like this here:
>
> if (level < AMDGPU_VM_PTB)
>     num_entries = amdgpu_vm_num_entries(...)
> else
>     num_entries = 0;
>
> bp.bo_ptr_size = struct_size(....)


Sure.


>
> If we have that calculation more than once then it might make sense to 
> unify it in a function, but I don't think so of hand.


Currently, we only need this calculation in amdgpu_vm_pt_create().


Nirmoy


>
>
> Regards,
> Christian.
>
>>       if (vm->use_cpu_for_update)
>>           bp.flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
>>   @@ -954,19 +959,14 @@ static int amdgpu_vm_alloc_pts(struct 
>> amdgpu_device *adev,
>>       struct amdgpu_bo_vm *pt;
>>       int r;
>>   -    if (cursor->level < AMDGPU_VM_PTB && !entry->entries) {
>> -        unsigned num_entries;
>> -
>> -        num_entries = amdgpu_vm_num_entries(adev, cursor->level);
>> -        entry->entries = kvmalloc_array(num_entries,
>> -                        sizeof(*entry->entries),
>> -                        GFP_KERNEL | __GFP_ZERO);
>> -        if (!entry->entries)
>> -            return -ENOMEM;
>> -    }
>> -
>> -    if (entry->base.bo)
>> +    if (entry->base.bo) {
>> +        if (cursor->level < AMDGPU_VM_PTB)
>> +            entry->entries =
>> +                to_amdgpu_bo_vm(entry->base.bo)->entries;
>> +        else
>> +            entry->entries = NULL;
>>           return 0;
>> +    }
>>         r = amdgpu_vm_pt_create(adev, vm, cursor->level, immediate, 
>> &pt);
>>       if (r)
>> @@ -978,6 +978,10 @@ static int amdgpu_vm_alloc_pts(struct 
>> amdgpu_device *adev,
>>       pt_bo = &pt->bo;
>>       pt_bo->parent = amdgpu_bo_ref(cursor->parent->base.bo);
>>       amdgpu_vm_bo_base_init(&entry->base, vm, pt_bo);
>> +    if (cursor->level < AMDGPU_VM_PTB)
>> +        entry->entries = pt->entries;
>> +    else
>> +        entry->entries = NULL;
>>         r = amdgpu_vm_clear_bo(adev, vm, pt_bo, immediate);
>>       if (r)
>> @@ -1005,7 +1009,6 @@ static void amdgpu_vm_free_table(struct 
>> amdgpu_vm_pt *entry)
>> amdgpu_bo_unref(&to_amdgpu_bo_vm(entry->base.bo)->shadow);
>>           amdgpu_bo_unref(&entry->base.bo);
>>       }
>> -    kvfree(entry->entries);
>>       entry->entries = NULL;
>>   }
>
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 1/7] drm/amdgpu: add amdgpu_bo_vm bo type
  2021-05-21 12:45 [PATCH 1/7] drm/amdgpu: add amdgpu_bo_vm bo type Nirmoy Das
                   ` (5 preceding siblings ...)
  2021-05-21 12:45 ` [PATCH 7/7] drm/amdgpu: do not allocate entries separately Nirmoy Das
@ 2021-05-21 14:54 ` Alex Deucher
  2021-05-21 15:19   ` Nirmoy
  6 siblings, 1 reply; 15+ messages in thread
From: Alex Deucher @ 2021-05-21 14:54 UTC (permalink / raw)
  To: Nirmoy Das; +Cc: Deucher, Alexander, Christian Koenig, amd-gfx list

On Fri, May 21, 2021 at 8:46 AM Nirmoy Das <nirmoy.das@amd.com> wrote:
>
> Add new BO subcalss that will be used by amdgpu vm code.

s/subcalss/subclass/

Alex

>
> Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 32 ++++++++++++++++++++++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 10 +++++++
>  2 files changed, 42 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> index 745fcf3ea450..61b1edcb490a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> @@ -692,6 +692,38 @@ int amdgpu_bo_create_user(struct amdgpu_device *adev,
>         *ubo_ptr = to_amdgpu_bo_user(bo_ptr);
>         return r;
>  }
> +
> +/**
> + * amdgpu_bo_create_vm - create an &amdgpu_bo_vm buffer object
> + * @adev: amdgpu device object
> + * @bp: parameters to be used for the buffer object
> + * @vmbo_ptr: pointer to the buffer object pointer
> + *
> + * Create a BO to be for GPUVM.
> + *
> + * Returns:
> + * 0 for success or a negative error code on failure.
> + */
> +
> +int amdgpu_bo_create_vm(struct amdgpu_device *adev,
> +                       struct amdgpu_bo_param *bp,
> +                       struct amdgpu_bo_vm **vmbo_ptr)
> +{
> +       struct amdgpu_bo *bo_ptr;
> +       int r;
> +
> +       /* bo_ptr_size will be determined by the caller and it depends on
> +        * num of amdgpu_vm_pt entries.
> +        */
> +       BUG_ON(bp->bo_ptr_size < sizeof(struct amdgpu_bo_vm));
> +       r = amdgpu_bo_create(adev, bp, &bo_ptr);
> +       if (r)
> +               return r;
> +
> +       *vmbo_ptr = to_amdgpu_bo_vm(bo_ptr);
> +       return r;
> +}
> +
>  /**
>   * amdgpu_bo_validate - validate an &amdgpu_bo buffer object
>   * @bo: pointer to the buffer object
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> index 11480c5a2716..a7fbf5f7051e 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> @@ -44,6 +44,7 @@
>  #define AMDGPU_AMDKFD_CREATE_SVM_BO    (1ULL << 62)
>
>  #define to_amdgpu_bo_user(abo) container_of((abo), struct amdgpu_bo_user, bo)
> +#define to_amdgpu_bo_vm(abo) container_of((abo), struct amdgpu_bo_vm, bo)
>
>  struct amdgpu_bo_param {
>         unsigned long                   size;
> @@ -125,6 +126,12 @@ struct amdgpu_bo_user {
>
>  };
>
> +struct amdgpu_bo_vm {
> +       struct amdgpu_bo                bo;
> +       struct amdgpu_bo                *shadow;
> +       struct amdgpu_vm_pt             entries[];
> +};
> +
>  static inline struct amdgpu_bo *ttm_to_amdgpu_bo(struct ttm_buffer_object *tbo)
>  {
>         return container_of(tbo, struct amdgpu_bo, tbo);
> @@ -272,6 +279,9 @@ int amdgpu_bo_create_kernel_at(struct amdgpu_device *adev,
>  int amdgpu_bo_create_user(struct amdgpu_device *adev,
>                           struct amdgpu_bo_param *bp,
>                           struct amdgpu_bo_user **ubo_ptr);
> +int amdgpu_bo_create_vm(struct amdgpu_device *adev,
> +                       struct amdgpu_bo_param *bp,
> +                       struct amdgpu_bo_vm **ubo_ptr);
>  void amdgpu_bo_free_kernel(struct amdgpu_bo **bo, u64 *gpu_addr,
>                            void **cpu_addr);
>  int amdgpu_bo_create_shadow(struct amdgpu_device *adev,
> --
> 2.31.1
>
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 1/7] drm/amdgpu: add amdgpu_bo_vm bo type
  2021-05-21 14:54 ` [PATCH 1/7] drm/amdgpu: add amdgpu_bo_vm bo type Alex Deucher
@ 2021-05-21 15:19   ` Nirmoy
  0 siblings, 0 replies; 15+ messages in thread
From: Nirmoy @ 2021-05-21 15:19 UTC (permalink / raw)
  To: Alex Deucher, Nirmoy Das
  Cc: Deucher, Alexander, Christian Koenig, amd-gfx list


On 5/21/21 4:54 PM, Alex Deucher wrote:
> On Fri, May 21, 2021 at 8:46 AM Nirmoy Das <nirmoy.das@amd.com> wrote:
>> Add new BO subcalss that will be used by amdgpu vm code.
> s/subcalss/subclass/


Thanks, Alex!

>
> Alex
>
>> Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
>> ---
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 32 ++++++++++++++++++++++
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 10 +++++++
>>   2 files changed, 42 insertions(+)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>> index 745fcf3ea450..61b1edcb490a 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>> @@ -692,6 +692,38 @@ int amdgpu_bo_create_user(struct amdgpu_device *adev,
>>          *ubo_ptr = to_amdgpu_bo_user(bo_ptr);
>>          return r;
>>   }
>> +
>> +/**
>> + * amdgpu_bo_create_vm - create an &amdgpu_bo_vm buffer object
>> + * @adev: amdgpu device object
>> + * @bp: parameters to be used for the buffer object
>> + * @vmbo_ptr: pointer to the buffer object pointer
>> + *
>> + * Create a BO to be for GPUVM.
>> + *
>> + * Returns:
>> + * 0 for success or a negative error code on failure.
>> + */
>> +
>> +int amdgpu_bo_create_vm(struct amdgpu_device *adev,
>> +                       struct amdgpu_bo_param *bp,
>> +                       struct amdgpu_bo_vm **vmbo_ptr)
>> +{
>> +       struct amdgpu_bo *bo_ptr;
>> +       int r;
>> +
>> +       /* bo_ptr_size will be determined by the caller and it depends on
>> +        * num of amdgpu_vm_pt entries.
>> +        */
>> +       BUG_ON(bp->bo_ptr_size < sizeof(struct amdgpu_bo_vm));
>> +       r = amdgpu_bo_create(adev, bp, &bo_ptr);
>> +       if (r)
>> +               return r;
>> +
>> +       *vmbo_ptr = to_amdgpu_bo_vm(bo_ptr);
>> +       return r;
>> +}
>> +
>>   /**
>>    * amdgpu_bo_validate - validate an &amdgpu_bo buffer object
>>    * @bo: pointer to the buffer object
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
>> index 11480c5a2716..a7fbf5f7051e 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
>> @@ -44,6 +44,7 @@
>>   #define AMDGPU_AMDKFD_CREATE_SVM_BO    (1ULL << 62)
>>
>>   #define to_amdgpu_bo_user(abo) container_of((abo), struct amdgpu_bo_user, bo)
>> +#define to_amdgpu_bo_vm(abo) container_of((abo), struct amdgpu_bo_vm, bo)
>>
>>   struct amdgpu_bo_param {
>>          unsigned long                   size;
>> @@ -125,6 +126,12 @@ struct amdgpu_bo_user {
>>
>>   };
>>
>> +struct amdgpu_bo_vm {
>> +       struct amdgpu_bo                bo;
>> +       struct amdgpu_bo                *shadow;
>> +       struct amdgpu_vm_pt             entries[];
>> +};
>> +
>>   static inline struct amdgpu_bo *ttm_to_amdgpu_bo(struct ttm_buffer_object *tbo)
>>   {
>>          return container_of(tbo, struct amdgpu_bo, tbo);
>> @@ -272,6 +279,9 @@ int amdgpu_bo_create_kernel_at(struct amdgpu_device *adev,
>>   int amdgpu_bo_create_user(struct amdgpu_device *adev,
>>                            struct amdgpu_bo_param *bp,
>>                            struct amdgpu_bo_user **ubo_ptr);
>> +int amdgpu_bo_create_vm(struct amdgpu_device *adev,
>> +                       struct amdgpu_bo_param *bp,
>> +                       struct amdgpu_bo_vm **ubo_ptr);
>>   void amdgpu_bo_free_kernel(struct amdgpu_bo **bo, u64 *gpu_addr,
>>                             void **cpu_addr);
>>   int amdgpu_bo_create_shadow(struct amdgpu_device *adev,
>> --
>> 2.31.1
>>
>> _______________________________________________
>> amd-gfx mailing list
>> amd-gfx@lists.freedesktop.org
>> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=04%7C01%7Cnirmoy.das%40amd.com%7C87c7640809fa40c6156808d91c68614e%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637572056899554154%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=57XL2ddPiPTzp1mM7xKi6o3vHzeDHB37vOjJyxL%2FD4s%3D&amp;reserved=0
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 1/7] drm/amdgpu: add amdgpu_bo_vm bo type
  2021-05-26 10:10 Nirmoy Das
@ 2021-05-26 12:01 ` Christian König
  0 siblings, 0 replies; 15+ messages in thread
From: Christian König @ 2021-05-26 12:01 UTC (permalink / raw)
  To: Nirmoy Das, amd-gfx; +Cc: alexander.deucher

Am 26.05.21 um 12:10 schrieb Nirmoy Das:
> Add new BO subclass that will be used by amdgpu vm code.
>
> Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 32 ++++++++++++++++++++++
>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 10 +++++++
>   2 files changed, 42 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> index 3f85ba8222ef..6870cc297ae6 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> @@ -694,6 +694,38 @@ int amdgpu_bo_create_user(struct amdgpu_device *adev,
>   	*ubo_ptr = to_amdgpu_bo_user(bo_ptr);
>   	return r;
>   }
> +
> +/**
> + * amdgpu_bo_create_vm - create an &amdgpu_bo_vm buffer object
> + * @adev: amdgpu device object
> + * @bp: parameters to be used for the buffer object
> + * @vmbo_ptr: pointer to the buffer object pointer
> + *
> + * Create a BO to be for GPUVM.
> + *
> + * Returns:
> + * 0 for success or a negative error code on failure.
> + */
> +
> +int amdgpu_bo_create_vm(struct amdgpu_device *adev,
> +			struct amdgpu_bo_param *bp,
> +			struct amdgpu_bo_vm **vmbo_ptr)
> +{
> +	struct amdgpu_bo *bo_ptr;
> +	int r;
> +
> +	/* bo_ptr_size will be determined by the caller and it depends on
> +	 * num of amdgpu_vm_pt entries.
> +	 */
> +	BUG_ON(bp->bo_ptr_size < sizeof(struct amdgpu_bo_vm));
> +	r = amdgpu_bo_create(adev, bp, &bo_ptr);
> +	if (r)
> +		return r;
> +
> +	*vmbo_ptr = to_amdgpu_bo_vm(bo_ptr);
> +	return r;
> +}
> +
>   /**
>    * amdgpu_bo_validate - validate an &amdgpu_bo buffer object
>    * @bo: pointer to the buffer object
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> index 11480c5a2716..a7fbf5f7051e 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> @@ -44,6 +44,7 @@
>   #define AMDGPU_AMDKFD_CREATE_SVM_BO	(1ULL << 62)
>   
>   #define to_amdgpu_bo_user(abo) container_of((abo), struct amdgpu_bo_user, bo)
> +#define to_amdgpu_bo_vm(abo) container_of((abo), struct amdgpu_bo_vm, bo)
>   
>   struct amdgpu_bo_param {
>   	unsigned long			size;
> @@ -125,6 +126,12 @@ struct amdgpu_bo_user {
>   
>   };
>   
> +struct amdgpu_bo_vm {
> +	struct amdgpu_bo		bo;
> +	struct amdgpu_bo		*shadow;
> +	struct amdgpu_vm_pt             entries[];
> +};
> +
>   static inline struct amdgpu_bo *ttm_to_amdgpu_bo(struct ttm_buffer_object *tbo)
>   {
>   	return container_of(tbo, struct amdgpu_bo, tbo);
> @@ -272,6 +279,9 @@ int amdgpu_bo_create_kernel_at(struct amdgpu_device *adev,
>   int amdgpu_bo_create_user(struct amdgpu_device *adev,
>   			  struct amdgpu_bo_param *bp,
>   			  struct amdgpu_bo_user **ubo_ptr);
> +int amdgpu_bo_create_vm(struct amdgpu_device *adev,
> +			struct amdgpu_bo_param *bp,
> +			struct amdgpu_bo_vm **ubo_ptr);
>   void amdgpu_bo_free_kernel(struct amdgpu_bo **bo, u64 *gpu_addr,
>   			   void **cpu_addr);
>   int amdgpu_bo_create_shadow(struct amdgpu_device *adev,

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 1/7] drm/amdgpu: add amdgpu_bo_vm bo type
@ 2021-05-26 10:10 Nirmoy Das
  2021-05-26 12:01 ` Christian König
  0 siblings, 1 reply; 15+ messages in thread
From: Nirmoy Das @ 2021-05-26 10:10 UTC (permalink / raw)
  To: amd-gfx; +Cc: alexander.deucher, Nirmoy Das, Christian.Koenig

Add new BO subclass that will be used by amdgpu vm code.

Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 32 ++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 10 +++++++
 2 files changed, 42 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index 3f85ba8222ef..6870cc297ae6 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -694,6 +694,38 @@ int amdgpu_bo_create_user(struct amdgpu_device *adev,
 	*ubo_ptr = to_amdgpu_bo_user(bo_ptr);
 	return r;
 }
+
+/**
+ * amdgpu_bo_create_vm - create an &amdgpu_bo_vm buffer object
+ * @adev: amdgpu device object
+ * @bp: parameters to be used for the buffer object
+ * @vmbo_ptr: pointer to the buffer object pointer
+ *
+ * Create a BO to be for GPUVM.
+ *
+ * Returns:
+ * 0 for success or a negative error code on failure.
+ */
+
+int amdgpu_bo_create_vm(struct amdgpu_device *adev,
+			struct amdgpu_bo_param *bp,
+			struct amdgpu_bo_vm **vmbo_ptr)
+{
+	struct amdgpu_bo *bo_ptr;
+	int r;
+
+	/* bo_ptr_size will be determined by the caller and it depends on
+	 * num of amdgpu_vm_pt entries.
+	 */
+	BUG_ON(bp->bo_ptr_size < sizeof(struct amdgpu_bo_vm));
+	r = amdgpu_bo_create(adev, bp, &bo_ptr);
+	if (r)
+		return r;
+
+	*vmbo_ptr = to_amdgpu_bo_vm(bo_ptr);
+	return r;
+}
+
 /**
  * amdgpu_bo_validate - validate an &amdgpu_bo buffer object
  * @bo: pointer to the buffer object
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
index 11480c5a2716..a7fbf5f7051e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
@@ -44,6 +44,7 @@
 #define AMDGPU_AMDKFD_CREATE_SVM_BO	(1ULL << 62)
 
 #define to_amdgpu_bo_user(abo) container_of((abo), struct amdgpu_bo_user, bo)
+#define to_amdgpu_bo_vm(abo) container_of((abo), struct amdgpu_bo_vm, bo)
 
 struct amdgpu_bo_param {
 	unsigned long			size;
@@ -125,6 +126,12 @@ struct amdgpu_bo_user {
 
 };
 
+struct amdgpu_bo_vm {
+	struct amdgpu_bo		bo;
+	struct amdgpu_bo		*shadow;
+	struct amdgpu_vm_pt             entries[];
+};
+
 static inline struct amdgpu_bo *ttm_to_amdgpu_bo(struct ttm_buffer_object *tbo)
 {
 	return container_of(tbo, struct amdgpu_bo, tbo);
@@ -272,6 +279,9 @@ int amdgpu_bo_create_kernel_at(struct amdgpu_device *adev,
 int amdgpu_bo_create_user(struct amdgpu_device *adev,
 			  struct amdgpu_bo_param *bp,
 			  struct amdgpu_bo_user **ubo_ptr);
+int amdgpu_bo_create_vm(struct amdgpu_device *adev,
+			struct amdgpu_bo_param *bp,
+			struct amdgpu_bo_vm **ubo_ptr);
 void amdgpu_bo_free_kernel(struct amdgpu_bo **bo, u64 *gpu_addr,
 			   void **cpu_addr);
 int amdgpu_bo_create_shadow(struct amdgpu_device *adev,
-- 
2.31.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2021-05-26 12:01 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-21 12:45 [PATCH 1/7] drm/amdgpu: add amdgpu_bo_vm bo type Nirmoy Das
2021-05-21 12:45 ` [PATCH 2/7] drm/amdgpu: add a new identifier for amdgpu_bo Nirmoy Das
2021-05-21 12:58   ` Christian König
2021-05-21 13:54     ` Nirmoy
2021-05-21 12:45 ` [PATCH 3/7] drm/amdgpu: use amdgpu_bo_vm for vm code Nirmoy Das
2021-05-21 12:45 ` [PATCH 4/7] drm/amdgpu: create shadow bo directly Nirmoy Das
2021-05-21 12:45 ` [PATCH 5/7] drm/amdgpu: switch to amdgpu_bo_vm's shadow Nirmoy Das
2021-05-21 12:45 ` [PATCH 6/7] drm/amdgpu: remove unused code Nirmoy Das
2021-05-21 12:45 ` [PATCH 7/7] drm/amdgpu: do not allocate entries separately Nirmoy Das
2021-05-21 13:01   ` Christian König
2021-05-21 14:04     ` Nirmoy
2021-05-21 14:54 ` [PATCH 1/7] drm/amdgpu: add amdgpu_bo_vm bo type Alex Deucher
2021-05-21 15:19   ` Nirmoy
2021-05-26 10:10 Nirmoy Das
2021-05-26 12:01 ` Christian König

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.