From: Boris Brezillon <boris.brezillon@collabora.com>
To: Philipp Stanner <phasta@mailbox.org>
Cc: phasta@kernel.org, "Danilo Krummrich" <dakr@kernel.org>,
"Sumit Semwal" <sumit.semwal@linaro.org>,
"Christian König" <christian.koenig@amd.com>,
"Alice Ryhl" <aliceryhl@google.com>,
"Daniel Almeida" <dwlsalmeida@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Tvrtko Ursulin" <tvrtko.ursulin@igalia.com>,
linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH] dma-fence: Fix races of fence callbacks versus destructors by locking
Date: Mon, 8 Jun 2026 18:16:30 +0200 [thread overview]
Message-ID: <20260608181630.20145d1c@fedora-2.home> (raw)
In-Reply-To: <256dc5ae3529e2548c4151af34a540476ac928c1.camel@mailbox.org>
On Mon, 08 Jun 2026 17:30:58 +0200
Philipp Stanner <phasta@mailbox.org> wrote:
> On Mon, 2026-06-08 at 17:23 +0200, Danilo Krummrich wrote:
> > On Mon Jun 8, 2026 at 5:17 PM CEST, Philipp Stanner wrote:
> > > On Mon, 2026-06-08 at 17:01 +0200, Boris Brezillon wrote:
> > > > On Mon, 8 Jun 2026 16:24:37 +0200
> > > > Philipp Stanner <phasta@kernel.org> wrote:
> > > >
> > > > > @@ -1020,11 +1024,20 @@ EXPORT_SYMBOL(dma_fence_wait_any_timeout);
> > > > > void dma_fence_set_deadline(struct dma_fence *fence, ktime_t deadline)
> > > > > {
> > > > > const struct dma_fence_ops *ops;
> > > > > + unsigned long flags;
> > > > >
> > > > > rcu_read_lock();
> > > > > ops = rcu_dereference(fence->ops);
> > > > > - if (ops && ops->set_deadline && !dma_fence_is_signaled(fence))
> > > > > + if (!ops || !ops->set_deadline) {
> > > > > + rcu_read_unlock();
> > > > > + return;
> > > > > + }
> > > > > +
> > > > > + dma_fence_lock_irqsave(fence, flags);
> > > > > + if (!dma_fence_is_signaled_locked(fence))
> > > > > ops->set_deadline(fence, deadline);
> > > >
> > > > You can't take the fence lock around ->set_deadline(), otherwise you'll
> > > > deadlock here [1] or here [2].
> > > >
> > > > > +
> > > > > + dma_fence_unlock_irqrestore(fence, flags);
> > > > > rcu_read_unlock();
> > > > > }
> > > >
> > > >
> > > > [1]https://elixir.bootlin.com/linux/v7.0.11/source/drivers/dma-buf/sw_sync.c#L182
> > > > [2]https://elixir.bootlin.com/linux/v7.0.11/source/drivers/gpu/drm/msm/msm_fence.c#L139
>
> Oh, MSM actually doesn't btw, that's a false positive. That's a
> distinct spinlock on their fence context object.
It's not, it's the same lock they attach to all their fences coming
from this context. It's just that this lock appears to be per-context,
like is the case for basically every driver, since the inline lock was
introduced only in this release cycle.
Anyway, this is all stuff we can fix if people think it's okay to
protect dma_fence_ops calls with the fence lock. But my point remains:
each op has its own locking-rules, some are called with the fence lock
held (enable_signaling(), signaled()), others are not (set_deadline(),
get_xxx_name()), so we need to carefully audit each of those to make
sure:
- calling with the lock held in the new places is not causing a
deadlock
- the returned data, if not a scalar, is protected by the RCU read lock
- any driver implementing ops that can be called without the lock held
need to hold on the device data for an RCU grace period
The last bullet is probably the one I'm the most worried about, because
instead of a single rule that applies to all ops, we have various cases
based on whether some ops are implemented or not, but that's already
the case with deprecated ops like .release() or .wait(), so maybe
that's okay with the proper doc.
If I were to choose, I'd probably go for a dedicated rwlock_t to
protect dma_fence_ops, so we can:
- protect all dma_buf_ops::xx() consistently no matter the kind of op
- protect returned data (get_xxx_name()) with this lock instead of the
RCU read lock
But the overhead of this extra lock might not be acceptable, dunno.
>
>
> But yes, before we could upstream this, we would go through all the
> implementors like Danilo did, to find all the others.
There's the two I pointed out, plus the array/chain containers I
mentioned, which are not problematic.
next prev parent reply other threads:[~2026-06-08 16:16 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-08 14:24 [RFC PATCH] dma-fence: Fix races of fence callbacks versus destructors by locking Philipp Stanner
2026-06-08 15:01 ` Boris Brezillon
2026-06-08 15:17 ` Philipp Stanner
2026-06-08 15:23 ` Danilo Krummrich
2026-06-08 15:30 ` Boris Brezillon
2026-06-08 15:30 ` Philipp Stanner
2026-06-08 16:16 ` Boris Brezillon [this message]
2026-06-09 8:02 ` Christian König
2026-06-09 8:54 ` Philipp Stanner
2026-06-09 8:43 ` Philipp Stanner
2026-06-09 8:47 ` Christian König
2026-06-09 9:00 ` Philipp Stanner
2026-06-08 15:07 ` Tvrtko Ursulin
2026-06-08 15:15 ` Philipp Stanner
2026-06-08 15:35 ` Christian König
2026-06-08 15:41 ` Philipp Stanner
2026-06-08 17:34 ` Christian König
2026-06-08 17:59 ` Danilo Krummrich
2026-06-08 18:32 ` Christian König
2026-06-08 18:39 ` Danilo Krummrich
2026-06-08 18:47 ` Christian König
2026-06-08 19:25 ` Danilo Krummrich
2026-06-09 8:17 ` Christian König
2026-06-09 5:52 ` Philipp Stanner
2026-06-09 10:26 ` Christian König
2026-06-09 10:42 ` Philipp Stanner
2026-06-09 10:53 ` Christian König
2026-06-09 11:39 ` Philipp Stanner
2026-06-09 13:19 ` Philipp Stanner
2026-06-09 13:34 ` Christian König
2026-06-10 14:25 ` Philipp Stanner
2026-06-10 15:15 ` Christian König
2026-06-11 8:35 ` Philipp Stanner
2026-06-11 9:14 ` Christian König
2026-06-11 9:50 ` Philipp Stanner
2026-06-11 11:06 ` Christian König
2026-06-09 13:36 ` Tvrtko Ursulin
2026-06-09 13:57 ` Philipp Stanner
2026-06-09 14:03 ` Christian König
2026-06-15 8:29 ` Properly synchronize dma_fence->signaled bit (Was: Re: [RFC PATCH] dma-fence: Fix races of fence callbacks versus destructors by locking) Philipp Stanner
2026-06-15 9:57 ` Christian König
2026-06-16 11:25 ` Philipp Stanner
2026-06-17 9:46 ` Christian König
2026-06-17 10:16 ` Philipp Stanner
2026-06-17 13:03 ` Christian König
2026-06-17 13:21 ` Philipp Stanner
2026-06-17 13:50 ` Gary Guo
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=20260608181630.20145d1c@fedora-2.home \
--to=boris.brezillon@collabora.com \
--cc=aliceryhl@google.com \
--cc=christian.koenig@amd.com \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=dwlsalmeida@gmail.com \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=phasta@kernel.org \
--cc=phasta@mailbox.org \
--cc=sumit.semwal@linaro.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox