From: Philipp Stanner <phasta@mailbox.org>
To: "Christian König" <christian.koenig@amd.com>,
phasta@kernel.org, "Danilo Krummrich" <dakr@kernel.org>
Cc: Sumit Semwal <sumit.semwal@linaro.org>,
Boris Brezillon <boris.brezillon@collabora.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: Properly synchronize dma_fence->signaled bit (Was: Re: [RFC PATCH] dma-fence: Fix races of fence callbacks versus destructors by locking)
Date: Tue, 16 Jun 2026 13:25:11 +0200 [thread overview]
Message-ID: <630a8a84ee8fdaa634c7b104742e7a28fcfe507c.camel@mailbox.org> (raw)
In-Reply-To: <6ea6c373-c6cb-4221-ad9d-e60b04d1368f@amd.com>
On Mon, 2026-06-15 at 11:57 +0200, Christian König wrote:
> On 6/15/26 10:29, Philipp Stanner wrote:
> >
> > This fast path check in my mind certainly breaks the intended dma_fence
> > design:
> >
> > void dma_fence_signal_timestamp_locked(struct dma_fence *fence,
> > ktime_t timestamp)
> > {
> > const struct dma_fence_ops *ops;
> > struct dma_fence_cb *cur, *tmp;
> > struct list_head cb_list;
> >
> > dma_fence_assert_held(fence);
> >
> > if (unlikely(test_and_set_bit(DMA_FENCE_FLAG_SIGNALED_BIT,
> > &fence->flags)))
> > return;
> >
> >
> > Modifying the bit is consistently done under lock protection, so
> > reading must be done, too.
> >
> > Do you remember who wanted those fast path checks? Who is spinning on
> > that lock?
>
> Simona Vetter and basically the rest of the community.
I did some git-blame and it would seem to me that this fast-path hack
was added in
e941759c74a4 fence: dma-buf cross-device synchronization (v18)
in 2014 A.D.
So it was there from the very beginning and was not added because there
was a performance bottleneck later. It is conceivable that a
performance issue was present from the get go, of course.
>
> And I can clearly say even if I don't like them that those
> optimizations are a must have.
>
> > In any case, that needs to be repaired.
>
> No, see my discussion with Simona on the mailing list. I need to dig
> that up as well, but it was around the time I added the same
> workaround to amdgpu.
>
> You are basically trying what I have been suggesting as well, but
> there is a very wide agreement that the current design is a must
> have.
I suggest at least three things:
A.
Very explicitly document all lockless mechanisms and their
justification in both code comments and commit messages.
* We need to document lockless magic *drastically* better in DRM. I
see code left and right where there is some barrier with the comment
simply being "so list_empty() works without a lock".
* The commit message needs to justify why a lock is missing, why this
is the preferred solution, why it is correct. The latter also needs
to be in a code comment.
* Note that WRITE_ONCE() is not only about volatile, but also about
"watch out, here is a lockless access!", as Linus pointed out
repeatedly.
B.
I think rejecting ideas with "we tried this, it >>didn't work<<" is not
a valid reason for refusing an idea. Point A above helps with that. If
your commit message contains measurements or links to tickets with
*real life* performance regressions (microbenchmarks are invalid), that
helps reducing discussion overhead drastically.
Now, in this particular case, I fail to see how taking the spinlock to
check that bit is evil. If it regresses someone's speed that much, it
would mean that someone is heavily punching that lock, like polling
24/7 with dma_fence_is_signaled().
Again, having that use case documented somewhere could save us all time
– especially for you, Christian, since you wouldn't be forced to have
the same discussion over and over again over the years ;-)
C.
Robustness and correctness always trump performance. They especially
trump microbenchmarks.
P.
next prev parent reply other threads:[~2026-06-16 11:25 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
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 [this message]
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=630a8a84ee8fdaa634c7b104742e7a28fcfe507c.camel@mailbox.org \
--to=phasta@mailbox.org \
--cc=aliceryhl@google.com \
--cc=boris.brezillon@collabora.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=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
Powered by JetHome