All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] drm/amdgpu: revert "drm/amdgpu: use AMDGPU_GEM_CREATE_VRAM_CLEARED for VM PD/PTs"
@ 2018-01-26 10:04 Christian König
       [not found] ` <20180126100442.1856-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
  0 siblings, 1 reply; 9+ messages in thread
From: Christian König @ 2018-01-26 10:04 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Using the standard clear turned out to be to inflexible.

First of all it is executed on the system queue, together with buffer
moves instead on the per VM queue.

And second we need to fill in the page tables with more than just zero.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 116 ++++++++++++++++++++++++++-------
 1 file changed, 92 insertions(+), 24 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 0df52cb1765b..5cdd8d9c3311 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -257,6 +257,74 @@ bool amdgpu_vm_ready(struct amdgpu_vm *vm)
 	return ready;
 }
 
+/**
+ * amdgpu_vm_clear_bo - initially clear the PDs/PTs
+ *
+ * @adev: amdgpu_device pointer
+ * @bo: BO to clear
+ * @level: level this BO is at
+ *
+ * Root PD needs to be reserved when calling this.
+ */
+static int amdgpu_vm_clear_bo(struct amdgpu_device *adev,
+			      struct amdgpu_vm *vm,
+			      struct amdgpu_bo *bo,
+			      unsigned level)
+{
+	struct ttm_operation_ctx ctx = { true, false };
+	struct dma_fence *fence = NULL;
+	uint64_t addr, init_value;
+	struct amdgpu_ring *ring;
+	struct amdgpu_job *job;
+	unsigned entries;
+	int r;
+
+	if (vm->pte_support_ats) {
+		init_value = AMDGPU_PTE_DEFAULT_ATC;
+		if (level != AMDGPU_VM_PTB)
+			init_value |= AMDGPU_PDE_PTE;
+	} else {
+		init_value = 0;
+	}
+
+	ring = container_of(vm->entity.sched, struct amdgpu_ring, sched);
+
+	r = reservation_object_reserve_shared(bo->tbo.resv);
+	if (r)
+		return r;
+
+	r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
+	if (r)
+		goto error;
+
+	addr = amdgpu_bo_gpu_offset(bo);
+	entries = amdgpu_bo_size(bo) / 8;
+
+	r = amdgpu_job_alloc_with_ib(adev, 64, &job);
+	if (r)
+		goto error;
+
+	amdgpu_vm_set_pte_pde(adev, &job->ibs[0], addr, 0,
+			      entries, 0, init_value);
+	amdgpu_ring_pad_ib(ring, &job->ibs[0]);
+
+	WARN_ON(job->ibs[0].length_dw > 64);
+	r = amdgpu_job_submit(job, ring, &vm->entity,
+			      AMDGPU_FENCE_OWNER_UNDEFINED, &fence);
+	if (r)
+		goto error_free;
+
+	amdgpu_bo_fence(bo, fence, true);
+	dma_fence_put(fence);
+	return 0;
+
+error_free:
+	amdgpu_job_free(job);
+
+error:
+	return r;
+}
+
 /**
  * amdgpu_vm_alloc_levels - allocate the PD/PT levels
  *
@@ -275,9 +343,8 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
 {
 	unsigned shift = amdgpu_vm_level_shift(adev, level);
 	unsigned pt_idx, from, to;
-	int r;
 	u64 flags;
-	uint64_t init_value = 0;
+	int r;
 
 	if (!parent->entries) {
 		unsigned num_entries = amdgpu_vm_num_entries(adev, level);
@@ -300,21 +367,13 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
 	saddr = saddr & ((1 << shift) - 1);
 	eaddr = eaddr & ((1 << shift) - 1);
 
-	flags = AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS |
-			AMDGPU_GEM_CREATE_VRAM_CLEARED;
+	flags = AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS;
 	if (vm->use_cpu_for_update)
 		flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
 	else
 		flags |= (AMDGPU_GEM_CREATE_NO_CPU_ACCESS |
 				AMDGPU_GEM_CREATE_SHADOW);
 
-	if (vm->pte_support_ats) {
-		init_value = AMDGPU_PTE_DEFAULT_ATC;
-		if (level != AMDGPU_VM_PTB)
-			init_value |= AMDGPU_PDE_PTE;
-
-	}
-
 	/* walk over the address space and allocate the page tables */
 	for (pt_idx = from; pt_idx <= to; ++pt_idx) {
 		struct reservation_object *resv = vm->root.base.bo->tbo.resv;
@@ -325,12 +384,17 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
 			r = amdgpu_bo_create(adev,
 					     amdgpu_vm_bo_size(adev, level),
 					     AMDGPU_GPU_PAGE_SIZE, true,
-					     AMDGPU_GEM_DOMAIN_VRAM,
-					     flags,
-					     NULL, resv, init_value, &pt);
+					     AMDGPU_GEM_DOMAIN_VRAM, flags,
+					     NULL, resv, 0, &pt);
 			if (r)
 				return r;
 
+			r = amdgpu_vm_clear_bo(adev, vm, pt, level);
+			if (r) {
+				amdgpu_bo_unref(&pt);
+				return r;
+			}
+
 			if (vm->use_cpu_for_update) {
 				r = amdgpu_bo_kmap(pt, NULL);
 				if (r) {
@@ -2241,11 +2305,11 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 {
 	const unsigned align = min(AMDGPU_VM_PTB_ALIGN_SIZE,
 		AMDGPU_VM_PTE_COUNT(adev) * 8);
-	uint64_t init_pde_value = 0, flags;
 	unsigned ring_instance;
 	struct amdgpu_ring *ring;
 	struct drm_sched_rq *rq;
 	unsigned long size;
+	uint64_t flags;
 	int r, i;
 
 	vm->va = RB_ROOT_CACHED;
@@ -2274,23 +2338,19 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 		vm->use_cpu_for_update = !!(adev->vm_manager.vm_update_mode &
 						AMDGPU_VM_USE_CPU_FOR_COMPUTE);
 
-		if (adev->asic_type == CHIP_RAVEN) {
+		if (adev->asic_type == CHIP_RAVEN)
 			vm->pte_support_ats = true;
-			init_pde_value = AMDGPU_PTE_DEFAULT_ATC
-					| AMDGPU_PDE_PTE;
-
-		}
-	} else
+	} else {
 		vm->use_cpu_for_update = !!(adev->vm_manager.vm_update_mode &
 						AMDGPU_VM_USE_CPU_FOR_GFX);
+	}
 	DRM_DEBUG_DRIVER("VM update mode is %s\n",
 			 vm->use_cpu_for_update ? "CPU" : "SDMA");
 	WARN_ONCE((vm->use_cpu_for_update & !amdgpu_vm_is_large_bar(adev)),
 		  "CPU update of VM recommended only for large BAR system\n");
 	vm->last_update = NULL;
 
-	flags = AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS |
-			AMDGPU_GEM_CREATE_VRAM_CLEARED;
+	flags = AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS;
 	if (vm->use_cpu_for_update)
 		flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
 	else
@@ -2299,7 +2359,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 
 	size = amdgpu_vm_bo_size(adev, adev->vm_manager.root_level);
 	r = amdgpu_bo_create(adev, size, align, true, AMDGPU_GEM_DOMAIN_VRAM,
-			     flags, NULL, NULL, init_pde_value,
+			     flags, NULL, NULL, 0,
 			     &vm->root.base.bo);
 	if (r)
 		goto error_free_sched_entity;
@@ -2308,6 +2368,11 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 	if (r)
 		goto error_free_root;
 
+	r = amdgpu_vm_clear_bo(adev, vm, vm->root.base.bo,
+			       adev->vm_manager.root_level);
+	if (r)
+		goto error_unreserve;
+
 	vm->root.base.vm = vm;
 	list_add_tail(&vm->root.base.bo_list, &vm->root.base.bo->va);
 	list_add_tail(&vm->root.base.vm_status, &vm->evicted);
@@ -2331,6 +2396,9 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 
 	return 0;
 
+error_unreserve:
+	amdgpu_bo_unreserve(vm->root.base.bo);
+
 error_free_root:
 	amdgpu_bo_unref(&vm->root.base.bo->shadow);
 	amdgpu_bo_unref(&vm->root.base.bo);
-- 
2.14.1

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

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

* [PATCH 2/4] drm/amdgpu: revert "Add a parameter to amdgpu_bo_create()"
       [not found] ` <20180126100442.1856-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
