diff mbox series

[2/3] drm/i915/gem: Lock the object as we unbind

Message ID 20191216103901.2518461-2-chris@chris-wilson.co.uk (mailing list archive)
State New, archived
Headers show
Series [1/3] drm/i915: Unpin vma->obj on early error | expand

Commit Message

Chris Wilson Dec. 16, 2019, 10:39 a.m. UTC
If the object is closed while we wait, that may move the vma we are
waiting on to the parked list allowing it to be destroyed underneath the
waiter. (i915_vma.kref! When do we want it? Yesterday!)

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/i915_gem.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 5eeef1ef7448..0f9e1411a031 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -139,6 +139,7 @@  int i915_gem_object_unbind(struct drm_i915_gem_object *obj,
 
 try_again:
 	ret = 0;
+	i915_gem_object_lock(obj); /* prevent i915_gem_close_object() */
 	spin_lock(&obj->vma.lock);
 	while (!ret && (vma = list_first_entry_or_null(&obj->vma.list,
 						       struct i915_vma,
@@ -177,6 +178,7 @@  int i915_gem_object_unbind(struct drm_i915_gem_object *obj,
 	}
 	list_splice_init(&still_in_list, &obj->vma.list);
 	spin_unlock(&obj->vma.lock);
+	i915_gem_object_unlock(obj);
 
 	if (ret == -EAGAIN && flags & I915_GEM_OBJECT_UNBIND_BARRIER) {
 		rcu_barrier(); /* flush the i915_vm_release() */