drm/i915: Remove superfluous locking around userfault_list
authorChris Wilson <chris@chris-wilson.co.uk>
Mon, 24 Oct 2016 12:42:16 +0000 (13:42 +0100)
committerChris Wilson <chris@chris-wilson.co.uk>
Mon, 24 Oct 2016 12:45:36 +0000 (13:45 +0100)
Now that we have reduced the access to the list to either (a) under the
struct_mutex whilst holding the RPM wakeref (so that concurrent writers to
the list are serialised by struct_mutex) and (b) under the atomic
runtime suspend (which cannot run concurrently with any other accessor due
to the atomic nature of the runtime suspend) we can remove the extra
locking around the list itself.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20161024124218.18252-3-chris@chris-wilson.co.uk
drivers/gpu/drm/i915/i915_drv.h
drivers/gpu/drm/i915/i915_gem.c

index a53172e7790fe522a8d20354724e913e29ac9460..ba87a852c0dbcd6afe12790c8423e968dc908f4b 100644 (file)
@@ -1361,9 +1361,6 @@ struct i915_gem_mm {
         */
        struct list_head unbound_list;
 
-       /** Protects access to the userfault_list */
-       spinlock_t userfault_lock;
-
        /** List of all objects in gtt_space, currently mmaped by userspace.
         * All objects within this list must also be on bound_list.
         */
index 63bf51b117a94464c7bf7950de23012a4727df45..38053434da8a0a564af53b62e36b922fd44a2775 100644 (file)
@@ -1842,10 +1842,8 @@ int i915_gem_fault(struct vm_area_struct *area, struct vm_fault *vmf)
 
        /* Mark as being mmapped into userspace for later revocation */
        assert_rpm_wakelock_held(dev_priv);
-       spin_lock(&dev_priv->mm.userfault_lock);
        if (list_empty(&obj->userfault_link))
                list_add(&obj->userfault_link, &dev_priv->mm.userfault_list);
-       spin_unlock(&dev_priv->mm.userfault_lock);
 
        /* Finally, remap it using the new GTT offset */
        ret = remap_io_mapping(area,
@@ -1922,7 +1920,6 @@ void
 i915_gem_release_mmap(struct drm_i915_gem_object *obj)
 {
        struct drm_i915_private *i915 = to_i915(obj->base.dev);
-       bool zap = false;
 
        /* Serialisation between user GTT access and our code depends upon
         * revoking the CPU's PTE whilst the mutex is held. The next user
@@ -1935,15 +1932,10 @@ i915_gem_release_mmap(struct drm_i915_gem_object *obj)
        lockdep_assert_held(&i915->drm.struct_mutex);
        intel_runtime_pm_get(i915);
 
-       spin_lock(&i915->mm.userfault_lock);
-       if (!list_empty(&obj->userfault_link)) {
-               list_del_init(&obj->userfault_link);
-               zap = true;
-       }
-       spin_unlock(&i915->mm.userfault_lock);
-       if (!zap)
+       if (list_empty(&obj->userfault_link))
                goto out;
 
+       list_del_init(&obj->userfault_link);
        drm_vma_node_unmap(&obj->base.vma_node,
                           obj->base.dev->anon_inode->i_mapping);
 
@@ -1963,21 +1955,21 @@ out:
 void
 i915_gem_release_all_mmaps(struct drm_i915_private *dev_priv)
 {
-       struct drm_i915_gem_object *obj;
+       struct drm_i915_gem_object *obj, *on;
 
-       spin_lock(&dev_priv->mm.userfault_lock);
-       while ((obj = list_first_entry_or_null(&dev_priv->mm.userfault_list,
-                                              struct drm_i915_gem_object,
-                                              userfault_link))) {
-               list_del_init(&obj->userfault_link);
-               spin_unlock(&dev_priv->mm.userfault_lock);
+       /*
+        * Only called during RPM suspend. All users of the userfault_list
+        * must be holding an RPM wakeref to ensure that this can not
+        * run concurrently with themselves (and use the struct_mutex for
+        * protection between themselves).
+        */
 
+       list_for_each_entry_safe(obj, on,
+                                &dev_priv->mm.userfault_list, userfault_link) {
+               list_del_init(&obj->userfault_link);
                drm_vma_node_unmap(&obj->base.vma_node,
                                   obj->base.dev->anon_inode->i_mapping);
-
-               spin_lock(&dev_priv->mm.userfault_lock);
        }
-       spin_unlock(&dev_priv->mm.userfault_lock);
 }
 
 /**
@@ -4547,7 +4539,6 @@ int i915_gem_init(struct drm_device *dev)
        int ret;
 
        mutex_lock(&dev->struct_mutex);
-       spin_lock_init(&dev_priv->mm.userfault_lock);
 
        if (!i915.enable_execlists) {
                dev_priv->gt.resume = intel_legacy_submission_resume;