Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Brost <matthew.brost@intel.com>
To: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
Cc: <dri-devel@lists.freedesktop.org>, <intel-xe@lists.freedesktop.org>
Subject: Re: [PATCH v2 3/6] drm/gem: add drm_gem_prime_dma_buf_to_gem() self-import helper
Date: Mon, 12 Oct 2026 18:36:47 -0700	[thread overview]
Message-ID: <as2LL7IIs6EcL6Pj@gsse-cloud1.jf.intel.com> (raw)
In-Reply-To: <20261013010614.1516799-11-niranjana.vishwanathapura@intel.com>

On Mon, Oct 12, 2026 at 06:06:15PM -0700, Niranjana Vishwanathapura wrote:
> drm_gem_is_prime_exported_dma_buf() is a bool predicate that open-codes
> the core PRIME self-import check. Its only caller, the shmem importer,
> then repeats the dma_buf->priv lookup and the reference get.
> 
> Replace it with drm_gem_prime_dma_buf_to_gem(), a thin wrapper around
> drm_gem_prime_self_import() that returns the backing GEM object -- with
> a reference taken -- for a core-PRIME self-export, or NULL otherwise.
> This consolidates self-import handling onto drm_gem_prime_self_import()
> and lets drm_gem_shmem_prime_import_no_map() reuse the object directly.
> 
> Unlike the removed predicate, the helper takes a reference on the
> returned object; the sole caller already wanted the referenced object.
> 
> Assisted-by: GitHub-Copilot:claude-opus-4.8

Assisted-by: LLM

I was going to suggest this last rev too as I noticed
drm_gem_shmem_prime_import_no_map called
drm_gem_is_prime_exported_dma_buf which should prefer the new helper but
shmem couldn't look at drm_gem_prime_dmabuf_ops.

This is a good cleanup:

Reviewed-by: Matthew Brost <matthew.brost@intel.com>

