On Tue, May 26, 2026 at 05:28:56PM -0400, Lyude Paul wrote:
Just a temporary holdover to make locking/unlocking the dma_resv lock much easier.
Signed-off-by: Lyude Paul lyude@redhat.com Co-authored-by: Alexandre Courbot acourbot@nvidia.com
Missing SoB for Alexandre.
rust/kernel/drm/gem/shmem.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/rust/kernel/drm/gem/shmem.rs b/rust/kernel/drm/gem/shmem.rs index 116ed0a13eac2..1b24cb1129a8b 100644 --- a/rust/kernel/drm/gem/shmem.rs +++ b/rust/kernel/drm/gem/shmem.rs @@ -27,7 +27,10 @@ Deref, DerefMut, // },
- ptr::NonNull,
- ptr::{
self,NonNull, //- },
}; use gem::{ BaseObjectPrivate, @@ -233,3 +236,29 @@ impl<T: DriverObject> driver::AllocImpl for Object<T> { dumb_map_offset: None, }; }
+/// Private helper-type for holding the `dma_resv` object for a GEM shmem object. +/// +/// When this is dropped, the `dma_resv` lock is dropped as well. +/// +// TODO: This should be replace with a WwMutex equivalent once we have such bindings in the kernel. +struct DmaResvGuard<'a, T: DriverObject>(&'a Object<T>);
Is this missing a NotThreadSafe, or is it safe to unlock on a different thread than where it was locked?
+impl<'a, T: DriverObject> DmaResvGuard<'a, T> {
- #[inline(always)]
- #[expect(unused)]
- fn new(obj: &'a Object<T>) -> Self {
// SAFETY: This lock is initialized throughout the lifetime of `object`.unsafe { bindings::dma_resv_lock(obj.raw_dma_resv(), ptr::null_mut()) };Self(obj)- }
+}
+impl<'a, T: DriverObject> Drop for DmaResvGuard<'a, T> {
- #[inline(always)]
- fn drop(&mut self) {
// SAFETY: We are releasing the lock grabbed during the creation of this object.unsafe { bindings::dma_resv_unlock(self.0.raw_dma_resv()) };- }
+}
2.54.0