All of 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>,
	kernel@collabora.com
Subject: Re: [PATCH v4 02/14] drm/gem: Add a drm_gem_object_funcs::sync() and a drm_gem_sync() helper
Date: Thu, 16 Oct 2025 12:32:17 +0200	[thread overview]
Message-ID: <20251016123217.01d32b85@fedora> (raw)
In-Reply-To: <c0f34c27-075a-49b1-be44-5b4d9c152ac7@suse.de>

On Thu, 16 Oct 2025 11:58:21 +0200
Thomas Zimmermann <tzimmermann@suse.de> wrote:

> Hi
> 
> Am 16.10.25 um 11:40 schrieb Boris Brezillon:
> > Hi Thomas,
> >
> > On Thu, 16 Oct 2025 10:32:46 +0200
> > Thomas Zimmermann <tzimmermann@suse.de> wrote:
> >  
> >> Hi,
> >>
> >> on patches 2 to 4: sync is really begin/end access wrapped into one
> >> interface, which I find questionable. I also don't like that these
> >> patches add generic infrastructure for a single driver.  
> > It's actually two drivers (panfrost and panthor), and the interface is
> > here so other drivers relying on drm_gem_shmem don't have to hand-roll
> > these things in the future.  
> 
> Ok.
> 
> But what about the unrelated drivers? Most GEM SHMEM drivers don't need 
> this. Looking at patch 4, there's a for loop over the SG table, which 
> appears to affect all drivers.

It doesn't. First off, this ::sync hook is optional, and if you look at
patch 4's commit message, it says:

"
We provide a drm_gem_shmem_object_sync() for drivers that wants to
have this default implementation as their drm_gem_object_funcs::sync,
but we don't set drm_gem_shmem_funcs::sync to
drm_gem_shmem_object_sync() to avoid changing the behavior of drivers
currently relying on the default gem_shmem vtable.
"

> 
> You know, there are two types of GEM SHMEM users. The ones like panthor 
> that build upon it with additional features. And the other type that 
> only use it as simple buffer storage. The former type what's building 
> blocks to combine as needed; that latter (actually the majority) wants a 
> simple solution. And TBH, I've considered spitting GEM SHMEM into two 
> for this reason.

That's the very reason I don't force

	::sync = drm_gem_shmem_sync

but leave it to each driver to decide whether they want it or not.

> 
> >  
> >> My proposal is to make your own dma_buf exporter in panthor and set the
> >> begin/end_cpu_access functions as you need. Panthor already contains its
> >> own GEM export helper at [1]. If you inline drm_gem_prime_export() [2]
> >> you can set the cpu_access callbacks to panthor-specific code. The other
> >> dma-buf helpers' symbols should be exported and can be re-used. That is
> >> a lot less intrusive and should provide what you need.  
> > I can of course do that in panthor, but then I'll have to duplicate
> > the same logic in panfrost. Also, the whole point of making it generic
> > is so that people don't forget that begin/end_cpu_access() is a thing
> > they should consider (like happened to me if you look at v2 of this
> > patchset), otherwise importers of their buffers might have unpleasant
> > side effects because of missing flush/invalidates. This, IMHO, is a good
> > reason to have it as a drm_gem_funcs::sync() callback. That, or we
> > decide that the default dma_buf_ops is not a thing, and we force
> > developers to think twice when they select the default hooks to pick
> > for their dma_buf implementation.  
> 
> See my comment above. Panthor and panfrost should treat GEM SHMEM like a 
> set of building blocks rather and a full solution.

That's exactly what it does. Panfrost/Panthor have their own
drm_gem_object_funcs, they just use the default drm_gem_shmem_sync
implementation provided by this patch, that's all. And yes,
hand-rolling your own drm_prime implem is not only annoying, it's also
error prone because some of the gem_shmem helpers [1] might rely on
drm_gem_is_prime_exported_dma_buf(), which checks the dma_buf ops
against the default drm_prime implementation.

> 
> >  
> >> I found that a hand full of other DRM drivers implement dma-buf's
> >> begin/end access callbacks. If you want a generic begin/end interface
> >> for GEM, you certainly want to get them on board. If there's something
> >> common to share, this should be done in a separate series.  
> > Fair enough. I'll try to convert freedreno and imagination to this new
> > interface, and gather some feedback.  
> 
> I did 'git grep \.begin_cpu_access' in the drm directory. This returned, 
> amdgpu, i915, tegra, omap, and xe. These where the ones I had in mind.

