Merge tag 'drm-misc-next-2019-08-19' of git://anongit.freedesktop.org/drm/drm-misc...
[sfrench/cifs-2.6.git] / drivers / gpu / drm / i915 / gem / i915_gem_object.c
index be6caccce0c5e0fd31a441e34bc89833c290dd21..afd75b85da1d9e1ba14171cf61d5d5f3bc9fcc00 100644 (file)
@@ -23,7 +23,7 @@
  */
 
 #include "display/intel_frontbuffer.h"
-
+#include "gt/intel_gt.h"
 #include "i915_drv.h"
 #include "i915_gem_clflush.h"
 #include "i915_gem_context.h"
@@ -146,6 +146,19 @@ void i915_gem_close_object(struct drm_gem_object *gem, struct drm_file *file)
        }
 }
 
+static void __i915_gem_free_object_rcu(struct rcu_head *head)
+{
+       struct drm_i915_gem_object *obj =
+               container_of(head, typeof(*obj), rcu);
+       struct drm_i915_private *i915 = to_i915(obj->base.dev);
+
+       dma_resv_fini(&obj->base._resv);
+       i915_gem_object_free(obj);
+
+       GEM_BUG_ON(!atomic_read(&i915->mm.free_count));
+       atomic_dec(&i915->mm.free_count);
+}
+
 static void __i915_gem_free_objects(struct drm_i915_private *i915,
                                    struct llist_node *freed)
 {
@@ -160,7 +173,6 @@ static void __i915_gem_free_objects(struct drm_i915_private *i915,
 
                mutex_lock(&i915->drm.struct_mutex);
 
-               GEM_BUG_ON(i915_gem_object_is_active(obj));
                list_for_each_entry_safe(vma, vn, &obj->vma.list, obj_link) {
                        GEM_BUG_ON(i915_vma_is_active(vma));
                        vma->flags &= ~I915_VMA_PIN_MASK;
@@ -169,22 +181,6 @@ static void __i915_gem_free_objects(struct drm_i915_private *i915,
                GEM_BUG_ON(!list_empty(&obj->vma.list));
                GEM_BUG_ON(!RB_EMPTY_ROOT(&obj->vma.tree));
 
-               /*
-                * This serializes freeing with the shrinker. Since the free
-                * is delayed, first by RCU then by the workqueue, we want the
-                * shrinker to be able to free pages of unreferenced objects,
-                * or else we may oom whilst there are plenty of deferred
-                * freed objects.
-                */
-               if (i915_gem_object_has_pages(obj) &&
-                   i915_gem_object_is_shrinkable(obj)) {
-                       unsigned long flags;
-
-                       spin_lock_irqsave(&i915->mm.obj_lock, flags);
-                       list_del_init(&obj->mm.link);
-                       spin_unlock_irqrestore(&i915->mm.obj_lock, flags);
-               }
-
                mutex_unlock(&i915->drm.struct_mutex);
 
                GEM_BUG_ON(atomic_read(&obj->bind_count));
@@ -192,25 +188,21 @@ static void __i915_gem_free_objects(struct drm_i915_private *i915,
                GEM_BUG_ON(atomic_read(&obj->frontbuffer_bits));
                GEM_BUG_ON(!list_empty(&obj->lut_list));
 
-               if (obj->ops->release)
-                       obj->ops->release(obj);
-
                atomic_set(&obj->mm.pages_pin_count, 0);
                __i915_gem_object_put_pages(obj, I915_MM_NORMAL);
                GEM_BUG_ON(i915_gem_object_has_pages(obj));
+               bitmap_free(obj->bit_17);
 
                if (obj->base.import_attach)
                        drm_prime_gem_destroy(&obj->base, NULL);
 
-               drm_gem_object_release(&obj->base);
+               drm_gem_free_mmap_offset(&obj->base);
 
-               bitmap_free(obj->bit_17);
-               i915_gem_object_free(obj);
-
-               GEM_BUG_ON(!atomic_read(&i915->mm.free_count));
-               atomic_dec(&i915->mm.free_count);
+               if (obj->ops->release)
+                       obj->ops->release(obj);
 
-               cond_resched();
+               /* But keep the pointer alive for RCU-protected lookups */
+               call_rcu(&obj->rcu, __i915_gem_free_object_rcu);
        }
        intel_runtime_pm_put(&i915->runtime_pm, wakeref);
 }
@@ -261,18 +253,34 @@ static void __i915_gem_free_work(struct work_struct *work)
        spin_unlock(&i915->mm.free_lock);
 }
 
-static void __i915_gem_free_object_rcu(struct rcu_head *head)
+void i915_gem_free_object(struct drm_gem_object *gem_obj)
 {
-       struct drm_i915_gem_object *obj =
-               container_of(head, typeof(*obj), rcu);
+       struct drm_i915_gem_object *obj = to_intel_bo(gem_obj);
        struct drm_i915_private *i915 = to_i915(obj->base.dev);
 
        /*
-        * We reuse obj->rcu for the freed list, so we had better not treat
-        * it like a rcu_head from this point forwards. And we expect all
-        * objects to be freed via this path.
+        * Before we free the object, make sure any pure RCU-only
+        * read-side critical sections are complete, e.g.
+        * i915_gem_busy_ioctl(). For the corresponding synchronized
+        * lookup see i915_gem_object_lookup_rcu().
         */
-       destroy_rcu_head(&obj->rcu);
+       atomic_inc(&i915->mm.free_count);
+
+       /*
+        * This serializes freeing with the shrinker. Since the free
+        * is delayed, first by RCU then by the workqueue, we want the
+        * shrinker to be able to free pages of unreferenced objects,
+        * or else we may oom whilst there are plenty of deferred
+        * freed objects.
+        */
+       if (i915_gem_object_has_pages(obj) &&
+           i915_gem_object_is_shrinkable(obj)) {
+               unsigned long flags;
+
+               spin_lock_irqsave(&i915->mm.obj_lock, flags);
+               list_del_init(&obj->mm.link);
+               spin_unlock_irqrestore(&i915->mm.obj_lock, flags);
+       }
 
        /*
         * Since we require blocking on struct_mutex to unbind the freed
@@ -288,20 +296,6 @@ static void __i915_gem_free_object_rcu(struct rcu_head *head)
                queue_work(i915->wq, &i915->mm.free_work);
 }
 
-void i915_gem_free_object(struct drm_gem_object *gem_obj)
-{
-       struct drm_i915_gem_object *obj = to_intel_bo(gem_obj);
-
-       /*
-        * Before we free the object, make sure any pure RCU-only
-        * read-side critical sections are complete, e.g.
-        * i915_gem_busy_ioctl(). For the corresponding synchronized
-        * lookup see i915_gem_object_lookup_rcu().
-        */
-       atomic_inc(&to_i915(obj->base.dev)->mm.free_count);
-       call_rcu(&obj->rcu, __i915_gem_free_object_rcu);
-}
-
 static inline enum fb_op_origin
 fb_write_origin(struct drm_i915_gem_object *obj, unsigned int domain)
 {
@@ -319,7 +313,6 @@ void
 i915_gem_object_flush_write_domain(struct drm_i915_gem_object *obj,
                                   unsigned int flush_domains)
 {
-       struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
        struct i915_vma *vma;
 
        assert_object_held(obj);
@@ -329,7 +322,8 @@ i915_gem_object_flush_write_domain(struct drm_i915_gem_object *obj,
 
        switch (obj->write_domain) {
        case I915_GEM_DOMAIN_GTT:
-               i915_gem_flush_ggtt_writes(dev_priv);
+               for_each_ggtt_vma(vma, obj)
+                       intel_gt_flush_ggtt_writes(vma->vm->gt);
 
                intel_fb_obj_flush(obj,
                                   fb_write_origin(obj, I915_GEM_DOMAIN_GTT));
@@ -340,6 +334,7 @@ i915_gem_object_flush_write_domain(struct drm_i915_gem_object *obj,
 
                        i915_vma_unset_ggtt_write(vma);
                }
+
                break;
 
        case I915_GEM_DOMAIN_WC: