On Tue, Apr 28, 2026 at 03:03:44PM -0400, Lyude Paul wrote:
In order to do this, we need to be careful to ensure that any interface we expose for scatterlists ensures that any mappings created from one are destroyed on driver-unbind. To do this, we introduce a Devres resource into shmem::Object that we use in order to ensure that we release any SGTable mappings on driver-unbind. We store this in an UnsafeCell and protect
Outdated? No longer UnsafeCell.
access to it using the dma_resv lock that we already have from the shmem gem object, which is the same lock that currently protects drm_gem_object_shmem->sgt.
We also provide two different methods for acquiring an sg table: self.sg_table(), and self.owned_sg_table(). The first function is for short-term uses of mapped SGTables, the second is for callers that need to hold onto the mapped SGTable for an extended period of time. The second variant uses Devres of course, whereas the first simply relies on rust's borrow checker to prevent driver-unbind when using the mapped SGTable.
Signed-off-by: Lyude Paul lyude@redhat.com
obj: Opaque<bindings::drm_gem_shmem_object>, /// Parent object that owns this object's DMA reservation object. parent_resv_obj: Option<ARef<Object<T>>>,
- /// Devres object for unmapping any SGTable on driver-unbind.
- /// TODO: Drop the mutex once we can use Init with SetOnce.
- #[pin]
- sgt_res: Mutex<SetOnce<Devres<SGTableMap<T>>>>,
As far as I can tell, you don't need this Mutex. Also, it causes problems like requiring the reference transmute below.
Alice