summaryrefslogtreecommitdiff
path: root/rust
diff options
context:
space:
mode:
authorLyude Paul <lyude@redhat.com>2026-06-12 15:43:33 -0400
committerLyude Paul <lyude@redhat.com>2026-06-12 15:47:59 -0400
commit5a22c80ae8f942d4b560d6a710a037f424e33b9a (patch)
treea204e5a1e89ba8839a8b88bcf05f74706271686c /rust
parent550dc7536644db2d67c6f8cf525bba682fba08d9 (diff)
downloadlinux-next-5a22c80ae8f942d4b560d6a710a037f424e33b9a.tar.gz
linux-next-5a22c80ae8f942d4b560d6a710a037f424e33b9a.zip
rust: drm: gem: shmem: Add DmaResvGuard helper
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> Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Acked-by: Danilo Krummrich <dakr@kernel.org> Link: https://patch.msgid.link/20260612194436.585385-2-lyude@redhat.com
Diffstat (limited to 'rust')
-rw-r--r--rust/kernel/drm/gem/shmem.rs39
1 files changed, 37 insertions, 2 deletions
diff --git a/rust/kernel/drm/gem/shmem.rs b/rust/kernel/drm/gem/shmem.rs
index 084b798ce795..090c5d869fdb 100644
--- a/rust/kernel/drm/gem/shmem.rs
+++ b/rust/kernel/drm/gem/shmem.rs
@@ -22,7 +22,10 @@ use crate::{
error::to_result,
prelude::*,
sync::aref::ARef,
- types::Opaque, //
+ types::{
+ NotThreadSafe,
+ Opaque, //
+ },
};
use core::{
marker::PhantomData,
@@ -30,7 +33,10 @@ use core::{
Deref,
DerefMut, //
},
- ptr::NonNull, //
+ ptr::{
+ self,
+ NonNull, //
+ },
};
use gem::{
BaseObjectPrivate,
@@ -244,3 +250,32 @@ impl<T: DriverObject, C: DeviceContext> driver::AllocImpl for Object<T, C> {
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, C: DeviceContext = Registered>(
+ &'a Object<T, C>,
+ NotThreadSafe,
+);
+
+impl<'a, T: DriverObject, C: DeviceContext> DmaResvGuard<'a, T, C> {
+ #[inline]
+ #[expect(unused)]
+ fn new(obj: &'a Object<T, C>) -> 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, NotThreadSafe)
+ }
+}
+
+impl<'a, T: DriverObject, C: DeviceContext> Drop for DmaResvGuard<'a, T, C> {
+ #[inline]
+ 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()) };
+ }
+}