From: Philipp Stanner <phasta@mailbox.org>
To: "Christian König" <christian.koenig@amd.com>,
"Danilo Krummrich" <dakr@kernel.org>
Cc: phasta@kernel.org, "Sumit Semwal" <sumit.semwal@linaro.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rust: DamFence: Remove warning about unsignaled drop
Date: Thu, 19 Nov 2026 10:58:57 +0100 [thread overview]
Message-ID: <202dd0c3d515ddfa77a8ec8751badadd31b8a7b0.camel@mailbox.org> (raw)
In-Reply-To: <a7f9e0f3-b299-4d40-9230-106003725dc2@amd.com>
On Thu, 2026-11-19 at 10:32 +0100, Christian König wrote:
> On 11/17/26 17:36, Danilo Krummrich wrote:
> > Drivers often reference count representations of hardware resources and hardware
> > states and hence keep them alive beyond what their actual lifetime should be --
> > even beyond driver unbind.
>
> Yeah, I agree 100% with that. I know why drivers do this and there are unfortunately really good reason for that.
To me it seems more that we are often working around fundamental design
errors. What good reasons come to mind?
>
> > This causes lot's of issues and I'm looking into fixing this up, see my talk in
> > [1] and an example from Xe [2] for reference.
> >
> > That said, in Rust we don't have this kind of ambiguity, lifetime and ownership
> > of resources are well defined and the core infrastructure guides drivers
> > accordingly.
>
> I disagree, you do have that in Rust as well.
>
> Background is that the fundamental problem of having two signaling
> directions which want to define lifetime differently doesn't go away
> because you switch the programming language.
For Rust DmaFence, this is addressed by having two distinct objects
sharing the same refcounted memory, DriverFence and Fence.
Dropping / signaling DriverFence is the decoupling point.
Which is by the way why I am trying to convince you so hard to give me
the spinlock, to make this simpler and fully sync ;)
> But even in Rust there is still the need to give HW drivers something
> like a template in which is defined how things should be done and
> what things need to be avoided.
see below
>
> > Consequently, it is perfectly reasonable to assume that a driver object that
> > owns device resources (such as DMA memory) will, in its destructor, tear down
> > the hardware to not access any of the resources it owns anymore.
>
> Exactly that is a pattern I have seen many many times before and I
> can say from experience that it is very prone to human errors as
> well.
Danilo's argument is that the object that halts the hardware is the
same that owns the fences.
You drop the hardware-ring-object, this halts the ring, waits for it
synchronously, then the fences drop and signal. Of course, you can
additionally signal them manually before their drop with another error
code than the default.
> > Insisting on an explicit method call is not improving anything in this model.
>
> I'm not insisting on an explicit method call.
>
> What I'm insisting on is that the response from the HW that the DMA
> operation has stopped is signaling the fence.
That is effectively the case, see above.
> And not that driver tell the HW stop DMA and then continue and dma
> fence is automatically signaled without explicitly saying that is the
> signal that DMA operations are stopped.
Again, the main point here is that the object layout ensures *exactly*
what you want, Christian
Like this, pseudocode
// Drops first, stops hardware
struct exec_context {
// drops second
jq: JobQueue, // signals remaining fences when it drops
}
It's maybe more implicit, but ensures exactly what needs to be ensured.
That's how teardown is done in Rust. You drop the lock, it unlocks
itself. You drop the memory, it frees itself. You drop the fence, it
signals itself.
That's by design because the object lifetime model falls naturally into
place.
> I think the most defensive way would be as last resort scream loud in
> the logs that the driver is somehow buggy and hasn't signaled it's
> fence, wait for a certain amount of time (100ms?) as safeguard and
> then signal the fence with an error.
Now that doesn't make any sense at all, either the hardware is stopped
or it isn't. Having some random delay is probably even worse because
the problem is then more difficult to even encounter and thus fix.
> Exactly that is what I disagree on.
>
> Stopping the HW is what makes fences signal and that is what this
> tear down process should block for.
Our point is that dropping stuff stops the hardware, and *then* signals
the fences. Exactly what you want! :)
> Well the question is can we enforce this?
>
> I mean there are usually only limited options from the compiler side
> to enforce things, but we should still push developers to use well
> proven patterns and coding practices.
You currently cannot prevent people from refcounting stuff if they
really want to. The Rust language is working on enforcing that, too,
though
https://goals.rust-lang.org/2026/move-trait.html
btw the best feature that Rust offers IMO is that the refcounting is at
least always right. That's quite cool. A great many hacks I've seen
stem from the fact that programmers are not disciplined when it comes
to copying pointers and their refcount.
P.
next prev parent reply other threads:[~2026-11-19 9:59 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 10:10 [PATCH] rust: DamFence: Remove warning about unsignaled drop Philipp Stanner
2026-11-12 10:29 ` Christian König
2026-11-17 8:24 ` Philipp Stanner
2026-11-17 9:51 ` Christian König
2026-11-17 10:54 ` Philipp Stanner
2026-11-17 13:40 ` Christian König
2026-11-17 13:50 ` Danilo Krummrich
2026-11-17 14:50 ` Christian König
2026-11-17 16:26 ` Gary Guo
2026-11-17 16:36 ` Danilo Krummrich
2026-11-19 9:32 ` Christian König
2026-11-19 9:58 ` Philipp Stanner [this message]
2026-11-19 10:47 ` Christian König
2026-11-19 12:35 ` Danilo Krummrich
2026-11-17 14:06 ` Danilo Krummrich
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=202dd0c3d515ddfa77a8ec8751badadd31b8a7b0.camel@mailbox.org \
--to=phasta@mailbox.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--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=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=phasta@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=sumit.semwal@linaro.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/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