drm/i915: Ignore duplicate VMA stored within the per-object handle LUT
authorChris Wilson <chris@chris-wilson.co.uk>
Tue, 22 Aug 2017 11:05:17 +0000 (12:05 +0100)
committerChris Wilson <chris@chris-wilson.co.uk>
Thu, 24 Aug 2017 14:28:05 +0000 (15:28 +0100)
By using drm_gem_flink/drm_gem_open on an object using the same fd, it
is possible for a client to create multiple handles pointing to the same
object (tied to the same contexts and VMA), as exemplified by
igt::gem_handle_to_libdrm_bo(). Since this duplication has been possible
since forever, we cannot assume that the handle:(fpriv, object) is
unique and so must handle the multiple users of a single VMA.

v2: Added commentary noise.

Testcase: igt/gem_close
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=102355
Fixes: d1b48c1e7184 ("drm/i915: Replace execbuf vma ht with an idr")
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20170822110517.22277-3-chris@chris-wilson.co.uk
Tested-by: Marta Lofstedt <marta.lofstedt@intel.com>
Reviewed-by: MichaƂ Winiarski <michal.winiarski@intel.com>
drivers/gpu/drm/i915/i915_gem.c
drivers/gpu/drm/i915/i915_gem_execbuffer.c
drivers/gpu/drm/i915/i915_vma.h

index 5dc396c20c063ecf61f0a7a1ef50f53ec0b5c9b5..ac02785fdaffa04d2567392b3316917dfe2a189b 100644 (file)
@@ -3258,7 +3258,13 @@ void i915_gem_close_object(struct drm_gem_object *gem, struct drm_file *file)
                        continue;
 
                vma = radix_tree_delete(&ctx->handles_vma, lut->handle);
-               if (!i915_vma_is_ggtt(vma))
+               GEM_BUG_ON(vma->obj != obj);
+
+               /* We allow the process to have multiple handles to the same
+                * vma, in the same fd namespace, by virtue of flink/open.
+                */
+               GEM_BUG_ON(!vma->open_count);
+               if (!--vma->open_count && !i915_vma_is_ggtt(vma))
                        i915_vma_close(vma);
 
                list_del(&lut->obj_link);
index 3d74f3a27c130815b1f51f3c17a3c2fc085f0b51..1c4fac03232943fa58d2faa9e30f1961f50133c9 100644 (file)
@@ -720,6 +720,7 @@ static int eb_lookup_vmas(struct i915_execbuffer *eb)
                        goto err_obj;
                }
 
+               vma->open_count++;
                list_add(&lut->obj_link, &obj->lut_list);
                list_add(&lut->ctx_link, &eb->ctx->handles_list);
                lut->ctx = eb->ctx;
index 1fd61e88cfd077c3708dfbb49098fb8dfbdc7bd1..e811067c7724f626c93c441586c3b4855210b225 100644 (file)
@@ -59,6 +59,12 @@ struct i915_vma {
        u32 fence_size;
        u32 fence_alignment;
 
+       /**
+        * Count of the number of times this vma has been opened by different
+        * handles (but same file) for execbuf, i.e. the number of aliases
+        * that exist in the ctx->handle_vmas LUT for this vma.
+        */
+       unsigned int open_count;
        unsigned int flags;
        /**
         * How many users have pinned this object in GTT space. The following