Re: [PATCH 4/4] rust: dma: tie Coherent and CoherentBox to the device's bound lifetime

From: Gary Guo

Date: Thu Sep 03 2026 - 10:36:14 EST


On Sun Aug 30, 2026 at 8:37 PM BST, Danilo Krummrich wrote:
> Add a lifetime parameter to Coherent and CoherentBox that ties the DMA
> allocation to the device's bound scope, ensuring it is freed before the
> device is unbound.
>
> DMA allocations carry device resources (e.g. IOMMU mappings) that must
> not outlive the device's bound lifetime. Without a lifetime parameter,
> there was no compile-time enforcement that a Coherent or CoherentBox is
> dropped before the device is unbound.
>
> Propagate the new lifetime parameter through all users.
>
> Signed-off-by: Danilo Krummrich <dakr@xxxxxxxxxx>

The rust/kernel code looks good to me. Haven't checked nova part in detail, but
it looks like a mechanical conversion, so would be fine if it builds.

Reviewed-by: Gary Guo <gary@xxxxxxxxxxx>

Sashiko points out that the `Coherent` could be leaked -- what's the implication
when that happens? I think it's not going to be as problematic like
registrations because coherent allocation carries no callbacks, so we probably
don't need this to be unsafe, but I do wonder how'd DMA subsystem handle this.

Best,
Gary

> ---
> drivers/gpu/nova-core/falcon.rs | 2 +-
> drivers/gpu/nova-core/fb.rs | 2 +-
> drivers/gpu/nova-core/firmware/booter.rs | 2 +-
> drivers/gpu/nova-core/firmware/fsp.rs | 8 +-
> .../nova-core/firmware/fwsec/bootloader.rs | 12 +-
> drivers/gpu/nova-core/firmware/gsp.rs | 14 +-
> drivers/gpu/nova-core/firmware/riscv.rs | 8 +-
> drivers/gpu/nova-core/fsp.rs | 20 +--
> drivers/gpu/nova-core/gpu.rs | 4 +-
> drivers/gpu/nova-core/gsp.rs | 30 ++---
> drivers/gpu/nova-core/gsp/boot.rs | 10 +-
> drivers/gpu/nova-core/gsp/cmdq.rs | 35 +++--
> drivers/gpu/nova-core/gsp/commands.rs | 2 +-
> drivers/gpu/nova-core/gsp/fw.rs | 12 +-
> drivers/gpu/nova-core/gsp/hal.rs | 14 +-
> drivers/gpu/nova-core/gsp/hal/gh100.rs | 16 +--
> drivers/gpu/nova-core/gsp/hal/tu102.rs | 34 ++---
> drivers/gpu/nova-core/gsp/sequencer.rs | 6 +-
> rust/kernel/dma.rs | 121 +++++++++---------
> rust/kernel/uaccess.rs | 4 +-
> samples/rust/rust_dma.rs | 4 +-
> 21 files changed, 176 insertions(+), 184 deletions(-)