AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@collabora.com>
To: Thomas Zimmermann <tzimmermann@suse.de>
Cc: "Steven Price" <steven.price@arm.com>,
	dri-devel@lists.freedesktop.org,
	"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
	"Maxime Ripard" <mripard@kernel.org>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Faith Ekstrand" <faith.ekstrand@collabora.com>,
	"Thierry Reding" <thierry.reding@gmail.com>,
	"Mikko Perttunen" <mperttunen@nvidia.com>,
	"Melissa Wen" <mwen@igalia.com>,
	"Maíra Canal" <mcanal@igalia.com>,
	"Lucas De Marchi" <lucas.demarchi@intel.com>,
	"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
	"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
	"Frank Binns" <frank.binns@imgtec.com>,
	"Matt Coster" <matt.coster@imgtec.com>,
	"Rob Clark" <robin.clark@oss.qualcomm.com>,
	"Dmitry Baryshkov" <lumag@kernel.org>,
	"Abhinav Kumar" <abhinav.kumar@linux.dev>,
	"Jessica Zhang" <jessica.zhang@oss.qualcomm.com>,
	"Sean Paul" <sean@poorly.run>,
	"Marijn Suijten" <marijn.suijten@somainline.org>,
	"Alex Deucher" <alexander.deucher@amd.com>,
	"Christian König" <christian.koenig@amd.com>,
	amd-gfx@lists.freedesktop.org, kernel@collabora.com
Subject: Re: [PATCH v6 01/16] drm/prime: Simplify life of drivers needing custom dma_buf_ops
Date: Thu, 27 Nov 2025 11:44:40 +0100	[thread overview]
Message-ID: <20251127114440.7a1d9e16@fedora> (raw)
In-Reply-To: <0d1fe2cf-dbda-4e64-bc3b-a2c9c0887820@suse.de>

On Thu, 27 Nov 2025 09:58:55 +0100
Thomas Zimmermann <tzimmermann@suse.de> wrote:

