[PATCH 0/2] Add a Rust GPUVM abstraction

Daniel Almeida
2025-03-24T15:14:56Z

Changes from v0:
This version changes how `LockedGpuVm` operates. The previous code assumed
that the interval tree would be protected if all the associated GEM's resvs
were locked, but this is completely unrelated. In fact, this initial version
only aims to support the core VA range management feature of GPUVM, and not any
of the "convenience" functions like "exec_lock()" and friends, so this function
was removed accordingly.

LockedGpuVm is now produced by a call to GpuVm::lock(). This takes a generic
guard type to signal that the driver-specific locks have been acquired in order
to protect the VMs tree, and hence its view of the address space. This approach
is somewhat similar to CondVar, but also incurs in the same pitfall: it is up
to the caller to give meaning to the guard by ensuring that it actually
protects against concurrent access to the VM. Maybe this is a good candidate to
the upcoming "Pitfall" docs section?

Note that LockedGpuVm::obj was removed. I'm not really sure why this field
was there in the first place, but callers should indicate the object through
the sm_map() and sm_unmap() APIs instead.

I am not sure why GpuVm::inner uses UnsafeCell, though. I did not touch this
so that we can first discuss whether UnsafeCell is really needed.

The docs were also updated. Care was taken to reuse the C documentation as
much as possible.

Itemized changes:

- Rebased on top of nova-drm
- Use `srctree` in the docs
- Add docs as appropriate and remove #[allow(missing_docs)]
- Remove `impl DriverGpuVa for ()`. Drivers can to that themselves, if they want.
- Added #[inline] to getters, as Rust cannot inline across crates otherwise (unless this changed recently?)
- Exposed `drm_gpuva_op_unmap::keep`.
- Removed `pub(super)` from unsafe fns meant to be called from the C code.
- Added "# Safety" blocks to the above.
- Removed `exec_lock_gem_object()`.
- Removed `exec_lock()`
- Removed `LockedGpuVm::vm_exec`. This initial version does not support `exec` calls at all.
- By the same token, removed `LockedGpuVm::drop()`
- Removed `LockedGpuVm::obj`. This object has to be passed explicitly.

---
Asahi Lina (2):
rust: helpers: Add bindings/wrappers for dma_resv
rust: drm: Add GPUVM abstraction

rust/bindings/bindings_helper.h | 5 +-
rust/helpers/dma-resv.c | 13 +
rust/helpers/drm_gpuvm.c | 29 ++
rust/helpers/helpers.c | 2 +
rust/kernel/drm/gpuvm.rs | 790 ++++++++++++++++++++++++++++++++++++++++
rust/kernel/drm/mod.rs | 2 +
6 files changed, 840 insertions(+), 1 deletion(-)
---
base-commit: e7de41cc4b01dd5500a0c2533c64bdb3f5360567
change-id: 20250320-gpuvm-29d3e0726f34

Best regards,
--
Daniel Almeida <daniel.almeida@collabora.com>