OSDN Git Service

drm/i915: Untangle the vma pages_mutex
authorThomas Hellström <thomas.hellstrom@linux.intel.com>
Tue, 1 Jun 2021 07:46:40 +0000 (09:46 +0200)
committerMatthew Auld <matthew.auld@intel.com>
Tue, 1 Jun 2021 08:31:55 +0000 (09:31 +0100)
Any sleeping dma_resv lock taken while the vma pages_mutex is held
will cause a lockdep splat.
Move the i915_gem_object_pin_pages() call out of the pages_mutex
critical section.

Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20210601074654.3103-2-thomas.hellstrom@linux.intel.com
drivers/gpu/drm/i915/i915_vma.c

index a6cd0fa..f2b5912 100644 (file)
@@ -800,32 +800,37 @@ unpinned:
 static int vma_get_pages(struct i915_vma *vma)
 {
        int err = 0;
+       bool pinned_pages = false;
 
        if (atomic_add_unless(&vma->pages_count, 1, 0))
                return 0;
 
+       if (vma->obj) {
+               err = i915_gem_object_pin_pages(vma->obj);
+               if (err)
+                       return err;
+               pinned_pages = true;
+       }
+
        /* Allocations ahoy! */
-       if (mutex_lock_interruptible(&vma->pages_mutex))
-               return -EINTR;
+       if (mutex_lock_interruptible(&vma->pages_mutex)) {
+               err = -EINTR;
+               goto unpin;
+       }
 
        if (!atomic_read(&vma->pages_count)) {
-               if (vma->obj) {
-                       err = i915_gem_object_pin_pages(vma->obj);
-                       if (err)
-                               goto unlock;
-               }
-
                err = vma->ops->set_pages(vma);
-               if (err) {
-                       if (vma->obj)
-                               i915_gem_object_unpin_pages(vma->obj);
+               if (err)
                        goto unlock;
-               }
+               pinned_pages = false;
        }
        atomic_inc(&vma->pages_count);
 
 unlock:
        mutex_unlock(&vma->pages_mutex);
+unpin:
+       if (pinned_pages)
+               __i915_gem_object_unpin_pages(vma->obj);
 
        return err;
 }