Skip to contentSkip to conversation

drm/ttm: allow mapping BOs while they are still on the swap list

PATCH New Christian König 3 participants 6 messages Sep 6, 2017 – Sep 7, 2017 2 messages not in the archive

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 drm/ttm: allow mapping BOs while they are still on the swap list

From: Christian König <[email protected]>

With shared reservation objects it is possible that we want to temporary kmap an BO while it is still on the swap list.

---
 drivers/gpu/drm/ttm/ttm_bo_util.c | 1 -
 1 file changed, 1 deletion(-)
drivers/gpu/drm/ttm/ttm_bo_util.c +0 -1
index c934ad5..78cb99b 100644
@@ -587,7 +587,6 @@ int ttm_bo_kmap(struct ttm_buffer_object *bo,
 	unsigned long offset, size;
 	int ret;
 
-	BUG_ON(!list_empty(&bo->swap));
 	map->virtual = NULL;
 	map->bo = bo;
 	if (num_pages > bo->num_pages)
Signature · 6 lines
2.7.4

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

A message that is not in the archive (sent off-list or not yet received): 1504713094-2455-1-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

#2 lore raw

PATCH 2/3 drm/amdgpu: move amdgpu_cs_sysvm_access_required into find_mapping

From: Christian König <[email protected]>

When we need to find the mapping we need sysvm access anyway.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h     |  8 ++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  | 64 ++++++++++++---------------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c | 16 ++++-----
 drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 11 +++---
 4 files changed, 36 insertions(+), 63 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +4 -4
index 4dc9744..6c37768 100644
@@ -180,6 +180,7 @@ struct amdgpu_cs_parser;
 struct amdgpu_job;
 struct amdgpu_irq_src;
 struct amdgpu_fpriv;
+struct amdgpu_bo_va_mapping;
 
 enum amdgpu_cp_irq {
 	AMDGPU_CP_IRQ_GFX_EOP = 0,
@@ -1900,10 +1901,9 @@ static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
 static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
 #endif
 
-struct amdgpu_bo_va_mapping *
-amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
-		       uint64_t addr, struct amdgpu_bo **bo);
-int amdgpu_cs_sysvm_access_required(struct amdgpu_cs_parser *parser);
+int amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
+			   uint64_t addr, struct amdgpu_bo **bo,
+			   struct amdgpu_bo_va_mapping **mapping);
 
 #if defined(CONFIG_DRM_AMD_DC)
 int amdgpu_dm_display_resume(struct amdgpu_device *adev );
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +22 -42

99 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c +6 -10
index e19928d..331e34a 100644
@@ -410,10 +410,10 @@ static int amdgpu_uvd_cs_pass1(struct amdgpu_uvd_cs_ctx *ctx)
 	uint64_t addr = amdgpu_uvd_get_addr_from_ctx(ctx);
 	int r = 0;
 
