mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Christian König" <christian.koenig@amd.com>
To: 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: Tue, 17 Nov 2026 15:50:06 +0100	[thread overview]
Message-ID: <8da4a8c0-1740-450c-9cf1-1a7b21d12997@amd.com> (raw)
In-Reply-To: <DMXJ8TBSZJJ4.3HG0OJDI9URTT@kernel.org>

On 11/17/26 14:50, Danilo Krummrich wrote:
> On Tue Nov 17, 2026 at 2:40 PM CET, Christian König wrote:
>> On 11/17/26 11:54, Philipp Stanner wrote:
>>> On Tue, 2026-11-17 at 10:51 +0100, Christian König wrote:
>>>> On 11/17/26 09:24, Philipp Stanner wrote:
>>>>> struct DriverFoo {
>>>>> 	f: DriverFence<()>,
>>>>> }
>>>>>
>>>>> impl Drop for Driver Foo {
>>>>> 	pub fn drop(&mut self) {
>>>>> 		// Signals fence implicitly & automatically.
>>>>> 		self.f.signal(ECANCELED);
>>>>> 	}
>>>>> }
>>>>
>>>> Yeah, exactly that is still a bad idea :) See the HW eventually
>>>> doesn't necessarily stop doing DMA if you unload the driver.
>>>
>>> I know.
>>>
>>>> So just signaling all fences with ECANCELED is not enough.
>>>
>>>
>>> Yes. What I was trying to tell you as that you have no way to enforce
>>> this in Rust or C.
>>>
>>> dma_fence_signal(f);
>>> free_driver_resources();
>>> // Driver forgets to stop the hardware. Memory corruption occurs.
>>>
>>> You see? Neither your BUG_ON() or WARN_ON() saves you if the driver
>>> does it like that, no matter the programming language. You cannot
>>> prevent it.
>>>
>>> The only one who understands how the hardware works is the driver. The
>>> only one who can stop it is the driver.
>>>
>>> In Rust, the place where a driver drops its JobQueue is the same place
>>> where it has to halt its GPU ring correctly. Enforcing this cannot be
>>> done by dma_fence code.
>>
>> 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.

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.

Signaling a DMA-buf should always be an explicit operation drivers do because of some HW event and not something which happens as a side effect cleanup because your object runs out of scope.

Regards,
Christian.


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

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 10:10 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 [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=8da4a8c0-1740-450c-9cf1-1a7b21d12997@amd.com \
    --to=christian.koenig@amd.com \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --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

all inboxes | Powered by JetHome®