Skip to contentSkip to conversation

Implement multi-GPU DMA mappings for KFD

PATCH Superseded Felix Kuehling 4 participants 20 messages Apr 14, 2021

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Felix Kuehling

author maintainer
#0 lore raw

cover Implement multi-GPU DMA mappings for KFD

This patch series fixes DMA-mappings of system memory (GTT and userptr) for KFD running on multi-GPU systems with IOMMU enabled. One SG-BO per GPU is needed to maintain the DMA mappings of each BO.

I ran into some reservation issues when unmapping or freeing DMA-buf imports. There are a few FIXME comments in this patch series where I'm hoping for some expert advice. Patches 8 and 9 are some related fixes in TTM and amdgpu_ttm. I'm pretty sure patch 9 is not the right way to do this.

Felix Kuehling (9):
drm/amdgpu: Rename kfd_bo_va_list to kfd_mem_attachment drm/amdgpu: Keep a bo-reference per-attachment drm/amdgpu: Simplify AQL queue mapping drm/amdgpu: Add multi-GPU DMA mapping helpers drm/amdgpu: DMA map/unmap when updating GPU mappings drm/amdgpu: Move kfd_mem_attach outside reservation drm/amdgpu: Add DMA mapping of GTT BOs
drm/ttm: Don't count pages in SG BOs against pages_limit drm/amdgpu: Lock the attached dmabuf in unpopulate

 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h    |  18 +-
 .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  | 535 ++++++++++++------
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c       |  13 +
 drivers/gpu/drm/ttm/ttm_tt.c                  |  27 +-
 4 files changed, 420 insertions(+), 173 deletions(-)
Signature · 6 lines
2.31.1

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

PATCH 1/9 drm/amdgpu: Rename kfd_bo_va_list to kfd_mem_attachment

This name is more fitting, especially for the changes coming next to support multi-GPU systems with proper DMA mappings. Cleaned up the code and renamed some related functions and variables to improve readability.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h    |   8 +-
 .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  | 209 +++++++++---------
 2 files changed, 104 insertions(+), 113 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +4 -4
index 14f68c028126..910c50956e16 100644
@@ -38,10 +38,10 @@ extern uint64_t amdgpu_amdkfd_total_mem_size;
 
 struct amdgpu_device;
 
