On Wednesday, March 22nd, 2023 at 20:45, Björn Roy Baron <bjorn3_gh@xxxxxxxxxxxxxx> wrote: > On Friday, March 17th, 2023 at 13:12, Maíra Canal <mcanal@xxxxxxxxxx> wrote: > > > A GEMObject, related to struct drm_gem_object, holds a pointer > > to reservation object associated with the this GEM object. Therefore, > > expose this reservation object through the DmaResv safe abstraction. > > > > Signed-off-by: Maíra Canal <mcanal@xxxxxxxxxx> > > --- > > rust/kernel/drm/gem/mod.rs | 7 +++++++ > > 1 file changed, 7 insertions(+) > > > > diff --git a/rust/kernel/drm/gem/mod.rs b/rust/kernel/drm/gem/mod.rs > > index c4a42bb2f718..dae95e5748a7 100644 > > --- a/rust/kernel/drm/gem/mod.rs > > +++ b/rust/kernel/drm/gem/mod.rs > > @@ -11,6 +11,7 @@ use alloc::boxed::Box; > > > > use crate::{ > > bindings, > > + dma_resv::DmaResv, > > drm::{device, drv, file}, > > error::{to_result, Result}, > > prelude::*, > > @@ -136,6 +137,12 @@ pub trait BaseObject: IntoGEMObject { > > self.gem_obj().size > > } > > > > + /// Returns the pointer to reservation object associated with this GEM object. > > + fn resv(&self) -> DmaResv { > > + // SAFETY: Every GEM object holds a reference to a reservation object > > + unsafe { DmaResv::from_raw(self.gem_obj().resv) } > > + } > > There is nothing ensuring that DmaResv doesn't outlive self and thus may have been deallocated. You could change DmaResv to be a newtype around UnsafeCell<dma_resv> and then return an &DmaResv here. This way &DmaResv can't outlive &self. Actually Opaque<dma_resv> may be better as no fields of dma_resv are used on the rust side. > > > + > > /// Sets the exportable flag, which controls whether the object can be exported via PRIME. > > fn set_exportable(&mut self, exportable: bool) { > > self.mut_gem_obj().exportable = exportable; > > -- > > 2.39.2 > > Cheers, > Bjorn Cheers, Bjorn