Skip to contentSkip to conversation

drm/amdgpu: expose amdgpu_bo_create_shadow()

PATCH In review Nirmoy Das 4 participants 10 messages Apr 22, 2021

Subsystems (3)
lore
Share & tools
lore

Nirmoy Das

author
#0 lore raw

PATCH 1/5 drm/amdgpu: expose amdgpu_bo_create_shadow()

Exposed amdgpu_bo_create_shadow() will be needed
for amdgpu_vm handling.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 6 +++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 3 +++
 2 files changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +3 -3
index 1345f7eba011..9cdeb20fb6cd 100644
@@ -625,9 +625,9 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev,
 	return r;
 }
 
-static int amdgpu_bo_create_shadow(struct amdgpu_device *adev,
-				   unsigned long size,
-				   struct amdgpu_bo *bo)
+int amdgpu_bo_create_shadow(struct amdgpu_device *adev,
+			    unsigned long size,
+			    struct amdgpu_bo *bo)
 {
 	struct amdgpu_bo_param bp;
 	int r;
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +3 -0
index 973c88bdf37b..e0ec48d6a3fd 100644
@@ -271,6 +271,9 @@ int amdgpu_bo_create_user(struct amdgpu_device *adev,
 			  struct amdgpu_bo_user **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);
Signature · 6 lines
2.31.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
author
#1 lore raw

PATCH 2/5 drm/amdgpu: initialize vm->is_compute_context properly

Fix vm->is_compute_context initialization in amdgpu_vm_init().

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3 -3
index f95bcda8463f..6f0a6011cb3d 100644
@@ -2815,9 +2815,9 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 		goto error_free_immediate;
 
 	vm->pte_support_ats = false;
-	vm->is_compute_context = false;
+	vm->is_compute_context = vm_context == AMDGPU_VM_CONTEXT_COMPUTE;
 
-	if (vm_context == AMDGPU_VM_CONTEXT_COMPUTE) {
+	if (vm->is_compute_context) {
 		vm->use_cpu_for_update = !!(adev->vm_manager.vm_update_mode &
 						AMDGPU_VM_USE_CPU_FOR_COMPUTE);
 
@@ -2844,7 +2844,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 	vm->evicting = false;
 
 	amdgpu_vm_bo_param(adev, vm, adev->vm_manager.root_level, false, &bp);
-	if (vm_context == AMDGPU_VM_CONTEXT_COMPUTE)
+	if (vm->is_compute_context)
 		bp.flags &= ~AMDGPU_GEM_CREATE_SHADOW;
 	r = amdgpu_bo_create(adev, &bp, &root);
 	if (r)
Signature · 6 lines
2.31.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#2 lore raw

Re: [PATCH 2/5] drm/amdgpu: initialize vm->is_compute_context properly

Am 2021-04-22 um 8:35 a.m. schrieb Nirmoy Das:

Quoted 12 lines

Fix vm->is_compute_context initialization in amdgpu_vm_init().

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
index f95bcda8463f..6f0a6011cb3d 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 2820

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -2
@@ -2815,9 +2815,9 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 		goto error_free_immediate;
 
 	vm->pte_support_ats = false;
-	vm->is_compute_context = false;
+	vm->is_compute_context = vm_context == AMDGPU_VM_CONTEXT_COMPUTE;
 
-	if (vm_context == AMDGPU_VM_CONTEXT_COMPUTE) {
+	if (vm->is_compute_context) {

A weak ago or so, I submitted a patch that removed the last call to amdgpu_vm_init with vm_context == AMDGPU_VM_CONTEXT_COMPUTE. We could probably clean this up now and remove the vm_context parameter and the AMDGPU_VM_CONTEXT* definitions. The only way to get a compute VM now is through amdgpu_vm_make_compute.

Regards,
  Felix

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 2850

Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
 		vm->use_cpu_for_update = !!(adev->vm_manager.vm_update_mode &
 						AMDGPU_VM_USE_CPU_FOR_COMPUTE);
 
@@ -2844,7 +2844,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 	vm->evicting = false;
 
 	amdgpu_vm_bo_param(adev, vm, adev->vm_manager.root_level, false, &bp);
-	if (vm_context == AMDGPU_VM_CONTEXT_COMPUTE)
+	if (vm->is_compute_context)
 		bp.flags &= ~AMDGPU_GEM_CREATE_SHADOW;
 	r = amdgpu_bo_create(adev, &bp, &root);
 	if (r)

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#3 lore raw

Re: [PATCH 2/5] drm/amdgpu: initialize vm->is_compute_context properly

Quoted 19 lines · Felix Kuehling

Am 2021-04-22 um 8:35 a.m. schrieb Nirmoy Das:

Quoted 18 lines

Fix vm->is_compute_context initialization in amdgpu_vm_init().

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
index f95bcda8463f..6f0a6011cb3d 100644
@@ -2815,9 +2815,9 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
  		goto error_free_immediate;
 
  	vm->pte_support_ats = false;
-	vm->is_compute_context = false;
+	vm->is_compute_context = vm_context == AMDGPU_VM_CONTEXT_COMPUTE;
 
Quoted 7 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 2820

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
-	if (vm_context == AMDGPU_VM_CONTEXT_COMPUTE) {
+	if (vm->is_compute_context) {

A weak ago or so, I submitted a patch that removed the last call to amdgpu_vm_init with vm_context == AMDGPU_VM_CONTEXT_COMPUTE. We could probably clean this up now and remove the vm_context parameter and the AMDGPU_VM_CONTEXT* definitions. The only way to get a compute VM now is through amdgpu_vm_make_compute.

I was wondering about that. I will remove vm_context.

Thanks,

Nirmoy

Quoted 10 lines

Regards,
  Felix

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
  		vm->use_cpu_for_update = !!(adev->vm_manager.vm_update_mode &
  						AMDGPU_VM_USE_CPU_FOR_COMPUTE);
 
@@ -2844,7 +2844,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
  	vm->evicting = false;
 
Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 2850

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
  	amdgpu_vm_bo_param(adev, vm, adev->vm_manager.root_level, false, &bp);
-	if (vm_context == AMDGPU_VM_CONTEXT_COMPUTE)
+	if (vm->is_compute_context)
  		bp.flags &= ~AMDGPU_GEM_CREATE_SHADOW;
  	r = amdgpu_bo_create(adev, &bp, &root);
  	if (r)

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

author
#4 lore raw

PATCH 3/5 drm/amdgpu: create shadow bo using amdgpu_bo_create_shadow()

In reply to Nirmoy Das

Shadow BOs are only needed for vm code so call amdgpu_bo_create_shadow() directly instead of depending on amdgpu_bo_create().

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 75 +++++++++++++++++---------
 1 file changed, 49 insertions(+), 26 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +49 -26
index 6f0a6011cb3d..0e1d08a88f54 100644
@@ -850,35 +850,64 @@ static int amdgpu_vm_clear_bo(struct amdgpu_device *adev,
 }
 
 /**
- * amdgpu_vm_bo_param - fill in parameters for PD/PT allocation
+ * amdgpu_vm_bo_create - create bo for PD/PT
  *
  * @adev: amdgpu_device pointer
  * @vm: requesting vm
  * @level: the page table level
  * @immediate: use a immediate update
- * @bp: resulting BO allocation parameters
+ * @bo: pointer to the buffer object pointer
  */
-static void amdgpu_vm_bo_param(struct amdgpu_device *adev, struct amdgpu_vm *vm,
-			       int level, bool immediate,
-			       struct amdgpu_bo_param *bp)
+static int amdgpu_vm_bo_create(struct amdgpu_device *adev,
+				struct amdgpu_vm *vm,
+				int level, bool immediate,
+				struct amdgpu_bo **bo)
 {
-	memset(bp, 0, sizeof(*bp));
+	struct amdgpu_bo_param bp;
+	bool create_shadow = false;
+	int r;
 
-	bp->size = amdgpu_vm_bo_size(adev, level);
-	bp->byte_align = AMDGPU_GPU_PAGE_SIZE;
-	bp->domain = AMDGPU_GEM_DOMAIN_VRAM;
-	bp->domain = amdgpu_bo_get_preferred_pin_domain(adev, bp->domain);
-	bp->flags = AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS |
+	memset(&bp, 0, sizeof(bp));
+
+	bp.size = amdgpu_vm_bo_size(adev, level);
+	bp.byte_align = AMDGPU_GPU_PAGE_SIZE;
+	bp.domain = AMDGPU_GEM_DOMAIN_VRAM;
+	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);
 	if (vm->use_cpu_for_update)
-		bp->flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
+		bp.flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
 	else if (!vm->root.base.bo || vm->root.base.bo->shadow)
-		bp->flags |= AMDGPU_GEM_CREATE_SHADOW;
-	bp->type = ttm_bo_type_kernel;
-	bp->no_wait_gpu = immediate;
+		create_shadow = true;
+
+	bp.type = ttm_bo_type_kernel;
+	bp.no_wait_gpu = immediate;
 	if (vm->root.base.bo)
-		bp->resv = vm->root.base.bo->tbo.base.resv;
+		bp.resv = vm->root.base.bo->tbo.base.resv;
+
+
+	r = amdgpu_bo_create(adev, &bp, bo);
+	if (r)
+		return r;
+	if (!vm->is_compute_context &&
+	    !(adev->flags & AMD_IS_APU) &&
+	    create_shadow) {
+		if (!bp.resv)
+			WARN_ON(dma_resv_lock((*bo)->tbo.base.resv,
+					      NULL));
+		r = amdgpu_bo_create_shadow(adev, bp.size, *bo);
+
+		if (!bp.resv)
+			dma_resv_unlock((*bo)->tbo.base.resv);
+
+		if (r) {
+			amdgpu_bo_unref(bo);
+			return r;
+		}
+	}
+
+	return 0;
 }
 
 /**
@@ -901,7 +930,6 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
 			       bool immediate)
 {
 	struct amdgpu_vm_pt *entry = cursor->entry;
-	struct amdgpu_bo_param bp;
 	struct amdgpu_bo *pt;
 	int r;
 
@@ -919,9 +947,7 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
 	if (entry->base.bo)
 		return 0;
 
-	amdgpu_vm_bo_param(adev, vm, cursor->level, immediate, &bp);
-
-	r = amdgpu_bo_create(adev, &bp, &pt);
+	r = amdgpu_vm_bo_create(adev, vm, cursor->level, immediate, &pt);
 	if (r)
 		return r;
 
@@ -2785,7 +2811,6 @@ long amdgpu_vm_wait_idle(struct amdgpu_vm *vm, long timeout)
 int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 		   int vm_context, u32 pasid)
 {
-	struct amdgpu_bo_param bp;
 	struct amdgpu_bo *root;
 	int r, i;
 
@@ -2843,10 +2868,8 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 	mutex_init(&vm->eviction_lock);
 	vm->evicting = false;
 
-	amdgpu_vm_bo_param(adev, vm, adev->vm_manager.root_level, false, &bp);
-	if (vm->is_compute_context)
-		bp.flags &= ~AMDGPU_GEM_CREATE_SHADOW;
-	r = amdgpu_bo_create(adev, &bp, &root);
+	r = amdgpu_vm_bo_create(adev, vm, adev->vm_manager.root_level,
+				false, &root);
 	if (r)
 		goto error_free_delayed;
 
Signature · 6 lines
2.31.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#5 lore raw

Re: [PATCH 3/5] drm/amdgpu: create shadow bo using amdgpu_bo_create_shadow()

Am 22.04.21 um 14:35 schrieb Nirmoy Das:

Quoted 13 lines

Shadow BOs are only needed for vm code so call amdgpu_bo_create_shadow() directly instead of depending on amdgpu_bo_create().

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 75 +++++++++++++++++---------
  1 file changed, 49 insertions(+), 26 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
index 6f0a6011cb3d..0e1d08a88f54 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_clear_bo(struct amdgpu_device *adev, · line 853

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
@@ -850,35 +850,64 @@ static int amdgpu_vm_clear_bo(struct amdgpu_device *adev,
  }
 
  /**
- * amdgpu_vm_bo_param - fill in parameters for PD/PT allocation
+ * amdgpu_vm_bo_create - create bo for PD/PT

Better name that amdgpu_vm_pt_create.

Quoted 48 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +21 -15
   *
   * @adev: amdgpu_device pointer
   * @vm: requesting vm
   * @level: the page table level
   * @immediate: use a immediate update
- * @bp: resulting BO allocation parameters
+ * @bo: pointer to the buffer object pointer
   */
-static void amdgpu_vm_bo_param(struct amdgpu_device *adev, struct amdgpu_vm *vm,
-			       int level, bool immediate,
-			       struct amdgpu_bo_param *bp)
+static int amdgpu_vm_bo_create(struct amdgpu_device *adev,
+				struct amdgpu_vm *vm,
+				int level, bool immediate,
+				struct amdgpu_bo **bo)
  {
-	memset(bp, 0, sizeof(*bp));
+	struct amdgpu_bo_param bp;
+	bool create_shadow = false;
+	int r;
 
-	bp->size = amdgpu_vm_bo_size(adev, level);
-	bp->byte_align = AMDGPU_GPU_PAGE_SIZE;
-	bp->domain = AMDGPU_GEM_DOMAIN_VRAM;
-	bp->domain = amdgpu_bo_get_preferred_pin_domain(adev, bp->domain);
-	bp->flags = AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS |
+	memset(&bp, 0, sizeof(bp));
+
+	bp.size = amdgpu_vm_bo_size(adev, level);
+	bp.byte_align = AMDGPU_GPU_PAGE_SIZE;
+	bp.domain = AMDGPU_GEM_DOMAIN_VRAM;
+	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);
  	if (vm->use_cpu_for_update)
-		bp->flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
+		bp.flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
  	else if (!vm->root.base.bo || vm->root.base.bo->shadow)
-		bp->flags |= AMDGPU_GEM_CREATE_SHADOW;
-	bp->type = ttm_bo_type_kernel;
-	bp->no_wait_gpu = immediate;
+		create_shadow = true;
+
+	bp.type = ttm_bo_type_kernel;
+	bp.no_wait_gpu = immediate;
  	if (vm->root.base.bo)

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_clear_bo(struct amdgpu_device *adev, · line 895

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +9 -1
-		bp->resv = vm->root.base.bo->tbo.base.resv;
+		bp.resv = vm->root.base.bo->tbo.base.resv;
+
+
+	r = amdgpu_bo_create(adev, &bp, bo);
+	if (r)
+		return r;
+	if (!vm->is_compute_context &&
+	    !(adev->flags & AMD_IS_APU) &&
+	    create_shadow) {

Better drop the create_show flag and just always check it like this:

if (vm->is_compute_context || adev->flags & AMD_IS_APU) return 0;

Apart from that looks good to me.

Christian.

Quoted 48 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +16 -5
+		if (!bp.resv)
+			WARN_ON(dma_resv_lock((*bo)->tbo.base.resv,
+					      NULL));
+		r = amdgpu_bo_create_shadow(adev, bp.size, *bo);
+
+		if (!bp.resv)
+			dma_resv_unlock((*bo)->tbo.base.resv);
+
+		if (r) {
+			amdgpu_bo_unref(bo);
+			return r;
+		}
+	}
+
+	return 0;
  }
 
  /**
@@ -901,7 +930,6 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
  			       bool immediate)
  {
  	struct amdgpu_vm_pt *entry = cursor->entry;
-	struct amdgpu_bo_param bp;
  	struct amdgpu_bo *pt;
  	int r;
 
@@ -919,9 +947,7 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
  	if (entry->base.bo)
  		return 0;
 
-	amdgpu_vm_bo_param(adev, vm, cursor->level, immediate, &bp);
-
-	r = amdgpu_bo_create(adev, &bp, &pt);
+	r = amdgpu_vm_bo_create(adev, vm, cursor->level, immediate, &pt);
  	if (r)
  		return r;
 
@@ -2785,7 +2811,6 @@ long amdgpu_vm_wait_idle(struct amdgpu_vm *vm, long timeout)
  int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
  		   int vm_context, u32 pasid)
  {
-	struct amdgpu_bo_param bp;
  	struct amdgpu_bo *root;
  	int r, i;
 
@@ -2843,10 +2868,8 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
  	mutex_init(&vm->eviction_lock);
  	vm->evicting = false;

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 2875

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -4
 
-	amdgpu_vm_bo_param(adev, vm, adev->vm_manager.root_level, false, &bp);
-	if (vm->is_compute_context)
-		bp.flags &= ~AMDGPU_GEM_CREATE_SHADOW;
-	r = amdgpu_bo_create(adev, &bp, &root);
+	r = amdgpu_vm_bo_create(adev, vm, adev->vm_manager.root_level,
+				false, &root);
  	if (r)
  		goto error_free_delayed;
 

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#6 lore raw

Re: [PATCH 3/5] drm/amdgpu: create shadow bo using amdgpu_bo_create_shadow()

Quoted 83 lines · Christian König

Am 22.04.21 um 14:35 schrieb Nirmoy Das:

Quoted 13 lines

Shadow BOs are only needed for vm code so call amdgpu_bo_create_shadow() directly instead of depending on amdgpu_bo_create().

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 75 +++++++++++++++++---------

  1 file changed, 49 insertions(+), 26 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
index 6f0a6011cb3d..0e1d08a88f54 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_clear_bo(struct · line 853

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
@@ -850,35 +850,64 @@ static int amdgpu_vm_clear_bo(struct 
 amdgpu_device *adev,
   }
     /**
- * amdgpu_vm_bo_param - fill in parameters for PD/PT allocation
+ * amdgpu_vm_bo_create - create bo for PD/PT

Better name that amdgpu_vm_pt_create.

Quoted 48 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +21 -14
    *
    * @adev: amdgpu_device pointer
    * @vm: requesting vm
    * @level: the page table level
    * @immediate: use a immediate update
- * @bp: resulting BO allocation parameters
+ * @bo: pointer to the buffer object pointer
    */
-static void amdgpu_vm_bo_param(struct amdgpu_device *adev, struct 
 amdgpu_vm *vm,
-                   int level, bool immediate,
-                   struct amdgpu_bo_param *bp)
+static int amdgpu_vm_bo_create(struct amdgpu_device *adev,
+                struct amdgpu_vm *vm,
+                int level, bool immediate,
+                struct amdgpu_bo **bo)
   {
-    memset(bp, 0, sizeof(*bp));
+    struct amdgpu_bo_param bp;
+    bool create_shadow = false;
+    int r;
   -    bp->size = amdgpu_vm_bo_size(adev, level);
-    bp->byte_align = AMDGPU_GPU_PAGE_SIZE;
-    bp->domain = AMDGPU_GEM_DOMAIN_VRAM;
-    bp->domain = amdgpu_bo_get_preferred_pin_domain(adev, bp->domain);
-    bp->flags = AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS |
+    memset(&bp, 0, sizeof(bp));
+
+    bp.size = amdgpu_vm_bo_size(adev, level);
+    bp.byte_align = AMDGPU_GPU_PAGE_SIZE;
+    bp.domain = AMDGPU_GEM_DOMAIN_VRAM;
+    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);
       if (vm->use_cpu_for_update)
-        bp->flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
+        bp.flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
       else if (!vm->root.base.bo || vm->root.base.bo->shadow)
-        bp->flags |= AMDGPU_GEM_CREATE_SHADOW;
-    bp->type = ttm_bo_type_kernel;
-    bp->no_wait_gpu = immediate;
+        create_shadow = true;
+
+    bp.type = ttm_bo_type_kernel;
+    bp.no_wait_gpu = immediate;
       if (vm->root.base.bo)

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_clear_bo(struct amdgpu_device *adev, · line 895

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +9 -1
-        bp->resv = vm->root.base.bo->tbo.base.resv;
+        bp.resv = vm->root.base.bo->tbo.base.resv;
+
+
+    r = amdgpu_bo_create(adev, &bp, bo);
+    if (r)
+        return r;
+    if (!vm->is_compute_context &&
+        !(adev->flags & AMD_IS_APU) &&
+        create_shadow) {

Better drop the create_show flag and just always check it like this:

Quoted 4 lines

if (vm->is_compute_context || adev->flags & AMD_IS_APU) return 0;

Apart from that looks good to me.

Thanks Christian, I will resend with your suggestions.

Nirmoy

Quoted 47 lines

Christian.

Quoted 44 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +15 -1
+        if (!bp.resv)
+            WARN_ON(dma_resv_lock((*bo)->tbo.base.resv,
+                          NULL));
+        r = amdgpu_bo_create_shadow(adev, bp.size, *bo);
+
+        if (!bp.resv)
+            dma_resv_unlock((*bo)->tbo.base.resv);
+
+        if (r) {
+            amdgpu_bo_unref(bo);
+            return r;
+        }
+    }
+
+    return 0;
   }
     /**
@@ -901,7 +930,6 @@ static int amdgpu_vm_alloc_pts(struct 
 amdgpu_device *adev,
                      bool immediate)
   {
       struct amdgpu_vm_pt *entry = cursor->entry;
-    struct amdgpu_bo_param bp;
       struct amdgpu_bo *pt;
       int r;

  @@ -919,9 +947,7 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev, if (entry->base.bo)
          return 0;
  -    amdgpu_vm_bo_param(adev, vm, cursor->level, immediate, &bp);
-
-    r = amdgpu_bo_create(adev, &bp, &pt);
+    r = amdgpu_vm_bo_create(adev, vm, cursor->level, immediate, &pt);
      if (r)
          return r;
  @@ -2785,7 +2811,6 @@ long amdgpu_vm_wait_idle(struct amdgpu_vm *vm, long timeout) int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
             int vm_context, u32 pasid)
  {
-    struct amdgpu_bo_param bp;
      struct amdgpu_bo *root;
      int r, i;
  @@ -2843,10 +2868,8 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, mutex_init(&vm->eviction_lock);
      vm->evicting = false;

Quoted 9 lines
Quoted 8 lines

  -    amdgpu_vm_bo_param(adev, vm, adev->vm_manager.root_level, false, &bp); -    if (vm->is_compute_context)
-        bp.flags &= ~AMDGPU_GEM_CREATE_SHADOW;
-    r = amdgpu_bo_create(adev, &bp, &root);
+    r = amdgpu_vm_bo_create(adev, vm, adev->vm_manager.root_level, +                false, &root);
      if (r)
          goto error_free_delayed;

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

author
#7 lore raw

PATCH 4/5 drm/amdgpu: cleanup amdgpu_bo_create()

In reply to Nirmoy Das

Remove shadow bo related code as vm code is creating shadow bo using proper API.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 30 ++--------------------
 1 file changed, 2 insertions(+), 28 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -28
index 9cdeb20fb6cd..4256cbfec5eb 100644
@@ -661,10 +661,7 @@ int amdgpu_bo_create_shadow(struct amdgpu_device *adev,
  * @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.
+ * Creates an &amdgpu_bo buffer object.
  *
  * Returns:
  * 0 for success or a negative error code on failure.
@@ -673,30 +670,7 @@ int amdgpu_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;
-
-	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;
+	return  amdgpu_bo_do_create(adev, bp, bo_ptr);
 }
 
 /**
Signature · 6 lines
2.31.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#8 lore raw

Re: [PATCH 4/5] drm/amdgpu: cleanup amdgpu_bo_create()

Am 22.04.21 um 14:35 schrieb Nirmoy Das:

Quoted 43 lines

Remove shadow bo related code as vm code is creating shadow bo using proper API.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 30 ++--------------------
  1 file changed, 2 insertions(+), 28 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -19
index 9cdeb20fb6cd..4256cbfec5eb 100644
@@ -661,10 +661,7 @@ int amdgpu_bo_create_shadow(struct amdgpu_device *adev,
   * @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.
+ * Creates an &amdgpu_bo buffer object.
   *
   * Returns:
   * 0 for success or a negative error code on failure.
@@ -673,30 +670,7 @@ int amdgpu_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;
-
-	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);

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create(struct amdgpu_device *adev, · line 673

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -9
-
-		if (!bp->resv)
-			dma_resv_unlock((*bo_ptr)->tbo.base.resv);
-
-		if (r)
-			amdgpu_bo_unref(bo_ptr);
-	}
-
-	return r;
+	return  amdgpu_bo_do_create(adev, bp, bo_ptr);

You can just rename amdgpu_bo_do_create() into amdgpu_bo_create() now and drop the wrapper as far as I can see.

Christian.

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create(struct amdgpu_device *adev, · line 676

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
  }
 
  /**

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

author
#9 lore raw

PATCH 5/5 drm/amdgpu: remove AMDGPU_GEM_CREATE_SHADOW flag

In reply to Nirmoy Das

Remove unused AMDGPU_GEM_CREATE_SHADOW flag.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 5 +----
 include/uapi/drm/amdgpu_drm.h              | 2 --
 2 files changed, 1 insertion(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -4
index 4256cbfec5eb..2d9bd0d4f81c 100644
@@ -638,8 +638,7 @@ int amdgpu_bo_create_shadow(struct amdgpu_device *adev,
 	memset(&bp, 0, sizeof(bp));
 	bp.size = size;
 	bp.domain = AMDGPU_GEM_DOMAIN_GTT;
-	bp.flags = AMDGPU_GEM_CREATE_CPU_GTT_USWC |
-		AMDGPU_GEM_CREATE_SHADOW;
+	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);
@@ -692,7 +691,6 @@ int amdgpu_bo_create_user(struct amdgpu_device *adev,
 	struct amdgpu_bo *bo_ptr;
 	int r;
 
-	bp->flags = bp->flags & ~AMDGPU_GEM_CREATE_SHADOW;
 	bp->bo_ptr_size = sizeof(struct amdgpu_bo_user);
 	r = amdgpu_bo_do_create(adev, bp, &bo_ptr);
 	if (r)
@@ -1566,7 +1564,6 @@ u64 amdgpu_bo_print_info(int id, struct amdgpu_bo *bo, struct seq_file *m)
 	amdgpu_bo_print_flag(m, bo, NO_CPU_ACCESS);
 	amdgpu_bo_print_flag(m, bo, CPU_GTT_USWC);
 	amdgpu_bo_print_flag(m, bo, VRAM_CLEARED);
-	amdgpu_bo_print_flag(m, bo, SHADOW);
 	amdgpu_bo_print_flag(m, bo, VRAM_CONTIGUOUS);
 	amdgpu_bo_print_flag(m, bo, VM_ALWAYS_VALID);
 	amdgpu_bo_print_flag(m, bo, EXPLICIT_SYNC);
include/uapi/drm/amdgpu_drm.h +0 -2
index 8b832f7458f2..9169df7fadee 100644
@@ -119,8 +119,6 @@ extern "C" {
 #define AMDGPU_GEM_CREATE_CPU_GTT_USWC		(1 << 2)
 /* Flag that the memory should be in VRAM and cleared */
 #define AMDGPU_GEM_CREATE_VRAM_CLEARED		(1 << 3)
-/* Flag that create shadow bo(GTT) while allocating vram bo */
-#define AMDGPU_GEM_CREATE_SHADOW		(1 << 4)
 /* Flag that allocating the BO should use linear VRAM */
 #define AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS	(1 << 5)
 /* Flag that BO is always valid in this VM */
Signature · 6 lines
2.31.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx