[34/39] single-vma-list

Submitted by Chris Wilson on Dec. 7, 2018, 9:27 a.m.

Details

Message ID 20181207092735.10509-34-chris@chris-wilson.co.uk
State New
Series "Series without cover letter"
Headers show

Commit Message

Chris Wilson Dec. 7, 2018, 9:27 a.m.
---
 drivers/gpu/drm/i915/i915_gem.c               |  4 +--
 drivers/gpu/drm/i915/i915_gem_evict.c         | 12 ++++++---
 drivers/gpu/drm/i915/i915_gem_gtt.c           | 27 ++++++-------------
 drivers/gpu/drm/i915/i915_gem_gtt.h           | 10 +------
 drivers/gpu/drm/i915/i915_gem_shrinker.c      |  3 +--
 drivers/gpu/drm/i915/i915_gem_stolen.c        |  4 ---
 drivers/gpu/drm/i915/i915_gpu_error.c         | 11 ++++----
 drivers/gpu/drm/i915/i915_vma.c               |  7 +----
 .../gpu/drm/i915/selftests/i915_gem_evict.c   | 11 +++-----
 drivers/gpu/drm/i915/selftests/i915_gem_gtt.c |  4 ---
 10 files changed, 32 insertions(+), 61 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 3ff5ebce4cb7..43d5d7dfba30 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -254,7 +254,7 @@  i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
 	mutex_lock(&ggtt->vm.mutex);
 
 	pinned = ggtt->vm.reserved;
-	list_for_each_entry(vma, &ggtt->vm.bound_list, vm_link)
+	list_for_each_entry(vma, &ggtt->vm.vma_list, vm_link)
 		if (i915_vma_is_pinned(vma))
 			pinned += vma->node.size;
 
@@ -1692,7 +1692,7 @@  static void i915_gem_object_bump_inactive_ggtt(struct drm_i915_gem_object *obj)
 		if (!drm_mm_node_allocated(&vma->node))
 			continue;
 
-		list_move_tail(&vma->vm_link, &vma->vm->bound_list);
+		list_move_tail(&vma->vm_link, &i915->ggtt.vm.vma_list);
 	}
 	mutex_unlock(&i915->ggtt.vm.mutex);
 
