From: Matthew Brost <matthew.brost@intel.com>
To: Tvrtko Ursulin <tursulin@ursulin.net>
Cc: "Christian König" <ckoenig.leichtzumerken@gmail.com>,
phasta@mailbox.org, alexdeucher@gmail.com,
simona.vetter@ffwll.ch, dri-devel@lists.freedesktop.org,
amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH 04/15] dma-buf: detach fence ops on signal
Date: Wed, 22 Oct 2025 21:23:50 -0700 [thread overview]
Message-ID: <aPmt1lZXAmom9Bko@lstrano-desk.jf.intel.com> (raw)
In-Reply-To: <23bafbad-fcc9-4baa-9bd5-d4ea37c397f3@ursulin.net>
On Thu, Oct 16, 2025 at 04:57:37PM +0100, Tvrtko Ursulin wrote:
>
> On 16/10/2025 09:56, Tvrtko Ursulin wrote:
> >
> > On 13/10/2025 14:48, Christian König wrote:
> > > When neither a release nor a wait operation is specified it is possible
> > > to let the dma_fence live on independent of the module who issued it.
> > >
> > > This makes it possible to unload drivers and only wait for all their
> > > fences to signal.
> >
> > Have you looked at whether the requirement to not have the release and
> > wait callbacks will exclude some drivers from being able to benefit from
> > this?
>
> I had a browse and this seems to be the situation:
>
> Custom .wait:
> - radeon, qxl, nouveau, i915
>
> Those would therefore still be vulnerable to the unbind->unload sequence.
> Actually not sure about qxl, but other three are PCI so in theory at least.
> I915 at least supports unbind and unload.
>
> Custom .release:
> - vgem, nouveau, lima, pvr, i915, usb-gadget, industrialio, etnaviv, xe
>
> Out of those there do not actually need a custom release and could probably
> be weaned off it:
> - usb-gadget, industrialio, etnaviv, xe
>
> (Xe would lose a debug assert and some would have their kfrees replaced with
> kfree_rcu. Plus build time asserts added the struct dma-fence remains first
> in the respective driver structs. It sounds feasible.)
FWIW, I pulled this series from Christian into Xe and attempted to
disconnect fences in Xe [1]. It seems to work in my local testing, but
let’s see what CI says.
I still needed a release callback [2] to maintain an external lock for
our HW fences and the dma-fence signaling IRQ, but it should now be
fully disconnected from the module. I coded this in about an hour, so
take it with a grain of salt.
Matt
[1] https://patchwork.freedesktop.org/series/156388/
[2] https://patchwork.freedesktop.org/patch/682962/?series=156388&rev=1
>
> That would leave us with .release in:
> - vgem, nouveau, lima, pvr, i915
>
> Combined list of custom .wait + .release:
> - radeon, qxl, nouveau, i915, lima, pvr, vgem
>
> From those the ones which support unbind and module unload would remain
> potentially vulnerable to use after free.
>
> It doesn't sound great to only solve it partially but maybe it is a
> reasonable next step. Where could we go from there to solve it for everyone?
>
> Regards,
>
> Tvrtko
>
> > > Signed-off-by: Christian König <christian.koenig@amd.com>
> > > ---
> > > drivers/dma-buf/dma-fence.c | 16 ++++++++++++----
> > > include/linux/dma-fence.h | 4 ++--
> > > 2 files changed, 14 insertions(+), 6 deletions(-)
> > >
> > > diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c
> > > index 982f2b2a62c0..39f73edf3a33 100644
> > > --- a/drivers/dma-buf/dma-fence.c
> > > +++ b/drivers/dma-buf/dma-fence.c
> > > @@ -374,6 +374,14 @@ int dma_fence_signal_timestamp_locked(struct
> > > dma_fence *fence,
> > > &fence->flags)))
> > > return -EINVAL;
> > > + /*
> > > + * When neither a release nor a wait operation is specified set
> > > the ops
> > > + * pointer to NULL to allow the fence structure to become
> > > independent
> > > + * who originally issued it.
> > > + */
> > > + if (!fence->ops->release && !fence->ops->wait)
> > > + RCU_INIT_POINTER(fence->ops, NULL);
> > > +
> > > /* Stash the cb_list before replacing it with the timestamp */
> > > list_replace(&fence->cb_list, &cb_list);
> > > @@ -513,7 +521,7 @@ dma_fence_wait_timeout(struct dma_fence *fence,
> > > bool intr, signed long timeout)
> > > rcu_read_lock();
> > > ops = rcu_dereference(fence->ops);
> > > trace_dma_fence_wait_start(fence);
> > > - if (ops->wait) {
> > > + if (ops && ops->wait) {
> > > /*
> > > * Implementing the wait ops is deprecated and not
> > > supported for
> > > * issuer independent fences, so it is ok to use the ops
> > > outside
> > > @@ -578,7 +586,7 @@ void dma_fence_release(struct kref *kref)
> > > }
> > > ops = rcu_dereference(fence->ops);
> > > - if (ops->release)
> > > + if (ops && ops->release)
> > > ops->release(fence);
> > > else
> > > dma_fence_free(fence);
> > > @@ -614,7 +622,7 @@ static bool __dma_fence_enable_signaling(struct
> > > dma_fence *fence)
> > > rcu_read_lock();
> > > ops = rcu_dereference(fence->ops);
> > > - if (!was_set && ops->enable_signaling) {
> > > + if (!was_set && ops && ops->enable_signaling) {
> > > trace_dma_fence_enable_signal(fence);
> > > if (!ops->enable_signaling(fence)) {
> > > @@ -1000,7 +1008,7 @@ void dma_fence_set_deadline(struct dma_fence
> > > *fence, ktime_t deadline)
> > > rcu_read_lock();
> > > ops = rcu_dereference(fence->ops);
> > > - if (ops->set_deadline && !dma_fence_is_signaled(fence))
> > > + if (ops && ops->set_deadline && !dma_fence_is_signaled(fence))
> > > ops->set_deadline(fence, deadline);
> > > rcu_read_unlock();
> > > }
> > > diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h
> > > index 38421a0c7c5b..e1ba1d53de88 100644
> > > --- a/include/linux/dma-fence.h
> > > +++ b/include/linux/dma-fence.h
> > > @@ -425,7 +425,7 @@ dma_fence_is_signaled_locked(struct dma_fence *fence)
> > > rcu_read_lock();
> > > ops = rcu_dereference(fence->ops);
> > > - if (ops->signaled && ops->signaled(fence)) {
> > > + if (ops && ops->signaled && ops->signaled(fence)) {
> > > rcu_read_unlock();
> > > dma_fence_signal_locked(fence);
> > > return true;
> > > @@ -461,7 +461,7 @@ dma_fence_is_signaled(struct dma_fence *fence)
> > > rcu_read_lock();
> > > ops = rcu_dereference(fence->ops);
> > > - if (ops->signaled && ops->signaled(fence)) {
> > > + if (ops && ops->signaled && ops->signaled(fence)) {
> > > rcu_read_unlock();
> > > dma_fence_signal(fence);
> > > return true;
> >
>
next prev parent reply other threads:[~2025-10-23 4:24 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-13 13:48 Independence for dma_fences! Christian König
2025-10-13 13:48 ` [PATCH 01/15] dma-buf: cleanup dma_fence_describe Christian König
2025-10-14 14:37 ` Tvrtko Ursulin
2025-10-23 3:45 ` Matthew Brost
2025-10-13 13:48 ` [PATCH 02/15] dma-buf: rework stub fence initialisation Christian König
2025-10-14 15:03 ` Tvrtko Ursulin
2025-10-24 7:29 ` Tvrtko Ursulin
2025-10-13 13:48 ` [PATCH 03/15] dma-buf: protected fence ops by RCU Christian König
2025-10-16 18:04 ` Tvrtko Ursulin
2025-10-31 10:35 ` Tvrtko Ursulin
2025-10-13 13:48 ` [PATCH 04/15] dma-buf: detach fence ops on signal Christian König
2025-10-16 8:56 ` Tvrtko Ursulin
2025-10-16 15:57 ` Tvrtko Ursulin
2025-10-23 4:23 ` Matthew Brost [this message]
2025-10-23 4:44 ` Matthew Brost
2025-10-30 13:52 ` Christian König
2025-10-31 10:31 ` Tvrtko Ursulin
2025-10-17 9:14 ` Philipp Stanner
2025-10-30 15:05 ` Christian König
2025-10-13 13:48 ` [PATCH 05/15] dma-buf: inline spinlock for fence protection Christian König
2025-10-16 9:26 ` Tvrtko Ursulin
2025-11-03 13:07 ` Philipp Stanner
2025-10-23 18:09 ` Matthew Brost
2025-10-30 15:14 ` Christian König
2025-10-13 13:48 ` [PATCH 06/15] dma-buf: use inline lock for the stub fence Christian König
2025-10-13 13:48 ` [PATCH 07/15] dma-buf: use inline lock for the dma-fence-array Christian König
2025-10-13 13:48 ` [PATCH 08/15] dma-buf: use inline lock for the dma-fence-chain Christian König
2025-10-13 13:48 ` [PATCH 09/15] drm/sched: use inline locks for the drm-sched-fence Christian König
2025-10-13 13:48 ` [PATCH 10/15] drm/amdgpu: fix KFD eviction fence enable_signaling path Christian König
2025-10-13 13:48 ` [PATCH 11/15] drm/amdgpu: independence for the amdgpu_fence! Christian König
2025-10-13 13:48 ` [PATCH 12/15] drm/amdgpu: independence for the amdgpu_eviction_fence! Christian König
2025-10-13 13:48 ` [PATCH 13/15] drm/amdgpu: independence for the amdgpu_vm_tlb_fence! Christian König
2025-10-13 13:48 ` [PATCH 14/15] drm/amdgpu: independence for the amdkfd_fence! Christian König
2025-10-17 22:22 ` Felix Kuehling
2025-10-30 15:07 ` Christian König
2025-10-30 20:04 ` Felix Kuehling
2025-10-13 13:48 ` [PATCH 15/15] drm/amdgpu: independence for the amdgpu_userq__fence! Christian König
2025-10-13 14:54 ` Independence for dma_fences! Philipp Stanner
2025-10-14 15:54 ` Christian König
2025-10-17 8:32 ` Philipp Stanner
2025-10-28 14:06 ` Christian König
2025-10-29 20:53 ` Matthew Brost
2025-10-30 10:59 ` Christian König
2025-10-31 17:44 ` Matthew Brost
2025-11-03 11:43 ` Christian König
2025-11-03 19:32 ` Matthew Brost
2025-10-15 0:51 ` Dave Airlie
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=aPmt1lZXAmom9Bko@lstrano-desk.jf.intel.com \
--to=matthew.brost@intel.com \
--cc=alexdeucher@gmail.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=ckoenig.leichtzumerken@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=phasta@mailbox.org \
--cc=simona.vetter@ffwll.ch \
--cc=tursulin@ursulin.net \
/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.