> > The lock might be held already by the driver or by TTM when things are called > from TTM callbacks. > > This is why GPUVM never takes locks by itself, but asserts that the correct > lock > is held. > > I think we really want to get proof by the driver by providing lock guard > references. > >> See my comment about “[..] a new type for GEM objects which are known to be >> locked" >> below. > > <snip> > >>>> + >>>> + /// Obtains the [`GpuVmBo`] object that connects `obj` to this VM. >>>> + /// >>>> + /// This connection is unique, so an instane of [`GpuVmBo`] will be >>>> + /// allocated for `obj` once, and that instance will be returned from >>>> that >>>> + /// point forward. >>>> + pub fn obtain_bo(&mut self, obj: &DriverObject<T>) -> >>>> Result<ARef<GpuVmBo<T>>> { >>>> + // SAFETY: LockedGpuVm implies the right locks are held. >>> >>> No, this must be locked by the dma-resv or the GEM gpuva lock, not by the >>> GPUVM lock that protects the interval tree. >> >> By “GEM gpuva lock” you’re referring to the custom lock which we >> currently do not support, right? > > Yes. > >> This series currently rely on manual calls to dma_resv_{lock,unlock}, I >> wonder >> if we should ditch that in favor of something written in Rust directly. This >> would let us introduce a new type for GEM objects which are known to have >> `resv` locked. WDYT? > > Not all functions that require the dma-resv lock to be held are called with a > GEM object parameter, it could also be a struct drm_gpuvm_bo, struct drm_gpuva > or struct drm_gpuvm, since they all carry GEM object pointers. > > For reference, you can look for "_held" in drivers/gpu/drm/drm_gpuvm.c. >
Looking at Lyude’s (excellent) KMS series, one thing that comes to mind is using Lock::from_raw() on the dma-resv lock. This will build a rust Mutex that we can then assert to be locked (or fail with an Error otherwise). See [0] for the specific patch whose idea I want to copy. Can I get a +1 on this idea before pursuing it? -- Daniel [0] https://lore.kernel.org/rust-for-linux/20250305230406.567126-10-ly...@redhat.com/