Linux Media Controller development
 help / color / mirror / Atom feed
From: "Danilo Krummrich" <dakr@kernel.org>
To: "Christian König" <christian.koenig@amd.com>
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: Tue, 17 Nov 2026 17:36:53 +0100	[thread overview]
Message-ID: <DMXMSIQONGUW.1RRNS7I6LACD6@kernel.org> (raw)
In-Reply-To: <8da4a8c0-1740-450c-9cf1-1a7b21d12997@amd.com>

On Tue Nov 17, 2026 at 3:50 PM CET, Christian König wrote:
> On 11/17/26 14:50, Danilo Krummrich wrote:
>> On Tue Nov 17, 2026 at 2:40 PM CET, Christian König wrote:
>>> I completely agree that we can't fix things from the dma_fence code, but it
>>> is our obligation to tell the user that something very very bad happened.
>> 
>> That's the point, we can't infer that "something very bad happened" from
>> dma::DriverFence being dropped unsignaled.
>> 
>> In Rust we use the RAII pattern, and drivers structurally embed a
>> dma::DriverFence within the struct that represents the corresponding hardware /
>> firmware queue (e.g. through Jobqueue).
>> 
>> Consequently, if dma::DriverFence drops unsignaled it means that the destructor
>> of the structure that embeds it (which does the required HW teardown) did run
>> already.
>
> Oh WOW! The signaling state of the fence should *NEVER* be bound to some
> object lifetime.

Let's engage with the argument and understand things before throwing
overgeneralized statements like this around please.

Realitiy is usually much more nuanced and what you say doesn't hold in all
cases. The case described above (and clarified below) is one of them.

I assume the fundamental reason why you say things like "software object running
out of scope is not an indicator that the HW stops doing something" is because
the lifetime model in a lot of existing C DRM drivers is backwards.

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.

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.

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.

For instance, think about how your logic would apply to e.g. DMA coherent
allocations.

Those are allocated with e.g. dma::Coherent::zeroed() and are freed on drop().
They are then owned by whatever object represents the lifetime of the HW using
this buffer.

Following your logic, we'd need to conclude that a dma::Coherent allocation
needs an explicit free() method independent of its destructor as well, and have
the destructor print a warning and then call free() anyway.

Now, eventually drivers would just call free() from the destructor of the object
owning the dma::Coherent allocation, so we wouldn't win anything.

More in general, in Rust the object taking ownership of a device resource is
responsible to deal with the device related state that makes use of this
resource regardless.

Insisting on an explicit method call is not improving anything in this model.

To get back to dma::DriverFence: This is slightly different, as there's two
different signal states, but the fundamental guarantee is the same: If it is
dropped, the HW has stopped accessing the resource that it guards already *by
design*.

Signaling with an error on drop is arguably the correct thing to do, since if
the operation would have been completed successfully before already, it would
have been signaled already -- if it drops unsignaled it means the hardware was
forcefully torn down (e.g. on driver unbind).


[1] https://youtu.be/3A2vGbc_rxs?t=668
[2] https://lore.kernel.org/all/as07AdBFlOQZrH_4@intel.com/

> That sounds like an extremely bad practice to me. Just imagine anybody
> grabbing an extra reference to the HW state object to inspect it for debugging
> and the fence not signaling because of this.

That's not how it works.

Rust ownership rules will guarantee that the driver fence will be signaled with
an error (if not signaled already) if the HW state object is destroyed (i.e. its
destructor runs that tears down the HW). But that doesn't mean that the fence
can't be signaled (and subsequently be dropped) independently through the
completion of a job before that.

IOW, the HW state object (for instance) owns Jobqueue, Jobqueue owns jobs, jobs
own driver fences.

If the HW state object drops (e.g. on driver unbind), the Jobqueue drops, which
makes their jobs drop, which makes the driver fences drop.

At this point the driver fence either has been signaled already because the job
completed before teardown (but wasn't dropped yet), or it will be signaled with
an error in its drop(), which is fine since at this point the HW state's drop()
is completed already and hence the HW is stopped.

Besides that, reference counting HW state objects is bad practice. HW state
objects have a bounded lifetime, so there's no point in reference counting them.

  parent reply	other threads:[~2026-11-17 16:36 UTC|newest]

Thread overview: 10+ 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
     [not found]       ` <ab99758408df682c68a3792cc3014b77d6e1c8ab.camel@mailbox.org>
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 [this message]
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=DMXMSIQONGUW.1RRNS7I6LACD6@kernel.org \
    --to=dakr@kernel.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=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