@ 2018-01-26 10:04   ` Christian König
  2018-01-26 10:04   ` [PATCH 3/4] drm/amdgpu: revert "Add support for filling a buffer with 64 bit value" Christian König
  2018-01-26 10:04   ` [PATCH 4/4] drm/amdgpu: fill only the lower range with ATS entries Christian König
  2 siblings, 0 replies; 9+ messages in thread
From: Christian König @ 2018-01-26 10:04 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

This reverts commit 2046d46db9166bddc84778f0b3477f6d1e9068ea.

Not needed any more.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c    |  3 +--
 drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c |  4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c       |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c      |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c       |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c    | 13 ++++---------
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h    |  1 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c     |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c        |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_test.c      |  4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c       |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c       |  4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c       |  4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c        |  5 ++---
 14 files changed, 21 insertions(+), 29 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
index 285916c93c3d..dced1d0b73e7 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
@@ -216,8 +216,7 @@ int alloc_gtt_mem(struct kgd_dev *kgd, size_t size,
 		return -ENOMEM;
 
 	r = amdgpu_bo_create(adev, size, PAGE_SIZE, true, AMDGPU_GEM_DOMAIN_GTT,
-			     AMDGPU_GEM_CREATE_CPU_GTT_USWC, NULL, NULL, 0,
-			     &(*mem)->bo);
+			     AMDGPU_GEM_CREATE_CPU_GTT_USWC, NULL, NULL, &(*mem)->bo);
 	if (r) {
 		dev_err(adev->dev,
 			"failed to allocate BO for amdkfd (%d)\n", r);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c
index 63ec1e1bb6aa..2fb299afc12b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c
@@ -81,7 +81,7 @@ static void amdgpu_benchmark_move(struct amdgpu_device *adev, unsigned size,
 
 	n = AMDGPU_BENCHMARK_ITERATIONS;
 	r = amdgpu_bo_create(adev, size, PAGE_SIZE, true, sdomain, 0, NULL,
-			     NULL, 0, &sobj);
+			     NULL, &sobj);
 	if (r) {
 		goto out_cleanup;
 	}
@@ -94,7 +94,7 @@ static void amdgpu_benchmark_move(struct amdgpu_device *adev, unsigned size,
 		goto out_cleanup;
 	}
 	r = amdgpu_bo_create(adev, size, PAGE_SIZE, true, ddomain, 0, NULL,
-			     NULL, 0, &dobj);
+			     NULL, &dobj);
 	if (r) {
 		goto out_cleanup;
 	}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c
index bccb0f70c997..71b4aec7f650 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c
@@ -109,7 +109,7 @@ static int amdgpu_cgs_alloc_gpu_mem(struct cgs_device *cgs_device,
 	*handle = 0;
 
 	ret = amdgpu_bo_create(adev, size, align, true, domain, flags,
-			       NULL, NULL, 0, &obj);
+			       NULL, NULL, &obj);
 	if (ret) {
 		DRM_ERROR("(%d) bo create failed\n", ret);
 		return ret;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
index 56b0b305a9fb..008eaee57114 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
@@ -120,7 +120,7 @@ int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev)
 				     PAGE_SIZE, true, AMDGPU_GEM_DOMAIN_VRAM,
 				     AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
 				     AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS,
-				     NULL, NULL, 0, &adev->gart.robj);
+				     NULL, NULL, &adev->gart.robj);
 		if (r) {
 			return r;
 		}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index 77304a81a290..a66f4c5de882 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -60,7 +60,7 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
 
 retry:
 	r = amdgpu_bo_create(adev, size, alignment, kernel, initial_domain,
-			     flags, NULL, resv, 0, &bo);
+			     flags, NULL, resv, &bo);
 	if (r) {
 		if (r != -ERESTARTSYS) {
 			if (flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) {
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index f0a685340cd4..512612ec3557 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -190,7 +190,7 @@ int amdgpu_bo_create_reserved(struct amdgpu_device *adev,
 		r = amdgpu_bo_create(adev, size, align, true, domain,
 				     AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
 				     AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS,
-				     NULL, NULL, 0, bo_ptr);
+				     NULL, NULL, bo_ptr);
 		if (r) {
 			dev_err(adev->dev, "(%d) failed to allocate kernel bo\n",
 				r);
@@ -336,7 +336,6 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev,
 			       bool kernel, u32 domain, u64 flags,
 			       struct sg_table *sg,
 			       struct reservation_object *resv,
-			       uint64_t init_value,
 			       struct amdgpu_bo **bo_ptr)
 {
 	struct ttm_operation_ctx ctx = {
@@ -443,7 +442,7 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev,
 	    bo->tbo.mem.placement & TTM_PL_FLAG_VRAM) {
 		struct dma_fence *fence;
 
-		r = amdgpu_fill_buffer(bo, init_value, bo->tbo.resv, &fence);
+		r = amdgpu_fill_buffer(bo, 0, bo->tbo.resv, &fence);
 		if (unlikely(r))
 			goto fail_unreserve;
 
@@ -484,7 +483,7 @@ static int amdgpu_bo_create_shadow(struct amdgpu_device *adev,
 				AMDGPU_GEM_DOMAIN_GTT,
 				AMDGPU_GEM_CREATE_CPU_GTT_USWC |
 				AMDGPU_GEM_CREATE_SHADOW,
-				NULL, bo->tbo.resv, 0,
+				NULL, bo->tbo.resv,
 				&bo->shadow);
 	if (!r) {
 		bo->shadow->parent = amdgpu_bo_ref(bo);
@@ -496,22 +495,18 @@ static int amdgpu_bo_create_shadow(struct amdgpu_device *adev,
 	return r;
 }
 
-/* init_value will only take effect when flags contains
- * AMDGPU_GEM_CREATE_VRAM_CLEARED.
- */
 int amdgpu_bo_create(struct amdgpu_device *adev,
 		     unsigned long size, int byte_align,
 		     bool kernel, u32 domain, u64 flags,
 		     struct sg_table *sg,
 		     struct reservation_object *resv,
-		     uint64_t init_value,
 		     struct amdgpu_bo **bo_ptr)
 {
 	uint64_t parent_flags = flags & ~AMDGPU_GEM_CREATE_SHADOW;
 	int r;
 
 	r = amdgpu_bo_do_create(adev, size, byte_align, kernel, domain,
-				parent_flags, sg, resv, init_value, bo_ptr);
+				parent_flags, sg, resv, bo_ptr);
 	if (r)
 		return r;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
index 33615e2ea2e6..c2b02f5c88d2 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
@@ -206,7 +206,6 @@ int amdgpu_bo_create(struct amdgpu_device *adev,
 			    bool kernel, u32 domain, u64 flags,
 			    struct sg_table *sg,
 			    struct reservation_object *resv,
-			    uint64_t init_value,
 			    struct amdgpu_bo **bo_ptr);
 int amdgpu_bo_create_reserved(struct amdgpu_device *adev,
 			      unsigned long size, int align,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
index 8afec21dc45d..2a8d980d17f6 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c
@@ -104,7 +104,7 @@ amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
 
 	ww_mutex_lock(&resv->lock, NULL);
 	ret = amdgpu_bo_create(adev, attach->dmabuf->size, PAGE_SIZE, false,
-			       AMDGPU_GEM_DOMAIN_GTT, 0, sg, resv, 0, &bo);
+			       AMDGPU_GEM_DOMAIN_GTT, 0, sg, resv, &bo);
 	ww_mutex_unlock(&resv->lock);
 	if (ret)
 		return ERR_PTR(ret);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c
index 3144400435b7..5ca75a456ad2 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_sa.c
@@ -64,7 +64,7 @@ int amdgpu_sa_bo_manager_init(struct amdgpu_device *adev,
 		INIT_LIST_HEAD(&sa_manager->flist[i]);
 
 	r = amdgpu_bo_create(adev, size, align, true, domain,
-			     0, NULL, NULL, 0, &sa_manager->bo);
+			     0, NULL, NULL, &sa_manager->bo);
 	if (r) {
 		dev_err(adev->dev, "(%d) failed to allocate bo for manager\n", r);
 		return r;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_test.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_test.c
index 30d84df20437..f3d81b6fb499 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_test.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_test.c
@@ -61,7 +61,7 @@ static void amdgpu_do_test_moves(struct amdgpu_device *adev)
 
 	r = amdgpu_bo_create(adev, size, PAGE_SIZE, true,
 			     AMDGPU_GEM_DOMAIN_VRAM, 0,
-			     NULL, NULL, 0, &vram_obj);
+			     NULL, NULL, &vram_obj);
 	if (r) {
 		DRM_ERROR("Failed to create VRAM object\n");
 		goto out_cleanup;
@@ -82,7 +82,7 @@ static void amdgpu_do_test_moves(struct amdgpu_device *adev)
 
 		r = amdgpu_bo_create(adev, size, PAGE_SIZE, true,
 				     AMDGPU_GEM_DOMAIN_GTT, 0, NULL,
-				     NULL, 0, gtt_obj + i);
+				     NULL, gtt_obj + i);
 		if (r) {
 			DRM_ERROR("Failed to create GTT object %d\n", i);
 			goto out_lclean;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index d32f48259c40..783715cd2d3c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -1312,7 +1312,7 @@ static int amdgpu_ttm_fw_reserve_vram_init(struct amdgpu_device *adev)
 		r = amdgpu_bo_create(adev, adev->fw_vram_usage.size,
 			PAGE_SIZE, true, AMDGPU_GEM_DOMAIN_VRAM,
 			AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
-			AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS, NULL, NULL, 0,
+			AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS, NULL, NULL,
 			&adev->fw_vram_usage.reserved_bo);
 		if (r)
 			goto error_create;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
index b2eae86bf906..7cdbe0c14496 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
@@ -1059,7 +1059,7 @@ int amdgpu_uvd_get_create_msg(struct amdgpu_ring *ring, uint32_t handle,
 			     AMDGPU_GEM_DOMAIN_VRAM,
 			     AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
 			     AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS,
-			     NULL, NULL, 0, &bo);
+			     NULL, NULL, &bo);
 	if (r)
 		return r;
 
@@ -1109,7 +1109,7 @@ int amdgpu_uvd_get_destroy_msg(struct amdgpu_ring *ring, uint32_t handle,
 			     AMDGPU_GEM_DOMAIN_VRAM,
 			     AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
 			     AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS,
-			     NULL, NULL, 0, &bo);
+			     NULL, NULL, &bo);
 	if (r)
 		return r;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
index 837962118dbc..e86d0b2e9b7a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
@@ -359,7 +359,7 @@ static int amdgpu_vcn_dec_get_create_msg(struct amdgpu_ring *ring, uint32_t hand
 			     AMDGPU_GEM_DOMAIN_VRAM,
 			     AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
 			     AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS,
-			     NULL, NULL, 0, &bo);
+			     NULL, NULL, &bo);
 	if (r)
 		return r;
 
@@ -411,7 +411,7 @@ static int amdgpu_vcn_dec_get_destroy_msg(struct amdgpu_ring *ring, uint32_t han
 			     AMDGPU_GEM_DOMAIN_VRAM,
 			     AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
 			     AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS,
-			     NULL, NULL, 0, &bo);
+			     NULL, NULL, &bo);
 	if (r)
 		return r;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 5cdd8d9c3311..4a9d45b2d54f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -385,7 +385,7 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
 					     amdgpu_vm_bo_size(adev, level),
 					     AMDGPU_GPU_PAGE_SIZE, true,
 					     AMDGPU_GEM_DOMAIN_VRAM, flags,
-					     NULL, resv, 0, &pt);
+					     NULL, resv, &pt);
 			if (r)
 				return r;
 
@@ -2359,8 +2359,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 
 	size = amdgpu_vm_bo_size(adev, adev->vm_manager.root_level);
 	r = amdgpu_bo_create(adev, size, align, true, AMDGPU_GEM_DOMAIN_VRAM,
-			     flags, NULL, NULL, 0,
-			     &vm->root.base.bo);
+			     flags, NULL, NULL, &vm->root.base.bo);
 	if (r)
 		goto error_free_sched_entity;
 
-- 
2.14.1

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

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

* [PATCH 3/4] drm/amdgpu: revert "Add support for filling a buffer with 64 bit value"
       [not found] ` <20180126100442.1856-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
  2018-01-26 10:04   ` [PATCH 2/4] drm/amdgpu: revert "Add a parameter to amdgpu_bo_create()" Christian König
@ 2018-01-26 10:04   ` Christian König
  2018-01-26 10:04   ` [PATCH 4/4] drm/amdgpu: fill only the lower range with ATS entries Christian König
  2 siblings, 0 replies; 9+ messages in thread
From: Christian König @ 2018-01-26 10:04 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

This reverts commit 7bdc53f925af085ffa0580f10489f82b36cc2f1c and commit
330df03b3abf944f8f5180f2abc61367749984c0.

Neither are needed any more.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h     |  7 -------
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 17 +++++------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c  |  5 ++---
 drivers/gpu/drm/amd/amdgpu/cik_sdma.c   |  3 ---
 drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c  |  3 ---
 drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c  |  4 ----
 drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c  |  3 ---
 drivers/gpu/drm/amd/amdgpu/si_dma.c     |  3 ---
 9 files changed, 8 insertions(+), 39 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 353186f3e58c..d7930f3ead33 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -319,13 +319,6 @@ struct amdgpu_vm_pte_funcs {
 	void (*write_pte)(struct amdgpu_ib *ib, uint64_t pe,
 			  uint64_t value, unsigned count,
 			  uint32_t incr);
-
-	/* maximum nums of PTEs/PDEs in a single operation */
-	uint32_t	set_max_nums_pte_pde;
-
-	/* number of dw to reserve per operation */
-	unsigned	set_pte_pde_num_dw;
-
 	/* for linear pte/pde updates without addr mapping */
 	void (*set_pte_pde)(struct amdgpu_ib *ib,
 			    uint64_t pe,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 783715cd2d3c..95f990140f2a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -1681,13 +1681,12 @@ int amdgpu_copy_buffer(struct amdgpu_ring *ring, uint64_t src_offset,
 }
 
 int amdgpu_fill_buffer(struct amdgpu_bo *bo,
-		       uint64_t src_data,
+		       uint32_t src_data,
 		       struct reservation_object *resv,
 		       struct dma_fence **fence)
 {
 	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
-	uint32_t max_bytes = 8 *
-			adev->vm_manager.vm_pte_funcs->set_max_nums_pte_pde;
+	uint32_t max_bytes = adev->mman.buffer_funcs->fill_max_bytes;
 	struct amdgpu_ring *ring = adev->mman.buffer_funcs_ring;
 
 	struct drm_mm_node *mm_node;
@@ -1718,9 +1717,7 @@ int amdgpu_fill_buffer(struct amdgpu_bo *bo,
 		num_pages -= mm_node->size;
 		++mm_node;
 	}
-
-	/* num of dwords for each SDMA_OP_PTEPDE cmd */
-	num_dw = num_loops * adev->vm_manager.vm_pte_funcs->set_pte_pde_num_dw;
+	num_dw = num_loops * adev->mman.buffer_funcs->fill_num_dw;
 
 	/* for IB padding */
 	num_dw += 64;
@@ -1745,16 +1742,12 @@ int amdgpu_fill_buffer(struct amdgpu_bo *bo,
 		uint32_t byte_count = mm_node->size << PAGE_SHIFT;
 		uint64_t dst_addr;
 
-		WARN_ONCE(byte_count & 0x7, "size should be a multiple of 8");
-
 		dst_addr = amdgpu_mm_node_addr(&bo->tbo, mm_node, &bo->tbo.mem);
 		while (byte_count) {
 			uint32_t cur_size_in_bytes = min(byte_count, max_bytes);
 
-			amdgpu_vm_set_pte_pde(adev, &job->ibs[0],
-					dst_addr, 0,
-					cur_size_in_bytes >> 3, 0,
-					src_data);
+			amdgpu_emit_fill_buffer(adev, &job->ibs[0], src_data,
+						dst_addr, cur_size_in_bytes);
 
 			dst_addr += cur_size_in_bytes;
 			byte_count -= cur_size_in_bytes;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
index 167856f6080f..1e275c7b006b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
@@ -86,7 +86,7 @@ int amdgpu_ttm_copy_mem_to_mem(struct amdgpu_device *adev,
 			       struct reservation_object *resv,
 			       struct dma_fence **f);
 int amdgpu_fill_buffer(struct amdgpu_bo *bo,
-			uint64_t src_data,
+			uint32_t src_data,
 			struct reservation_object *resv,
 			struct dma_fence **fence);
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 4a9d45b2d54f..14798e20abca 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -1247,11 +1247,10 @@ static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev,
 
 	} else {
 		/* set page commands needed */
-		ndw += ncmds * adev->vm_manager.vm_pte_funcs->set_pte_pde_num_dw;
+		ndw += ncmds * 10;
 
 		/* extra commands for begin/end fragments */
-		ndw += 2 * adev->vm_manager.vm_pte_funcs->set_pte_pde_num_dw
-				* adev->vm_manager.fragment_size;
+		ndw += 2 * 10 * adev->vm_manager.fragment_size;
 
 		params.func = amdgpu_vm_do_set_ptes;
 	}
diff --git a/drivers/gpu/drm/amd/amdgpu/cik_sdma.c b/drivers/gpu/drm/amd/amdgpu/cik_sdma.c
index 5d18512cd090..d78bf183488b 100644
--- a/drivers/gpu/drm/amd/amdgpu/cik_sdma.c
+++ b/drivers/gpu/drm/amd/amdgpu/cik_sdma.c
@@ -1382,9 +1382,6 @@ static const struct amdgpu_vm_pte_funcs cik_sdma_vm_pte_funcs = {
 	.copy_pte = cik_sdma_vm_copy_pte,
 
 	.write_pte = cik_sdma_vm_write_pte,
-
-	.set_max_nums_pte_pde = 0x1fffff >> 3,
-	.set_pte_pde_num_dw = 10,
 	.set_pte_pde = cik_sdma_vm_set_pte_pde,
 };
 
diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c b/drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c
index 6a7a82a8c65d..792774eee909 100644
--- a/drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c
+++ b/drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c
@@ -1306,9 +1306,6 @@ static const struct amdgpu_vm_pte_funcs sdma_v2_4_vm_pte_funcs = {
 	.copy_pte = sdma_v2_4_vm_copy_pte,
 
 	.write_pte = sdma_v2_4_vm_write_pte,
-
-	.set_max_nums_pte_pde = 0x1fffff >> 3,
-	.set_pte_pde_num_dw = 10,
 	.set_pte_pde = sdma_v2_4_vm_set_pte_pde,
 };
 
diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c b/drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c
index 88178d81bd5a..83dde3b4c3ae 100644
--- a/drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c
@@ -1739,10 +1739,6 @@ static const struct amdgpu_vm_pte_funcs sdma_v3_0_vm_pte_funcs = {
 	.copy_pte = sdma_v3_0_vm_copy_pte,
 
 	.write_pte = sdma_v3_0_vm_write_pte,
-
-	/* not 0x3fffff due to HW limitation */
-	.set_max_nums_pte_pde = 0x3fffe0 >> 3,
-	.set_pte_pde_num_dw = 10,
 	.set_pte_pde = sdma_v3_0_vm_set_pte_pde,
 };
 
diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c b/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c
index e9b1b834fee1..8505458d7041 100644
--- a/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c
@@ -1686,9 +1686,6 @@ static const struct amdgpu_vm_pte_funcs sdma_v4_0_vm_pte_funcs = {
 	.copy_pte = sdma_v4_0_vm_copy_pte,
 
 	.write_pte = sdma_v4_0_vm_write_pte,
-
-	.set_max_nums_pte_pde = 0x400000 >> 3,
-	.set_pte_pde_num_dw = 10,
 	.set_pte_pde = sdma_v4_0_vm_set_pte_pde,
 };
 
diff --git a/drivers/gpu/drm/amd/amdgpu/si_dma.c b/drivers/gpu/drm/amd/amdgpu/si_dma.c
index e59521bacf0b..2db5bfba771e 100644
--- a/drivers/gpu/drm/amd/amdgpu/si_dma.c
+++ b/drivers/gpu/drm/amd/amdgpu/si_dma.c
@@ -875,9 +875,6 @@ static const struct amdgpu_vm_pte_funcs si_dma_vm_pte_funcs = {
 	.copy_pte = si_dma_vm_copy_pte,
 
 	.write_pte = si_dma_vm_write_pte,
-
-	.set_max_nums_pte_pde = 0xffff8 >> 3,
-	.set_pte_pde_num_dw = 9,
 	.set_pte_pde = si_dma_vm_set_pte_pde,
 };
 
-- 
2.14.1

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

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

* [PATCH 4/4] drm/amdgpu: fill only the lower range with ATS entries
       [not found] ` <20180126100442.1856-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
  2018-01-26 10:04   ` [PATCH 2/4] drm/amdgpu: revert "Add a parameter to amdgpu_bo_create()" Christian König
  2018-01-26 10:04   ` [PATCH 3/4] drm/amdgpu: revert "Add support for filling a buffer with 64 bit value" Christian König
