[Intel-gfx] [PATCH 04/20] drm/i915: Ignore duplicate VMA stored within the per-object handle LUT

Michał Winiarski michal.winiarski at intel.com
Wed Aug 23 17:40:17 UTC 2017


On Wed, Aug 23, 2017 at 10:14:58AM +0100, Chris Wilson wrote:
> 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.
> 
> 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 at chris-wilson.co.uk>
> Cc: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
> Cc: Joonas Lahtinen <joonas.lahtinen at linux.intel.com>
> ---
>  drivers/gpu/drm/i915/i915_gem.c            | 8 +++++++-
>  drivers/gpu/drm/i915/i915_gem_execbuffer.c | 1 +
>  drivers/gpu/drm/i915/i915_vma.h            | 1 +
>  3 files changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
> index 5dc396c20c06..ac02785fdaff 100644
> --- a/drivers/gpu/drm/i915/i915_gem.c
> +++ b/drivers/gpu/drm/i915/i915_gem.c
> @@ -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);
> diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
> index 3d74f3a27c13..1c4fac032329 100644
> --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
> +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
> @@ -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;
> diff --git a/drivers/gpu/drm/i915/i915_vma.h b/drivers/gpu/drm/i915/i915_vma.h
> index 1fd61e88cfd0..893467a28801 100644
> --- a/drivers/gpu/drm/i915/i915_vma.h
> +++ b/drivers/gpu/drm/i915/i915_vma.h
> @@ -59,6 +59,7 @@ struct i915_vma {
>  	u32 fence_size;
>  	u32 fence_alignment;
>  
> +	unsigned int open_count;
	/**
	 * Number of different handles observed while handling this vma.
	 * We allow the process to have multiple handles to the same vma, in the
	 * same fd namespace, by virtue of flink/open.
	 */

Or different wording.

While the name is pretty self-explanatory in context of a patch, the reader may
be looking at this outside of that context or without any prior knowledge about
flink/open handling.

With that:

Reviewed-by: Michał Winiarski <michal.winiarski at intel.com>

-Michał

>  	unsigned int flags;
>  	/**
>  	 * How many users have pinned this object in GTT space. The following
> -- 
> 2.14.1
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx


More information about the Intel-gfx mailing list