> Signed-off-by: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
> ---
>  drivers/gpu/drm/drm_gem_shmem_helper.c | 14 ++++++--------
>  drivers/gpu/drm/drm_prime.c            | 26 +++++++++++++++-----------
>  include/drm/drm_prime.h                |  4 ++--
>  3 files changed, 23 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c
> index d654a22a30de..a0e161f2333e 100644
> --- a/drivers/gpu/drm/drm_gem_shmem_helper.c
> +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c
> @@ -954,15 +954,13 @@ struct drm_gem_object *drm_gem_shmem_prime_import_no_map(struct drm_device *dev,
>  	size_t size;
>  	int ret;
>  
> -	if (drm_gem_is_prime_exported_dma_buf(dev, dma_buf)) {
> -		/*
> -		 * Importing dmabuf exported from our own gem increases
> -		 * refcount on gem itself instead of f_count of dmabuf.
> -		 */
> -		obj = dma_buf->priv;
> -		drm_gem_object_get(obj);
> +	/*
> +	 * Importing a dmabuf exported from our own gem increases the refcount
> +	 * on the gem itself instead of the f_count of the dmabuf.
> +	 */
> +	obj = drm_gem_prime_dma_buf_to_gem(dev, dma_buf);
> +	if (obj)
>  		return obj;
> -	}
>  
>  	attach = dma_buf_attach(dma_buf, dev->dev);
>  	if (IS_ERR(attach))
> diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c
> index 588910c250b8..275c5661528d 100644
> --- a/drivers/gpu/drm/drm_prime.c
> +++ b/drivers/gpu/drm/drm_prime.c
> @@ -933,23 +933,27 @@ EXPORT_SYMBOL(drm_gem_prime_export);
>  
>  
>  /**
> - * drm_gem_is_prime_exported_dma_buf -
> - * checks if the DMA-BUF was exported from a GEM object belonging to @dev.
> + * drm_gem_prime_dma_buf_to_gem - GEM object backing a self-exported PRIME dma-buf
>   * @dev: drm_device to check against
>   * @dma_buf: dma-buf object to import
>   *
> - * Return: true if the DMA-BUF was exported from a GEM object belonging
> - * to @dev, false otherwise.
> + * If @dma_buf is a PRIME export of a GEM object that belongs to @dev and uses
> + * the core PRIME dma-buf ops, return that GEM object with an extra reference
> + * taken, so a self-import reuses the GEM object instead of referencing the
> + * dma-buf file. Returns NULL for a foreign dma-buf or one using driver-private
> + * ops; such drivers call drm_gem_prime_self_import() with their own ops.
> + *
> + * The returned object carries a reference the caller must drop with
> + * drm_gem_object_put().
> + *
> + * Return: the referenced GEM object on self-import, or NULL otherwise.
>   */
> -
> -bool drm_gem_is_prime_exported_dma_buf(struct drm_device *dev,
> -				       struct dma_buf *dma_buf)
> +struct drm_gem_object *drm_gem_prime_dma_buf_to_gem(struct drm_device *dev,
> +						    struct dma_buf *dma_buf)
>  {
> -	struct drm_gem_object *obj = dma_buf->priv;
> -
> -	return (dma_buf->ops == &drm_gem_prime_dmabuf_ops) && (obj->dev == dev);
> +	return drm_gem_prime_self_import(dev, dma_buf, &drm_gem_prime_dmabuf_ops);
>  }
> -EXPORT_SYMBOL(drm_gem_is_prime_exported_dma_buf);
> +EXPORT_SYMBOL(drm_gem_prime_dma_buf_to_gem);
>  
>  /**
>   * drm_gem_prime_import_dev - core implementation of the import callback
> diff --git a/include/drm/drm_prime.h b/include/drm/drm_prime.h
> index d378404f8ab4..02665205aed1 100644
> --- a/include/drm/drm_prime.h
> +++ b/include/drm/drm_prime.h
> @@ -101,8 +101,8 @@ struct dma_buf *drm_gem_prime_export(struct drm_gem_object *obj,
>  unsigned long drm_prime_get_contiguous_size(struct sg_table *sgt);
>  
>  /* helper functions for importing */
> -bool drm_gem_is_prime_exported_dma_buf(struct drm_device *dev,
> -				       struct dma_buf *dma_buf);
> +struct drm_gem_object *drm_gem_prime_dma_buf_to_gem(struct drm_device *dev,
> +						    struct dma_buf *dma_buf);
>  
>  struct drm_gem_object *drm_gem_prime_import_dev(struct drm_device *dev,
>  						struct dma_buf *dma_buf,
> -- 
> 2.43.0
> 

  reply	other threads:[~2026-10-13  1:37 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-13  1:06 [PATCH v2 0/6] drm: consolidate self-imported PRIME dma-buf detection Niranjana Vishwanathapura
2026-10-13  1:06 ` [PATCH v2 1/6] drm/gem: add helper to detect self-imported PRIME dma-bufs Niranjana Vishwanathapura
2026-10-13  1:06 ` [PATCH v2 2/6] drm/xe/dma-buf: Use drm helper to detect dma-buf self-import Niranjana Vishwanathapura
2026-10-13  1:06 ` [PATCH v2 3/6] drm/gem: add drm_gem_prime_dma_buf_to_gem() self-import helper Niranjana Vishwanathapura
2026-10-13  1:36   ` Matthew Brost [this message]
2026-10-13  7:17     ` Thomas Zimmermann
2026-10-13 18:37       ` Matthew Brost
2026-10-13  1:06 ` [PATCH v2 4/6] drm/panthor: use drm_gem_prime_self_import() helper Niranjana Vishwanathapura
2026-10-13  1:06 ` [PATCH v2 5/6] drm/panfrost: " Niranjana Vishwanathapura
2026-10-13  1:06 ` [PATCH v2 6/6] drm/amdgpu: " Niranjana Vishwanathapura
2026-10-13  1:38 ` [PATCH v2 0/6] drm: consolidate self-imported PRIME dma-buf detection Matthew Brost
2026-10-13  7:17 ` Thomas Zimmermann
2026-10-13 18:29   ` Niranjana Vishwanathapura

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=as2LL7IIs6EcL6Pj@gsse-cloud1.jf.intel.com \
    --to=matthew.brost@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=niranjana.vishwanathapura@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox