[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <AEB7ACF6-EF2A-4F7B-A7E2-8E4B2A0B7EC8@collabora.com>
Date: Wed, 14 May 2025 17:11:50 -0300
From: Daniel Almeida <daniel.almeida@...labora.com>
To: Danilo Krummrich <dakr@...nel.org>
Cc: Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>,
Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>,
Andreas Hindborg <a.hindborg@...nel.org>,
Alice Ryhl <aliceryhl@...gle.com>,
Trevor Gross <tmgross@...ch.edu>,
Sumit Semwal <sumit.semwal@...aro.org>,
Christian König <christian.koenig@....com>,
Boris Brezillon <boris.brezillon@...labora.com>,
Alyssa Rosenzweig <alyssa@...enzweig.io>,
Lyude Paul <lyude@...hat.com>,
Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>,
Maxime Ripard <mripard@...nel.org>,
Thomas Zimmermann <tzimmermann@...e.de>,
David Airlie <airlied@...il.com>,
Simona Vetter <simona@...ll.ch>,
linux-kernel@...r.kernel.org,
rust-for-linux@...r.kernel.org,
dri-devel@...ts.freedesktop.org,
Asahi Lina <lina@...hilina.net>
Subject: Re: [PATCH v2 2/2] rust: drm: Add GPUVM abstraction
>
> 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-lyude@redhat.com/
Powered by blists - more mailing lists