From: Matthew Brost <matthew.brost@intel.com>
To: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
Cc: <intel-xe@lists.freedesktop.org>
Subject: Re: [PATCH] drm/xe/dma-buf: Add xe_dma_buf_to_gem() self-import helper
Date: Thu, 29 Oct 2026 07:39:23 -0700 [thread overview]
Message-ID: <auNamy4jovDxiDPq@gsse-cloud1.jf.intel.com> (raw)
In-Reply-To: <20261029142111.2590982-2-niranjana.vishwanathapura@intel.com>
On Thu, Oct 29, 2026 at 07:21:12AM -0700, Niranjana Vishwanathapura wrote:
> Factor the dma-buf self-import detection out of xe_gem_prime_import()
> into a standalone xe_dma_buf_to_gem() helper. The helper checks that the
> dma-buf was exported by this Xe device (matching ops and drm_device) and,
> if so, takes an extra reference on the backing GEM object instead of the
> dma-buf file. Expose it for future use within Xe.
>
> Signed-off-by: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
> Signed-off-by: Farah Kassabri <farah.kassabri@intel.com>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
> ---
> drivers/gpu/drm/xe/xe_dma_buf.c | 38 ++++++++++++++++++++++++---------
> drivers/gpu/drm/xe/xe_dma_buf.h | 2 ++
> 2 files changed, 30 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/gpu/drm/xe/xe_dma_buf.c b/drivers/gpu/drm/xe/xe_dma_buf.c
> index 6a85b292dee7..5bf13dc4b61d 100644
> --- a/drivers/gpu/drm/xe/xe_dma_buf.c
> +++ b/drivers/gpu/drm/xe/xe_dma_buf.c
> @@ -239,6 +239,27 @@ static const struct dma_buf_ops xe_dmabuf_ops = {
> .vunmap = drm_gem_dmabuf_vunmap,
> };
>
> +struct drm_gem_object *xe_dma_buf_to_gem(struct drm_device *dev,
> + struct dma_buf *dma_buf)
> +{
> + struct drm_gem_object *obj;
> +
> + if (dma_buf->ops != &xe_dmabuf_ops)
> + return NULL;
> +
> + obj = dma_buf->priv;
> + if (obj->dev != dev)
> + return NULL;
> +
> + /*
> + * Importing dmabuf exported from our own gem increases
> + * refcount on gem itself instead of f_count of dmabuf.
> + */
> + drm_gem_object_get(obj);
> +
> + return obj;
> +}
> +
> struct dma_buf *xe_gem_prime_export(struct drm_gem_object *obj, int flags)
> {
> struct xe_bo *bo = gem_to_xe_bo(obj);
> @@ -372,17 +393,14 @@ struct drm_gem_object *xe_gem_prime_import(struct drm_device *dev,
> struct dma_buf_attachment *attach;
> struct drm_gem_object *obj;
>
> - if (dma_buf->ops == &xe_dmabuf_ops) {
> - obj = dma_buf->priv;
> - if (obj->dev == dev &&
> - !XE_TEST_ONLY(test && test->force_different_devices)) {
> - /*
> - * Importing dmabuf exported from out own gem increases
> - * refcount on gem itself instead of f_count of dmabuf.
> - */
> - drm_gem_object_get(obj);
> + obj = xe_dma_buf_to_gem(dev, dma_buf);
> + if (obj) {
> + if (!XE_TEST_ONLY(test && test->force_different_devices))
> return obj;
> - }
> +
> + /* Test only: force different devices */
> + drm_gem_object_put(obj);
> + obj = NULL;
> }
>
> /*
> diff --git a/drivers/gpu/drm/xe/xe_dma_buf.h b/drivers/gpu/drm/xe/xe_dma_buf.h
> index 861dd28a862c..d0c7893a5a6f 100644
> --- a/drivers/gpu/drm/xe/xe_dma_buf.h
> +++ b/drivers/gpu/drm/xe/xe_dma_buf.h
> @@ -8,6 +8,8 @@
>
> #include <drm/drm_gem.h>
>
> +struct drm_gem_object *xe_dma_buf_to_gem(struct drm_device *dev,
> + struct dma_buf *dma_buf);
> struct dma_buf *xe_gem_prime_export(struct drm_gem_object *obj, int flags);
> struct drm_gem_object *xe_gem_prime_import(struct drm_device *dev,
> struct dma_buf *dma_buf);
> --
> 2.43.0
>
next prev parent reply other threads:[~2026-10-29 14:39 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-29 14:21 [PATCH] drm/xe/dma-buf: Add xe_dma_buf_to_gem() self-import helper Niranjana Vishwanathapura
2026-10-29 14:39 ` Matthew Brost [this message]
2026-10-29 15:35 ` ✓ CI.KUnit: success for " Patchwork
2026-10-29 16:24 ` ✓ Xe.CI.BAT: " Patchwork
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=auNamy4jovDxiDPq@gsse-cloud1.jf.intel.com \
--to=matthew.brost@intel.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.