Re: [PATCH] rust: DamFence: Remove warning about unsignaled drop
From: Philipp Stanner
Date: Thu Nov 19 2026 - 04:59:19 EST
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.