From: Philipp Stanner <phasta@mailbox.org>
To: "Gary Guo" <gary@garyguo.net>,
"Philipp Stanner" <phasta@kernel.org>,
"Sumit Semwal" <sumit.semwal@linaro.org>,
"Christian König" <christian.koenig@amd.com>,
"Simona Vetter" <simona.vetter@ffwll.ch>,
"Chris Wilson" <chris@chris-wilson.co.uk>,
"Danilo Krummrich" <dakr@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tvrtko Ursulin" <tvrtko.ursulin@igalia.com>
Cc: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH v2] dma-buf/dma-fence: Prevent misordering for error checks
Date: Wed, 18 Nov 2026 14:15:54 +0100 [thread overview]
Message-ID: <3792b7f8f4729820a924e0d60d17c97489827732.camel@mailbox.org> (raw)
In-Reply-To: <DMYCSXNA6VQ9.22FS1PMBBYWRO@garyguo.net>
On Wed, 2026-11-18 at 12:59 +0000, Gary Guo wrote:
> On Wed Nov 18, 2026 at 11:09 AM GMT, Philipp Stanner wrote:
[…]
> > static inline bool
> > dma_fence_test_signaled_flag(struct dma_fence *fence)
> > {
> > - return test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags);
> > + /*
> > + * Best-effort ordering of the locklessly evaluated signaled-bit,
> > + * especially so that reads of fence->error are not misordered.
>
> I am not sure if this should focus on the error, or it should just provide a
> general guarantee that anything happens before dma_fence_signal is visible when
> signal test returns true. I would lean on the latter?
See below.
>
> > + *
> > + * The release counterpart is typically ensured like this:
> > + * a) Error codes must only be set before a fence signals and
> > + * b) The fence's spinlock's barriers effective in dma_fence_signal()
> > + * ensure ordering.
>
> Spinlock has nothing to do with this. The only thing that guarantees the
> ordering is test_and_set_bit in (c).
Why not? A spinlock includes full barriers. If it were set_bit()
instead of test_and_set_bit(), it would still work.
>
> So probably easier just to say something like
>
> /* Pairs with test_and_set_bit() in dma_fence_signal_timestamp_locked */
It is easier.
I am, however, unhappy with the unclear state of the API contract. It's
still unclear what the signaled-flag even is supposed to mean. So this
comment was also supposed to hint at the unclear state.
The desired meaning aimed for by Christian is that it's only meaning is
"hardware is done".
But as we see here it has implications for the entire semantic, too:
a) signaled == true -> the error code is valid (what else?)
b) The fence has either signaled or "is still signaling", i.e. running
callbacks
I still maintain the position that it is inconsistent to run
test_and_set_bit() under lock protection and evaluate it without the
lock. Should be one or the other, not both.
Note that this patch intends just to hot-fix the error code evaluation,
not to make the fence API fully consistent. It's currently not even
clear whether manual flag evaluation is legal. It used to be legal. I'm
the one who added dma_fence_test_signaled_flag(), but mostly for
readability, not for semantic correctness.
It should be illegal to evaluate error codes with anything other than
dma_fence_get_status(). But there then the meaning of the spinlock is
currently also undefined. The lock there, with the current thinking,
would seem surplus with this patch here.
P.
next prev parent reply other threads:[~2026-11-18 13:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 11:09 Philipp Stanner
2026-11-18 12:59 ` Gary Guo
2026-11-18 13:15 ` Philipp Stanner [this message]
2026-11-18 13:49 ` 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=3792b7f8f4729820a924e0d60d17c97489827732.camel@mailbox.org \
--to=phasta@mailbox.org \
--cc=aliceryhl@google.com \
--cc=chris@chris-wilson.co.uk \
--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=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=phasta@kernel.org \
--cc=simona.vetter@ffwll.ch \
--cc=stable@vger.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
all inboxes | Powered by JetHome®