From: Boris Brezillon <boris.brezillon@collabora.com>
To: "Christian König" <christian.koenig@amd.com>
Cc: phasta@kernel.org, dakr@kernel.org,
Tvrtko Ursulin <tvrtko.ursulin@igalia.com>,
dri-devel <dri-devel@lists.freedesktop.org>
Subject: Re: dma_fence: force users to take the lock manually
Date: Fri, 6 Mar 2026 12:24:17 +0100 [thread overview]
Message-ID: <20260306122417.6febebf4@fedora> (raw)
In-Reply-To: <b5830a15-af9f-47b0-a811-d43c0c3828dd@amd.com>
On Fri, 6 Mar 2026 12:03:19 +0100
Christian König <christian.koenig@amd.com> wrote:
> On 3/6/26 11:37, Boris Brezillon wrote:
> > On Fri, 6 Mar 2026 10:58:07 +0100
> > Christian König <christian.koenig@amd.com> wrote:
> >
> >> On 3/6/26 10:46, Boris Brezillon wrote:
> >>> On Fri, 6 Mar 2026 09:10:52 +0100
> >>> Christian König <christian.koenig@amd.com> wrote:
> >>>> Well as I wrote above you either have super reliable locking in
> >>>> your signaling path or you will need that for error handling.
> >>>
> >>> Not really. With rust's ownership model, you can make it so only
> >>> one thread gets to own the DriverFence (the signal-able fence
> >>> object), and the DriverFence::signal() method consumes this
> >>> object. This implies that only one path gets to signal the
> >>> DriverFence, and after that it vanishes, so no one else can
> >>> signal it anymore. Just to clarify, by vanishes, I mean that the
> >>> signal-able view disappears, but the observable object (Fence)
> >>> can stay around, so it can be monitored (and only monitored) by
> >>> others. With this model, it doesn't matter that _set_error() is
> >>> set under a dma_fence locked section or not, because the
> >>> concurrency is addressed at a higher level.
> >>
> >> That whole approach won't work. You have at least the IRQ handler
> >> which signals completion and the timeout handler which signals
> >> completion with an error.
> >
> > From a pure rust standpoint, and assuming both path (IRQ handler and
> > timeout handler) are written in rust, the compiler won't let you
> > signal concurrently if we design the thing properly, that's what
> > I'm trying to say. Just to be clear, it doesn't mean you can't have
> > one worker (in a workqueue context) that can signal a fence and an
> > IRQ handler that can signal the same fence. It just means that rust
> > won't let you do that unless you have proper locking in place, and
> > rust will also guarantee you won't be able to signal a fence that
> > has already been signaled, because as soon as it's signaled, the
> > signal-able fence should be consumed.
>
> Ah got it! I've worked a lot with OCaml in the past which has some
> similarities, but doesn't push things that far.
>
> >>
> >> We have documented that this handling is mandatory for DMA-fences
> >> since so many driver implementations got it wrong.
> >
> > Again, I'm just talking about the rust implementation we're aiming
> > for. If you start mixing C and rust in the same driver, you're back
> > to the original problem you described.
>
> The key point is the Rust implementation should not repeat the
> mistakes we made in the C implementation.
>
> For example blocking that multiple threads can't signal a DMA-fence
> is completely irrelevant.
From a correctness standpoint, I think it's important to ensure no more
than one thread gets to signal the object.
>
> What we need to guarantee is correct timeout handling and that
> DMA-fence can only signal from something delivered from a HW event,
> e.g. a HW interrupt or interrupt worker or similar.
We've mostly focused on coming up with a solution that would annotate
signaling paths in an automated way, and making sure dma_fence_signal()
is never called outside of a non-annotated path:
- creation of DmaFenceWorkqueue/DmaFence[Delayed]Work that guarantees
all works are executed in a dma_fence_signalling_{begin,end}()
section, so we can properly detect deadlocks (through lockdep)
- creation of a DmaFenceIrqHandler for the same reason
- we'll need variants for each new deferred mechanism drivers might
want to use (kthread_worker?)
But there's currently no restriction on calling dma_fence_signal() in a
user thread context (IOCTL()). I guess that shouldn't be too hard to
add (is_user_task() to the rescue).
>
> A DMA-fence should *never* signal because of an IOCTL
Okay, that's understandable.
> or because some
> object runs out of scope. E.g. when you cleanup a HW ring buffer, FW
> queue, etc...
We were actually going in the opposite direction:
auto-signal(ECANCELED) on DriverFenceTimeline object destruction (which
is the thing that would be attached to the HW ringbuf. The reason is:
we don't want to leave unsignalled fences behind, and if the HW ring is
gone, there's nothing that can signal it. Mind explaining why you think
this shouldn't be done, because I originally interpreted your
suggestion as exactly the opposite.
next prev parent reply other threads:[~2026-03-06 11:24 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-05 13:54 dma_fence: force users to take the lock manually Philipp Stanner
2026-03-05 13:59 ` Christian König
2026-03-05 15:12 ` Boris Brezillon
2026-03-06 8:10 ` Christian König
2026-03-06 9:46 ` Boris Brezillon
2026-03-06 9:54 ` Philipp Stanner
2026-03-06 10:27 ` Boris Brezillon
2026-03-06 9:58 ` Christian König
2026-03-06 10:37 ` Boris Brezillon
2026-03-06 11:03 ` Christian König
2026-03-06 11:24 ` Boris Brezillon [this message]
2026-03-06 11:57 ` Philipp Stanner
2026-03-06 12:31 ` Christian König
2026-03-06 12:36 ` Philipp Stanner
2026-03-06 12:54 ` Christian König
2026-03-06 14:55 ` Boris Brezillon
2026-03-09 9:33 ` Christian König
2026-03-09 15:06 ` Boris Brezillon
2026-03-09 16:46 ` Christian König
2026-03-06 13:03 ` Danilo Krummrich
2026-03-06 13:15 ` Christian König
2026-03-06 13:36 ` Philipp Stanner
2026-03-06 14:37 ` Christian König
2026-03-06 15:25 ` Boris Brezillon
2026-03-06 15:43 ` Boris Brezillon
2026-03-06 19:02 ` Philipp Stanner
2026-03-09 8:16 ` Boris Brezillon
2026-03-09 9:36 ` Christian König
2026-03-06 14:21 ` Boris Brezillon
2026-03-06 12:48 ` 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=20260306122417.6febebf4@fedora \
--to=boris.brezillon@collabora.com \
--cc=christian.koenig@amd.com \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=phasta@kernel.org \
--cc=tvrtko.ursulin@igalia.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.