From: "Christian König" <christian.koenig@amd.com>
To: phasta@kernel.org, "Sumit Semwal" <sumit.semwal@linaro.org>,
"Danilo Krummrich" <dakr@kernel.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>
Cc: 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 10:51:38 +0100 [thread overview]
Message-ID: <e2ec8a39-56c3-4274-91ce-60c273904877@amd.com> (raw)
In-Reply-To: <49298d3a328c1695ea27993f714c20b8a1c05f32.camel@mailbox.org>
On 11/17/26 09:24, Philipp Stanner wrote:
> On Thu, 2026-11-12 at 11:29 +0100, Christian König wrote:
>> On 11/12/26 11:10, Philipp Stanner wrote:
>>> DriverFence::drop() contains a pr_warn!() for when the fence drops
>>> unsignaled. This warning gets into the way of canonical teardown in
>>> Rust: when you drop a lock, it unlocks itself, when you drop a KBox, it
>>> frees itself etc. Congruently, users should be able to tear down fences
>>> they don't care about anymore with ECANCELED, which is already the
>>> default error code.
>>
>> Well a dma_fence should never automatically signal when the last
>> reference drops.
>>
>> Leaving it unsignaled is the most defensive path we can go. That can
>> lead to deadlocks but it can at least not lead to memory corruption.
>
> True, you choose between the Unholy Trinity of DRM: deadlocks, UAF and
> memory corruption :]
>
> In this particular case, however, Rust does not allow for preventing
> the user from signaling "forgotten" fences anyways, no matter how we
> write the fence core:
>
> 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 even know about one case where a driver fully intentionally leaks memory on unload because the devs couldn't figure out which FW keeps writing into a buffer.
This was suggested as problem solving approach for AMDGPU as well, but we have been able to avoid it by clearing the DMA master flag in the PCI config dword.
The fundamental problem here is that a software object running out of scope is not an indicator that the HW stops doing something.
So just signaling all fences with ECANCELED is not enough. When the driver runs out of scope without all fences being signaling we seriously need at least some kind of warning in the system log, potentially even better call BUG() or maybe even panic().
Cheers,
Christian.
>
>
> So we decided to die this death because this way we get rid of the two
> of the three problems that *can* be solved in the API.
>
>
> But it will please you to hear that all users of drm::JobQueue do not
> have access to fences directly anyways, they can only signal them
> through JobQueue. Thus, they can also not forget them (signaled or
> unsignaled), because they would have to forget / leak the entire
> JobQueue as a whole, so effectively forgetting also their GPU ring. If
> that would happen, the driver would be broken beyond repair anyways.
>
> Regards
> P.
prev parent reply other threads:[~2026-11-17 9:51 UTC|newest]
Thread overview: 4+ 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 [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=e2ec8a39-56c3-4274-91ce-60c273904877@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®