Re: [PATCH] rust: DamFence: Remove warning about unsignaled drop
From: Christian König
Date: Tue Nov 17 2026 - 09:50:21 EST
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.