@ 2018-01-26 10:04   ` Christian König
       [not found]     ` <20180126100442.1856-4-christian.koenig-5C7GfCeVMHo@public.gmane.org>
  2 siblings, 1 reply; 9+ messages in thread
From: Christian König @ 2018-01-26 10:04 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

At least on x86-64 the upper range is purely used by the kernel,
avoid creating any ATS mappings there as security precaution and to
allow proper page fault reporting in the upper range.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 83 ++++++++++++++++++++++------------
 1 file changed, 54 insertions(+), 29 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 14798e20abca..a3b9c3976eb3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -267,24 +267,34 @@ bool amdgpu_vm_ready(struct amdgpu_vm *vm)
  * Root PD needs to be reserved when calling this.
  */
 static int amdgpu_vm_clear_bo(struct amdgpu_device *adev,
-			      struct amdgpu_vm *vm,
-			      struct amdgpu_bo *bo,
-			      unsigned level)
+			      struct amdgpu_vm *vm, struct amdgpu_bo *bo,
+			      unsigned level, bool pte_support_ats)
 {
 	struct ttm_operation_ctx ctx = { true, false };
 	struct dma_fence *fence = NULL;
-	uint64_t addr, init_value;
+	unsigned entries, ats_entries;
+	uint64_t addr, ats_value;
 	struct amdgpu_ring *ring;
 	struct amdgpu_job *job;
-	unsigned entries;
 	int r;
 
-	if (vm->pte_support_ats) {
-		init_value = AMDGPU_PTE_DEFAULT_ATC;
-		if (level != AMDGPU_VM_PTB)
-			init_value |= AMDGPU_PDE_PTE;
+	addr = amdgpu_bo_gpu_offset(bo);
+	entries = amdgpu_bo_size(bo) / 8;
+
+	if (pte_support_ats) {
+		if (level == adev->vm_manager.root_level) {
+			ats_entries = amdgpu_vm_level_shift(adev, level);
+			ats_entries += AMDGPU_GPU_PAGE_SHIFT;
+			ats_entries = AMDGPU_VA_HOLE_START >> ats_entries;
+			ats_entries = min(ats_entries, entries);
+			entries -= ats_entries;
+		} else {
+			ats_entries = entries;
+			entries = 0;
+		}
 	} else {
-		init_value = 0;
+		ats_entries = 0;
+		ats_value = 0;
 	}
 
 	ring = container_of(vm->entity.sched, struct amdgpu_ring, sched);
@@ -297,15 +307,26 @@ static int amdgpu_vm_clear_bo(struct amdgpu_device *adev,
 	if (r)
 		goto error;
 
-	addr = amdgpu_bo_gpu_offset(bo);
-	entries = amdgpu_bo_size(bo) / 8;
-
 	r = amdgpu_job_alloc_with_ib(adev, 64, &job);
 	if (r)
 		goto error;
 
-	amdgpu_vm_set_pte_pde(adev, &job->ibs[0], addr, 0,
-			      entries, 0, init_value);
+	if (ats_entries) {
+		uint64_t ats_value;
+
+		ats_value = AMDGPU_PTE_DEFAULT_ATC;
+		if (level != AMDGPU_VM_PTB)
+			ats_value |= AMDGPU_PDE_PTE;
+
+		amdgpu_vm_set_pte_pde(adev, &job->ibs[0], addr, 0,
+				      ats_entries, 0, ats_value);
+		addr += ats_entries * 8;
+	}
+
+	if (entries)
+		amdgpu_vm_set_pte_pde(adev, &job->ibs[0], addr, 0,
+				      entries, 0, 0);
+
 	amdgpu_ring_pad_ib(ring, &job->ibs[0]);
 
 	WARN_ON(job->ibs[0].length_dw > 64);
@@ -339,7 +360,7 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
 				  struct amdgpu_vm *vm,
 				  struct amdgpu_vm_pt *parent,
 				  uint64_t saddr, uint64_t eaddr,
-				  unsigned level)
+				  unsigned level, bool ats)
 {
 	unsigned shift = amdgpu_vm_level_shift(adev, level);
 	unsigned pt_idx, from, to;
@@ -389,7 +410,7 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
 			if (r)
 				return r;
 
-			r = amdgpu_vm_clear_bo(adev, vm, pt, level);
+			r = amdgpu_vm_clear_bo(adev, vm, pt, level, ats);
 			if (r) {
 				amdgpu_bo_unref(&pt);
 				return r;
@@ -421,7 +442,7 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
 			uint64_t sub_eaddr = (pt_idx == to) ? eaddr :
 				((1 << shift) - 1);
 			r = amdgpu_vm_alloc_levels(adev, vm, entry, sub_saddr,
-						   sub_eaddr, level);
+						   sub_eaddr, level, ats);
 			if (r)
 				return r;
 		}
@@ -444,26 +465,29 @@ int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
 			struct amdgpu_vm *vm,
 			uint64_t saddr, uint64_t size)
 {
-	uint64_t last_pfn;
 	uint64_t eaddr;
+	bool ats = false;
 
 	/* validate the parameters */
 	if (saddr & AMDGPU_GPU_PAGE_MASK || size & AMDGPU_GPU_PAGE_MASK)
 		return -EINVAL;
 
 	eaddr = saddr + size - 1;
-	last_pfn = eaddr / AMDGPU_GPU_PAGE_SIZE;
-	if (last_pfn >= adev->vm_manager.max_pfn) {
-		dev_err(adev->dev, "va above limit (0x%08llX >= 0x%08llX)\n",
-			last_pfn, adev->vm_manager.max_pfn);
-		return -EINVAL;
-	}
+
+	if (vm->pte_support_ats)
+		ats = saddr < AMDGPU_VA_HOLE_START;
 
 	saddr /= AMDGPU_GPU_PAGE_SIZE;
 	eaddr /= AMDGPU_GPU_PAGE_SIZE;
 
+	if (eaddr >= adev->vm_manager.max_pfn) {
+		dev_err(adev->dev, "va above limit (0x%08llX >= 0x%08llX)\n",
+			eaddr, adev->vm_manager.max_pfn);
+		return -EINVAL;
+	}
+
 	return amdgpu_vm_alloc_levels(adev, vm, &vm->root, saddr, eaddr,
-				      adev->vm_manager.root_level);
+				      adev->vm_manager.root_level, ats);
 }
 
 /**
@@ -1665,16 +1689,16 @@ int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
 			  struct dma_fence **fence)
 {
 	struct amdgpu_bo_va_mapping *mapping;
+	uint64_t init_pte_value = 0;
 	struct dma_fence *f = NULL;
 	int r;
-	uint64_t init_pte_value = 0;
 
 	while (!list_empty(&vm->freed)) {
 		mapping = list_first_entry(&vm->freed,
 			struct amdgpu_bo_va_mapping, list);
 		list_del(&mapping->list);
 
-		if (vm->pte_support_ats)
+		if (vm->pte_support_ats && mapping->start < AMDGPU_VA_HOLE_START)
 			init_pte_value = AMDGPU_PTE_DEFAULT_ATC;
 
 		r = amdgpu_vm_bo_update_mapping(adev, NULL, NULL, vm,
@@ -2367,7 +2391,8 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 		goto error_free_root;
 
 	r = amdgpu_vm_clear_bo(adev, vm, vm->root.base.bo,
-			       adev->vm_manager.root_level);
+			       adev->vm_manager.root_level,
+			       vm->pte_support_ats);
 	if (r)
 		goto error_unreserve;
 
-- 
2.14.1

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

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

* Re: [PATCH 4/4] drm/amdgpu: fill only the lower range with ATS entries
       [not found]     ` <20180126100442.1856-4-christian.koenig-5C7GfCeVMHo@public.gmane.org>
@ 2018-01-26 20:18       ` Felix Kuehling
       [not found]         ` <aa16d6ac-643a-45cf-d530-2776a66c7339-5C7GfCeVMHo@public.gmane.org>
  2018-01-27  1:49       ` Felix Kuehling
  1 sibling, 1 reply; 9+ messages in thread
From: Felix Kuehling @ 2018-01-26 20:18 UTC (permalink / raw)
  To: Christian König, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Shouldn't this change come before all the reverts? Otherwise you're
briefly breaking ATS support on Raven for KFD.

Regards,
  Felix


On 2018-01-26 05:04 AM, Christian König wrote:
> At least on x86-64 the upper range is purely used by the kernel,
> avoid creating any ATS mappings there as security precaution and to
> allow proper page fault reporting in the upper range.
>
> Signed-off-by: Christian König <christian.koenig@amd.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 83 ++++++++++++++++++++++------------
>  1 file changed, 54 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index 14798e20abca..a3b9c3976eb3 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -267,24 +267,34 @@ bool amdgpu_vm_ready(struct amdgpu_vm *vm)
>   * Root PD needs to be reserved when calling this.
>   */
>  static int amdgpu_vm_clear_bo(struct amdgpu_device *adev,
> -			      struct amdgpu_vm *vm,
> -			      struct amdgpu_bo *bo,
> -			      unsigned level)
> +			      struct amdgpu_vm *vm, struct amdgpu_bo *bo,
> +			      unsigned level, bool pte_support_ats)
>  {
>  	struct ttm_operation_ctx ctx = { true, false };
>  	struct dma_fence *fence = NULL;
> -	uint64_t addr, init_value;
> +	unsigned entries, ats_entries;
> +	uint64_t addr, ats_value;
>  	struct amdgpu_ring *ring;
>  	struct amdgpu_job *job;
> -	unsigned entries;
>  	int r;
>  
> -	if (vm->pte_support_ats) {
> -		init_value = AMDGPU_PTE_DEFAULT_ATC;
> -		if (level != AMDGPU_VM_PTB)
> -			init_value |= AMDGPU_PDE_PTE;
> +	addr = amdgpu_bo_gpu_offset(bo);
> +	entries = amdgpu_bo_size(bo) / 8;
> +
> +	if (pte_support_ats) {
> +		if (level == adev->vm_manager.root_level) {
> +			ats_entries = amdgpu_vm_level_shift(adev, level);
> +			ats_entries += AMDGPU_GPU_PAGE_SHIFT;
> +			ats_entries = AMDGPU_VA_HOLE_START >> ats_entries;
> +			ats_entries = min(ats_entries, entries);
> +			entries -= ats_entries;
> +		} else {
> +			ats_entries = entries;
> +			entries = 0;
> +		}
>  	} else {
> -		init_value = 0;
> +		ats_entries = 0;
> +		ats_value = 0;
>  	}
>  
>  	ring = container_of(vm->entity.sched, struct amdgpu_ring, sched);
> @@ -297,15 +307,26 @@ static int amdgpu_vm_clear_bo(struct amdgpu_device *adev,
>  	if (r)
>  		goto error;
>  
> -	addr = amdgpu_bo_gpu_offset(bo);
> -	entries = amdgpu_bo_size(bo) / 8;
> -
>  	r = amdgpu_job_alloc_with_ib(adev, 64, &job);
>  	if (r)
>  		goto error;
>  
> -	amdgpu_vm_set_pte_pde(adev, &job->ibs[0], addr, 0,
> -			      entries, 0, init_value);
> +	if (ats_entries) {
> +		uint64_t ats_value;
> +
> +		ats_value = AMDGPU_PTE_DEFAULT_ATC;
> +		if (level != AMDGPU_VM_PTB)
> +			ats_value |= AMDGPU_PDE_PTE;
> +
> +		amdgpu_vm_set_pte_pde(adev, &job->ibs[0], addr, 0,
> +				      ats_entries, 0, ats_value);
> +		addr += ats_entries * 8;
> +	}
> +
> +	if (entries)
> +		amdgpu_vm_set_pte_pde(adev, &job->ibs[0], addr, 0,
> +				      entries, 0, 0);
> +
>  	amdgpu_ring_pad_ib(ring, &job->ibs[0]);
>  
>  	WARN_ON(job->ibs[0].length_dw > 64);
> @@ -339,7 +360,7 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
>  				  struct amdgpu_vm *vm,
>  				  struct amdgpu_vm_pt *parent,
>  				  uint64_t saddr, uint64_t eaddr,
> -				  unsigned level)
> +				  unsigned level, bool ats)
>  {
>  	unsigned shift = amdgpu_vm_level_shift(adev, level);
>  	unsigned pt_idx, from, to;
> @@ -389,7 +410,7 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
>  			if (r)
>  				return r;
>  
> -			r = amdgpu_vm_clear_bo(adev, vm, pt, level);
> +			r = amdgpu_vm_clear_bo(adev, vm, pt, level, ats);
>  			if (r) {
>  				amdgpu_bo_unref(&pt);
>  				return r;
> @@ -421,7 +442,7 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
>  			uint64_t sub_eaddr = (pt_idx == to) ? eaddr :
>  				((1 << shift) - 1);
>  			r = amdgpu_vm_alloc_levels(adev, vm, entry, sub_saddr,
> -						   sub_eaddr, level);
> +						   sub_eaddr, level, ats);
>  			if (r)
>  				return r;
>  		}
> @@ -444,26 +465,29 @@ int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
>  			struct amdgpu_vm *vm,
>  			uint64_t saddr, uint64_t size)
>  {
> -	uint64_t last_pfn;
>  	uint64_t eaddr;
> +	bool ats = false;
>  
>  	/* validate the parameters */
>  	if (saddr & AMDGPU_GPU_PAGE_MASK || size & AMDGPU_GPU_PAGE_MASK)
>  		return -EINVAL;
>  
>  	eaddr = saddr + size - 1;
> -	last_pfn = eaddr / AMDGPU_GPU_PAGE_SIZE;
> -	if (last_pfn >= adev->vm_manager.max_pfn) {
> -		dev_err(adev->dev, "va above limit (0x%08llX >= 0x%08llX)\n",
> -			last_pfn, adev->vm_manager.max_pfn);
> -		return -EINVAL;
> -	}
> +
> +	if (vm->pte_support_ats)
> +		ats = saddr < AMDGPU_VA_HOLE_START;
>  
>  	saddr /= AMDGPU_GPU_PAGE_SIZE;
>  	eaddr /= AMDGPU_GPU_PAGE_SIZE;
>  
> +	if (eaddr >= adev->vm_manager.max_pfn) {
> +		dev_err(adev->dev, "va above limit (0x%08llX >= 0x%08llX)\n",
> +			eaddr, adev->vm_manager.max_pfn);
> +		return -EINVAL;
> +	}
> +
>  	return amdgpu_vm_alloc_levels(adev, vm, &vm->root, saddr, eaddr,
> -				      adev->vm_manager.root_level);
> +				      adev->vm_manager.root_level, ats);
>  }
>  
>  /**
> @@ -1665,16 +1689,16 @@ int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
>  			  struct dma_fence **fence)
>  {
>  	struct amdgpu_bo_va_mapping *mapping;
> +	uint64_t init_pte_value = 0;
>  	struct dma_fence *f = NULL;
>  	int r;
> -	uint64_t init_pte_value = 0;
>  
>  	while (!list_empty(&vm->freed)) {
>  		mapping = list_first_entry(&vm->freed,
>  			struct amdgpu_bo_va_mapping, list);
>  		list_del(&mapping->list);
>  
> -		if (vm->pte_support_ats)
> +		if (vm->pte_support_ats && mapping->start < AMDGPU_VA_HOLE_START)
>  			init_pte_value = AMDGPU_PTE_DEFAULT_ATC;
>  
>  		r = amdgpu_vm_bo_update_mapping(adev, NULL, NULL, vm,
> @@ -2367,7 +2391,8 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
>  		goto error_free_root;
>  
>  	r = amdgpu_vm_clear_bo(adev, vm, vm->root.base.bo,
> -			       adev->vm_manager.root_level);
> +			       adev->vm_manager.root_level,
> +			       vm->pte_support_ats);
>  	if (r)
>  		goto error_unreserve;
>  

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

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

* Re: [PATCH 4/4] drm/amdgpu: fill only the lower range with ATS entries
       [not found]         ` <aa16d6ac-643a-45cf-d530-2776a66c7339-5C7GfCeVMHo@public.gmane.org>
@ 2018-01-26 20:21           ` Christian König
       [not found]             ` <a1448771-71db-41c8-97fa-c9b5743aaef6-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 9+ messages in thread
From: Christian König @ 2018-01-26 20:21 UTC (permalink / raw)
  To: Felix Kuehling, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

The amdgpu_vm_clear_bo function takes over this functionality in the 
first patch.

This patch only limits filling in the ats values in the lower halve of 
the address range (previously it was filled in the whole address space).

Regards,
Christian.

Am 26.01.2018 um 21:18 schrieb Felix Kuehling:
> Shouldn't this change come before all the reverts? Otherwise you're
> briefly breaking ATS support on Raven for KFD.
>
> Regards,
>    Felix
>
>
> On 2018-01-26 05:04 AM, Christian König wrote:
>> At least on x86-64 the upper range is purely used by the kernel,
>> avoid creating any ATS mappings there as security precaution and to
>> allow proper page fault reporting in the upper range.
>>
>> Signed-off-by: Christian König <christian.koenig@amd.com>
>> ---
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 83 ++++++++++++++++++++++------------
>>   1 file changed, 54 insertions(+), 29 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>> index 14798e20abca..a3b9c3976eb3 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>> @@ -267,24 +267,34 @@ bool amdgpu_vm_ready(struct amdgpu_vm *vm)
>>    * Root PD needs to be reserved when calling this.
>>    */
>>   static int amdgpu_vm_clear_bo(struct amdgpu_device *adev,
>> -			      struct amdgpu_vm *vm,
>> -			      struct amdgpu_bo *bo,
>> -			      unsigned level)
>> +			      struct amdgpu_vm *vm, struct amdgpu_bo *bo,
>> +			      unsigned level, bool pte_support_ats)
>>   {
>>   	struct ttm_operation_ctx ctx = { true, false };
>>   	struct dma_fence *fence = NULL;
>> -	uint64_t addr, init_value;
>> +	unsigned entries, ats_entries;
>> +	uint64_t addr, ats_value;
>>   	struct amdgpu_ring *ring;
>>   	struct amdgpu_job *job;
>> -	unsigned entries;
>>   	int r;
>>   
>> -	if (vm->pte_support_ats) {
>> -		init_value = AMDGPU_PTE_DEFAULT_ATC;
>> -		if (level != AMDGPU_VM_PTB)
>> -			init_value |= AMDGPU_PDE_PTE;
>> +	addr = amdgpu_bo_gpu_offset(bo);
>> +	entries = amdgpu_bo_size(bo) / 8;
>> +
>> +	if (pte_support_ats) {
>> +		if (level == adev->vm_manager.root_level) {
>> +			ats_entries = amdgpu_vm_level_shift(adev, level);
>> +			ats_entries += AMDGPU_GPU_PAGE_SHIFT;
>> +			ats_entries = AMDGPU_VA_HOLE_START >> ats_entries;
>> +			ats_entries = min(ats_entries, entries);
>> +			entries -= ats_entries;
>> +		} else {
>> +			ats_entries = entries;
>> +			entries = 0;
>> +		}
>>   	} else {
>> -		init_value = 0;
>> +		ats_entries = 0;
>> +		ats_value = 0;
>>   	}
>>   
>>   	ring = container_of(vm->entity.sched, struct amdgpu_ring, sched);
>> @@ -297,15 +307,26 @@ static int amdgpu_vm_clear_bo(struct amdgpu_device *adev,
>>   	if (r)
>>   		goto error;
>>   
>> -	addr = amdgpu_bo_gpu_offset(bo);
>> -	entries = amdgpu_bo_size(bo) / 8;
>> -
>>   	r = amdgpu_job_alloc_with_ib(adev, 64, &job);
>>   	if (r)
>>   		goto error;
>>   
>> -	amdgpu_vm_set_pte_pde(adev, &job->ibs[0], addr, 0,
>> -			      entries, 0, init_value);
>> +	if (ats_entries) {
>> +		uint64_t ats_value;
>> +
>> +		ats_value = AMDGPU_PTE_DEFAULT_ATC;
>> +		if (level != AMDGPU_VM_PTB)
>> +			ats_value |= AMDGPU_PDE_PTE;
>> +
>> +		amdgpu_vm_set_pte_pde(adev, &job->ibs[0], addr, 0,
>> +				      ats_entries, 0, ats_value);
>> +		addr += ats_entries * 8;
>> +	}
>> +
>> +	if (entries)
>> +		amdgpu_vm_set_pte_pde(adev, &job->ibs[0], addr, 0,
>> +				      entries, 0, 0);
>> +
>>   	amdgpu_ring_pad_ib(ring, &job->ibs[0]);
>>   
>>   	WARN_ON(job->ibs[0].length_dw > 64);
>> @@ -339,7 +360,7 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
>>   				  struct amdgpu_vm *vm,
>>   				  struct amdgpu_vm_pt *parent,
>>   				  uint64_t saddr, uint64_t eaddr,
>> -				  unsigned level)
>> +				  unsigned level, bool ats)
>>   {
>>   	unsigned shift = amdgpu_vm_level_shift(adev, level);
>>   	unsigned pt_idx, from, to;
>> @@ -389,7 +410,7 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
>>   			if (r)
>>   				return r;
>>   
>> -			r = amdgpu_vm_clear_bo(adev, vm, pt, level);
>> +			r = amdgpu_vm_clear_bo(adev, vm, pt, level, ats);
>>   			if (r) {
>>   				amdgpu_bo_unref(&pt);
>>   				return r;
>> @@ -421,7 +442,7 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
>>   			uint64_t sub_eaddr = (pt_idx == to) ? eaddr :
>>   				((1 << shift) - 1);
>>   			r = amdgpu_vm_alloc_levels(adev, vm, entry, sub_saddr,
>> -						   sub_eaddr, level);
>> +						   sub_eaddr, level, ats);
>>   			if (r)
>>   				return r;
>>   		}
>> @@ -444,26 +465,29 @@ int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
>>   			struct amdgpu_vm *vm,
>>   			uint64_t saddr, uint64_t size)
>>   {
>> -	uint64_t last_pfn;
>>   	uint64_t eaddr;
>> +	bool ats = false;
>>   
>>   	/* validate the parameters */
>>   	if (saddr & AMDGPU_GPU_PAGE_MASK || size & AMDGPU_GPU_PAGE_MASK)
>>   		return -EINVAL;
>>   
>>   	eaddr = saddr + size - 1;
>> -	last_pfn = eaddr / AMDGPU_GPU_PAGE_SIZE;
>> -	if (last_pfn >= adev->vm_manager.max_pfn) {
>> -		dev_err(adev->dev, "va above limit (0x%08llX >= 0x%08llX)\n",
>> -			last_pfn, adev->vm_manager.max_pfn);
>> -		return -EINVAL;
>> -	}
>> +
>> +	if (vm->pte_support_ats)
>> +		ats = saddr < AMDGPU_VA_HOLE_START;
>>   
>>   	saddr /= AMDGPU_GPU_PAGE_SIZE;
>>   	eaddr /= AMDGPU_GPU_PAGE_SIZE;
>>   
>> +	if (eaddr >= adev->vm_manager.max_pfn) {
>> +		dev_err(adev->dev, "va above limit (0x%08llX >= 0x%08llX)\n",
>> +			eaddr, adev->vm_manager.max_pfn);
>> +		return -EINVAL;
>> +	}
>> +
>>   	return amdgpu_vm_alloc_levels(adev, vm, &vm->root, saddr, eaddr,
>> -				      adev->vm_manager.root_level);
>> +				      adev->vm_manager.root_level, ats);
>>   }
>>   
>>   /**
>> @@ -1665,16 +1689,16 @@ int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
>>   			  struct dma_fence **fence)
>>   {
>>   	struct amdgpu_bo_va_mapping *mapping;
>> +	uint64_t init_pte_value = 0;
>>   	struct dma_fence *f = NULL;
>>   	int r;
>> -	uint64_t init_pte_value = 0;
>>   
>>   	while (!list_empty(&vm->freed)) {
>>   		mapping = list_first_entry(&vm->freed,
>>   			struct amdgpu_bo_va_mapping, list);
>>   		list_del(&mapping->list);
>>   
>> -		if (vm->pte_support_ats)
>> +		if (vm->pte_support_ats && mapping->start < AMDGPU_VA_HOLE_START)
>>   			init_pte_value = AMDGPU_PTE_DEFAULT_ATC;
>>   
>>   		r = amdgpu_vm_bo_update_mapping(adev, NULL, NULL, vm,
>> @@ -2367,7 +2391,8 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
>>   		goto error_free_root;
>>   
>>   	r = amdgpu_vm_clear_bo(adev, vm, vm->root.base.bo,
>> -			       adev->vm_manager.root_level);
>> +			       adev->vm_manager.root_level,
>> +			       vm->pte_support_ats);
>>   	if (r)
>>   		goto error_unreserve;
>>   

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

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

* Re: [PATCH 4/4] drm/amdgpu: fill only the lower range with ATS entries
       [not found]             ` <a1448771-71db-41c8-97fa-c9b5743aaef6-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2018-01-26 20:24               ` Felix Kuehling
       [not found]                 ` <acbd7b9a-15bb-295b-25c1-2a4955b3935a-5C7GfCeVMHo@public.gmane.org>
  0 siblings, 1 reply; 9+ messages in thread
From: Felix Kuehling @ 2018-01-26 20:24 UTC (permalink / raw)
  To: christian.koenig-5C7GfCeVMHo, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

So the first patch is not a straight revert, although the title looks
like it is. I'll read the first patch more carefully.


On 2018-01-26 03:21 PM, Christian König wrote:
> The amdgpu_vm_clear_bo function takes over this functionality in the
> first patch.
>
> This patch only limits filling in the ats values in the lower halve of
> the address range (previously it was filled in the whole address space).
>
> Regards,
> Christian.
>
> Am 26.01.2018 um 21:18 schrieb Felix Kuehling:
>> Shouldn't this change come before all the reverts? Otherwise you're
>> briefly breaking ATS support on Raven for KFD.
>>
>> Regards,
>>    Felix
>>
>>
>> On 2018-01-26 05:04 AM, Christian König wrote:
>>> At least on x86-64 the upper range is purely used by the kernel,
>>> avoid creating any ATS mappings there as security precaution and to
>>> allow proper page fault reporting in the upper range.
>>>
>>> Signed-off-by: Christian König <christian.koenig@amd.com>
>>> ---
>>>   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 83
>>> ++++++++++++++++++++++------------
>>>   1 file changed, 54 insertions(+), 29 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>>> index 14798e20abca..a3b9c3976eb3 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>>> @@ -267,24 +267,34 @@ bool amdgpu_vm_ready(struct amdgpu_vm *vm)
>>>    * Root PD needs to be reserved when calling this.
>>>    */
>>>   static int amdgpu_vm_clear_bo(struct amdgpu_device *adev,
>>> -                  struct amdgpu_vm *vm,
>>> -                  struct amdgpu_bo *bo,
>>> -                  unsigned level)
>>> +                  struct amdgpu_vm *vm, struct amdgpu_bo *bo,
>>> +                  unsigned level, bool pte_support_ats)
>>>   {
>>>       struct ttm_operation_ctx ctx = { true, false };
>>>       struct dma_fence *fence = NULL;
>>> -    uint64_t addr, init_value;
>>> +    unsigned entries, ats_entries;
>>> +    uint64_t addr, ats_value;
>>>       struct amdgpu_ring *ring;
>>>       struct amdgpu_job *job;
>>> -    unsigned entries;
>>>       int r;
>>>   -    if (vm->pte_support_ats) {
>>> -        init_value = AMDGPU_PTE_DEFAULT_ATC;
>>> -        if (level != AMDGPU_VM_PTB)
>>> -            init_value |= AMDGPU_PDE_PTE;
>>> +    addr = amdgpu_bo_gpu_offset(bo);
>>> +    entries = amdgpu_bo_size(bo) / 8;
>>> +
>>> +    if (pte_support_ats) {
>>> +        if (level == adev->vm_manager.root_level) {
>>> +            ats_entries = amdgpu_vm_level_shift(adev, level);
>>> +            ats_entries += AMDGPU_GPU_PAGE_SHIFT;
>>> +            ats_entries = AMDGPU_VA_HOLE_START >> ats_entries;
>>> +            ats_entries = min(ats_entries, entries);
>>> +            entries -= ats_entries;
>>> +        } else {
>>> +            ats_entries = entries;
>>> +            entries = 0;
>>> +        }
>>>       } else {
>>> -        init_value = 0;
>>> +        ats_entries = 0;
>>> +        ats_value = 0;
>>>       }
>>>         ring = container_of(vm->entity.sched, struct amdgpu_ring,
>>> sched);
>>> @@ -297,15 +307,26 @@ static int amdgpu_vm_clear_bo(struct
>>> amdgpu_device *adev,
>>>       if (r)
>>>           goto error;
>>>   -    addr = amdgpu_bo_gpu_offset(bo);
>>> -    entries = amdgpu_bo_size(bo) / 8;
>>> -
>>>       r = amdgpu_job_alloc_with_ib(adev, 64, &job);
>>>       if (r)
>>>           goto error;
>>>   -    amdgpu_vm_set_pte_pde(adev, &job->ibs[0], addr, 0,
>>> -                  entries, 0, init_value);
>>> +    if (ats_entries) {
>>> +        uint64_t ats_value;
>>> +
>>> +        ats_value = AMDGPU_PTE_DEFAULT_ATC;
>>> +        if (level != AMDGPU_VM_PTB)
>>> +            ats_value |= AMDGPU_PDE_PTE;
>>> +
>>> +        amdgpu_vm_set_pte_pde(adev, &job->ibs[0], addr, 0,
>>> +                      ats_entries, 0, ats_value);
>>> +        addr += ats_entries * 8;
>>> +    }
>>> +
>>> +    if (entries)
>>> +        amdgpu_vm_set_pte_pde(adev, &job->ibs[0], addr, 0,
>>> +                      entries, 0, 0);
>>> +
>>>       amdgpu_ring_pad_ib(ring, &job->ibs[0]);
>>>         WARN_ON(job->ibs[0].length_dw > 64);
>>> @@ -339,7 +360,7 @@ static int amdgpu_vm_alloc_levels(struct
>>> amdgpu_device *adev,
>>>                     struct amdgpu_vm *vm,
>>>                     struct amdgpu_vm_pt *parent,
>>>                     uint64_t saddr, uint64_t eaddr,
>>> -                  unsigned level)
>>> +                  unsigned level, bool ats)
>>>   {
>>>       unsigned shift = amdgpu_vm_level_shift(adev, level);
>>>       unsigned pt_idx, from, to;
>>> @@ -389,7 +410,7 @@ static int amdgpu_vm_alloc_levels(struct
>>> amdgpu_device *adev,
>>>               if (r)
>>>                   return r;
>>>   -            r = amdgpu_vm_clear_bo(adev, vm, pt, level);
>>> +            r = amdgpu_vm_clear_bo(adev, vm, pt, level, ats);
>>>               if (r) {
>>>                   amdgpu_bo_unref(&pt);
>>>                   return r;
>>> @@ -421,7 +442,7 @@ static int amdgpu_vm_alloc_levels(struct
>>> amdgpu_device *adev,
>>>               uint64_t sub_eaddr = (pt_idx == to) ? eaddr :
>>>                   ((1 << shift) - 1);
>>>               r = amdgpu_vm_alloc_levels(adev, vm, entry, sub_saddr,
>>> -                           sub_eaddr, level);
>>> +                           sub_eaddr, level, ats);
>>>               if (r)
>>>                   return r;
>>>           }
>>> @@ -444,26 +465,29 @@ int amdgpu_vm_alloc_pts(struct amdgpu_device
>>> *adev,
>>>               struct amdgpu_vm *vm,
>>>               uint64_t saddr, uint64_t size)
>>>   {
>>> -    uint64_t last_pfn;
>>>       uint64_t eaddr;
>>> +    bool ats = false;
>>>         /* validate the parameters */
>>>       if (saddr & AMDGPU_GPU_PAGE_MASK || size & AMDGPU_GPU_PAGE_MASK)
>>>           return -EINVAL;
>>>         eaddr = saddr + size - 1;
>>> -    last_pfn = eaddr / AMDGPU_GPU_PAGE_SIZE;
>>> -    if (last_pfn >= adev->vm_manager.max_pfn) {
>>> -        dev_err(adev->dev, "va above limit (0x%08llX >= 0x%08llX)\n",
>>> -            last_pfn, adev->vm_manager.max_pfn);
>>> -        return -EINVAL;
>>> -    }
>>> +
>>> +    if (vm->pte_support_ats)
>>> +        ats = saddr < AMDGPU_VA_HOLE_START;
>>>         saddr /= AMDGPU_GPU_PAGE_SIZE;
>>>       eaddr /= AMDGPU_GPU_PAGE_SIZE;
>>>   +    if (eaddr >= adev->vm_manager.max_pfn) {
>>> +        dev_err(adev->dev, "va above limit (0x%08llX >= 0x%08llX)\n",
>>> +            eaddr, adev->vm_manager.max_pfn);
>>> +        return -EINVAL;
>>> +    }
>>> +
>>>       return amdgpu_vm_alloc_levels(adev, vm, &vm->root, saddr, eaddr,
>>> -                      adev->vm_manager.root_level);
>>> +                      adev->vm_manager.root_level, ats);
>>>   }
>>>     /**
>>> @@ -1665,16 +1689,16 @@ int amdgpu_vm_clear_freed(struct
>>> amdgpu_device *adev,
>>>                 struct dma_fence **fence)
>>>   {
>>>       struct amdgpu_bo_va_mapping *mapping;
>>> +    uint64_t init_pte_value = 0;
>>>       struct dma_fence *f = NULL;
>>>       int r;
>>> -    uint64_t init_pte_value = 0;
>>>         while (!list_empty(&vm->freed)) {
>>>           mapping = list_first_entry(&vm->freed,
>>>               struct amdgpu_bo_va_mapping, list);
>>>           list_del(&mapping->list);
>>>   -        if (vm->pte_support_ats)
>>> +        if (vm->pte_support_ats && mapping->start <
>>> AMDGPU_VA_HOLE_START)
>>>               init_pte_value = AMDGPU_PTE_DEFAULT_ATC;
>>>             r = amdgpu_vm_bo_update_mapping(adev, NULL, NULL, vm,
>>> @@ -2367,7 +2391,8 @@ int amdgpu_vm_init(struct amdgpu_device *adev,
>>> struct amdgpu_vm *vm,
>>>           goto error_free_root;
>>>         r = amdgpu_vm_clear_bo(adev, vm, vm->root.base.bo,
>>> -                   adev->vm_manager.root_level);
>>> +                   adev->vm_manager.root_level,
>>> +                   vm->pte_support_ats);
>>>       if (r)
>>>           goto error_unreserve;
>>>   
>

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

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

* Re: [PATCH 4/4] drm/amdgpu: fill only the lower range with ATS entries
       [not found]                 ` <acbd7b9a-15bb-295b-25c1-2a4955b3935a-5C7GfCeVMHo@public.gmane.org>
@ 2018-01-26 20:26                   ` Christian König
  0 siblings, 0 replies; 9+ messages in thread
From: Christian König @ 2018-01-26 20:26 UTC (permalink / raw)
  To: Felix Kuehling, christian.koenig-5C7GfCeVMHo,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Yeah, good point. I should better note that in the first patch.

Christian.

Am 26.01.2018 um 21:24 schrieb Felix Kuehling:
> So the first patch is not a straight revert, although the title looks
> like it is. I'll read the first patch more carefully.
>
>
> On 2018-01-26 03:21 PM, Christian König wrote:
>> The amdgpu_vm_clear_bo function takes over this functionality in the
>> first patch.
>>
>> This patch only limits filling in the ats values in the lower halve of
>> the address range (previously it was filled in the whole address space).
>>
>> Regards,
>> Christian.
>>
>> Am 26.01.2018 um 21:18 schrieb Felix Kuehling:
>>> Shouldn't this change come before all the reverts? Otherwise you're
>>> briefly breaking ATS support on Raven for KFD.
>>>
>>> Regards,
>>>     Felix
>>>
>>>
>>> On 2018-01-26 05:04 AM, Christian König wrote:
>>>> At least on x86-64 the upper range is purely used by the kernel,
>>>> avoid creating any ATS mappings there as security precaution and to
>>>> allow proper page fault reporting in the upper range.
>>>>
>>>> Signed-off-by: Christian König <christian.koenig@amd.com>
>>>> ---
>>>>    drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 83
>>>> ++++++++++++++++++++++------------
>>>>    1 file changed, 54 insertions(+), 29 deletions(-)
>>>>
>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>>>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>>>> index 14798e20abca..a3b9c3976eb3 100644
>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>>>> @@ -267,24 +267,34 @@ bool amdgpu_vm_ready(struct amdgpu_vm *vm)
>>>>     * Root PD needs to be reserved when calling this.
>>>>     */
>>>>    static int amdgpu_vm_clear_bo(struct amdgpu_device *adev,
>>>> -                  struct amdgpu_vm *vm,
>>>> -                  struct amdgpu_bo *bo,
>>>> -                  unsigned level)
>>>> +                  struct amdgpu_vm *vm, struct amdgpu_bo *bo,
>>>> +                  unsigned level, bool pte_support_ats)
>>>>    {
>>>>        struct ttm_operation_ctx ctx = { true, false };
>>>>        struct dma_fence *fence = NULL;
>>>> -    uint64_t addr, init_value;
>>>> +    unsigned entries, ats_entries;
>>>> +    uint64_t addr, ats_value;
>>>>        struct amdgpu_ring *ring;
>>>>        struct amdgpu_job *job;
>>>> -    unsigned entries;
>>>>        int r;
>>>>    -    if (vm->pte_support_ats) {
>>>> -        init_value = AMDGPU_PTE_DEFAULT_ATC;
>>>> -        if (level != AMDGPU_VM_PTB)
>>>> -            init_value |= AMDGPU_PDE_PTE;
>>>> +    addr = amdgpu_bo_gpu_offset(bo);
>>>> +    entries = amdgpu_bo_size(bo) / 8;
>>>> +
>>>> +    if (pte_support_ats) {
>>>> +        if (level == adev->vm_manager.root_level) {
>>>> +            ats_entries = amdgpu_vm_level_shift(adev, level);
>>>> +            ats_entries += AMDGPU_GPU_PAGE_SHIFT;
>>>> +            ats_entries = AMDGPU_VA_HOLE_START >> ats_entries;
>>>> +            ats_entries = min(ats_entries, entries);
>>>> +            entries -= ats_entries;
>>>> +        } else {
>>>> +            ats_entries = entries;
>>>> +            entries = 0;
>>>> +        }
>>>>        } else {
>>>> -        init_value = 0;
>>>> +        ats_entries = 0;
>>>> +        ats_value = 0;
>>>>        }
>>>>          ring = container_of(vm->entity.sched, struct amdgpu_ring,
>>>> sched);
>>>> @@ -297,15 +307,26 @@ static int amdgpu_vm_clear_bo(struct
>>>> amdgpu_device *adev,
>>>>        if (r)
>>>>            goto error;
>>>>    -    addr = amdgpu_bo_gpu_offset(bo);
>>>> -    entries = amdgpu_bo_size(bo) / 8;
>>>> -
>>>>        r = amdgpu_job_alloc_with_ib(adev, 64, &job);
>>>>        if (r)
>>>>            goto error;
>>>>    -    amdgpu_vm_set_pte_pde(adev, &job->ibs[0], addr, 0,
>>>> -                  entries, 0, init_value);
>>>> +    if (ats_entries) {
>>>> +        uint64_t ats_value;
>>>> +
>>>> +        ats_value = AMDGPU_PTE_DEFAULT_ATC;
>>>> +        if (level != AMDGPU_VM_PTB)
>>>> +            ats_value |= AMDGPU_PDE_PTE;
>>>> +
>>>> +        amdgpu_vm_set_pte_pde(adev, &job->ibs[0], addr, 0,
>>>> +                      ats_entries, 0, ats_value);
>>>> +        addr += ats_entries * 8;
>>>> +    }
>>>> +
>>>> +    if (entries)
>>>> +        amdgpu_vm_set_pte_pde(adev, &job->ibs[0], addr, 0,
>>>> +                      entries, 0, 0);
>>>> +
>>>>        amdgpu_ring_pad_ib(ring, &job->ibs[0]);
>>>>          WARN_ON(job->ibs[0].length_dw > 64);
>>>> @@ -339,7 +360,7 @@ static int amdgpu_vm_alloc_levels(struct
>>>> amdgpu_device *adev,
>>>>                      struct amdgpu_vm *vm,
>>>>                      struct amdgpu_vm_pt *parent,
>>>>                      uint64_t saddr, uint64_t eaddr,
>>>> -                  unsigned level)
>>>> +                  unsigned level, bool ats)
>>>>    {
>>>>        unsigned shift = amdgpu_vm_level_shift(adev, level);
>>>>        unsigned pt_idx, from, to;
>>>> @@ -389,7 +410,7 @@ static int amdgpu_vm_alloc_levels(struct
>>>> amdgpu_device *adev,
>>>>                if (r)
>>>>                    return r;
>>>>    -            r = amdgpu_vm_clear_bo(adev, vm, pt, level);
>>>> +            r = amdgpu_vm_clear_bo(adev, vm, pt, level, ats);
>>>>                if (r) {
>>>>                    amdgpu_bo_unref(&pt);
>>>>                    return r;
>>>> @@ -421,7 +442,7 @@ static int amdgpu_vm_alloc_levels(struct
>>>> amdgpu_device *adev,
>>>>                uint64_t sub_eaddr = (pt_idx == to) ? eaddr :
>>>>                    ((1 << shift) - 1);
>>>>                r = amdgpu_vm_alloc_levels(adev, vm, entry, sub_saddr,
>>>> -                           sub_eaddr, level);
>>>> +                           sub_eaddr, level, ats);
>>>>                if (r)
>>>>                    return r;
>>>>            }
>>>> @@ -444,26 +465,29 @@ int amdgpu_vm_alloc_pts(struct amdgpu_device
>>>> *adev,
>>>>                struct amdgpu_vm *vm,
>>>>                uint64_t saddr, uint64_t size)
>>>>    {
>>>> -    uint64_t last_pfn;
>>>>        uint64_t eaddr;
>>>> +    bool ats = false;
>>>>          /* validate the parameters */
>>>>        if (saddr & AMDGPU_GPU_PAGE_MASK || size & AMDGPU_GPU_PAGE_MASK)
>>>>            return -EINVAL;
>>>>          eaddr = saddr + size - 1;
>>>> -    last_pfn = eaddr / AMDGPU_GPU_PAGE_SIZE;
>>>> -    if (last_pfn >= adev->vm_manager.max_pfn) {
>>>> -        dev_err(adev->dev, "va above limit (0x%08llX >= 0x%08llX)\n",
>>>> -            last_pfn, adev->vm_manager.max_pfn);
>>>> -        return -EINVAL;
>>>> -    }
>>>> +
>>>> +    if (vm->pte_support_ats)
>>>> +        ats = saddr < AMDGPU_VA_HOLE_START;
>>>>          saddr /= AMDGPU_GPU_PAGE_SIZE;
>>>>        eaddr /= AMDGPU_GPU_PAGE_SIZE;
>>>>    +    if (eaddr >= adev->vm_manager.max_pfn) {
>>>> +        dev_err(adev->dev, "va above limit (0x%08llX >= 0x%08llX)\n",
>>>> +            eaddr, adev->vm_manager.max_pfn);
>>>> +        return -EINVAL;
>>>> +    }
>>>> +
>>>>        return amdgpu_vm_alloc_levels(adev, vm, &vm->root, saddr, eaddr,
>>>> -                      adev->vm_manager.root_level);
>>>> +                      adev->vm_manager.root_level, ats);
>>>>    }
>>>>      /**
>>>> @@ -1665,16 +1689,16 @@ int amdgpu_vm_clear_freed(struct
>>>> amdgpu_device *adev,
>>>>                  struct dma_fence **fence)
>>>>    {
>>>>        struct amdgpu_bo_va_mapping *mapping;
>>>> +    uint64_t init_pte_value = 0;
>>>>        struct dma_fence *f = NULL;
>>>>        int r;
>>>> -    uint64_t init_pte_value = 0;
>>>>          while (!list_empty(&vm->freed)) {
>>>>            mapping = list_first_entry(&vm->freed,
>>>>                struct amdgpu_bo_va_mapping, list);
>>>>            list_del(&mapping->list);
>>>>    -        if (vm->pte_support_ats)
>>>> +        if (vm->pte_support_ats && mapping->start <
>>>> AMDGPU_VA_HOLE_START)
>>>>                init_pte_value = AMDGPU_PTE_DEFAULT_ATC;
>>>>              r = amdgpu_vm_bo_update_mapping(adev, NULL, NULL, vm,
>>>> @@ -2367,7 +2391,8 @@ int amdgpu_vm_init(struct amdgpu_device *adev,
>>>> struct amdgpu_vm *vm,
>>>>            goto error_free_root;
>>>>          r = amdgpu_vm_clear_bo(adev, vm, vm->root.base.bo,
>>>> -                   adev->vm_manager.root_level);
>>>> +                   adev->vm_manager.root_level,
>>>> +                   vm->pte_support_ats);
>>>>        if (r)
>>>>            goto error_unreserve;
>>>>    
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx

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

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

* Re: [PATCH 4/4] drm/amdgpu: fill only the lower range with ATS entries
       [not found]     ` <20180126100442.1856-4-christian.koenig-5C7GfCeVMHo@public.gmane.org>
  2018-01-26 20:18       ` Felix Kuehling
@ 2018-01-27  1:49       ` Felix Kuehling
  1 sibling, 0 replies; 9+ messages in thread
From: Felix Kuehling @ 2018-01-27  1:49 UTC (permalink / raw)
  To: Christian König, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

One minor nit-pick inline. Other than that and the confusing headline on
Patch 1 the series is Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>


On 2018-01-26 05:04 AM, Christian König wrote:
> At least on x86-64 the upper range is purely used by the kernel,
> avoid creating any ATS mappings there as security precaution and to
> allow proper page fault reporting in the upper range.
>
> Signed-off-by: Christian König <christian.koenig@amd.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 83 ++++++++++++++++++++++------------
>  1 file changed, 54 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index 14798e20abca..a3b9c3976eb3 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -267,24 +267,34 @@ bool amdgpu_vm_ready(struct amdgpu_vm *vm)
>   * Root PD needs to be reserved when calling this.
>   */
>  static int amdgpu_vm_clear_bo(struct amdgpu_device *adev,
> -			      struct amdgpu_vm *vm,
> -			      struct amdgpu_bo *bo,
> -			      unsigned level)
> +			      struct amdgpu_vm *vm, struct amdgpu_bo *bo,
> +			      unsigned level, bool pte_support_ats)
>  {
>  	struct ttm_operation_ctx ctx = { true, false };
>  	struct dma_fence *fence = NULL;
> -	uint64_t addr, init_value;
> +	unsigned entries, ats_entries;
> +	uint64_t addr, ats_value;
>  	struct amdgpu_ring *ring;
>  	struct amdgpu_job *job;
> -	unsigned entries;
>  	int r;
>  
> -	if (vm->pte_support_ats) {
> -		init_value = AMDGPU_PTE_DEFAULT_ATC;
> -		if (level != AMDGPU_VM_PTB)
> -			init_value |= AMDGPU_PDE_PTE;
> +	addr = amdgpu_bo_gpu_offset(bo);
> +	entries = amdgpu_bo_size(bo) / 8;
> +
> +	if (pte_support_ats) {
> +		if (level == adev->vm_manager.root_level) {
> +			ats_entries = amdgpu_vm_level_shift(adev, level);
> +			ats_entries += AMDGPU_GPU_PAGE_SHIFT;
> +			ats_entries = AMDGPU_VA_HOLE_START >> ats_entries;
> +			ats_entries = min(ats_entries, entries);
> +			entries -= ats_entries;
> +		} else {
> +			ats_entries = entries;
> +			entries = 0;
> +		}
>  	} else {
> -		init_value = 0;
> +		ats_entries = 0;
> +		ats_value = 0;

You don't need to initialize ats_value here. It won't be used, and for
the ATS case it's actually initialized below anyway.

Regards,
  Felix

>  	}
>  
>  	ring = container_of(vm->entity.sched, struct amdgpu_ring, sched);
> @@ -297,15 +307,26 @@ static int amdgpu_vm_clear_bo(struct amdgpu_device *adev,
>  	if (r)
>  		goto error;
>  
> -	addr = amdgpu_bo_gpu_offset(bo);
> -	entries = amdgpu_bo_size(bo) / 8;
> -
>  	r = amdgpu_job_alloc_with_ib(adev, 64, &job);
>  	if (r)
>  		goto error;
>  
> -	amdgpu_vm_set_pte_pde(adev, &job->ibs[0], addr, 0,
> -			      entries, 0, init_value);
> +	if (ats_entries) {
> +		uint64_t ats_value;
> +
> +		ats_value = AMDGPU_PTE_DEFAULT_ATC;
> +		if (level != AMDGPU_VM_PTB)
> +			ats_value |= AMDGPU_PDE_PTE;
> +
> +		amdgpu_vm_set_pte_pde(adev, &job->ibs[0], addr, 0,
> +				      ats_entries, 0, ats_value);
> +		addr += ats_entries * 8;
> +	}
> +
> +	if (entries)
> +		amdgpu_vm_set_pte_pde(adev, &job->ibs[0], addr, 0,
> +				      entries, 0, 0);
> +
>  	amdgpu_ring_pad_ib(ring, &job->ibs[0]);
>  
>  	WARN_ON(job->ibs[0].length_dw > 64);
> @@ -339,7 +360,7 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
>  				  struct amdgpu_vm *vm,
>  				  struct amdgpu_vm_pt *parent,
>  				  uint64_t saddr, uint64_t eaddr,
> -				  unsigned level)
> +				  unsigned level, bool ats)
>  {
>  	unsigned shift = amdgpu_vm_level_shift(adev, level);
>  	unsigned pt_idx, from, to;
> @@ -389,7 +410,7 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
>  			if (r)
>  				return r;
>  
> -			r = amdgpu_vm_clear_bo(adev, vm, pt, level);
> +			r = amdgpu_vm_clear_bo(adev, vm, pt, level, ats);
>  			if (r) {
>  				amdgpu_bo_unref(&pt);
>  				return r;
> @@ -421,7 +442,7 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
>  			uint64_t sub_eaddr = (pt_idx == to) ? eaddr :
>  				((1 << shift) - 1);
>  			r = amdgpu_vm_alloc_levels(adev, vm, entry, sub_saddr,
> -						   sub_eaddr, level);
> +						   sub_eaddr, level, ats);
>  			if (r)
>  				return r;
>  		}
> @@ -444,26 +465,29 @@ int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
>  			struct amdgpu_vm *vm,
>  			uint64_t saddr, uint64_t size)
>  {
> -	uint64_t last_pfn;
>  	uint64_t eaddr;
> +	bool ats = false;
>  
>  	/* validate the parameters */
>  	if (saddr & AMDGPU_GPU_PAGE_MASK || size & AMDGPU_GPU_PAGE_MASK)
>  		return -EINVAL;
>  
>  	eaddr = saddr + size - 1;
> -	last_pfn = eaddr / AMDGPU_GPU_PAGE_SIZE;
> -	if (last_pfn >= adev->vm_manager.max_pfn) {
> -		dev_err(adev->dev, "va above limit (0x%08llX >= 0x%08llX)\n",
> -			last_pfn, adev->vm_manager.max_pfn);
> -		return -EINVAL;
> -	}
> +
> +	if (vm->pte_support_ats)
> +		ats = saddr < AMDGPU_VA_HOLE_START;
>  
>  	saddr /= AMDGPU_GPU_PAGE_SIZE;
>  	eaddr /= AMDGPU_GPU_PAGE_SIZE;
>  
> +	if (eaddr >= adev->vm_manager.max_pfn) {
> +		dev_err(adev->dev, "va above limit (0x%08llX >= 0x%08llX)\n",
> +			eaddr, adev->vm_manager.max_pfn);
> +		return -EINVAL;
> +	}
> +
>  	return amdgpu_vm_alloc_levels(adev, vm, &vm->root, saddr, eaddr,
> -				      adev->vm_manager.root_level);
> +				      adev->vm_manager.root_level, ats);
>  }
>  
>  /**
> @@ -1665,16 +1689,16 @@ int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
>  			  struct dma_fence **fence)
>  {
>  	struct amdgpu_bo_va_mapping *mapping;
> +	uint64_t init_pte_value = 0;
>  	struct dma_fence *f = NULL;
>  	int r;
> -	uint64_t init_pte_value = 0;
>  
>  	while (!list_empty(&vm->freed)) {
>  		mapping = list_first_entry(&vm->freed,
>  			struct amdgpu_bo_va_mapping, list);
>  		list_del(&mapping->list);
>  
> -		if (vm->pte_support_ats)
> +		if (vm->pte_support_ats && mapping->start < AMDGPU_VA_HOLE_START)
>  			init_pte_value = AMDGPU_PTE_DEFAULT_ATC;
>  
>  		r = amdgpu_vm_bo_update_mapping(adev, NULL, NULL, vm,
> @@ -2367,7 +2391,8 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
>  		goto error_free_root;
>  
>  	r = amdgpu_vm_clear_bo(adev, vm, vm->root.base.bo,
> -			       adev->vm_manager.root_level);
> +			       adev->vm_manager.root_level,
> +			       vm->pte_support_ats);
>  	if (r)
>  		goto error_unreserve;
>  

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

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

end of thread, other threads:[~2018-01-27  1:49 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-26 10:04 [PATCH 1/4] drm/amdgpu: revert "drm/amdgpu: use AMDGPU_GEM_CREATE_VRAM_CLEARED for VM PD/PTs" Christian König
     [not found] ` <20180126100442.1856-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
2018-01-26 10:04   ` [PATCH 2/4] drm/amdgpu: revert "Add a parameter to amdgpu_bo_create()" Christian König
2018-01-26 10:04   ` [PATCH 3/4] drm/amdgpu: revert "Add support for filling a buffer with 64 bit value" Christian König
2018-01-26 10:04   ` [PATCH 4/4] drm/amdgpu: fill only the lower range with ATS entries Christian König
     [not found]     ` <20180126100442.1856-4-christian.koenig-5C7GfCeVMHo@public.gmane.org>
2018-01-26 20:18       ` Felix Kuehling
     [not found]         ` <aa16d6ac-643a-45cf-d530-2776a66c7339-5C7GfCeVMHo@public.gmane.org>
2018-01-26 20:21           ` Christian König
     [not found]             ` <a1448771-71db-41c8-97fa-c9b5743aaef6-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-01-26 20:24               ` Felix Kuehling
     [not found]                 ` <acbd7b9a-15bb-295b-25c1-2a4955b3935a-5C7GfCeVMHo@public.gmane.org>
2018-01-26 20:26                   ` Christian König
2018-01-27  1:49       ` Felix Kuehling

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.