[PATCH 8/9] drm/i915: Move vm locking to i915_gem_evict_vm

Maarten Lankhorst maarten.lankhorst at linux.intel.com
Thu Jan 6 10:13:40 UTC 2022


There's no reason for callers to lock the vm, this function can do
it, as none of the callers require the lock. This will allow us
to drop the lock inside that function when locking for eviction.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst at linux.intel.com>
---
 drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c  |  6 +-----
 drivers/gpu/drm/i915/gem/i915_gem_mman.c        |  7 ++-----
 drivers/gpu/drm/i915/i915_gem_evict.c           | 11 ++++++++---
 drivers/gpu/drm/i915/i915_vma.c                 | 10 +---------
 drivers/gpu/drm/i915/selftests/i915_gem_evict.c |  4 ----
 5 files changed, 12 insertions(+), 26 deletions(-)

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
index ea157905b452..aeb3c8f518e1 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
@@ -760,11 +760,7 @@ static int eb_reserve(struct i915_execbuffer *eb)
 			unpinned = eb_unbind(eb, pass == 2);
 
 		if (pass == 2) {
-			err = mutex_lock_interruptible(&eb->context->vm->mutex);
-			if (!err) {
-				err = i915_gem_evict_vm(eb->context->vm, &eb->ww);
-				mutex_unlock(&eb->context->vm->mutex);
-			}
+			err = i915_gem_evict_vm(eb->context->vm, &eb->ww);
 			if (err)
 				return err;
 		}
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_mman.c b/drivers/gpu/drm/i915/gem/i915_gem_mman.c
index 8c120fd815ad..0366821652b7 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_mman.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_mman.c
@@ -364,13 +364,10 @@ static vm_fault_t vm_fault_gtt(struct vm_fault *vmf)
 		 * due to lack of short term pinning inside execbuf.
 		 */
 		if (vma == ERR_PTR(-ENOSPC)) {
-			ret = mutex_lock_interruptible(&ggtt->vm.mutex);
-			if (!ret) {
-				ret = i915_gem_evict_vm(&ggtt->vm, &ww);
-				mutex_unlock(&ggtt->vm.mutex);
-			}
+			ret = i915_gem_evict_vm(&ggtt->vm, &ww);
 			if (ret)
 				goto err_reset;
+
 			vma = i915_gem_object_ggtt_pin_ww(obj, &ww, &view, 0, 0, flags);
 		}
 		GEM_WARN_ON(vma == ERR_PTR(-ENOSPC));
diff --git a/drivers/gpu/drm/i915/i915_gem_evict.c b/drivers/gpu/drm/i915/i915_gem_evict.c
index f502a617b35c..68a83ee01c7a 100644
--- a/drivers/gpu/drm/i915/i915_gem_evict.c
+++ b/drivers/gpu/drm/i915/i915_gem_evict.c
@@ -391,9 +391,12 @@ int i915_gem_evict_for_node(struct i915_address_space *vm,
  */
 int i915_gem_evict_vm(struct i915_address_space *vm, struct i915_gem_ww_ctx *ww)
 {
-	int ret = 0;
+	int ret;
+
+	ret = mutex_lock_interruptible(&vm->mutex);
+	if (ret)
+		return ret;
 
-	lockdep_assert_held(&vm->mutex);
 	trace_i915_gem_evict_vm(vm);
 
 	/* Switch back to the default context in order to unpin
@@ -404,7 +407,7 @@ int i915_gem_evict_vm(struct i915_address_space *vm, struct i915_gem_ww_ctx *ww)
 	if (i915_is_ggtt(vm)) {
 		ret = ggtt_flush(vm->gt);
 		if (ret)
-			return ret;
+			goto out;
 	}
 
 	do {
@@ -457,6 +460,8 @@ int i915_gem_evict_vm(struct i915_address_space *vm, struct i915_gem_ww_ctx *ww)
 		}
 	} while (ret == 0);
 
+out:
+	mutex_unlock(&vm->mutex);
 	return ret;
 }
 
diff --git a/drivers/gpu/drm/i915/i915_vma.c b/drivers/gpu/drm/i915/i915_vma.c
index 5f43100638b5..85a22288d024 100644
--- a/drivers/gpu/drm/i915/i915_vma.c
+++ b/drivers/gpu/drm/i915/i915_vma.c
@@ -1436,15 +1436,7 @@ static int __i915_ggtt_pin(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,
 
 		/* Unlike i915_vma_pin, we don't take no for an answer! */
 		flush_idle_contexts(vm->gt);
-		if (mutex_lock_interruptible(&vm->mutex) == 0) {
-			/*
-			 * We pass NULL ww here, as we don't want to unbind
-			 * locked objects when called from execbuf when pinning
-			 * is removed. This would probably regress badly.
-			 */
-			i915_gem_evict_vm(vm, NULL);
-			mutex_unlock(&vm->mutex);
-		}
+		i915_gem_evict_vm(vm, NULL);
 	} while (1);
 }
 
diff --git a/drivers/gpu/drm/i915/selftests/i915_gem_evict.c b/drivers/gpu/drm/i915/selftests/i915_gem_evict.c
index 15b4e5631070..a387d9ce3ece 100644
--- a/drivers/gpu/drm/i915/selftests/i915_gem_evict.c
+++ b/drivers/gpu/drm/i915/selftests/i915_gem_evict.c
@@ -343,9 +343,7 @@ static int igt_evict_vm(void *arg)
 		goto cleanup;
 
 	/* Everything is pinned, nothing should happen */
-	mutex_lock(&ggtt->vm.mutex);
 	err = i915_gem_evict_vm(&ggtt->vm, NULL);
-	mutex_unlock(&ggtt->vm.mutex);
 	if (err) {
 		pr_err("i915_gem_evict_vm on a full GGTT returned err=%d]\n",
 		       err);
@@ -355,9 +353,7 @@ static int igt_evict_vm(void *arg)
 	unpin_ggtt(ggtt);
 
 	i915_gem_ww_ctx_init(&ww, false);
-	mutex_lock(&ggtt->vm.mutex);
 	err = i915_gem_evict_vm(&ggtt->vm, &ww);
-	mutex_unlock(&ggtt->vm.mutex);
 
 	/* no -EDEADLK handling; can't happen with vm.mutex in place */
 	i915_gem_ww_ctx_fini(&ww);
-- 
2.34.1



More information about the Intel-gfx-trybot mailing list