[PATCH 2/2] drm/i915/gem: Rework i915_gem_object_unbind slightly

Thomas Hellström thomas.hellstrom at linux.intel.com
Thu May 12 15:04:38 UTC 2022


Since vma destruction from the vm destruction path now takes the
object lock, we no longer need to take a vm reference from
i915_gem_object_unbind to make sure vmas are kept alive, the
required object lock taken across i915_gem_object_unbind is
sufficient. This also means we can skip retrying when we detect a race
with vm destruction.

Also make sure we don't have removed vmas from the list

Signed-off-by: Thomas Hellström <thomas.hellstrom at linux.intel.com>
---
 drivers/gpu/drm/i915/i915_gem.c | 18 ------------------
 1 file changed, 18 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 702e5b89be22..df16a5e8f5c7 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -137,7 +137,6 @@ int i915_gem_object_unbind(struct drm_i915_gem_object *obj,
 	 */
 	wakeref = intel_runtime_pm_get(rpm);
 
-try_again:
 	ret = 0;
 	spin_lock(&obj->vma.lock);
 	while (!ret && (vma = list_first_entry_or_null(&obj->vma.list,
@@ -152,17 +151,6 @@ int i915_gem_object_unbind(struct drm_i915_gem_object *obj,
 			break;
 		}
 
-		/*
-		 * Requiring the vm destructor to take the object lock
-		 * before destroying a vma would help us eliminate the
-		 * i915_vm_tryget() here, AND thus also the barrier stuff
-		 * at the end. That's an easy fix, but sleeping locks in
-		 * a kthread should generally be avoided.
-		 */
-		ret = -EAGAIN;
-		if (!i915_vm_tryget(vma->vm))
-			break;
-
 		spin_unlock(&obj->vma.lock);
 
 		/*
@@ -189,17 +177,11 @@ int i915_gem_object_unbind(struct drm_i915_gem_object *obj,
 			}
 		}
 
-		i915_vm_put(vma->vm);
 		spin_lock(&obj->vma.lock);
 	}
 	list_splice_init(&still_in_list, &obj->vma.list);
 	spin_unlock(&obj->vma.lock);
 
-	if (ret == -EAGAIN && flags & I915_GEM_OBJECT_UNBIND_BARRIER) {
-		rcu_barrier(); /* flush the i915_vm_release() */
-		goto try_again;
-	}
-
 	intel_runtime_pm_put(rpm, wakeref);
 
 	return ret;
-- 
2.34.1



More information about the Intel-gfx-trybot mailing list