drm/i915/gt: Pull marking vm as closed underneath the vm->mutex
authorChris Wilson <chris@chris-wilson.co.uk>
Thu, 27 Feb 2020 08:57:13 +0000 (08:57 +0000)
committerChris Wilson <chris@chris-wilson.co.uk>
Fri, 28 Feb 2020 12:33:07 +0000 (12:33 +0000)
Pull the final atomic_dec of vm->open (marking the vm as closed)
underneath the same vm->mutex as used to close it. This is required to
correctly serialise with attempting to reuse the vma as the vm is closed
by a second thread.

References: 00de702c6c6f ("drm/i915: Check that the vma hasn't been closed before we insert it")
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200227085723.1961649-10-chris@chris-wilson.co.uk
drivers/gpu/drm/i915/gt/intel_gtt.c
drivers/gpu/drm/i915/gt/intel_gtt.h

index c8db4f95c1b793b1a9615813fea83f8f1d28a781..2a72cce63fd9131c35cb9f14dae27703e9161418 100644 (file)
@@ -171,7 +171,9 @@ void __i915_vm_close(struct i915_address_space *vm)
 {
        struct i915_vma *vma, *vn;
 
-       mutex_lock(&vm->mutex);
+       if (!atomic_dec_and_mutex_lock(&vm->open, &vm->mutex))
+               return;
+
        list_for_each_entry_safe(vma, vn, &vm->bound_list, vm_link) {
                struct drm_i915_gem_object *obj = vma->obj;
 
@@ -186,6 +188,7 @@ void __i915_vm_close(struct i915_address_space *vm)
                i915_gem_object_put(obj);
        }
        GEM_BUG_ON(!list_empty(&vm->bound_list));
+
        mutex_unlock(&vm->mutex);
 }
 
index 9a185f4537e1e9968244eceddb458bc5782a8224..b3116fe8d1807dd09e5a3e54076e1c7105a3ea9a 100644 (file)
@@ -429,8 +429,7 @@ static inline void
 i915_vm_close(struct i915_address_space *vm)
 {
        GEM_BUG_ON(!atomic_read(&vm->open));
-       if (atomic_dec_and_test(&vm->open))
-               __i915_vm_close(vm);
+       __i915_vm_close(vm);
 
        i915_vm_put(vm);
 }