> Hi
> 
> Am 27.11.25 um 09:42 schrieb Thomas Zimmermann:
> > Hi
> >
> > Am 27.11.25 um 09:34 schrieb Thomas Zimmermann:  
> >> Hi
> >>
> >> Am 26.11.25 um 13:44 schrieb Boris Brezillon:  
> >>> drm_gem_is_prime_exported_dma_buf() checks the dma_buf->ops against
> >>> drm_gem_prime_dmabuf_ops, which makes it impossible to use if the
> >>> driver implements custom dma_buf_ops. Instead of duplicating a bunch
> >>> of helpers to work around it, let's provide a way for drivers to
> >>> expose their custom dma_buf_ops so the core prime helpers can rely on
> >>> that instead of hardcoding &drm_gem_prime_dmabuf_ops.  
> >>
> >> This can't go in as-is. I've spent an awful amount of patches on 
> >> removing buffer callbacks from struct drm_driver. Let's please not go 
> >> back to that.
> >>  
> >>>
> >>> v5:
> >>> - New patch
> >>>
> >>> v6:
> >>> - Pass custom dma_buf_ops directly instead of through a getter
> >>>
> >>> Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
> >>> ---
> >>>   drivers/gpu/drm/drm_prime.c | 10 ++++++++--
> >>>   include/drm/drm_drv.h       |  8 ++++++++
> >>>   2 files changed, 16 insertions(+), 2 deletions(-)
> >>>
> >>> diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c
> >>> index 21809a82187b..86fd95f0c105 100644
> >>> --- a/drivers/gpu/drm/drm_prime.c
> >>> +++ b/drivers/gpu/drm/drm_prime.c
> >>> @@ -904,6 +904,12 @@ unsigned long 
> >>> drm_prime_get_contiguous_size(struct sg_table *sgt)
> >>>   }
> >>>   EXPORT_SYMBOL(drm_prime_get_contiguous_size);
> >>>   +static const struct dma_buf_ops *
> >>> +drm_gem_prime_get_dma_buf_ops(struct drm_device *dev)
> >>> +{
> >>> +    return dev->driver->dma_buf_ops ?: &drm_gem_prime_dmabuf_ops;
> >>> +}
> >>> +
> >>>   /**
> >>>    * drm_gem_prime_export - helper library implementation of the 
> >>> export callback
> >>>    * @obj: GEM object to export
> >>> @@ -920,7 +926,7 @@ struct dma_buf *drm_gem_prime_export(struct 
> >>> drm_gem_object *obj,
> >>>       struct dma_buf_export_info exp_info = {
> >>>           .exp_name = KBUILD_MODNAME, /* white lie for debug */
> >>>           .owner = dev->driver->fops->owner,
> >>> -        .ops = &drm_gem_prime_dmabuf_ops,
> >>> +        .ops = drm_gem_prime_get_dma_buf_ops(dev),  
> >>
> >> Rather provide a new function drm_gem_prime_export_with_ops() that 
> >> takes an additional dma_ops instance. The current 
> >> drm_gem_prime_export() would call it with &drm_gem_prime_dmabuf_ops.
> >>
> >> If this really does not work, you could add a pointer to dma_buf_ops 
> >> to drm_gem_object_funcs and fetch that from drm_gem_prime_export(). 
> >> We already vm_ops there.
> >>
> >> Other drivers, such as amdgpu, would also benefit from such a change
> >>  
> >>>           .size = obj->size,
> >>>           .flags = flags,
> >>>           .priv = obj,
> >>> @@ -947,7 +953,7 @@ bool drm_gem_is_prime_exported_dma_buf(struct 
> >>> drm_device *dev,
> >>>   {
> >>>       struct drm_gem_object *obj = dma_buf->priv;
> >>>   -    return (dma_buf->ops == &drm_gem_prime_dmabuf_ops) && 
> >>> (obj->dev == dev);
> >>> +    return dma_buf->ops == drm_gem_prime_get_dma_buf_ops(dev) && 
> >>> obj->dev == dev;  
> >
> > On a second thought, we probably cannot be sure that dma_buf->priv 
> > really is a GEM object until we tested the ops field. :/  IIRC that's 
> > why the ops test goes first and the test for obj->dev goes second. So 
> > neither solution works.  
> 
> I think, instead of looking at the ops field, the test could look at 
> dma_buf->owner == dev->driver->fops->owner.  This will tell if the 
> dma_buf comes from the same driver and hence is a GEM object. In the 
> next step, do obj->dev == dev as before.  This will also allow drivers 
> like amdgpu to use the helper for testing. See [1].

Except this doesn't work when the driver is linked statically (not
enabled as a module), because THIS_MODULE is NULL in that case.

  reply	other threads:[~2025-11-27 10:44 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-26 12:44 [PATCH v6 00/16] drm/panfrost, panthor: Cached maps and explicit flushing Boris Brezillon
2025-11-26 12:44 ` [PATCH v6 01/16] drm/prime: Simplify life of drivers needing custom dma_buf_ops Boris Brezillon
2025-11-26 16:20   ` Steven Price
2025-11-27  8:34   ` Thomas Zimmermann
2025-11-27  8:42     ` Thomas Zimmermann
2025-11-27  8:58       ` Thomas Zimmermann
2025-11-27 10:44         ` Boris Brezillon [this message]
2025-11-27 12:32           ` Boris Brezillon
2025-11-27 13:05             ` Boris Brezillon
2025-11-27 10:34       ` Boris Brezillon
2025-11-27 10:40     ` Boris Brezillon
2025-11-26 12:44 ` [PATCH v6 02/16] drm/shmem: Provide a generic {begin, end}_cpu_access() implementation Boris Brezillon
2025-11-26 16:23   ` [PATCH v6 02/16] drm/shmem: Provide a generic {begin,end}_cpu_access() implementation Steven Price
2025-11-26 12:44 ` [PATCH v6 03/16] drm/shmem: Add a drm_gem_shmem_sync() helper Boris Brezillon
2025-11-26 12:44 ` [PATCH v6 04/16] drm/panthor: Provide a custom dma_buf implementation Boris Brezillon
2025-11-26 12:44 ` [PATCH v6 05/16] drm/panthor: Fix panthor_gpu_coherency_set() Boris Brezillon
2025-11-26 12:44 ` [PATCH v6 06/16] drm/panthor: Expose the selected coherency protocol to the UMD Boris Brezillon
2025-11-26 13:25   ` Boris Brezillon
2025-11-26 12:44 ` [PATCH v6 07/16] drm/panthor: Add a PANTHOR_BO_SYNC ioctl Boris Brezillon
2025-11-26 16:25   ` Steven Price
2025-11-26 12:44 ` [PATCH v6 08/16] drm/panthor: Add an ioctl to query BO flags Boris Brezillon
2025-11-26 12:44 ` [PATCH v6 09/16] drm/panthor: Add flag to map GEM object Write-Back Cacheable Boris Brezillon
2025-11-26 16:27   ` Steven Price
2025-11-26 12:44 ` [PATCH v6 10/16] drm/panthor: Bump the driver version to 1.6 Boris Brezillon
2025-11-26 12:44 ` [PATCH v6 11/16] drm/panfrost: Provide a custom dma_buf implementation Boris Brezillon
2025-11-26 12:44 ` [PATCH v6 12/16] drm/panfrost: Expose the selected coherency protocol to the UMD Boris Brezillon
2025-11-26 12:44 ` [PATCH v6 13/16] drm/panfrost: Add a PANFROST_SYNC_BO ioctl Boris Brezillon
2025-11-26 16:47   ` Steven Price
2025-11-26 12:44 ` [PATCH v6 14/16] drm/panfrost: Add an ioctl to query BO flags Boris Brezillon
2025-11-26 12:44 ` [PATCH v6 15/16] drm/panfrost: Add flag to map GEM object Write-Back Cacheable Boris Brezillon
2025-11-26 12:44 ` [PATCH v6 16/16] drm/panfrost: Bump the driver version to 1.6 Boris Brezillon
2025-11-26 16:20 ` [PATCH v6 00/16] drm/panfrost,panthor: Cached maps and explicit flushing Thomas Zimmermann
2025-11-26 17:24   ` Boris Brezillon

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=20251127114440.7a1d9e16@fedora \
    --to=boris.brezillon@collabora.com \
    --cc=abhinav.kumar@linux.dev \
    --cc=airlied@gmail.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=faith.ekstrand@collabora.com \
    --cc=frank.binns@imgtec.com \
    --cc=jessica.zhang@oss.qualcomm.com \
    --cc=kernel@collabora.com \
    --cc=lucas.demarchi@intel.com \
    --cc=lumag@kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=marijn.suijten@somainline.org \
    --cc=matt.coster@imgtec.com \
    --cc=mcanal@igalia.com \
    --cc=mperttunen@nvidia.com \
    --cc=mripard@kernel.org \
    --cc=mwen@igalia.com \
    --cc=robin.clark@oss.qualcomm.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=sean@poorly.run \
    --cc=simona@ffwll.ch \
    --cc=steven.price@arm.com \
    --cc=thierry.reding@gmail.com \
    --cc=thomas.hellstrom@linux.intel.com \
    --cc=tzimmermann@suse.de \
    /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