diff --git a/drivers/gpu/drm/i915/i915_gem_evict.c b/drivers/gpu/drm/i915/i915_gem_evict.c
index b7c2a396a63f..8ccde5761c2c 100644
--- a/drivers/gpu/drm/i915/i915_gem_evict.c
+++ b/drivers/gpu/drm/i915/i915_gem_evict.c
@@ -170,7 +170,10 @@  i915_gem_evict_something(struct i915_address_space *vm,
 search_again:
 	active = NULL;
 	INIT_LIST_HEAD(&eviction_list);
-	list_for_each_entry_safe(vma, next, &vm->bound_list, vm_link) {
+	list_for_each_entry_safe(vma, next, &vm->vma_list, vm_link) {
+		if (!drm_mm_node_allocated(&vma->node))
+			continue;
+
 		if (i915_vma_is_active(vma)) {
 			if (vma == active) {
 				if (flags & PIN_NONBLOCK)
@@ -183,7 +186,7 @@  i915_gem_evict_something(struct i915_address_space *vm,
 				if (!active)
 					active = vma;
 
-				list_move_tail(&vma->vm_link, &vm->bound_list);
+				list_move_tail(&vma->vm_link, &vm->vma_list);
 				continue;
 			}
 		}
@@ -419,7 +422,10 @@  int i915_gem_evict_vm(struct i915_address_space *vm)
 
 	INIT_LIST_HEAD(&eviction_list);
 	mutex_lock(&vm->mutex);
-	list_for_each_entry(vma, &vm->bound_list, vm_link) {
+	list_for_each_entry(vma, &vm->vma_list, vm_link) {
+		if (!drm_mm_node_allocated(&vma->node))
+			continue;
+
 		if (i915_vma_is_pinned(vma))
 			continue;
 
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index 06a32ebbb50d..59afea3fc19c 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -492,8 +492,7 @@  static void i915_address_space_init(struct i915_address_space *vm, int subclass)
 
 	stash_init(&vm->free_pages);
 
-	INIT_LIST_HEAD(&vm->unbound_list);
-	INIT_LIST_HEAD(&vm->bound_list);
+	INIT_LIST_HEAD(&vm->vma_list);
 }
 
 static void i915_address_space_fini(struct i915_address_space *vm)
@@ -1934,7 +1933,7 @@  static struct i915_vma *pd_vma_create(struct gen6_hw_ppgtt *ppgtt, int size)
 	INIT_LIST_HEAD(&vma->obj_link);
 
 	mutex_lock(&vma->vm->mutex);
-	list_add(&vma->vm_link, &vma->vm->unbound_list);
+	list_add(&vma->vm_link, &vma->vm->vma_list);
 	mutex_unlock(&vma->vm->mutex);
 
 	return vma;
@@ -2104,19 +2103,12 @@  void i915_ppgtt_close(struct i915_address_space *vm)
 
 static void ppgtt_destroy_vma(struct i915_address_space *vm)
 {
-	struct list_head *phases[] = {
-		&vm->bound_list,
-		&vm->unbound_list,
-		NULL,
-	}, **phase;
+	struct i915_vma *vma, *vn;
 
 	vm->closed = true;
-	for (phase = phases; *phase; phase++) {
-		struct i915_vma *vma, *vn;
-
-		list_for_each_entry_safe(vma, vn, *phase, vm_link)
-			i915_vma_destroy(vma);
-	}
+	list_for_each_entry_safe(vma, vn, &vm->vma_list, vm_link)
+		i915_vma_destroy(vma);
+	GEM_BUG_ON(!list_empty(&vm->vma_list));
 }
 
 void i915_ppgtt_release(struct kref *kref)
@@ -2128,9 +2120,6 @@  void i915_ppgtt_release(struct kref *kref)
 
 	ppgtt_destroy_vma(&ppgtt->vm);
 
-	GEM_BUG_ON(!list_empty(&ppgtt->vm.bound_list));
-	GEM_BUG_ON(!list_empty(&ppgtt->vm.unbound_list));
-
 	ppgtt->vm.cleanup(&ppgtt->vm);
 	i915_address_space_fini(&ppgtt->vm);
 	kfree(ppgtt);
@@ -2793,7 +2782,7 @@  void i915_ggtt_cleanup_hw(struct drm_i915_private *dev_priv)
 	mutex_lock(&dev_priv->drm.struct_mutex);
 	i915_gem_fini_aliasing_ppgtt(dev_priv);
 
-	list_for_each_entry_safe(vma, vn, &ggtt->vm.bound_list, vm_link)
+	list_for_each_entry_safe(vma, vn, &ggtt->vm.vma_list, vm_link)
 		WARN_ON(i915_vma_unbind(vma));
 
 	if (drm_mm_node_allocated(&ggtt->error_capture))
@@ -3505,7 +3494,7 @@  void i915_gem_restore_gtt_mappings(struct drm_i915_private *dev_priv)
 	ggtt->vm.closed = true; /* skip rewriting PTE on VMA unbind */
 
 	/* clflush objects bound into the GGTT and rebind them. */
-	list_for_each_entry_safe(vma, vn, &ggtt->vm.bound_list, vm_link) {
+	list_for_each_entry_safe(vma, vn, &ggtt->vm.vma_list, vm_link) {
 		struct drm_i915_gem_object *obj = vma->obj;
 
 		if (!(vma->flags & I915_VMA_GLOBAL_BIND))
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.h b/drivers/gpu/drm/i915/i915_gem_gtt.h
index bd679c8c56dd..ac11f2bce2d5 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.h
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.h
@@ -298,15 +298,7 @@  struct i915_address_space {
 	struct i915_page_directory *scratch_pd;
 	struct i915_page_directory_pointer *scratch_pdp; /* GEN8+ & 48b PPGTT */
 
-	/**
-	 * List of vma currently bound.
-	 */
-	struct list_head bound_list;
-
-	/**
-	 * List of vma that are not unbound.
-	 */
-	struct list_head unbound_list;
+	struct list_head vma_list;
 
 	struct pagestash free_pages;
 
diff --git a/drivers/gpu/drm/i915/i915_gem_shrinker.c b/drivers/gpu/drm/i915/i915_gem_shrinker.c
index 9d04c26c04f9..f4bc72d4f44f 100644
--- a/drivers/gpu/drm/i915/i915_gem_shrinker.c
+++ b/drivers/gpu/drm/i915/i915_gem_shrinker.c
@@ -491,8 +491,7 @@  i915_gem_shrinker_vmap(struct notifier_block *nb, unsigned long event, void *ptr
 
 	/* We also want to clear any cached iomaps as they wrap vmap */
 	mutex_lock(&i915->ggtt.vm.mutex);
-	list_for_each_entry_safe(vma, next,
-				 &i915->ggtt.vm.bound_list, vm_link) {
+	list_for_each_entry_safe(vma, next, &i915->ggtt.vm.vma_list, vm_link) {
 		unsigned long count = vma->node.size >> PAGE_SHIFT;
 
 		if (!vma->iomap || i915_vma_is_active(vma))
diff --git a/drivers/gpu/drm/i915/i915_gem_stolen.c b/drivers/gpu/drm/i915/i915_gem_stolen.c
index 8a2bb44c284c..4564fc5246c3 100644
--- a/drivers/gpu/drm/i915/i915_gem_stolen.c
+++ b/drivers/gpu/drm/i915/i915_gem_stolen.c
@@ -702,10 +702,6 @@  i915_gem_object_create_stolen_for_preallocated(struct drm_i915_private *dev_priv
 	vma->flags |= I915_VMA_GLOBAL_BIND;
 	__i915_vma_set_map_and_fenceable(vma);
 
-	mutex_lock(&ggtt->vm.mutex);
-	list_move_tail(&vma->vm_link, &ggtt->vm.bound_list);
-	mutex_unlock(&ggtt->vm.mutex);
-
 	spin_lock(&dev_priv->mm.obj_lock);
 	list_move_tail(&obj->mm.link, &dev_priv->mm.bound_list);
 	obj->bind_count++;
diff --git a/drivers/gpu/drm/i915/i915_gpu_error.c b/drivers/gpu/drm/i915/i915_gpu_error.c
index a5a07a92416b..454d17d0aa7f 100644
--- a/drivers/gpu/drm/i915/i915_gpu_error.c
+++ b/drivers/gpu/drm/i915/i915_gpu_error.c
@@ -1616,7 +1616,7 @@  static void gem_capture_vm(struct i915_gpu_state *error,
 	int count;
 
 	count = 0;
-	list_for_each_entry(vma, &vm->bound_list, vm_link)
+	list_for_each_entry(vma, &vm->vma_list, vm_link)
 		if (i915_vma_is_active(vma))
 			count++;
 
@@ -1624,7 +1624,7 @@  static void gem_capture_vm(struct i915_gpu_state *error,
 	if (count)
 		active_bo = kcalloc(count, sizeof(*active_bo), GFP_ATOMIC);
 	if (active_bo)
-		count = capture_error_bo(active_bo, count, &vm->bound_list,
+		count = capture_error_bo(active_bo, count, &vm->vma_list,
 					 true, false);
 	else
 		count = 0;
@@ -1666,8 +1666,9 @@  static void capture_pinned_buffers(struct i915_gpu_state *error)
 	int count;
 
 	count = 0;
-	list_for_each_entry(vma, &vm->bound_list, vm_link)
-		count++;
+	list_for_each_entry(vma, &vm->vma_list, vm_link)
+		if (i915_vma_is_pinned(vma))
+			count++;
 
 	bo = NULL;
 	if (count)
@@ -1676,7 +1677,7 @@  static void capture_pinned_buffers(struct i915_gpu_state *error)
 		return;
 
 	error->pinned_bo_count =
-		capture_error_bo(bo, count, &vm->bound_list, false, true);
+		capture_error_bo(bo, count, &vm->vma_list, false, true);
 	error->pinned_bo = bo;
 }
 
diff --git a/drivers/gpu/drm/i915/i915_vma.c b/drivers/gpu/drm/i915/i915_vma.c
index dcbd0d345c72..ad76a3309830 100644
--- a/drivers/gpu/drm/i915/i915_vma.c
+++ b/drivers/gpu/drm/i915/i915_vma.c
@@ -215,7 +215,7 @@  vma_create(struct drm_i915_gem_object *obj,
 	rb_insert_color(&vma->obj_node, &obj->vma_tree);
 
 	mutex_lock(&vm->mutex);
-	list_add(&vma->vm_link, &vm->unbound_list);
+	list_add_tail(&vma->vm_link, &vm->vma_list);
 	mutex_unlock(&vm->mutex);
 
 	return vma;
@@ -659,10 +659,6 @@  i915_vma_insert(struct i915_vma *vma, u64 size, u64 alignment, u64 flags)
 	GEM_BUG_ON(!drm_mm_node_allocated(&vma->node));
 	GEM_BUG_ON(!i915_gem_valid_gtt_space(vma, cache_level));
 
-	mutex_lock(&vma->vm->mutex);
-	list_move_tail(&vma->vm_link, &vma->vm->bound_list);
-	mutex_unlock(&vma->vm->mutex);
-
 	if (vma->obj) {
 		struct drm_i915_gem_object *obj = vma->obj;
 
@@ -696,7 +692,6 @@  i915_vma_remove(struct i915_vma *vma)
 
 	mutex_lock(&vma->vm->mutex);
 	drm_mm_remove_node(&vma->node);
-	list_move_tail(&vma->vm_link, &vma->vm->unbound_list);
 	mutex_unlock(&vma->vm->mutex);
 
 	/*
diff --git a/drivers/gpu/drm/i915/selftests/i915_gem_evict.c b/drivers/gpu/drm/i915/selftests/i915_gem_evict.c
index eaefba7470f7..8750cfbf1486 100644
--- a/drivers/gpu/drm/i915/selftests/i915_gem_evict.c
+++ b/drivers/gpu/drm/i915/selftests/i915_gem_evict.c
@@ -57,11 +57,6 @@  static int populate_ggtt(struct drm_i915_private *i915)
 		return -EINVAL;
 	}
 
-	if (list_empty(&i915->ggtt.vm.bound_list)) {
-		pr_err("No objects on the GGTT inactive list!\n");
-		return -EINVAL;
-	}
-
 	return 0;
 }
 
@@ -71,8 +66,10 @@  static void unpin_ggtt(struct drm_i915_private *i915)
 	struct i915_vma *vma;
 
 	mutex_lock(&ggtt->vm.mutex);
-	list_for_each_entry(vma, &i915->ggtt.vm.bound_list, vm_link)
-		i915_vma_unpin(vma);
+	list_for_each_entry(vma, &i915->ggtt.vm.vma_list, vm_link) {
+		if (i915_vma_is_pinned(vma))
+			i915_vma_unpin(vma);
+	}
 	mutex_unlock(&ggtt->vm.mutex);
 }
 
diff --git a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
index 850f9eff6029..550cb72f1e2b 100644
--- a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
@@ -1237,10 +1237,6 @@  static void track_vma_bind(struct i915_vma *vma)
 	__i915_gem_object_pin_pages(obj);
 
 	vma->pages = obj->mm.pages;
-
-	mutex_lock(&vma->vm->mutex);
-	list_move_tail(&vma->vm_link, &vma->vm->bound_list);
-	mutex_unlock(&vma->vm->mutex);
 }
 
 static int exercise_mock(struct drm_i915_private *i915,