-	mapping = amdgpu_cs_find_mapping(ctx->parser, addr, &bo);
-	if (mapping == NULL) {
+	r = amdgpu_cs_find_mapping(ctx->parser, addr, &bo, &mapping);
+	if (r) {
 		DRM_ERROR("Can't find BO for addr 0x%08Lx\n", addr);
-		return -EINVAL;
+		return r;
 	}
 
 	if (!ctx->parser->adev->uvd.address_64_bit) {
@@ -737,10 +737,10 @@ static int amdgpu_uvd_cs_pass2(struct amdgpu_uvd_cs_ctx *ctx)
 	uint64_t addr = amdgpu_uvd_get_addr_from_ctx(ctx);
 	int r;
 
-	mapping = amdgpu_cs_find_mapping(ctx->parser, addr, &bo);
-	if (mapping == NULL) {
+	r = amdgpu_cs_find_mapping(ctx->parser, addr, &bo, &mapping);
+	if (r) {
 		DRM_ERROR("Can't find BO for addr 0x%08Lx\n", addr);
-		return -EINVAL;
+		return r;
 	}
 
 	start = amdgpu_bo_gpu_offset(bo);
@@ -917,10 +917,6 @@ int amdgpu_uvd_ring_parse_cs(struct amdgpu_cs_parser *parser, uint32_t ib_idx)
 		return -EINVAL;
 	}
 
-	r = amdgpu_cs_sysvm_access_required(parser);
-	if (r)
-		return r;
-
 	ctx.parser = parser;
 	ctx.buf_sizes = buf_sizes;
 	ctx.ib_idx = ib_idx;
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +4 -7
index c855366..b46280c 100644
@@ -559,6 +559,7 @@ static int amdgpu_vce_cs_reloc(struct amdgpu_cs_parser *p, uint32_t ib_idx,
 	struct amdgpu_bo_va_mapping *mapping;
 	struct amdgpu_bo *bo;
 	uint64_t addr;
+	int r;
 
 	if (index == 0xffffffff)
 		index = 0;
@@ -567,11 +568,11 @@ static int amdgpu_vce_cs_reloc(struct amdgpu_cs_parser *p, uint32_t ib_idx,
 	       ((uint64_t)amdgpu_get_ib_value(p, ib_idx, hi)) << 32;
 	addr += ((uint64_t)size) * ((uint64_t)index);
 
-	mapping = amdgpu_cs_find_mapping(p, addr, &bo);
-	if (mapping == NULL) {
+	r = amdgpu_cs_find_mapping(p, addr, &bo, &mapping);
+	if (r) {
 		DRM_ERROR("Can't find BO for addr 0x%010Lx %d %d %d %d\n",
 			  addr, lo, hi, size, index);
-		return -EINVAL;
+		return r;
 	}
 
 	if ((addr + (uint64_t)size) >
@@ -652,10 +653,6 @@ int amdgpu_vce_ring_parse_cs(struct amdgpu_cs_parser *p, uint32_t ib_idx)
 	p->job->vm = NULL;
 	ib->gpu_addr = amdgpu_sa_bo_gpu_addr(ib->sa_bo);
 
-	r = amdgpu_cs_sysvm_access_required(p);
-	if (r)
-		return r;
-
 	while (idx < ib->length_dw) {
 		uint32_t len = amdgpu_get_ib_value(p, ib_idx, idx);
 		uint32_t cmd = amdgpu_get_ib_value(p, ib_idx, idx + 1);
Signature · 6 lines
2.7.4

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

PATCH 3/3 drm/amdgpu: rework amdgpu_cs_find_mapping

In reply to a message not in the archive

From: Christian König <[email protected]>

Use the VM instead of the BO list to find the BO for a virtual address.

This fixes UVD/VCE in physical mode with VM local BOs.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c     | 42 +++++++-----------------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c     | 17 ++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h     |  2 ++
 4 files changed, 30 insertions(+), 32 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +10 -32
index bcb3548..132e17a 100644
@@ -1374,46 +1374,24 @@ int amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
 			   uint64_t addr, struct amdgpu_bo **bo,
 			   struct amdgpu_bo_va_mapping **map)
 {
+	struct amdgpu_fpriv *fpriv = parser->filp->driver_priv;
+	struct amdgpu_vm *vm = &fpriv->vm;
 	struct amdgpu_bo_va_mapping *mapping;
-	unsigned i;
 	int r;
 
-	if (!parser->bo_list)
-		return 0;
-
 	addr /= AMDGPU_GPU_PAGE_SIZE;
 
-	for (i = 0; i < parser->bo_list->num_entries; i++) {
-		struct amdgpu_bo_list_entry *lobj;
-
-		lobj = &parser->bo_list->array[i];
-		if (!lobj->bo_va)
-			continue;
-
-		list_for_each_entry(mapping, &lobj->bo_va->valids, list) {
-			if (mapping->start > addr ||
-			    addr > mapping->last)
-				continue;
-
-			*bo = lobj->bo_va->base.bo;
-			*map = mapping;
-			goto found;
-		}
-
-		list_for_each_entry(mapping, &lobj->bo_va->invalids, list) {
-			if (mapping->start > addr ||
-			    addr > mapping->last)
-				continue;
+	mapping = amdgpu_vm_bo_lookup_mapping(vm, addr);
+	if (!mapping || !mapping->bo_va || !mapping->bo_va->base.bo)
+		return -EINVAL;
 
-			*bo = lobj->bo_va->base.bo;
-			*map = mapping;
-			goto found;
-		}
-	}
+	*bo = mapping->bo_va->base.bo;
+	*map = mapping;
 
-	return -EINVAL;
+	/* Double check that the BO is reserved by this CS */
+	if (READ_ONCE((*bo)->tbo.resv->lock.ctx) != &parser->ticket)
+		return -EINVAL;
 
-found:
 	r = amdgpu_ttm_bind(&(*bo)->tbo, &(*bo)->tbo.mem);
 	if (unlikely(r))
 		return r;
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -0
index 42492e6..a4891be 100644
@@ -35,6 +35,7 @@
 
 /* bo virtual addresses in a vm */
 struct amdgpu_bo_va_mapping {
+	struct amdgpu_bo_va		*bo_va;
 	struct list_head		list;
 	struct rb_node			rb;
 	uint64_t			start;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +17 -0
index cfc8de8..ab9dfd7 100644
@@ -2083,6 +2083,7 @@ static void amdgpu_vm_bo_insert_map(struct amdgpu_device *adev,
 	struct amdgpu_vm *vm = bo_va->base.vm;
 	struct amdgpu_bo *bo = bo_va->base.bo;
 
+	mapping->bo_va = bo_va;
 	list_add(&mapping->list, &bo_va->invalids);
 	amdgpu_vm_it_insert(mapping, &vm->va);
 
@@ -2260,6 +2261,7 @@ int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,
 
 	list_del(&mapping->list);
 	amdgpu_vm_it_remove(mapping, &vm->va);
+	mapping->bo_va = NULL;
 	trace_amdgpu_vm_bo_unmap(bo_va, mapping);
 
 	if (valid)
@@ -2345,6 +2347,7 @@ int amdgpu_vm_bo_clear_mappings(struct amdgpu_device *adev,
 		if (tmp->last > eaddr)
 		    tmp->last = eaddr;
 
+		tmp->bo_va = NULL;
 		list_add(&tmp->list, &vm->freed);
 		trace_amdgpu_vm_bo_unmap(NULL, tmp);
 	}
@@ -2371,6 +2374,19 @@ int amdgpu_vm_bo_clear_mappings(struct amdgpu_device *adev,
 }
 
 /**
+ * amdgpu_vm_bo_lookup_mapping - find mapping by address
+ *
+ * @vm: the requested VM
+ *
+ * Find a mapping by it's address.
+ */
+struct amdgpu_bo_va_mapping *amdgpu_vm_bo_lookup_mapping(struct amdgpu_vm *vm,
+							 uint64_t addr)
+{
+	return amdgpu_vm_it_iter_first(&vm->va, addr, addr);
+}
+
+/**
  * amdgpu_vm_bo_rmv - remove a bo to a specific vm
  *
  * @adev: amdgpu_device pointer
@@ -2395,6 +2411,7 @@ void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
 	list_for_each_entry_safe(mapping, next, &bo_va->valids, list) {
 		list_del(&mapping->list);
 		amdgpu_vm_it_remove(mapping, &vm->va);
+		mapping->bo_va = NULL;
 		trace_amdgpu_vm_bo_unmap(bo_va, mapping);
 		list_add(&mapping->list, &vm->freed);
 	}
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +2 -0
index 90b7741..c1accd1 100644
@@ -276,6 +276,8 @@ int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,
 int amdgpu_vm_bo_clear_mappings(struct amdgpu_device *adev,
 				struct amdgpu_vm *vm,
 				uint64_t saddr, uint64_t size);
+struct amdgpu_bo_va_mapping *amdgpu_vm_bo_lookup_mapping(struct amdgpu_vm *vm,
+							 uint64_t addr);
 void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
 		      struct amdgpu_bo_va *bo_va);
 void amdgpu_vm_set_fragment_size(struct amdgpu_device *adev,
Signature · 6 lines
2.7.4

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

Re: [PATCH 3/3] drm/amdgpu: rework amdgpu_cs_find_mapping

Quoted 5 lines · Christian König

From: Christian König <[email protected]>

Use the VM instead of the BO list to find the BO for a virtual address.

This fixes UVD/VCE in physical mode with VM local BOs.

The series is

Quoted 143 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c     | 42 +++++++-----------------------
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c     | 17 ++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h     |  2 ++
  4 files changed, 30 insertions(+), 32 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +10 -32
index bcb3548..132e17a 100644
@@ -1374,46 +1374,24 @@ int amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
  			   uint64_t addr, struct amdgpu_bo **bo,
  			   struct amdgpu_bo_va_mapping **map)
  {
+	struct amdgpu_fpriv *fpriv = parser->filp->driver_priv;
+	struct amdgpu_vm *vm = &fpriv->vm;
  	struct amdgpu_bo_va_mapping *mapping;
-	unsigned i;
  	int r;
 
-	if (!parser->bo_list)
-		return 0;
-
  	addr /= AMDGPU_GPU_PAGE_SIZE;
 
-	for (i = 0; i < parser->bo_list->num_entries; i++) {
-		struct amdgpu_bo_list_entry *lobj;
-
-		lobj = &parser->bo_list->array[i];
-		if (!lobj->bo_va)
-			continue;
-
-		list_for_each_entry(mapping, &lobj->bo_va->valids, list) {
-			if (mapping->start > addr ||
-			    addr > mapping->last)
-				continue;
-
-			*bo = lobj->bo_va->base.bo;
-			*map = mapping;
-			goto found;
-		}
-
-		list_for_each_entry(mapping, &lobj->bo_va->invalids, list) {
-			if (mapping->start > addr ||
-			    addr > mapping->last)
-				continue;
+	mapping = amdgpu_vm_bo_lookup_mapping(vm, addr);
+	if (!mapping || !mapping->bo_va || !mapping->bo_va->base.bo)
+		return -EINVAL;
 
-			*bo = lobj->bo_va->base.bo;
-			*map = mapping;
-			goto found;
-		}
-	}
+	*bo = mapping->bo_va->base.bo;
+	*map = mapping;
 
-	return -EINVAL;
+	/* Double check that the BO is reserved by this CS */
+	if (READ_ONCE((*bo)->tbo.resv->lock.ctx) != &parser->ticket)
+		return -EINVAL;
 
-found:
  	r = amdgpu_ttm_bind(&(*bo)->tbo, &(*bo)->tbo.mem);
  	if (unlikely(r))
  		return r;
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -0
index 42492e6..a4891be 100644
@@ -35,6 +35,7 @@
 
  /* bo virtual addresses in a vm */
  struct amdgpu_bo_va_mapping {
+	struct amdgpu_bo_va		*bo_va;
  	struct list_head		list;
  	struct rb_node			rb;
  	uint64_t			start;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +17 -0
index cfc8de8..ab9dfd7 100644
@@ -2083,6 +2083,7 @@ static void amdgpu_vm_bo_insert_map(struct amdgpu_device *adev,
  	struct amdgpu_vm *vm = bo_va->base.vm;
  	struct amdgpu_bo *bo = bo_va->base.bo;
 
+	mapping->bo_va = bo_va;
  	list_add(&mapping->list, &bo_va->invalids);
  	amdgpu_vm_it_insert(mapping, &vm->va);
 
@@ -2260,6 +2261,7 @@ int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,
 
  	list_del(&mapping->list);
  	amdgpu_vm_it_remove(mapping, &vm->va);
+	mapping->bo_va = NULL;
  	trace_amdgpu_vm_bo_unmap(bo_va, mapping);
 
  	if (valid)
@@ -2345,6 +2347,7 @@ int amdgpu_vm_bo_clear_mappings(struct amdgpu_device *adev,
  		if (tmp->last > eaddr)
  		    tmp->last = eaddr;
 
+		tmp->bo_va = NULL;
  		list_add(&tmp->list, &vm->freed);
  		trace_amdgpu_vm_bo_unmap(NULL, tmp);
  	}
@@ -2371,6 +2374,19 @@ int amdgpu_vm_bo_clear_mappings(struct amdgpu_device *adev,
  }
 
  /**
+ * amdgpu_vm_bo_lookup_mapping - find mapping by address
+ *
+ * @vm: the requested VM
+ *
+ * Find a mapping by it's address.
+ */
+struct amdgpu_bo_va_mapping *amdgpu_vm_bo_lookup_mapping(struct amdgpu_vm *vm,
+							 uint64_t addr)
+{
+	return amdgpu_vm_it_iter_first(&vm->va, addr, addr);
+}
+
+/**
   * amdgpu_vm_bo_rmv - remove a bo to a specific vm
   *
   * @adev: amdgpu_device pointer
@@ -2395,6 +2411,7 @@ void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
  	list_for_each_entry_safe(mapping, next, &bo_va->valids, list) {
  		list_del(&mapping->list);
  		amdgpu_vm_it_remove(mapping, &vm->va);
+		mapping->bo_va = NULL;
  		trace_amdgpu_vm_bo_unmap(bo_va, mapping);
  		list_add(&mapping->list, &vm->freed);
  	}
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0 -0
index 90b7741..c1accd1 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h int amdgpu_vm_bo_unmap(struct amdgpu_device *adev, · line 283

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +2 -0
@@ -276,6 +276,8 @@ int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,
  int amdgpu_vm_bo_clear_mappings(struct amdgpu_device *adev,
  				struct amdgpu_vm *vm,
  				uint64_t saddr, uint64_t size);
+struct amdgpu_bo_va_mapping *amdgpu_vm_bo_lookup_mapping(struct amdgpu_vm *vm,
+							 uint64_t addr);
  void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
  		      struct amdgpu_bo_va *bo_va);
  void amdgpu_vm_set_fragment_size(struct amdgpu_device *adev,

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

A message that is not in the archive (sent off-list or not yet received): d12e5300-f31f-3ce7-fa52-71593234dc58-5C7GfCeVMHo@public.gmane.org

#6 lore raw

Re: [PATCH 3/3] drm/amdgpu: rework amdgpu_cs_find_mapping

Am 06.09.2017 um 18:33 schrieb Leo Liu:

Quoted 11 lines · Christian König
Quoted 5 lines

From: Christian König <[email protected]>

Use the VM instead of the BO list to find the BO for a virtual address.

This fixes UVD/VCE in physical mode with VM local BOs.

The series is

Can I get an rb or ab as well? Alex is on vacation and I would really like to push this patch.

Christian.

Quoted 140 lines
Quoted 140 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c     | 42 
+++++++-----------------------
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c     | 17 ++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h     |  2 ++
  4 files changed, 30 insertions(+), 32 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +10 -27
index bcb3548..132e17a 100644
@@ -1374,46 +1374,24 @@ int amdgpu_cs_find_mapping(struct 
 amdgpu_cs_parser *parser,
                 uint64_t addr, struct amdgpu_bo **bo,
                 struct amdgpu_bo_va_mapping **map)
  {
+    struct amdgpu_fpriv *fpriv = parser->filp->driver_priv;
+    struct amdgpu_vm *vm = &fpriv->vm;
      struct amdgpu_bo_va_mapping *mapping;
-    unsigned i;
      int r;
  -    if (!parser->bo_list)
-        return 0;
-
      addr /= AMDGPU_GPU_PAGE_SIZE;
  -    for (i = 0; i < parser->bo_list->num_entries; i++) {
-        struct amdgpu_bo_list_entry *lobj;
-
-        lobj = &parser->bo_list->array[i];
-        if (!lobj->bo_va)
-            continue;
-
-        list_for_each_entry(mapping, &lobj->bo_va->valids, list) {
-            if (mapping->start > addr ||
-                addr > mapping->last)
-                continue;
-
-            *bo = lobj->bo_va->base.bo;
-            *map = mapping;
-            goto found;
-        }
-
-        list_for_each_entry(mapping, &lobj->bo_va->invalids, list) {
-            if (mapping->start > addr ||
-                addr > mapping->last)
-                continue;
+    mapping = amdgpu_vm_bo_lookup_mapping(vm, addr);
+    if (!mapping || !mapping->bo_va || !mapping->bo_va->base.bo)
+        return -EINVAL;
  -            *bo = lobj->bo_va->base.bo;
-            *map = mapping;
-            goto found;
-        }
-    }
+    *bo = mapping->bo_va->base.bo;
+    *map = mapping;
  -    return -EINVAL;
+    /* Double check that the BO is reserved by this CS */
+    if (READ_ONCE((*bo)->tbo.resv->lock.ctx) != &parser->ticket)
+        return -EINVAL;
  -found:
      r = amdgpu_ttm_bind(&(*bo)->tbo, &(*bo)->tbo.mem);
      if (unlikely(r))
          return r;
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -0
index 42492e6..a4891be 100644
@@ -35,6 +35,7 @@
    /* bo virtual addresses in a vm */
  struct amdgpu_bo_va_mapping {
+    struct amdgpu_bo_va        *bo_va;
      struct list_head        list;
      struct rb_node            rb;
      uint64_t            start;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
index cfc8de8..ab9dfd7 100644
@@ -2083,6 +2083,7 @@ static void amdgpu_vm_bo_insert_map(struct 
 amdgpu_device *adev,
      struct amdgpu_vm *vm = bo_va->base.vm;
      struct amdgpu_bo *bo = bo_va->base.bo;
  +    mapping->bo_va = bo_va;
      list_add(&mapping->list, &bo_va->invalids);
      amdgpu_vm_it_insert(mapping, &vm->va);
  @@ -2260,6 +2261,7 @@ int amdgpu_vm_bo_unmap(struct amdgpu_device 

*adev,

        list_del(&mapping->list);
      amdgpu_vm_it_remove(mapping, &vm->va);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +14 -0
+    mapping->bo_va = NULL;
      trace_amdgpu_vm_bo_unmap(bo_va, mapping);
        if (valid)
@@ -2345,6 +2347,7 @@ int amdgpu_vm_bo_clear_mappings(struct 
 amdgpu_device *adev,
          if (tmp->last > eaddr)
              tmp->last = eaddr;
  +        tmp->bo_va = NULL;
          list_add(&tmp->list, &vm->freed);
          trace_amdgpu_vm_bo_unmap(NULL, tmp);
      }
@@ -2371,6 +2374,19 @@ int amdgpu_vm_bo_clear_mappings(struct 
 amdgpu_device *adev,
  }
    /**
+ * amdgpu_vm_bo_lookup_mapping - find mapping by address
+ *
+ * @vm: the requested VM
+ *
+ * Find a mapping by it's address.
+ */
+struct amdgpu_bo_va_mapping *amdgpu_vm_bo_lookup_mapping(struct 
 amdgpu_vm *vm,
+                             uint64_t addr)
+{
+    return amdgpu_vm_it_iter_first(&vm->va, addr, addr);
+}
+
+/**
   * amdgpu_vm_bo_rmv - remove a bo to a specific vm
   *

* @adev: amdgpu_device pointer

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -0
@@ -2395,6 +2411,7 @@ void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
      list_for_each_entry_safe(mapping, next, &bo_va->valids, list) {
          list_del(&mapping->list);
          amdgpu_vm_it_remove(mapping, &vm->va);
+        mapping->bo_va = NULL;
          trace_amdgpu_vm_bo_unmap(bo_va, mapping);
          list_add(&mapping->list, &vm->freed);
      }
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0 -0
index 90b7741..c1accd1 100644
@@ -276,6 +276,8 @@ int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,
  int amdgpu_vm_bo_clear_mappings(struct amdgpu_device *adev,
Quoted 9 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +2 -0
                  struct amdgpu_vm *vm,
                  uint64_t saddr, uint64_t size);
+struct amdgpu_bo_va_mapping *amdgpu_vm_bo_lookup_mapping(struct 
 amdgpu_vm *vm,
+                             uint64_t addr);
  void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
                struct amdgpu_bo_va *bo_va);

void amdgpu_vm_set_fragment_size(struct amdgpu_device *adev,

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

Acked-by
#7 lore raw

Re: [PATCH 3/3] drm/amdgpu: rework amdgpu_cs_find_mapping

Quoted 6 lines · Christian König

Am 06.09.2017 um 18:33 schrieb Leo Liu:

Quoted 5 lines · Christian König
Quoted 2 lines

From: Christian König <[email protected]>

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Use the VM instead of the BO list to find the BO for a virtual address.

This fixes UVD/VCE in physical mode with VM local BOs.

The series is

Can I get an rb or ab as well? Alex is on vacation and I would really like to push this patch.

Since we need to fix the legacy UVD/VCE issue ASAP, The series is

Quoted 153 lines

Christian.

Quoted 149 lines
Quoted 148 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c     | 42 
+++++++-----------------------
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c     | 17 ++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h     |  2 ++
  4 files changed, 30 insertions(+), 32 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +10 -27
index bcb3548..132e17a 100644
@@ -1374,46 +1374,24 @@ int amdgpu_cs_find_mapping(struct 
 amdgpu_cs_parser *parser,
                 uint64_t addr, struct amdgpu_bo **bo,
                 struct amdgpu_bo_va_mapping **map)
  {
+    struct amdgpu_fpriv *fpriv = parser->filp->driver_priv;
+    struct amdgpu_vm *vm = &fpriv->vm;
      struct amdgpu_bo_va_mapping *mapping;
-    unsigned i;
      int r;
  -    if (!parser->bo_list)
-        return 0;
-
      addr /= AMDGPU_GPU_PAGE_SIZE;
  -    for (i = 0; i < parser->bo_list->num_entries; i++) {
-        struct amdgpu_bo_list_entry *lobj;
-
-        lobj = &parser->bo_list->array[i];
-        if (!lobj->bo_va)
-            continue;
-
-        list_for_each_entry(mapping, &lobj->bo_va->valids, list) {
-            if (mapping->start > addr ||
-                addr > mapping->last)
-                continue;
-
-            *bo = lobj->bo_va->base.bo;
-            *map = mapping;
-            goto found;
-        }
-
-        list_for_each_entry(mapping, &lobj->bo_va->invalids, list) {
-            if (mapping->start > addr ||
-                addr > mapping->last)
-                continue;
+    mapping = amdgpu_vm_bo_lookup_mapping(vm, addr);
+    if (!mapping || !mapping->bo_va || !mapping->bo_va->base.bo)
+        return -EINVAL;
  -            *bo = lobj->bo_va->base.bo;
-            *map = mapping;
-            goto found;
-        }
-    }
+    *bo = mapping->bo_va->base.bo;
+    *map = mapping;
  -    return -EINVAL;
+    /* Double check that the BO is reserved by this CS */
+    if (READ_ONCE((*bo)->tbo.resv->lock.ctx) != &parser->ticket)
+        return -EINVAL;
  -found:
      r = amdgpu_ttm_bind(&(*bo)->tbo, &(*bo)->tbo.mem);
      if (unlikely(r))
          return r;
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -0
index 42492e6..a4891be 100644
@@ -35,6 +35,7 @@
    /* bo virtual addresses in a vm */
  struct amdgpu_bo_va_mapping {
+    struct amdgpu_bo_va        *bo_va;
      struct list_head        list;
      struct rb_node            rb;
      uint64_t            start;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
index cfc8de8..ab9dfd7 100644
@@ -2083,6 +2083,7 @@ static void amdgpu_vm_bo_insert_map(struct 
 amdgpu_device *adev,
      struct amdgpu_vm *vm = bo_va->base.vm;
      struct amdgpu_bo *bo = bo_va->base.bo;
  +    mapping->bo_va = bo_va;
      list_add(&mapping->list, &bo_va->invalids);
      amdgpu_vm_it_insert(mapping, &vm->va);
  @@ -2260,6 +2261,7 @@ int amdgpu_vm_bo_unmap(struct amdgpu_device 

*adev,

        list_del(&mapping->list);
      amdgpu_vm_it_remove(mapping, &vm->va);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +14 -0
+    mapping->bo_va = NULL;
      trace_amdgpu_vm_bo_unmap(bo_va, mapping);
        if (valid)
@@ -2345,6 +2347,7 @@ int amdgpu_vm_bo_clear_mappings(struct 
 amdgpu_device *adev,
          if (tmp->last > eaddr)
              tmp->last = eaddr;
  +        tmp->bo_va = NULL;
          list_add(&tmp->list, &vm->freed);
          trace_amdgpu_vm_bo_unmap(NULL, tmp);
      }
@@ -2371,6 +2374,19 @@ int amdgpu_vm_bo_clear_mappings(struct 
 amdgpu_device *adev,
  }
    /**
+ * amdgpu_vm_bo_lookup_mapping - find mapping by address
+ *
+ * @vm: the requested VM
+ *
+ * Find a mapping by it's address.
+ */
+struct amdgpu_bo_va_mapping *amdgpu_vm_bo_lookup_mapping(struct 
 amdgpu_vm *vm,
+                             uint64_t addr)
+{
+    return amdgpu_vm_it_iter_first(&vm->va, addr, addr);
+}
+
+/**
   * amdgpu_vm_bo_rmv - remove a bo to a specific vm
   *

* @adev: amdgpu_device pointer

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -0
@@ -2395,6 +2411,7 @@ void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
      list_for_each_entry_safe(mapping, next, &bo_va->valids, list) {
          list_del(&mapping->list);
          amdgpu_vm_it_remove(mapping, &vm->va);
+        mapping->bo_va = NULL;
          trace_amdgpu_vm_bo_unmap(bo_va, mapping);
          list_add(&mapping->list, &vm->freed);
      }
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +2 -0
index 90b7741..c1accd1 100644
@@ -276,6 +276,8 @@ int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,
  int amdgpu_vm_bo_clear_mappings(struct amdgpu_device *adev,
                  struct amdgpu_vm *vm,
                  uint64_t saddr, uint64_t size);
+struct amdgpu_bo_va_mapping *amdgpu_vm_bo_lookup_mapping(struct 
 amdgpu_vm *vm,
+                             uint64_t addr);
  void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
                struct amdgpu_bo_va *bo_va);

void amdgpu_vm_set_fragment_size(struct amdgpu_device *adev,

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