public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@collabora.com>
To: Philipp Stanner <phasta@mailbox.org>
Cc: phasta@kernel.org, "Gary Guo" <gary@garyguo.net>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Christian König" <christian.koenig@amd.com>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Joel Fernandes" <joelagnelf@nvidia.com>,
	linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
	rust-for-linux@vger.kernel.org
Subject: Re: [RFC PATCH 2/4] rust: sync: Add dma_fence abstractions
Date: Fri, 6 Feb 2026 12:04:42 +0100	[thread overview]
Message-ID: <20260206120442.51c5ca75@fedora> (raw)
In-Reply-To: <62b82ffdd40d568d822bda8cdea83cd030851f68.camel@mailbox.org>

On Fri, 06 Feb 2026 10:32:38 +0100
Philipp Stanner <phasta@mailbox.org> wrote:

> On Thu, 2026-02-05 at 13:16 +0000, Gary Guo wrote:
> > On Thu Feb 5, 2026 at 10:16 AM GMT, Boris Brezillon wrote:  
> > > On Tue,  3 Feb 2026 09:14:01 +0100
> > > Philipp Stanner <phasta@kernel.org> wrote:
> > >   
> > > >   
> 
> […]
> 
> > > > +#[pin_data]
> > > > +pub struct DmaFence<T> {
> > > > +    /// The actual dma_fence passed to C.
> > > > +    #[pin]
> > > > +    inner: Opaque<bindings::dma_fence>,
> > > > +    /// User data.
> > > > +    #[pin]
> > > > +    data: T,  
> > > 
> > > A DmaFence is a cross-device synchronization mechanism that can (and
> > > will)
> > >   
> 
> I'm not questioning the truth behind this statement. They are designed
> to do that. But is that actually being done, currently? I recently
> found that the get_driver_name() callback intended to inform the
> consumer of a fence about who actually issued the fence is only ever
> used by i915.
> 
> Who actually uses that feature? Who needs fences from another driver?

Display controller (AKA KMS) drivers waiting on fences emitted by a GPU
driver, for instance.

> 
> Just out of curiousity
> 
> 
> > >  cross the driver boundary (one driver can wait on a fence emitted
> > > by a different driver). As such, I don't think embedding a generic T in
> > > the DmaFence and considering it's the object being passed around is
> > > going to work, because, how can one driver know the T chosen by the
> > > driver that created the fence? If you want to have some fence emitter
> > > data attached to the DmaFence allocation, you'll need two kind of
> > > objects:
> > > 
> > > - one that's type agnostic and on which you can do the callback
> > >   registration/unregistration, signalling checks, and generally all
> > >   type-agnostic operations. That's basically just a wrapper around a
> > >   bindings::dma_fence implementing AlwaysRefCounted.
> > > - one that has the extra data and fctx, with a way to transmute from a
> > >   generic fence to a implementer specific one in case the driver wants
> > >   to do something special when waiting on its own fences (check done
> > >   with the fence ops in C, I don't know how that translates in rust)  
> > 
> > If `data` is moved to the end of struct and `DmaFence<T>` changed to
> > `DmaFence<T: ?Sized>`, you would also gain the ability to coerce `DmaFence<T>`
> > to `DmaFence<dyn Trait>`, e.g. `DmaFence<dyn Any>`.  
> 
> 
> I think we should go one step back here and question the general
> design.
> 
> I only included data: T because it was among the early feedback that
> this is how you do it in Rust.
> 
> I was never convinced that it's a good idea. Jobqueue doesn't need the
> 'data' field. Can anyone think of anyone who would need it?
> 
> What kind of data would be in there? It seems a driver would store its
> equivalent of C's
> 
> struct my_fence {
>    struct dma_fence f;
>    /* other driver data */
> }
> 
> which is then accessed in C with container_of.
> 
> But that data is only ever needed by that very driver.
> 
> 
> My main point here is:
> dma_fence's are a synchronization primitive very similar to
> completions: informing about that something is done, executing every
> registrants callbacks.
> 
> They are *not* a data transfer mechanism. It seems very wrong design-
> wise to transfer generic data T from one driver to another. That's not
> a fence's purpose. Another primitive should be used for that.
> 
> If another driver could touch / consume / see / use the emitter's data:
> T, that would grossly decouple us from the original dma_fence design.
> It would be akin to doing a container_of to consume foreign driver
> data.
> 
> Like Xe  doing a
> 
> struct nouveau_fence *f = container_of(generic_fence, …);
> 
> Why would that ever be done? Seems totally broken.
> 
> So I strongly think that we'd either want to drop data: T, or we should
> think about possibilities to hide it from other drivers.
> 
> I've got currently no idea how that could be addressed in Rust, though 

So, as Danilo explained in his reply, there's two kind of users:

1. those that want to wait on fences (that'd be the JobQueue, for
   instance)
2. those that are emitting fences (AKA those implementing the fence_ops
   in C)

And each of them should be given different access to the underlying
dma_fence, hence the proposal to have different objects to back
those concepts.

  parent reply	other threads:[~2026-02-06 11:04 UTC|newest]

Thread overview: 103+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-03  8:13 [RFC PATCH 0/4] Add dma_fence abstractions and DRM Jobqueue Philipp Stanner
2026-02-03  8:14 ` [RFC PATCH 1/4] rust: list: Add unsafe for container_of Philipp Stanner
2026-02-03 15:25   ` Gary Guo
2026-02-04 10:30   ` Alice Ryhl
2026-02-03  8:14 ` [RFC PATCH 2/4] rust: sync: Add dma_fence abstractions Philipp Stanner
2026-02-05  8:57   ` Boris Brezillon
2026-02-06 10:23     ` Danilo Krummrich
2026-02-09  8:19       ` Philipp Stanner
2026-02-09 14:58         ` Boris Brezillon
2026-02-10  8:16           ` Christian König
2026-02-10  8:38             ` Alice Ryhl
2026-02-10  9:06               ` Philipp Stanner
2026-02-10  9:54                 ` Christian König
2026-02-10  9:15               ` Boris Brezillon
2026-02-10 10:15                 ` Alice Ryhl
2026-02-10 10:36                   ` Danilo Krummrich
2026-02-10 10:46                     ` Christian König
2026-02-10 11:40                       ` Alice Ryhl
2026-02-10 12:28                         ` Boris Brezillon
2026-02-11  9:57                         ` Danilo Krummrich
2026-02-11 10:08                           ` Philipp Stanner
2026-02-11 10:28                             ` Boris Brezillon
2026-02-11 10:20                           ` Boris Brezillon
2026-02-11 11:00                             ` Danilo Krummrich
2026-02-11 11:12                               ` Boris Brezillon
2026-02-11 14:38                                 ` Danilo Krummrich
2026-02-11 15:00                                   ` Boris Brezillon
2026-02-11 15:05                                     ` Danilo Krummrich
2026-02-11 15:14                                       ` Boris Brezillon
2026-02-11 15:16                                         ` Danilo Krummrich
2026-03-13 17:27                                     ` Matthew Brost
2026-02-10 10:46                   ` Boris Brezillon
2026-02-10 11:34                   ` Boris Brezillon
2026-02-10 11:45                     ` Alice Ryhl
2026-02-10 12:21                       ` Boris Brezillon
2026-02-10 13:34                         ` Alice Ryhl
2026-02-10 12:36                   ` Boris Brezillon
2026-02-10 13:15                     ` Alice Ryhl
2026-02-10 13:26                       ` Boris Brezillon
2026-02-10 13:49                         ` Alice Ryhl
2026-02-10 13:56                           ` Christian König
2026-02-10 14:00                             ` Philipp Stanner
2026-02-10 14:06                               ` Christian König
2026-02-10 15:32                                 ` Philipp Stanner
2026-02-10 15:50                                   ` Christian König
2026-02-10 15:07                             ` Alice Ryhl
2026-02-10 15:45                               ` Christian König
2026-02-11  8:16                                 ` Philipp Stanner
2026-02-17 14:03                                 ` Philipp Stanner
2026-02-17 14:09                                   ` Alice Ryhl
2026-02-17 14:22                                     ` Christian König
2026-02-17 14:28                                       ` Philipp Stanner
2026-02-17 14:44                                         ` Danilo Krummrich
2026-03-13 23:20                                           ` Matthew Brost
2026-02-17 15:01                                         ` Christian König
2026-02-18  9:50                                         ` Alice Ryhl
2026-02-18 10:48                                           ` Boris Brezillon
2026-02-10 12:49                   ` Boris Brezillon
2026-02-10 12:56                     ` Boris Brezillon
2026-02-10 13:26                     ` Alice Ryhl
2026-02-10 13:51                       ` Boris Brezillon
2026-02-10 14:11                         ` Alice Ryhl
2026-02-10 14:50                           ` Boris Brezillon
2026-02-11  8:16                             ` Alice Ryhl
2026-02-11  9:20                               ` Boris Brezillon
2026-02-10  9:26               ` Christian König
2026-02-05 10:16   ` Boris Brezillon
2026-02-05 13:16     ` Gary Guo
2026-02-06  9:32       ` Philipp Stanner
2026-02-06 10:16         ` Danilo Krummrich
2026-02-06 13:24           ` Philipp Stanner
2026-02-06 11:04         ` Boris Brezillon [this message]
2026-02-09  8:21           ` Philipp Stanner
2026-02-06 11:23         ` Boris Brezillon
2026-02-09 11:30   ` Alice Ryhl
2026-02-03  8:14 ` [RFC PATCH 3/4] rust/drm: Add DRM Jobqueue Philipp Stanner
2026-02-10 14:57   ` Boris Brezillon
2026-02-11 10:47     ` Philipp Stanner
2026-02-11 11:07       ` Boris Brezillon
2026-02-11 11:19         ` Danilo Krummrich
2026-02-11 12:10           ` Boris Brezillon
2026-02-11 12:32             ` Danilo Krummrich
2026-02-11 12:51               ` Boris Brezillon
2026-02-11 11:19         ` Philipp Stanner
2026-02-11 11:59           ` Boris Brezillon
2026-02-11 12:14             ` Philipp Stanner
2026-02-11 12:24               ` Boris Brezillon
2026-02-11 12:22           ` Alice Ryhl
2026-02-11 12:44             ` Philipp Stanner
2026-02-11 12:52               ` Alice Ryhl
2026-02-11 13:53                 ` Philipp Stanner
2026-02-11 15:28                   ` Alice Ryhl
2026-02-11 12:45             ` Danilo Krummrich
2026-02-11 13:45             ` Gary Guo
2026-02-11 14:07               ` Boris Brezillon
2026-02-11 15:17                 ` Alice Ryhl
2026-02-11 15:20                   ` Philipp Stanner
2026-02-11 15:51                     ` Boris Brezillon
2026-02-11 15:53                     ` Alice Ryhl
2026-02-11 15:54                     ` Danilo Krummrich
2026-02-11 15:33               ` Alice Ryhl
2026-02-03  8:14 ` [RFC PATCH 4/4] samples: rust: Add jobqueue tester Philipp Stanner
2026-02-03 16:46 ` [RFC PATCH 0/4] Add dma_fence abstractions and DRM Jobqueue Daniel Almeida

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=20260206120442.51c5ca75@fedora \
    --to=boris.brezillon@collabora.com \
    --cc=airlied@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=christian.koenig@amd.com \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gary@garyguo.net \
    --cc=joelagnelf@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=phasta@kernel.org \
    --cc=phasta@mailbox.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=simona@ffwll.ch \
    /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