Re: [PATCH] dma-buf/dma-fence: Prevent misordering for error checks
From: Philipp Stanner
Date: Tue Nov 17 2026 - 12:47:25 EST
On Tue, 2026-11-17 at 15:55 +0100, Christian König wrote:
> On 11/17/26 10:01, Philipp Stanner wrote:
> > Many users of dma_fence do things like:
> >
> > // Thread A
> > dma_fence_set_error(f, -EINVAL);
> > dma_fence_signal(f); // <- Takes lock, which orders against the above.
> >
> > // Thread B
> > if (dma_fence_is_signaled(f)) // <- Does test_bit(), no ordering.
> > pr_info("err: %i\n", f->error); // <- Can be loaded first.
[…]
> > + // test_and_set_bit() should do the trick.
>
> That should probably be a C comment, e.g. /* ... */.
huh, how did that happen…
-ETOOMUCHRUST
I provide a v2
> Apart from that really good catch.
Found without any LLM 8-)
I saw it while reworking Rust-fence to force users to always evaluate a
fence's error code, i.e., you can only check whether a fence is
signaled when you also check for the error.
dma_fence_is_signaled() incentivizes wrong behavior.
But btw. we really want to carefully rethink our beloved signaled-bit
and its semantics. Mind all our past discussions about it.
This patch is more like a temporary hotfix. Much of our API is quite
fragile.
Regards
Philipp