mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Philipp Stanner <phasta@mailbox.org>
To: "Christian König" <christian.koenig@amd.com>,
	"Philipp Stanner" <phasta@kernel.org>,
	"Sumit Semwal" <sumit.semwal@linaro.org>,
	"Simona Vetter" <simona.vetter@ffwll.ch>,
	"Chris Wilson" <chris@chris-wilson.co.uk>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Gary Guo" <gary@garyguo.net>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Daniel Almeida" <daniel.almeida@collabora.com>
Cc: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org,
	 linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] dma-buf/dma-fence: Prevent misordering for error checks
Date: Tue, 17 Nov 2026 18:47:08 +0100	[thread overview]
Message-ID: <3005c4692d538785e225f9372e4a261dc457edb2.camel@mailbox.org> (raw)
In-Reply-To: <efce5fe0-6e7d-417c-93a3-35247b431448@amd.com>

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

      reply	other threads:[~2026-11-17 17:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17  9:01 Philipp Stanner
2026-11-17 14:55 ` Christian König
2026-11-17 17:47   ` Philipp Stanner [this message]

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=3005c4692d538785e225f9372e4a261dc457edb2.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 \
    /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®