Hm, so tegra/omap should be relatively easy, but I'm reluctant to touch
the big drivers here (amdgpu, i915 and xe). Because it's an opt-in, and
because these drivers already have hand-rolled these dma_buf_ops, I'd
rather let their owners deal with the transition if they want to. IOW,
if you ask me to find new users, I'd like to focus on relatively small
drivers, and primarily those relying on drm_gem_shmem already. Note
that there might be drivers lacking a {begin,end}_cpu_access()
implementation, but don't know it, because there's very few use cases
where GPU is the exporter and the importer is not the same GPU device.
The other reason would be that most drivers relying on gem_shmem set
::map_wc=true unconditionally (CPU mappings are not cached, and thus
don't require synchronization), or just that those devices are IO
coherent.

Honestly, I'm not too sure why this is a problem if this hook is
optional. If it turns out to be too simple for more complex use cases
others have, it can still be extended when those drivers transition to
this ::sync() approach, as no in-kernel API is immutable. And in the
meantime, we have a solution for two drivers that doesn't imply
duplicating a bunch of drm_prime boiler-plate that's otherwise rather
generic.

[1]https://elixir.bootlin.com/linux/v6.17.1/source/drivers/gpu/drm/drm_gem_shmem_helper.c#L825

  reply	other threads:[~2025-10-16 10:32 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-15 16:03 [PATCH v4 00/14] drm/panfrost, panthor: Cached maps and explicit flushing Boris Brezillon
2025-10-15 16:03 ` [PATCH v4 01/14] drm/panthor: Fix panthor_gpu_coherency_set() Boris Brezillon
2025-10-15 16:03 ` [PATCH v4 02/14] drm/gem: Add a drm_gem_object_funcs::sync() and a drm_gem_sync() helper Boris Brezillon
2025-10-16  8:13   ` Maxime Ripard
2025-10-16 12:57     ` Boris Brezillon
2025-10-16 13:07       ` Boris Brezillon
2025-10-29  9:30         ` Maxime Ripard
2025-10-30 14:07           ` Boris Brezillon
2025-10-16  8:32   ` Thomas Zimmermann
2025-10-16  9:40     ` Boris Brezillon
2025-10-16  9:58       ` Thomas Zimmermann
2025-10-16 10:32         ` Boris Brezillon [this message]
2025-10-16 11:42           ` Thomas Zimmermann
2025-10-16 12:24             ` Boris Brezillon
2025-10-30 14:11             ` Boris Brezillon
2025-10-17 14:32   ` Faith Ekstrand
2025-10-17 14:40     ` Faith Ekstrand
2025-10-17 15:26       ` Boris Brezillon
2025-10-17 15:35         ` Faith Ekstrand
2025-10-17 15:50           ` Boris Brezillon
2025-10-17 15:57             ` Faith Ekstrand
2025-10-17 16:35               ` Boris Brezillon
2025-10-15 16:03 ` [PATCH v4 03/14] drm/prime: Provide default ::{begin, end}_cpu_access() implementations Boris Brezillon
2025-10-15 16:03 ` [PATCH v4 04/14] drm/shmem: Add a drm_gem_shmem_sync() helper Boris Brezillon
2025-10-15 16:03 ` [PATCH v4 05/14] drm/panthor: Expose the selected coherency protocol to the UMD Boris Brezillon
2025-10-15 16:03 ` [PATCH v4 06/14] drm/panthor: Add a PANTHOR_BO_SYNC ioctl Boris Brezillon
2025-10-15 16:03 ` [PATCH v4 07/14] drm/panthor: Add an ioctl to query BO flags Boris Brezillon
2025-10-15 16:03 ` [PATCH v4 08/14] drm/panthor: Add flag to map GEM object Write-Back Cacheable Boris Brezillon
2025-10-15 16:03 ` [PATCH v4 09/14] drm/panthor: Bump the driver version to 1.6 Boris Brezillon
2025-10-15 16:03 ` [PATCH v4 10/14] drm/panfrost: Expose the selected coherency protocol to the UMD Boris Brezillon
2025-10-15 16:06   ` Steven Price
2025-10-15 16:03 ` [PATCH v4 11/14] drm/panfrost: Add a PANFROST_SYNC_BO ioctl Boris Brezillon
2025-10-16  8:42   ` Marcin Ślusarz
2025-10-16  9:52     ` Boris Brezillon
2025-10-16 10:02       ` Marcin Ślusarz
2025-10-16 10:35         ` Boris Brezillon
2025-10-15 16:03 ` [PATCH v4 12/14] drm/panfrost: Add an ioctl to query BO flags Boris Brezillon
2025-10-15 16:03 ` [PATCH v4 13/14] drm/panfrost: Add flag to map GEM object Write-Back Cacheable Boris Brezillon
2025-10-15 16:06   ` Steven Price
2025-10-15 16:03 ` [PATCH v4 14/14] drm/panfrost: Bump the driver version to 1.6 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=20251016123217.01d32b85@fedora \
    --to=boris.brezillon@collabora.com \
    --cc=airlied@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=faith.ekstrand@collabora.com \
    --cc=kernel@collabora.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=steven.price@arm.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 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.