-struct kfd_bo_va_list {
-	struct list_head bo_list;
+struct kfd_mem_attachment {
+	struct list_head list;
 	struct amdgpu_bo_va *bo_va;
-	void *kgd_dev;
+	struct amdgpu_device *adev;
 	bool is_mapped;
 	uint64_t va;
 	uint64_t pte_flags;
@@ -50,7 +50,7 @@ struct kfd_bo_va_list {
 struct kgd_mem {
 	struct mutex lock;
 	struct amdgpu_bo *bo;
-	struct list_head bo_va_list;
+	struct list_head attachments;
 	/* protected by amdkfd_process_info.lock */
 	struct ttm_validate_buffer validate_list;
 	struct ttm_validate_buffer resv_list;
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +100 -109

412 lines not on this page · raw message

Signature · 6 lines
2.31.1

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

PATCH 2/9 drm/amdgpu: Keep a bo-reference per-attachment

In reply to Felix Kuehling

For now they all reference the same BO. For correct DMA mappings they will refer to different BOs per-GPU.

---
 .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  | 22 ++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +17 -5
index d021152314ad..40a296ca37b9 100644
@@ -487,11 +487,11 @@ static int kfd_mem_attach(struct amdgpu_device *adev, struct kgd_mem *mem,
 		struct amdgpu_vm *vm, bool is_aql,
 		struct kfd_mem_attachment **p_attachment)
 {
-	int ret;
-	struct kfd_mem_attachment *attachment;
-	struct amdgpu_bo *bo = mem->bo;
+	unsigned long bo_size = mem->bo->tbo.base.size;
 	uint64_t va = mem->va;
-	unsigned long bo_size = bo->tbo.base.size;
+	struct kfd_mem_attachment *attachment;
+	struct amdgpu_bo *bo;
+	int ret;
 
 	if (!va) {
 		pr_err("Invalid VA when adding BO to VM\n");
@@ -508,6 +508,14 @@ static int kfd_mem_attach(struct amdgpu_device *adev, struct kgd_mem *mem,
 	pr_debug("\t add VA 0x%llx - 0x%llx to vm %p\n", va,
 			va + bo_size, vm);
 
+	/* FIXME: For now all attachments use the same BO. This is incorrect
+	 * because one BO can only have one DMA mapping for one GPU. We need
+	 * one BO per GPU, e.g. a DMABuf import with dynamic attachment. This
+	 * will be addressed one BO-type at a time in subsequent patches.
+	 */
+	bo = mem->bo;
+	drm_gem_object_get(&bo->tbo.base);
+
 	/* Add BO to VM internal data structures*/
 	attachment->bo_va = amdgpu_vm_bo_add(adev, vm, bo);
 	if (!attachment->bo_va) {
@@ -527,7 +535,7 @@ static int kfd_mem_attach(struct amdgpu_device *adev, struct kgd_mem *mem,
 
 	/* Allocate validate page tables if needed */
 	ret = vm_validate_pt_pd_bos(vm);
-	if (ret) {
+	if (unlikely(ret)) {
 		pr_err("validate_pt_pd_bos() failed\n");
 		goto err_alloc_pts;
 	}
@@ -538,15 +546,19 @@ static int kfd_mem_attach(struct amdgpu_device *adev, struct kgd_mem *mem,
 	amdgpu_vm_bo_rmv(adev, attachment->bo_va);
 	list_del(&attachment->list);
 err_vmadd:
+	drm_gem_object_put(&bo->tbo.base);
 	kfree(attachment);
 	return ret;
 }
 
 static void kfd_mem_detach(struct kfd_mem_attachment *attachment)
 {
+	struct amdgpu_bo *bo = attachment->bo_va->base.bo;
+
 	pr_debug("\t remove VA 0x%llx in entry %p\n",
 			attachment->va, attachment);
 	amdgpu_vm_bo_rmv(attachment->adev, attachment->bo_va);
+	drm_gem_object_put(&bo->tbo.base);
 	list_del(&attachment->list);
 	kfree(attachment);
 }
Signature · 6 lines
2.31.1

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

PATCH 3/9 drm/amdgpu: Simplify AQL queue mapping

In reply to Felix Kuehling

Do AQL queue double-mapping with a single attach call. That will make it easier to create per-GPU BOs later, to be shared between the two BO VA mappings on the same GPU.

Freeing the attachments is not necessary if map_to_gpu fails. These will be cleaned up when the kdg_mem object is destroyed in amdgpu_amdkfd_gpuvm_free_memory_of_gpu.

---
 .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  | 103 ++++++++----------
 1 file changed, 48 insertions(+), 55 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +48 -55
index 40a296ca37b9..114fbf508707 100644
@@ -484,70 +484,76 @@ static uint64_t get_pte_flags(struct amdgpu_device *adev, struct kgd_mem *mem)
  * 4a.  Validate new page tables and directories
  */
 static int kfd_mem_attach(struct amdgpu_device *adev, struct kgd_mem *mem,
-		struct amdgpu_vm *vm, bool is_aql,
-		struct kfd_mem_attachment **p_attachment)
+		struct amdgpu_vm *vm, bool is_aql)
 {
 	unsigned long bo_size = mem->bo->tbo.base.size;
 	uint64_t va = mem->va;
-	struct kfd_mem_attachment *attachment;
-	struct amdgpu_bo *bo;
-	int ret;
+	struct kfd_mem_attachment *attachment[2] = {NULL, NULL};
+	struct amdgpu_bo *bo[2] = {NULL, NULL};
+	int i, ret;
 
 	if (!va) {
 		pr_err("Invalid VA when adding BO to VM\n");
 		return -EINVAL;
 	}
 
-	if (is_aql)
-		va += bo_size;
-
-	attachment = kzalloc(sizeof(*attachment), GFP_KERNEL);
-	if (!attachment)
-		return -ENOMEM;
+	for (i = 0; i <= is_aql; i++) {
+		attachment[i] = kzalloc(sizeof(*attachment[i]), GFP_KERNEL);
+		if (unlikely(!attachment[i])) {
+			ret = -ENOMEM;
+			goto unwind;
+		}
 
-	pr_debug("\t add VA 0x%llx - 0x%llx to vm %p\n", va,
-			va + bo_size, vm);
+		pr_debug("\t add VA 0x%llx - 0x%llx to vm %p\n", va,
+			 va + bo_size, vm);
 
-	/* FIXME: For now all attachments use the same BO. This is incorrect
-	 * because one BO can only have one DMA mapping for one GPU. We need
-	 * one BO per GPU, e.g. a DMABuf import with dynamic attachment. This
-	 * will be addressed one BO-type at a time in subsequent patches.
-	 */
-	bo = mem->bo;
-	drm_gem_object_get(&bo->tbo.base);
+		/* FIXME: For now all attachments use the same BO. This is
+		 * incorrect because one BO can only have one DMA mapping
+		 * for one GPU. We need one BO per GPU, e.g. a DMABuf
+		 * import with dynamic attachment. This will be addressed
+		 * one BO-type at a time in subsequent patches.
+		 */
+		bo[i] = mem->bo;
+		drm_gem_object_get(&bo[i]->tbo.base);
 
-	/* Add BO to VM internal data structures*/
-	attachment->bo_va = amdgpu_vm_bo_add(adev, vm, bo);
-	if (!attachment->bo_va) {
-		ret = -EINVAL;
-		pr_err("Failed to add BO object to VM. ret == %d\n",
-				ret);
-		goto err_vmadd;
-	}
+		/* Add BO to VM internal data structures */
+		attachment[i]->bo_va = amdgpu_vm_bo_add(adev, vm, bo[i]);
+		if (unlikely(!attachment[i]->bo_va)) {
+			ret = -ENOMEM;
+			pr_err("Failed to add BO object to VM. ret == %d\n",
+			       ret);
+			goto unwind;
+		}
 
-	attachment->va = va;
-	attachment->pte_flags = get_pte_flags(adev, mem);
-	attachment->adev = adev;
-	list_add(&attachment->list, &mem->attachments);
+		attachment[i]->va = va;
+		attachment[i]->pte_flags = get_pte_flags(adev, mem);
+		attachment[i]->adev = adev;
+		list_add(&attachment[i]->list, &mem->attachments);
 
-	if (p_attachment)
-		*p_attachment = attachment;
+		va += bo_size;
+	}
 
 	/* Allocate validate page tables if needed */
 	ret = vm_validate_pt_pd_bos(vm);
 	if (unlikely(ret)) {
 		pr_err("validate_pt_pd_bos() failed\n");
-		goto err_alloc_pts;
+		goto unwind;
 	}
 
 	return 0;
 
-err_alloc_pts:
-	amdgpu_vm_bo_rmv(adev, attachment->bo_va);
-	list_del(&attachment->list);
-err_vmadd:
-	drm_gem_object_put(&bo->tbo.base);
-	kfree(attachment);
+unwind:
+	for (; i >= 0; i--) {
+		if (!attachment[i])
+			continue;
+		if (attachment[i]->bo_va) {
+			amdgpu_vm_bo_rmv(adev, attachment[i]->bo_va);
+			list_del(&attachment[i]->list);
+		}
+		if (bo[i])
+			drm_gem_object_put(&bo[i]->tbo.base);
+		kfree(attachment[i]);
+	}
 	return ret;
 }
 
@@ -1414,8 +1420,6 @@ int amdgpu_amdkfd_gpuvm_map_memory_to_gpu(
 	uint32_t domain;
 	struct kfd_mem_attachment *entry;
 	struct bo_vm_reservation_context ctx;
-	struct kfd_mem_attachment *attachment = NULL;
-	struct kfd_mem_attachment *attachment_aql = NULL;
 	unsigned long bo_size;
 	bool is_invalid_userptr = false;
 
@@ -1465,15 +1469,9 @@ int amdgpu_amdkfd_gpuvm_map_memory_to_gpu(
 		is_invalid_userptr = true;
 
 	if (!kfd_mem_is_attached(avm, mem)) {
-		ret = kfd_mem_attach(adev, mem, avm, false, &attachment);
+		ret = kfd_mem_attach(adev, mem, avm, mem->aql_queue);
 		if (ret)
 			goto attach_failed;
-		if (mem->aql_queue) {
-			ret = kfd_mem_attach(adev, mem, avm, true,
-					     &attachment_aql);
-			if (ret)
-				goto attach_failed_aql;
-		}
 	} else {
 		ret = vm_validate_pt_pd_bos(avm);
 		if (unlikely(ret))
@@ -1528,11 +1526,6 @@ int amdgpu_amdkfd_gpuvm_map_memory_to_gpu(
 	goto out;
 
 map_bo_to_gpuvm_failed:
-	if (attachment_aql)
-		kfd_mem_detach(attachment_aql);
-attach_failed_aql:
-	if (attachment)
-		kfd_mem_detach(attachment);
 attach_failed:
 	unreserve_bo_and_vms(&ctx, false, false);
 out:
Signature · 6 lines
2.31.1

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

PATCH 4/9 drm/amdgpu: Add multi-GPU DMA mapping helpers

In reply to Felix Kuehling

Add BO-type specific helpers functions to DMA-map and unmap kfd_mem_attachments. Implement this functionality for userptrs by creating one SG BO per GPU and filling it with a DMA mapping of the pages from the original mem->bo.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h    |   8 +-
 .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  | 155 ++++++++++++++++--
 2 files changed, 152 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +7 -1
index 910c50956e16..fc3514ed1b74 100644
@@ -38,11 +38,17 @@ extern uint64_t amdgpu_amdkfd_total_mem_size;
 
 struct amdgpu_device;
 
+enum kfd_mem_attachment_type {
+	KFD_MEM_ATT_SHARED,	/* Share kgd_mem->bo or another attachment's */
+	KFD_MEM_ATT_USERPTR,	/* SG bo to DMA map pages from a userptr bo */
+};
+
 struct kfd_mem_attachment {
 	struct list_head list;
+	enum kfd_mem_attachment_type type;
+	bool is_mapped;
 	struct amdgpu_bo_va *bo_va;
 	struct amdgpu_device *adev;
-	bool is_mapped;
 	uint64_t va;
 	uint64_t pte_flags;
 };
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +145 -10

201 lines not on this page · raw message

Signature · 6 lines
2.31.1

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

PATCH 5/9 drm/amdgpu: DMA map/unmap when updating GPU mappings

In reply to Felix Kuehling

DMA map kfd_mem_attachments in update_gpuvm_pte. This function is called with the BO and page tables reserved, so we can safely update the DMA mapping.

DMA unmap when a BO is unmapped from a GPU and before updating mappings in restore workers.

---
 .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  | 56 ++++++++++---------
 1 file changed, 29 insertions(+), 27 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +29 -27
index 51502a07fc1d..3bb2ae185bbb 100644
@@ -964,11 +964,12 @@ static int unreserve_bo_and_vms(struct bo_vm_reservation_context *ctx,
 	return ret;
 }
 
-static int unmap_bo_from_gpuvm(struct amdgpu_device *adev,
+static void unmap_bo_from_gpuvm(struct kgd_mem *mem,
 				struct kfd_mem_attachment *entry,
 				struct amdgpu_sync *sync)
 {
 	struct amdgpu_bo_va *bo_va = entry->bo_va;
+	struct amdgpu_device *adev = entry->adev;
 	struct amdgpu_vm *vm = bo_va->base.vm;
 
 	amdgpu_vm_bo_unmap(adev, bo_va, entry->va);
@@ -977,15 +978,20 @@ static int unmap_bo_from_gpuvm(struct amdgpu_device *adev,
 
 	amdgpu_sync_fence(sync, bo_va->last_pt_update);
 
-	return 0;
+	kfd_mem_dmaunmap_attachment(mem, entry);
 }
 
-static int update_gpuvm_pte(struct amdgpu_device *adev,
-		struct kfd_mem_attachment *entry,
-		struct amdgpu_sync *sync)
+static int update_gpuvm_pte(struct kgd_mem *mem,
+			    struct kfd_mem_attachment *entry,
+			    struct amdgpu_sync *sync)
 {
-	int ret;
 	struct amdgpu_bo_va *bo_va = entry->bo_va;
+	struct amdgpu_device *adev = entry->adev;
+	int ret;
+
+	ret = kfd_mem_dmamap_attachment(mem, entry);
+	if (ret)
+		return ret;
 
 	/* Update the page tables  */
 	ret = amdgpu_vm_bo_update(adev, bo_va, false);
@@ -997,14 +1003,15 @@ static int update_gpuvm_pte(struct amdgpu_device *adev,
 	return amdgpu_sync_fence(sync, bo_va->last_pt_update);
 }
 
-static int map_bo_to_gpuvm(struct amdgpu_device *adev,
-		struct kfd_mem_attachment *entry, struct amdgpu_sync *sync,
-		bool no_update_pte)
+static int map_bo_to_gpuvm(struct kgd_mem *mem,
+			   struct kfd_mem_attachment *entry,
+			   struct amdgpu_sync *sync,
+			   bool no_update_pte)
 {
 	int ret;
 
 	/* Set virtual address for the allocation */
-	ret = amdgpu_vm_bo_map(adev, entry->bo_va, entry->va, 0,
+	ret = amdgpu_vm_bo_map(entry->adev, entry->bo_va, entry->va, 0,
 			       amdgpu_bo_size(entry->bo_va->base.bo),
 			       entry->pte_flags);
 	if (ret) {
@@ -1016,7 +1023,7 @@ static int map_bo_to_gpuvm(struct amdgpu_device *adev,
 	if (no_update_pte)
 		return 0;
 
-	ret = update_gpuvm_pte(adev, entry, sync);
+	ret = update_gpuvm_pte(mem, entry, sync);
 	if (ret) {
 		pr_err("update_gpuvm_pte() failed\n");
 		goto update_gpuvm_pte_failed;
@@ -1025,7 +1032,7 @@ static int map_bo_to_gpuvm(struct amdgpu_device *adev,
 	return 0;
 
 update_gpuvm_pte_failed:
-	unmap_bo_from_gpuvm(adev, entry, sync);
+	unmap_bo_from_gpuvm(mem, entry, sync);
 	return ret;
 }
 
@@ -1633,7 +1640,7 @@ int amdgpu_amdkfd_gpuvm_map_memory_to_gpu(
 		pr_debug("\t map VA 0x%llx - 0x%llx in entry %p\n",
 			 entry->va, entry->va + bo_size, entry);
 
-		ret = map_bo_to_gpuvm(adev, entry, ctx.sync,
+		ret = map_bo_to_gpuvm(mem, entry, ctx.sync,
 				      is_invalid_userptr);
 		if (ret) {
 			pr_err("Failed to map bo to gpuvm\n");
@@ -1672,7 +1679,6 @@ int amdgpu_amdkfd_gpuvm_map_memory_to_gpu(
 int amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu(
 		struct kgd_dev *kgd, struct kgd_mem *mem, void *vm)
 {
-	struct amdgpu_device *adev = get_amdgpu_device(kgd);
 	struct amdkfd_process_info *process_info =
 		((struct amdgpu_vm *)vm)->process_info;
 	unsigned long bo_size = mem->bo->tbo.base.size;
@@ -1707,13 +1713,8 @@ int amdgpu_amdkfd_gpuvm_unmap_memory_from_gpu(
 		pr_debug("\t unmap VA 0x%llx - 0x%llx from entry %p\n",
 			 entry->va, entry->va + bo_size, entry);
 
-		ret = unmap_bo_from_gpuvm(adev, entry, ctx.sync);
-		if (ret == 0) {
-			entry->is_mapped = false;
-		} else {
-			pr_err("failed to unmap VA 0x%llx\n", mem->va);
-			goto unreserve_out;
-		}
+		unmap_bo_from_gpuvm(mem, entry, ctx.sync);
+		entry->is_mapped = false;
 
 		mem->mapped_to_gpu_memory--;
 		pr_debug("\t DEC mapping count %d\n",
@@ -2083,9 +2084,8 @@ static int validate_invalid_user_pages(struct amdkfd_process_info *process_info)
 			if (!attachment->is_mapped)
 				continue;
 
-			ret = update_gpuvm_pte((struct amdgpu_device *)
-					       attachment->adev,
-					       attachment, &sync);
+			kfd_mem_dmaunmap_attachment(mem, attachment);
+			ret = update_gpuvm_pte(mem, attachment, &sync);
 			if (ret) {
 				pr_err("%s: update PTE failed\n", __func__);
 				/* make sure this gets validated again */
@@ -2287,9 +2287,11 @@ int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence **ef)
 			goto validate_map_fail;
 		}
 		list_for_each_entry(attachment, &mem->attachments, list) {
-			ret = update_gpuvm_pte((struct amdgpu_device *)
-					      attachment->adev, attachment,
-					      &sync_obj);
+			if (!attachment->is_mapped)
+				continue;
+
+			kfd_mem_dmaunmap_attachment(mem, attachment);
+			ret = update_gpuvm_pte(mem, attachment, &sync_obj);
 			if (ret) {
 				pr_debug("Memory eviction: update PTE failed. Try again\n");
 				goto validate_map_fail;
Signature · 6 lines
2.31.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#6 lore raw

PATCH 6/9 drm/amdgpu: Move kfd_mem_attach outside reservation

In reply to Felix Kuehling

This is needed to avoid deadlocks with DMA buf import in the next patch. Also move PT/PD validation out of kfd_mem_attach, that way the caller can bo this unconditionally.

---
 .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  | 72 +++++++++++--------
 1 file changed, 42 insertions(+), 30 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +42 -30
index 3bb2ae185bbb..1416f3c03f1d 100644
@@ -575,6 +575,32 @@ kfd_mem_dmaunmap_attachment(struct kgd_mem *mem,
 	}
 }
 
+static int
+kfd_mem_attach_userptr(struct amdgpu_device *adev, struct kgd_mem *mem,
+		       struct amdgpu_bo **bo)
+{
+	unsigned long bo_size = mem->bo->tbo.base.size;
+	struct drm_gem_object *gobj;
+	int ret;
+
+	ret = amdgpu_bo_reserve(mem->bo, false);
+	if (ret)
+		return ret;
+
+	ret = amdgpu_gem_object_create(adev, bo_size, 1,
+				       AMDGPU_GEM_DOMAIN_CPU,
+				       0, ttm_bo_type_sg,
+				       mem->bo->tbo.base.resv,
+				       &gobj);
+	if (ret)
+		return ret;
+
+	amdgpu_bo_unreserve(mem->bo);
+
+	*bo = gem_to_amdgpu_bo(gobj);
+	return 0;
+}
+
 /* kfd_mem_attach - Add a BO to a VM
  *
  * Everything that needs to bo done only once when a BO is first added
@@ -596,7 +622,6 @@ static int kfd_mem_attach(struct amdgpu_device *adev, struct kgd_mem *mem,
 	uint64_t va = mem->va;
 	struct kfd_mem_attachment *attachment[2] = {NULL, NULL};
 	struct amdgpu_bo *bo[2] = {NULL, NULL};
-	struct drm_gem_object *gobj;
 	int i, ret;
 
 	if (!va) {
@@ -630,14 +655,9 @@ static int kfd_mem_attach(struct amdgpu_device *adev, struct kgd_mem *mem,
 		} else if (amdgpu_ttm_tt_get_usermm(mem->bo->tbo.ttm)) {
 			/* Create an SG BO to DMA-map userptrs on other GPUs */
 			attachment[i]->type = KFD_MEM_ATT_USERPTR;
-			ret = amdgpu_gem_object_create(adev, bo_size, 1,
-						       AMDGPU_GEM_DOMAIN_CPU,
-						       0, ttm_bo_type_sg,
-						       mem->bo->tbo.base.resv,
-						       &gobj);
+			ret = kfd_mem_attach_userptr(adev, mem, &bo[i]);
 			if (ret)
 				goto unwind;
-			bo[i] = gem_to_amdgpu_bo(gobj);
 		} else {
 			/* FIXME: Need to DMA-map other BO types */
 			attachment[i]->type = KFD_MEM_ATT_SHARED;
@@ -662,13 +682,6 @@ static int kfd_mem_attach(struct amdgpu_device *adev, struct kgd_mem *mem,
 		va += bo_size;
 	}
 
-	/* Allocate validate page tables if needed */
-	ret = vm_validate_pt_pd_bos(vm);
-	if (unlikely(ret)) {
-		pr_err("validate_pt_pd_bos() failed\n");
-		goto unwind;
-	}
-
 	return 0;
 
 unwind:
@@ -1516,12 +1529,12 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(
 	pr_debug("Release VA 0x%llx - 0x%llx\n", mem->va,
 		mem->va + bo_size * (1 + mem->aql_queue));
 
+	ret = unreserve_bo_and_vms(&ctx, false, false);
+
 	/* Remove from VM internal data structures */
 	list_for_each_entry_safe(entry, tmp, &mem->attachments, list)
 		kfd_mem_detach(mem, entry);
 
-	ret = unreserve_bo_and_vms(&ctx, false, false);
-
 	/* Free the sync object */
 	amdgpu_sync_free(&mem->sync);
 
@@ -1597,6 +1610,12 @@ int amdgpu_amdkfd_gpuvm_map_memory_to_gpu(
 			mem->va + bo_size * (1 + mem->aql_queue),
 			vm, domain_string(domain));
 
+	if (!kfd_mem_is_attached(avm, mem)) {
+		ret = kfd_mem_attach(adev, mem, avm, mem->aql_queue);
+		if (ret)
+			goto out;
+	}
+
 	ret = reserve_bo_and_vm(mem, vm, &ctx);
 	if (unlikely(ret))
 		goto out;
@@ -1610,15 +1629,9 @@ int amdgpu_amdkfd_gpuvm_map_memory_to_gpu(
 	    bo->tbo.mem.mem_type == TTM_PL_SYSTEM)
 		is_invalid_userptr = true;
 
-	if (!kfd_mem_is_attached(avm, mem)) {
-		ret = kfd_mem_attach(adev, mem, avm, mem->aql_queue);
-		if (ret)
-			goto attach_failed;
-	} else {
-		ret = vm_validate_pt_pd_bos(avm);
-		if (unlikely(ret))
-			goto attach_failed;
-	}
+	ret = vm_validate_pt_pd_bos(avm);
+	if (unlikely(ret))
+		goto out_unreserve;
 
 	if (mem->mapped_to_gpu_memory == 0 &&
 	    !amdgpu_ttm_tt_get_usermm(bo->tbo.ttm)) {
@@ -1629,7 +1642,7 @@ int amdgpu_amdkfd_gpuvm_map_memory_to_gpu(
 		ret = amdgpu_amdkfd_bo_validate(bo, domain, true);
 		if (ret) {
 			pr_debug("Validate failed\n");
-			goto map_bo_to_gpuvm_failed;
+			goto out_unreserve;
 		}
 	}
 
@@ -1644,13 +1657,13 @@ int amdgpu_amdkfd_gpuvm_map_memory_to_gpu(
 				      is_invalid_userptr);
 		if (ret) {
 			pr_err("Failed to map bo to gpuvm\n");
-			goto map_bo_to_gpuvm_failed;
+			goto out_unreserve;
 		}
 
 		ret = vm_update_pds(vm, ctx.sync);
 		if (ret) {
 			pr_err("Failed to update page directories\n");
-			goto map_bo_to_gpuvm_failed;
+			goto out_unreserve;
 		}
 
 		entry->is_mapped = true;
@@ -1667,8 +1680,7 @@ int amdgpu_amdkfd_gpuvm_map_memory_to_gpu(
 
 	goto out;
 
-map_bo_to_gpuvm_failed:
-attach_failed:
+out_unreserve:
 	unreserve_bo_and_vms(&ctx, false, false);
 out:
 	mutex_unlock(&mem->process_info->lock);
Signature · 6 lines
2.31.1

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

PATCH 7/9 drm/amdgpu: Add DMA mapping of GTT BOs

In reply to Felix Kuehling

Use DMABufs with dynamic attachment to DMA-map GTT BOs on other GPUs.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h    |  2 +
 .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  | 74 ++++++++++++++++++-
 2 files changed, 75 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +2 -0
index fc3514ed1b74..3ea51982b720 100644
@@ -41,6 +41,7 @@ struct amdgpu_device;
 enum kfd_mem_attachment_type {
 	KFD_MEM_ATT_SHARED,	/* Share kgd_mem->bo or another attachment's */
 	KFD_MEM_ATT_USERPTR,	/* SG bo to DMA map pages from a userptr bo */
+	KFD_MEM_ATT_DMABUF,	/* DMAbuf to DMA map TTM BOs */
 };
 
 struct kfd_mem_attachment {
@@ -56,6 +57,7 @@ struct kfd_mem_attachment {
 struct kgd_mem {
 	struct mutex lock;
 	struct amdgpu_bo *bo;
+	struct dma_buf *dmabuf;
 	struct list_head attachments;
 	/* protected by amdkfd_process_info.lock */
 	struct ttm_validate_buffer validate_list;
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +73 -1

117 lines not on this page · raw message

Signature · 6 lines
2.31.1

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

PATCH 8/9 drm/ttm: Don't count pages in SG BOs against pages_limit

In reply to Felix Kuehling

Pages in SG BOs were not allocated by TTM. So don't count them against TTM's pages limit.

---
 drivers/gpu/drm/ttm/ttm_tt.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)
drivers/gpu/drm/ttm/ttm_tt.c +18 -9
index 5d8820725b75..e8b8c3257392 100644
@@ -317,9 +317,12 @@ int ttm_tt_populate(struct ttm_device *bdev,
 	if (ttm_tt_is_populated(ttm))
 		return 0;
 
-	atomic_long_add(ttm->num_pages, &ttm_pages_allocated);
-	if (bdev->pool.use_dma32)
-		atomic_long_add(ttm->num_pages, &ttm_dma32_pages_allocated);
+	if (!(ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+		atomic_long_add(ttm->num_pages, &ttm_pages_allocated);
+		if (bdev->pool.use_dma32)
+			atomic_long_add(ttm->num_pages,
+					&ttm_dma32_pages_allocated);
+	}
 
 	while (atomic_long_read(&ttm_pages_allocated) > ttm_pages_limit ||
 	       atomic_long_read(&ttm_dma32_pages_allocated) >
@@ -350,9 +353,12 @@ int ttm_tt_populate(struct ttm_device *bdev,
 	return 0;
 
 error:
-	atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);
-	if (bdev->pool.use_dma32)
-		atomic_long_sub(ttm->num_pages, &ttm_dma32_pages_allocated);
+	if (!(ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+		atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);
+		if (bdev->pool.use_dma32)
+			atomic_long_sub(ttm->num_pages,
+					&ttm_dma32_pages_allocated);
+	}
 	return ret;
 }
 EXPORT_SYMBOL(ttm_tt_populate);
@@ -382,9 +388,12 @@ void ttm_tt_unpopulate(struct ttm_device *bdev, struct ttm_tt *ttm)
 	else
 		ttm_pool_free(&bdev->pool, ttm);
 
-	atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);
-	if (bdev->pool.use_dma32)
-		atomic_long_sub(ttm->num_pages, &ttm_dma32_pages_allocated);
+	if (!(ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+		atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);
+		if (bdev->pool.use_dma32)
+			atomic_long_sub(ttm->num_pages,
+					&ttm_dma32_pages_allocated);
+	}
 
 	ttm->page_flags &= ~TTM_PAGE_FLAG_PRIV_POPULATED;
 }
Signature · 6 lines
2.31.1

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

Re: [PATCH 8/9] drm/ttm: Don't count pages in SG BOs against pages_limit

Am 14.04.21 um 08:48 schrieb Felix Kuehling:

Quoted 4 lines

Pages in SG BOs were not allocated by TTM. So don't count them against TTM's pages limit.

Going to pick that one up for inclusion in drm-misc-next.

Regards,
Christian.

Quoted 46 lines
---
  drivers/gpu/drm/ttm/ttm_tt.c | 27 ++++++++++++++++++---------
  1 file changed, 18 insertions(+), 9 deletions(-)
drivers/gpu/drm/ttm/ttm_tt.c +12 -8
index 5d8820725b75..e8b8c3257392 100644
@@ -317,9 +317,12 @@ int ttm_tt_populate(struct ttm_device *bdev,
  	if (ttm_tt_is_populated(ttm))
  		return 0;
 
-	atomic_long_add(ttm->num_pages, &ttm_pages_allocated);
-	if (bdev->pool.use_dma32)
-		atomic_long_add(ttm->num_pages, &ttm_dma32_pages_allocated);
+	if (!(ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+		atomic_long_add(ttm->num_pages, &ttm_pages_allocated);
+		if (bdev->pool.use_dma32)
+			atomic_long_add(ttm->num_pages,
+					&ttm_dma32_pages_allocated);
+	}
 
  	while (atomic_long_read(&ttm_pages_allocated) > ttm_pages_limit ||
  	       atomic_long_read(&ttm_dma32_pages_allocated) >
@@ -350,9 +353,12 @@ int ttm_tt_populate(struct ttm_device *bdev,
  	return 0;
 
  error:
-	atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);
-	if (bdev->pool.use_dma32)
-		atomic_long_sub(ttm->num_pages, &ttm_dma32_pages_allocated);
+	if (!(ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+		atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);
+		if (bdev->pool.use_dma32)
+			atomic_long_sub(ttm->num_pages,
+					&ttm_dma32_pages_allocated);
+	}
  	return ret;
  }
  EXPORT_SYMBOL(ttm_tt_populate);
@@ -382,9 +388,12 @@ void ttm_tt_unpopulate(struct ttm_device *bdev, struct ttm_tt *ttm)
  	else
  		ttm_pool_free(&bdev->pool, ttm);
 
-	atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);
-	if (bdev->pool.use_dma32)

drivers/gpu/drm/ttm/ttm_tt.c void ttm_tt_unpopulate(struct ttm_device *bdev, struct ttm_tt *ttm) · line 399

Quoted 10 lines
drivers/gpu/drm/ttm/ttm_tt.c +6 -1
-		atomic_long_sub(ttm->num_pages, &ttm_dma32_pages_allocated);
+	if (!(ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+		atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);
+		if (bdev->pool.use_dma32)
+			atomic_long_sub(ttm->num_pages,
+					&ttm_dma32_pages_allocated);
+	}
 
  	ttm->page_flags &= ~TTM_PAGE_FLAG_PRIV_POPULATED;
  }

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

#10 lore raw

Re: [PATCH 8/9] drm/ttm: Don't count pages in SG BOs against pages_limit

Quoted 9 lines · Christian König

Am 14.04.21 um 08:48 schrieb Felix Kuehling:

Quoted 4 lines

Pages in SG BOs were not allocated by TTM. So don't count them against TTM's pages limit.

Going to pick that one up for inclusion in drm-misc-next.

See my other email, but why do we need this? A bit more explanation is imo needed here at least, since we still need to guarantee that allocations don't over the limit in total for all gpu buffers together. At least until the shrinker has landed.

And this here just opens up the barn door without any explanation why it's ok.
-Daniel

Quoted 60 lines

Regards,
Christian.

Quoted 41 lines
---
  drivers/gpu/drm/ttm/ttm_tt.c | 27 ++++++++++++++++++---------
  1 file changed, 18 insertions(+), 9 deletions(-)
drivers/gpu/drm/ttm/ttm_tt.c +12 -7
index 5d8820725b75..e8b8c3257392 100644
@@ -317,9 +317,12 @@ int ttm_tt_populate(struct ttm_device *bdev,
  	if (ttm_tt_is_populated(ttm))
  		return 0;
-	atomic_long_add(ttm->num_pages, &ttm_pages_allocated);
-	if (bdev->pool.use_dma32)
-		atomic_long_add(ttm->num_pages, &ttm_dma32_pages_allocated);
+	if (!(ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+		atomic_long_add(ttm->num_pages, &ttm_pages_allocated);
+		if (bdev->pool.use_dma32)
+			atomic_long_add(ttm->num_pages,
+					&ttm_dma32_pages_allocated);
+	}
  	while (atomic_long_read(&ttm_pages_allocated) > ttm_pages_limit ||
  	       atomic_long_read(&ttm_dma32_pages_allocated) >
@@ -350,9 +353,12 @@ int ttm_tt_populate(struct ttm_device *bdev,
  	return 0;
  error:
-	atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);
-	if (bdev->pool.use_dma32)
-		atomic_long_sub(ttm->num_pages, &ttm_dma32_pages_allocated);
+	if (!(ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+		atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);
+		if (bdev->pool.use_dma32)
+			atomic_long_sub(ttm->num_pages,
+					&ttm_dma32_pages_allocated);
+	}
  	return ret;
  }
  EXPORT_SYMBOL(ttm_tt_populate);
@@ -382,9 +388,12 @@ void ttm_tt_unpopulate(struct ttm_device *bdev, struct ttm_tt *ttm)
  	else
  		ttm_pool_free(&bdev->pool, ttm);
-	atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);

drivers/gpu/drm/ttm/ttm_tt.c void ttm_tt_unpopulate(struct ttm_device *bdev, struct ttm_tt *ttm) · line 397

Quoted 10 lines
drivers/gpu/drm/ttm/ttm_tt.c +6 -2
-	if (bdev->pool.use_dma32)
-		atomic_long_sub(ttm->num_pages, &ttm_dma32_pages_allocated);
+	if (!(ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+		atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);
+		if (bdev->pool.use_dma32)
+			atomic_long_sub(ttm->num_pages,
+					&ttm_dma32_pages_allocated);
+	}
  	ttm->page_flags &= ~TTM_PAGE_FLAG_PRIV_POPULATED;
  }

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

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
maintainer
#11 lore raw

Re: [PATCH 8/9] drm/ttm: Don't count pages in SG BOs against pages_limit

Am 14.04.21 um 11:15 schrieb Daniel Vetter:

Quoted 8 lines · Christian König
Quoted 7 lines

Am 14.04.21 um 08:48 schrieb Felix Kuehling:

Quoted 4 lines

Pages in SG BOs were not allocated by TTM. So don't count them against TTM's pages limit.

Quoted 8 lines
Quoted 1 line

Going to pick that one up for inclusion in drm-misc-next.

See my other email, but why do we need this? A bit more explanation is imo needed here at least, since we still need to guarantee that allocations don't over the limit in total for all gpu buffers together. At least until the shrinker has landed.

And this here just opens up the barn door without any explanation why it's ok.

The SG based BOs might not even be backed by pages. E.g. exported VRAM.

So either they are exported by a driver which should have accounted for the allocation, exported by TTM which already did the accounting or doesn't even point to pages at all.

This is really a bug fix to recreate the behavior we had before moving the accounting to this place.

Christian.

Quoted 60 lines

-Daniel

Quoted 58 lines

Regards,
Christian.

Quoted 41 lines
---
   drivers/gpu/drm/ttm/ttm_tt.c | 27 ++++++++++++++++++---------
   1 file changed, 18 insertions(+), 9 deletions(-)
drivers/gpu/drm/ttm/ttm_tt.c +12 -7
index 5d8820725b75..e8b8c3257392 100644
@@ -317,9 +317,12 @@ int ttm_tt_populate(struct ttm_device *bdev,
   	if (ttm_tt_is_populated(ttm))
   		return 0;
-	atomic_long_add(ttm->num_pages, &ttm_pages_allocated);
-	if (bdev->pool.use_dma32)
-		atomic_long_add(ttm->num_pages, &ttm_dma32_pages_allocated);
+	if (!(ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+		atomic_long_add(ttm->num_pages, &ttm_pages_allocated);
+		if (bdev->pool.use_dma32)
+			atomic_long_add(ttm->num_pages,
+					&ttm_dma32_pages_allocated);
+	}
   	while (atomic_long_read(&ttm_pages_allocated) > ttm_pages_limit ||
   	       atomic_long_read(&ttm_dma32_pages_allocated) >
@@ -350,9 +353,12 @@ int ttm_tt_populate(struct ttm_device *bdev,
   	return 0;
   error:
-	atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);
-	if (bdev->pool.use_dma32)
-		atomic_long_sub(ttm->num_pages, &ttm_dma32_pages_allocated);
+	if (!(ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+		atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);
+		if (bdev->pool.use_dma32)
+			atomic_long_sub(ttm->num_pages,
+					&ttm_dma32_pages_allocated);
+	}
   	return ret;
   }
   EXPORT_SYMBOL(ttm_tt_populate);
@@ -382,9 +388,12 @@ void ttm_tt_unpopulate(struct ttm_device *bdev, struct ttm_tt *ttm)
   	else
   		ttm_pool_free(&bdev->pool, ttm);
-	atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);

drivers/gpu/drm/ttm/ttm_tt.c void ttm_tt_unpopulate(struct ttm_device *bdev, struct ttm_tt *ttm) · line 397

Quoted 10 lines
drivers/gpu/drm/ttm/ttm_tt.c +6 -2
-	if (bdev->pool.use_dma32)
-		atomic_long_sub(ttm->num_pages, &ttm_dma32_pages_allocated);
+	if (!(ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+		atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);
+		if (bdev->pool.use_dma32)
+			atomic_long_sub(ttm->num_pages,
+					&ttm_dma32_pages_allocated);
+	}
   	ttm->page_flags &= ~TTM_PAGE_FLAG_PRIV_POPULATED;
   }

_______________________________________________
dri-devel mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Fdri-devel&amp;data=04%7C01%7Cchristian.koenig%40amd.com%7C3075d7fd16644322a13608d8ff25d59b%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637539885255795187%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=KOnHA1CbNFjjMZR2rgHmGkH%2B7C84YCtA6u9V1wBAay4%3D&amp;reserved=0

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

#12 lore raw

Re: [PATCH 8/9] drm/ttm: Don't count pages in SG BOs against pages_limit

Quoted 18 lines · Christian König

Am 14.04.21 um 11:15 schrieb Daniel Vetter:

Quoted 8 lines · Christian König
Quoted 7 lines

Am 14.04.21 um 08:48 schrieb Felix Kuehling:

Quoted 4 lines

Pages in SG BOs were not allocated by TTM. So don't count them against TTM's pages limit.

Quoted 8 lines
Quoted 1 line

Going to pick that one up for inclusion in drm-misc-next.

See my other email, but why do we need this? A bit more explanation is imo needed here at least, since we still need to guarantee that allocations don't over the limit in total for all gpu buffers together. At least until the shrinker has landed.

And this here just opens up the barn door without any explanation why it's ok.

Quoted 8 lines

The SG based BOs might not even be backed by pages. E.g. exported VRAM.

So either they are exported by a driver which should have accounted for the allocation, exported by TTM which already did the accounting or doesn't even point to pages at all.

This is really a bug fix to recreate the behavior we had before moving the accounting to this place.

Throw that into the commit message and a-b: me. Ideally with a Fixes: line or so pointing at the offending commit that broke stuff. Commit messages should really go into more detail when there's an entire story behind a small change like this one.
-Daniel

Quoted 64 lines

Christian.

Quoted 60 lines

-Daniel

Quoted 58 lines

Regards,
Christian.

Quoted 41 lines
---
   drivers/gpu/drm/ttm/ttm_tt.c | 27 ++++++++++++++++++---------
   1 file changed, 18 insertions(+), 9 deletions(-)
drivers/gpu/drm/ttm/ttm_tt.c +12 -7
index 5d8820725b75..e8b8c3257392 100644
@@ -317,9 +317,12 @@ int ttm_tt_populate(struct ttm_device *bdev,
   	if (ttm_tt_is_populated(ttm))
   		return 0;
-	atomic_long_add(ttm->num_pages, &ttm_pages_allocated);
-	if (bdev->pool.use_dma32)
-		atomic_long_add(ttm->num_pages, &ttm_dma32_pages_allocated);
+	if (!(ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+		atomic_long_add(ttm->num_pages, &ttm_pages_allocated);
+		if (bdev->pool.use_dma32)
+			atomic_long_add(ttm->num_pages,
+					&ttm_dma32_pages_allocated);
+	}
   	while (atomic_long_read(&ttm_pages_allocated) > ttm_pages_limit ||
   	       atomic_long_read(&ttm_dma32_pages_allocated) >
@@ -350,9 +353,12 @@ int ttm_tt_populate(struct ttm_device *bdev,
   	return 0;
   error:
-	atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);
-	if (bdev->pool.use_dma32)
-		atomic_long_sub(ttm->num_pages, &ttm_dma32_pages_allocated);
+	if (!(ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+		atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);
+		if (bdev->pool.use_dma32)
+			atomic_long_sub(ttm->num_pages,
+					&ttm_dma32_pages_allocated);
+	}
   	return ret;
   }
   EXPORT_SYMBOL(ttm_tt_populate);
@@ -382,9 +388,12 @@ void ttm_tt_unpopulate(struct ttm_device *bdev, struct ttm_tt *ttm)
   	else
   		ttm_pool_free(&bdev->pool, ttm);
-	atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);

drivers/gpu/drm/ttm/ttm_tt.c void ttm_tt_unpopulate(struct ttm_device *bdev, struct ttm_tt *ttm) · line 397

Quoted 10 lines
drivers/gpu/drm/ttm/ttm_tt.c +6 -2
-	if (bdev->pool.use_dma32)
-		atomic_long_sub(ttm->num_pages, &ttm_dma32_pages_allocated);
+	if (!(ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+		atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);
+		if (bdev->pool.use_dma32)
+			atomic_long_sub(ttm->num_pages,
+					&ttm_dma32_pages_allocated);
+	}
   	ttm->page_flags &= ~TTM_PAGE_FLAG_PRIV_POPULATED;
   }

_______________________________________________
dri-devel mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Fdri-devel&amp;data=04%7C01%7Cchristian.koenig%40amd.com%7C3075d7fd16644322a13608d8ff25d59b%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637539885255795187%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=KOnHA1CbNFjjMZR2rgHmGkH%2B7C84YCtA6u9V1wBAay4%3D&amp;reserved=0

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#13 lore raw

Re: [PATCH 8/9] drm/ttm: Don't count pages in SG BOs against pages_limit

Am 14.04.21 um 12:26 schrieb Daniel Vetter:

Quoted 24 lines · Christian König
Quoted 23 lines

Am 14.04.21 um 11:15 schrieb Daniel Vetter:

Quoted 8 lines · Christian König
Quoted 7 lines

Am 14.04.21 um 08:48 schrieb Felix Kuehling:

Quoted 4 lines

Pages in SG BOs were not allocated by TTM. So don't count them against TTM's pages limit.

Quoted 8 lines
Quoted 1 line

Going to pick that one up for inclusion in drm-misc-next.

See my other email, but why do we need this? A bit more explanation is imo needed here at least, since we still need to guarantee that allocations don't over the limit in total for all gpu buffers together. At least until the shrinker has landed.

And this here just opens up the barn door without any explanation why it's ok.

The SG based BOs might not even be backed by pages. E.g. exported VRAM.

So either they are exported by a driver which should have accounted for the allocation, exported by TTM which already did the accounting or doesn't even point to pages at all.

Quoted 6 lines
Quoted 2 lines

This is really a bug fix to recreate the behavior we had before moving the accounting to this place.

Throw that into the commit message and a-b: me. Ideally with a Fixes: line or so pointing at the offending commit that broke stuff. Commit messages should really go into more detail when there's an entire story behind a small change like this one.

Sorry I though that this would be obvious :)

I've already pushed the patch in the morning, but going to keep that in mind for the next time.

Christian.

Quoted 64 lines

-Daniel

Quoted 62 lines

Christian.

Quoted 60 lines

-Daniel

Quoted 58 lines

Regards,
Christian.

Quoted 41 lines
---
    drivers/gpu/drm/ttm/ttm_tt.c | 27 ++++++++++++++++++---------
    1 file changed, 18 insertions(+), 9 deletions(-)
drivers/gpu/drm/ttm/ttm_tt.c +12 -7
index 5d8820725b75..e8b8c3257392 100644
@@ -317,9 +317,12 @@ int ttm_tt_populate(struct ttm_device *bdev,
    	if (ttm_tt_is_populated(ttm))
    		return 0;
-	atomic_long_add(ttm->num_pages, &ttm_pages_allocated);
-	if (bdev->pool.use_dma32)
-		atomic_long_add(ttm->num_pages, &ttm_dma32_pages_allocated);
+	if (!(ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+		atomic_long_add(ttm->num_pages, &ttm_pages_allocated);
+		if (bdev->pool.use_dma32)
+			atomic_long_add(ttm->num_pages,
+					&ttm_dma32_pages_allocated);
+	}
    	while (atomic_long_read(&ttm_pages_allocated) > ttm_pages_limit ||
    	       atomic_long_read(&ttm_dma32_pages_allocated) >
@@ -350,9 +353,12 @@ int ttm_tt_populate(struct ttm_device *bdev,
    	return 0;
    error:
-	atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);
-	if (bdev->pool.use_dma32)
-		atomic_long_sub(ttm->num_pages, &ttm_dma32_pages_allocated);
+	if (!(ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+		atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);
+		if (bdev->pool.use_dma32)
+			atomic_long_sub(ttm->num_pages,
+					&ttm_dma32_pages_allocated);
+	}
    	return ret;
    }
    EXPORT_SYMBOL(ttm_tt_populate);
@@ -382,9 +388,12 @@ void ttm_tt_unpopulate(struct ttm_device *bdev, struct ttm_tt *ttm)
    	else
    		ttm_pool_free(&bdev->pool, ttm);
-	atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);

drivers/gpu/drm/ttm/ttm_tt.c void ttm_tt_unpopulate(struct ttm_device *bdev, struct ttm_tt *ttm) · line 397

Quoted 10 lines
drivers/gpu/drm/ttm/ttm_tt.c +6 -2
-	if (bdev->pool.use_dma32)
-		atomic_long_sub(ttm->num_pages, &ttm_dma32_pages_allocated);
+	if (!(ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+		atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);
+		if (bdev->pool.use_dma32)
+			atomic_long_sub(ttm->num_pages,
+					&ttm_dma32_pages_allocated);
+	}
    	ttm->page_flags &= ~TTM_PAGE_FLAG_PRIV_POPULATED;
    }

_______________________________________________
dri-devel mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Fdri-devel&amp;data=04%7C01%7Cchristian.koenig%40amd.com%7C3075d7fd16644322a13608d8ff25d59b%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637539885255795187%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=KOnHA1CbNFjjMZR2rgHmGkH%2B7C84YCtA6u9V1wBAay4%3D&amp;reserved=0

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

#14 lore raw

Re: [PATCH 8/9] drm/ttm: Don't count pages in SG BOs against pages_limit

Quoted 33 lines · Christian König

Am 14.04.21 um 12:26 schrieb Daniel Vetter:

Quoted 24 lines · Christian König
Quoted 23 lines

Am 14.04.21 um 11:15 schrieb Daniel Vetter:

Quoted 8 lines · Christian König
Quoted 7 lines

Am 14.04.21 um 08:48 schrieb Felix Kuehling:

Quoted 4 lines

Pages in SG BOs were not allocated by TTM. So don't count them against TTM's pages limit.

Quoted 8 lines
Quoted 1 line

Going to pick that one up for inclusion in drm-misc-next.

See my other email, but why do we need this? A bit more explanation is imo needed here at least, since we still need to guarantee that allocations don't over the limit in total for all gpu buffers together. At least until the shrinker has landed.

And this here just opens up the barn door without any explanation why it's ok.

The SG based BOs might not even be backed by pages. E.g. exported VRAM.

So either they are exported by a driver which should have accounted for the allocation, exported by TTM which already did the accounting or doesn't even point to pages at all.

Quoted 6 lines
Quoted 2 lines

This is really a bug fix to recreate the behavior we had before moving the accounting to this place.

Throw that into the commit message and a-b: me. Ideally with a Fixes: line or so pointing at the offending commit that broke stuff. Commit messages should really go into more detail when there's an entire story behind a small change like this one.

Quoted 4 lines

Sorry I though that this would be obvious :)

I've already pushed the patch in the morning, but going to keep that in mind for the next time.

I'll keep reminding you to pls elaborate more in commit messages, it's coming up every once in a while :-)

Also in general I think a few days of letting patches soak out there, especially shared code, is good curtesy. Some folks demand 2 weeks, which I think is too much, but less than 24h just means you're guaranteed to leave out half the globe with their feedback. Which isn't great.

Driver code I don't care since there you know all the stakeholders ofc. -Daniel

Quoted 68 lines

Christian.

Quoted 64 lines

-Daniel

Quoted 62 lines

Christian.

Quoted 60 lines

-Daniel

Quoted 58 lines

Regards,
Christian.

Quoted 41 lines
---
    drivers/gpu/drm/ttm/ttm_tt.c | 27 ++++++++++++++++++---------
    1 file changed, 18 insertions(+), 9 deletions(-)
drivers/gpu/drm/ttm/ttm_tt.c +12 -7
index 5d8820725b75..e8b8c3257392 100644
@@ -317,9 +317,12 @@ int ttm_tt_populate(struct ttm_device *bdev,
          if (ttm_tt_is_populated(ttm))
                  return 0;
- atomic_long_add(ttm->num_pages, &ttm_pages_allocated);
- if (bdev->pool.use_dma32)
-         atomic_long_add(ttm->num_pages, &ttm_dma32_pages_allocated);
+ if (!(ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+         atomic_long_add(ttm->num_pages, &ttm_pages_allocated);
+         if (bdev->pool.use_dma32)
+                 atomic_long_add(ttm->num_pages,
+                                 &ttm_dma32_pages_allocated);
+ }
          while (atomic_long_read(&ttm_pages_allocated) > ttm_pages_limit ||
                 atomic_long_read(&ttm_dma32_pages_allocated) >
@@ -350,9 +353,12 @@ int ttm_tt_populate(struct ttm_device *bdev,
          return 0;
    error:
- atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);
- if (bdev->pool.use_dma32)
-         atomic_long_sub(ttm->num_pages, &ttm_dma32_pages_allocated);
+ if (!(ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+         atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);
+         if (bdev->pool.use_dma32)
+                 atomic_long_sub(ttm->num_pages,
+                                 &ttm_dma32_pages_allocated);
+ }
          return ret;
    }
    EXPORT_SYMBOL(ttm_tt_populate);
@@ -382,9 +388,12 @@ void ttm_tt_unpopulate(struct ttm_device *bdev, struct ttm_tt *ttm)
          else
                  ttm_pool_free(&bdev->pool, ttm);
- atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);

drivers/gpu/drm/ttm/ttm_tt.c void ttm_tt_unpopulate(struct ttm_device *bdev, struct ttm_tt *ttm) · line 397

Quoted 10 lines
drivers/gpu/drm/ttm/ttm_tt.c +6 -2
- if (bdev->pool.use_dma32)
-         atomic_long_sub(ttm->num_pages, &ttm_dma32_pages_allocated);
+ if (!(ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+         atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);
+         if (bdev->pool.use_dma32)
+                 atomic_long_sub(ttm->num_pages,
+                                 &ttm_dma32_pages_allocated);
+ }
          ttm->page_flags &= ~TTM_PAGE_FLAG_PRIV_POPULATED;
    }

_______________________________________________
dri-devel mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Fdri-devel&amp;data=04%7C01%7Cchristian.koenig%40amd.com%7C3075d7fd16644322a13608d8ff25d59b%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637539885255795187%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=KOnHA1CbNFjjMZR2rgHmGkH%2B7C84YCtA6u9V1wBAay4%3D&amp;reserved=0

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
maintainer
#15 lore raw

Re: [PATCH 8/9] drm/ttm: Don't count pages in SG BOs against pages_limit

Am 14.04.21 um 14:25 schrieb Daniel Vetter:

Quoted 33 lines
Quoted 31 lines · Christian König

Am 14.04.21 um 12:26 schrieb Daniel Vetter:

Quoted 30 lines · Christian König
Quoted 17 lines

Am 14.04.21 um 11:15 schrieb Daniel Vetter:

Quoted 8 lines · Christian König
Quoted 7 lines

Am 14.04.21 um 08:48 schrieb Felix Kuehling:

Quoted 4 lines

Pages in SG BOs were not allocated by TTM. So don't count them against TTM's pages limit.

Quoted 8 lines
Quoted 1 line

Going to pick that one up for inclusion in drm-misc-next.

See my other email, but why do we need this? A bit more explanation is imo needed here at least, since we still need to guarantee that allocations don't over the limit in total for all gpu buffers together. At least until the shrinker has landed.

And this here just opens up the barn door without any explanation why it's ok.

Quoted 8 lines

The SG based BOs might not even be backed by pages. E.g. exported VRAM.

So either they are exported by a driver which should have accounted for the allocation, exported by TTM which already did the accounting or doesn't even point to pages at all.

This is really a bug fix to recreate the behavior we had before moving the accounting to this place.

Throw that into the commit message and a-b: me. Ideally with a Fixes: line or so pointing at the offending commit that broke stuff. Commit messages should really go into more detail when there's an entire story behind a small change like this one.

Quoted 6 lines
Quoted 4 lines

Sorry I though that this would be obvious :)

I've already pushed the patch in the morning, but going to keep that in mind for the next time.

I'll keep reminding you to pls elaborate more in commit messages, it's coming up every once in a while :-)

Well, describing stuff in a commit message which is obvious is just redundant.

I can of course explain the whole background of the code in question in the commit message, but for obvious bug fixes like this it is just overkill.

Quoted 5 lines

Also in general I think a few days of letting patches soak out there, especially shared code, is good curtesy. Some folks demand 2 weeks, which I think is too much, but less than 24h just means you're guaranteed to leave out half the globe with their feedback. Which isn't great.

Well for structural changes I certainly agree, but not for a bug fix which adds a missing check for a special case.

Christian.

Quoted 71 lines

Driver code I don't care since there you know all the stakeholders ofc. -Daniel

Quoted 66 lines

Christian.

Quoted 64 lines

-Daniel

Quoted 62 lines

Christian.

Quoted 60 lines

-Daniel

Quoted 58 lines

Regards,
Christian.

Quoted 41 lines
---
     drivers/gpu/drm/ttm/ttm_tt.c | 27 ++++++++++++++++++---------
     1 file changed, 18 insertions(+), 9 deletions(-)
drivers/gpu/drm/ttm/ttm_tt.c +12 -7
index 5d8820725b75..e8b8c3257392 100644
@@ -317,9 +317,12 @@ int ttm_tt_populate(struct ttm_device *bdev,
           if (ttm_tt_is_populated(ttm))
                   return 0;
- atomic_long_add(ttm->num_pages, &ttm_pages_allocated);
- if (bdev->pool.use_dma32)
-         atomic_long_add(ttm->num_pages, &ttm_dma32_pages_allocated);
+ if (!(ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+         atomic_long_add(ttm->num_pages, &ttm_pages_allocated);
+         if (bdev->pool.use_dma32)
+                 atomic_long_add(ttm->num_pages,
+                                 &ttm_dma32_pages_allocated);
+ }
           while (atomic_long_read(&ttm_pages_allocated) > ttm_pages_limit ||
                  atomic_long_read(&ttm_dma32_pages_allocated) >
@@ -350,9 +353,12 @@ int ttm_tt_populate(struct ttm_device *bdev,
           return 0;
     error:
- atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);
- if (bdev->pool.use_dma32)
-         atomic_long_sub(ttm->num_pages, &ttm_dma32_pages_allocated);
+ if (!(ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+         atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);
+         if (bdev->pool.use_dma32)
+                 atomic_long_sub(ttm->num_pages,
+                                 &ttm_dma32_pages_allocated);
+ }
           return ret;
     }
     EXPORT_SYMBOL(ttm_tt_populate);
@@ -382,9 +388,12 @@ void ttm_tt_unpopulate(struct ttm_device *bdev, struct ttm_tt *ttm)
           else
                   ttm_pool_free(&bdev->pool, ttm);
- atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);

drivers/gpu/drm/ttm/ttm_tt.c void ttm_tt_unpopulate(struct ttm_device *bdev, struct ttm_tt *ttm) · line 397

Quoted 10 lines
drivers/gpu/drm/ttm/ttm_tt.c +6 -2
- if (bdev->pool.use_dma32)
-         atomic_long_sub(ttm->num_pages, &ttm_dma32_pages_allocated);
+ if (!(ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+         atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);
+         if (bdev->pool.use_dma32)
+                 atomic_long_sub(ttm->num_pages,
+                                 &ttm_dma32_pages_allocated);
+ }
           ttm->page_flags &= ~TTM_PAGE_FLAG_PRIV_POPULATED;
     }

_______________________________________________
dri-devel mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Fdri-devel&amp;data=04%7C01%7Cchristian.koenig%40amd.com%7C503f240d409740c1333508d8ff406545%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637539999355330481%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=6sW53%2FGpxk4rZKM7mpHDfgBhreCXY4McypKGqTH13b8%3D&amp;reserved=0

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

#16 lore raw

Re: [PATCH 8/9] drm/ttm: Don't count pages in SG BOs against pages_limit

Quoted 48 lines · Christian König

Am 14.04.21 um 14:25 schrieb Daniel Vetter:

Quoted 33 lines
Quoted 31 lines · Christian König

Am 14.04.21 um 12:26 schrieb Daniel Vetter:

Quoted 30 lines · Christian König
Quoted 17 lines

Am 14.04.21 um 11:15 schrieb Daniel Vetter:

Quoted 8 lines · Christian König
Quoted 7 lines

Am 14.04.21 um 08:48 schrieb Felix Kuehling:

Quoted 4 lines

Pages in SG BOs were not allocated by TTM. So don't count them against TTM's pages limit.

Quoted 8 lines
Quoted 1 line

Going to pick that one up for inclusion in drm-misc-next.

See my other email, but why do we need this? A bit more explanation is imo needed here at least, since we still need to guarantee that allocations don't over the limit in total for all gpu buffers together. At least until the shrinker has landed.

And this here just opens up the barn door without any explanation why it's ok.

Quoted 8 lines

The SG based BOs might not even be backed by pages. E.g. exported VRAM.

So either they are exported by a driver which should have accounted for the allocation, exported by TTM which already did the accounting or doesn't even point to pages at all.

This is really a bug fix to recreate the behavior we had before moving the accounting to this place.

Throw that into the commit message and a-b: me. Ideally with a Fixes: line or so pointing at the offending commit that broke stuff. Commit messages should really go into more detail when there's an entire story behind a small change like this one.

Quoted 6 lines
Quoted 4 lines

Sorry I though that this would be obvious :)

I've already pushed the patch in the morning, but going to keep that in mind for the next time.

I'll keep reminding you to pls elaborate more in commit messages, it's coming up every once in a while :-)

Well, describing stuff in a commit message which is obvious is just redundant.

I can of course explain the whole background of the code in question in the commit message, but for obvious bug fixes like this it is just overkill.

Quoted 8 lines
Quoted 5 lines

Also in general I think a few days of letting patches soak out there, especially shared code, is good curtesy. Some folks demand 2 weeks, which I think is too much, but less than 24h just means you're guaranteed to leave out half the globe with their feedback. Which isn't great.

Well for structural changes I certainly agree, but not for a bug fix which adds a missing check for a special case.

Well if it's a bugfix should at least indicate that, and regression fixes should come with Fixes: tags. Obvious for you who screamed at the code is generally not implying it's obvious for anyone else. So yeah I think in general more explanations would be good. -Daniel

Quoted 75 lines

Christian.

Quoted 71 lines

Driver code I don't care since there you know all the stakeholders ofc. -Daniel

Quoted 66 lines

Christian.

Quoted 64 lines

-Daniel

Quoted 62 lines

Christian.

Quoted 60 lines

-Daniel

Quoted 58 lines

Regards,
Christian.

Quoted 41 lines
---
     drivers/gpu/drm/ttm/ttm_tt.c | 27 ++++++++++++++++++---------
     1 file changed, 18 insertions(+), 9 deletions(-)
drivers/gpu/drm/ttm/ttm_tt.c +12 -7
index 5d8820725b75..e8b8c3257392 100644
@@ -317,9 +317,12 @@ int ttm_tt_populate(struct ttm_device *bdev,
           if (ttm_tt_is_populated(ttm))
                   return 0;
- atomic_long_add(ttm->num_pages, &ttm_pages_allocated);
- if (bdev->pool.use_dma32)
-         atomic_long_add(ttm->num_pages, &ttm_dma32_pages_allocated);
+ if (!(ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+         atomic_long_add(ttm->num_pages, &ttm_pages_allocated);
+         if (bdev->pool.use_dma32)
+                 atomic_long_add(ttm->num_pages,
+                                 &ttm_dma32_pages_allocated);
+ }
           while (atomic_long_read(&ttm_pages_allocated) > ttm_pages_limit ||
                  atomic_long_read(&ttm_dma32_pages_allocated) >
@@ -350,9 +353,12 @@ int ttm_tt_populate(struct ttm_device *bdev,
           return 0;
     error:
- atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);
- if (bdev->pool.use_dma32)
-         atomic_long_sub(ttm->num_pages, &ttm_dma32_pages_allocated);
+ if (!(ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+         atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);
+         if (bdev->pool.use_dma32)
+                 atomic_long_sub(ttm->num_pages,
+                                 &ttm_dma32_pages_allocated);
+ }
           return ret;
     }
     EXPORT_SYMBOL(ttm_tt_populate);
@@ -382,9 +388,12 @@ void ttm_tt_unpopulate(struct ttm_device *bdev, struct ttm_tt *ttm)
           else
                   ttm_pool_free(&bdev->pool, ttm);
- atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);

drivers/gpu/drm/ttm/ttm_tt.c void ttm_tt_unpopulate(struct ttm_device *bdev, struct ttm_tt *ttm) · line 397

Quoted 10 lines
drivers/gpu/drm/ttm/ttm_tt.c +6 -2
- if (bdev->pool.use_dma32)
-         atomic_long_sub(ttm->num_pages, &ttm_dma32_pages_allocated);
+ if (!(ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+         atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);
+         if (bdev->pool.use_dma32)
+                 atomic_long_sub(ttm->num_pages,
+                                 &ttm_dma32_pages_allocated);
+ }
           ttm->page_flags &= ~TTM_PAGE_FLAG_PRIV_POPULATED;
     }

_______________________________________________
dri-devel mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Fdri-devel&amp;data=04%7C01%7Cchristian.koenig%40amd.com%7C503f240d409740c1333508d8ff406545%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637539999355330481%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=6sW53%2FGpxk4rZKM7mpHDfgBhreCXY4McypKGqTH13b8%3D&amp;reserved=0

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
maintainer
#17 lore raw

Re: [PATCH 8/9] drm/ttm: Don't count pages in SG BOs against pages_limit

Am 14.04.21 um 14:47 schrieb Daniel Vetter:

Quoted 53 lines
Quoted 51 lines · Christian König

Am 14.04.21 um 14:25 schrieb Daniel Vetter:

Quoted 33 lines
Quoted 31 lines · Christian König

Am 14.04.21 um 12:26 schrieb Daniel Vetter:

Quoted 30 lines · Christian König
Quoted 17 lines

Am 14.04.21 um 11:15 schrieb Daniel Vetter:

Quoted 8 lines · Christian König
Quoted 7 lines

Am 14.04.21 um 08:48 schrieb Felix Kuehling:

Quoted 4 lines

Pages in SG BOs were not allocated by TTM. So don't count them against TTM's pages limit.

Quoted 8 lines
Quoted 1 line

Going to pick that one up for inclusion in drm-misc-next.

See my other email, but why do we need this? A bit more explanation is imo needed here at least, since we still need to guarantee that allocations don't over the limit in total for all gpu buffers together. At least until the shrinker has landed.

And this here just opens up the barn door without any explanation why it's ok.

Quoted 8 lines

The SG based BOs might not even be backed by pages. E.g. exported VRAM.

So either they are exported by a driver which should have accounted for the allocation, exported by TTM which already did the accounting or doesn't even point to pages at all.

This is really a bug fix to recreate the behavior we had before moving the accounting to this place.

Throw that into the commit message and a-b: me. Ideally with a Fixes: line or so pointing at the offending commit that broke stuff. Commit messages should really go into more detail when there's an entire story behind a small change like this one.

Quoted 6 lines
Quoted 4 lines

Sorry I though that this would be obvious :)

I've already pushed the patch in the morning, but going to keep that in mind for the next time.

I'll keep reminding you to pls elaborate more in commit messages, it's coming up every once in a while :-)

Well, describing stuff in a commit message which is obvious is just redundant.

I can of course explain the whole background of the code in question in the commit message, but for obvious bug fixes like this it is just overkill.

Quoted 5 lines

Also in general I think a few days of letting patches soak out there, especially shared code, is good curtesy. Some folks demand 2 weeks, which I think is too much, but less than 24h just means you're guaranteed to leave out half the globe with their feedback. Which isn't great.

Quoted 6 lines
Quoted 2 lines

Well for structural changes I certainly agree, but not for a bug fix which adds a missing check for a special case.

Well if it's a bugfix should at least indicate that, and regression fixes should come with Fixes: tags. Obvious for you who screamed at the code is generally not implying it's obvious for anyone else. So yeah I think in general more explanations would be good.

Ok, seconded. The missing Fixes tag is a good point and the wording doesn't made it clear that this is a bug fix.

Going to keep that in mind.

Christian.

Quoted 74 lines

-Daniel

Quoted 71 lines

Christian.

Quoted 69 lines

Driver code I don't care since there you know all the stakeholders ofc. -Daniel

Quoted 66 lines

Christian.

Quoted 64 lines

-Daniel

Quoted 62 lines

Christian.

Quoted 60 lines

-Daniel

Quoted 58 lines

Regards,
Christian.

Quoted 41 lines
---
      drivers/gpu/drm/ttm/ttm_tt.c | 27 ++++++++++++++++++---------
      1 file changed, 18 insertions(+), 9 deletions(-)
drivers/gpu/drm/ttm/ttm_tt.c +12 -7
index 5d8820725b75..e8b8c3257392 100644
@@ -317,9 +317,12 @@ int ttm_tt_populate(struct ttm_device *bdev,
            if (ttm_tt_is_populated(ttm))
                    return 0;
- atomic_long_add(ttm->num_pages, &ttm_pages_allocated);
- if (bdev->pool.use_dma32)
-         atomic_long_add(ttm->num_pages, &ttm_dma32_pages_allocated);
+ if (!(ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+         atomic_long_add(ttm->num_pages, &ttm_pages_allocated);
+         if (bdev->pool.use_dma32)
+                 atomic_long_add(ttm->num_pages,
+                                 &ttm_dma32_pages_allocated);
+ }
            while (atomic_long_read(&ttm_pages_allocated) > ttm_pages_limit ||
                   atomic_long_read(&ttm_dma32_pages_allocated) >
@@ -350,9 +353,12 @@ int ttm_tt_populate(struct ttm_device *bdev,
            return 0;
      error:
- atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);
- if (bdev->pool.use_dma32)
-         atomic_long_sub(ttm->num_pages, &ttm_dma32_pages_allocated);
+ if (!(ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+         atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);
+         if (bdev->pool.use_dma32)
+                 atomic_long_sub(ttm->num_pages,
+                                 &ttm_dma32_pages_allocated);
+ }
            return ret;
      }
      EXPORT_SYMBOL(ttm_tt_populate);
@@ -382,9 +388,12 @@ void ttm_tt_unpopulate(struct ttm_device *bdev, struct ttm_tt *ttm)
            else
                    ttm_pool_free(&bdev->pool, ttm);
- atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);

drivers/gpu/drm/ttm/ttm_tt.c void ttm_tt_unpopulate(struct ttm_device *bdev, struct ttm_tt *ttm) · line 397

Quoted 10 lines
drivers/gpu/drm/ttm/ttm_tt.c +6 -2
- if (bdev->pool.use_dma32)
-         atomic_long_sub(ttm->num_pages, &ttm_dma32_pages_allocated);
+ if (!(ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+         atomic_long_sub(ttm->num_pages, &ttm_pages_allocated);
+         if (bdev->pool.use_dma32)
+                 atomic_long_sub(ttm->num_pages,
+                                 &ttm_dma32_pages_allocated);
+ }
            ttm->page_flags &= ~TTM_PAGE_FLAG_PRIV_POPULATED;
      }

_______________________________________________
dri-devel mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Fdri-devel&amp;data=04%7C01%7Cchristian.koenig%40amd.com%7C1be30de6774b44ce302808d8ff437774%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637540012543510114%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=R5IkjKJV%2BmGDul5YqoUCDQKCNaYtbm3oOqT9fTF%2Bguk%3D&amp;reserved=0

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

author maintainer
#18 lore raw

Re: [PATCH 8/9] drm/ttm: Don't count pages in SG BOs against pages_limit

In reply to Daniel Vetter

Am 2021-04-14 um 8:25 a.m. schrieb Daniel Vetter:

Quoted 6 lines
Quoted 4 lines

Sorry I though that this would be obvious :)

I've already pushed the patch in the morning, but going to keep that in mind for the next time.

I'll keep reminding you to pls elaborate more in commit messages, it's coming up every once in a while :-)

It was actually my patch and commit message. I was not aware of the history of this bug or the fact that it was a regression. Otherwise I would have included a "Fixes:" tag. From my point of view it was just a pretty obvious problem exposed when testing my DMA mapping patch series for KFD.

Regards,
  Felix

Quoted 10 lines

Also in general I think a few days of letting patches soak out there, especially shared code, is good curtesy. Some folks demand 2 weeks, which I think is too much, but less than 24h just means you're guaranteed to leave out half the globe with their feedback. Which isn't great.

Driver code I don't care since there you know all the stakeholders ofc. -Daniel

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

author maintainer
#19 lore raw

PATCH 9/9 drm/amdgpu: Lock the attached dmabuf in unpopulate

In reply to Felix Kuehling

amdgpu_ttm_tt_unpopulate can be called during bo_destroy. The dmabuf->resv must not be held by the caller or dma_buf_detach will deadlock. This is probably not the right fix. I get a recursive lock warning with the reservation held in ttm_bo_release. Should unmap_attachment move to backend_unbind instead?

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +13 -0
index 936b3cfdde55..257750921eed 100644
@@ -1216,9 +1216,22 @@ static void amdgpu_ttm_tt_unpopulate(struct ttm_device *bdev,
 
 	if (ttm->sg && gtt->gobj->import_attach) {
 		struct dma_buf_attachment *attach;
+		bool locked;
 
 		attach = gtt->gobj->import_attach;
+		/* FIXME: unpopulate can be called during bo_destroy.
+		 * The dmabuf->resv must not be held by the caller or
+		 * dma_buf_detach will deadlock. This is probably not
+		 * the right fix. I get a recursive lock warning with the
+		 * reservation held in ttm_bo_releas.. Should
+		 * unmap_attachment move to backend_unbind instead?
+		 */
+		locked = dma_resv_is_locked(attach->dmabuf->resv);
+		if (!locked)
+			dma_resv_lock(attach->dmabuf->resv, NULL);
 		dma_buf_unmap_attachment(attach, ttm->sg, DMA_BIDIRECTIONAL);
+		if (!locked)
+			dma_resv_unlock(attach->dmabuf->resv);
 		ttm->sg = NULL;
 		return;
 	}
Signature · 6 lines
2.31.1

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