Skip to content

Commit 386aa6f

Browse files
committed
fixup! rust: drm: gem: shmem: Add DRM shmem helper abstraction
1 parent 36c9bfe commit 386aa6f

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

rust/kernel/drm/gem/shmem.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,14 @@ impl<T: DriverObject> Object<T> {
199199
pub fn vmap(&self) -> Result<VMap<T>> {
200200
let mut map: MaybeUninit<bindings::iosys_map> = MaybeUninit::uninit();
201201

202-
// SAFETY: drm_gem_shmem_vmap is thread-safe
203-
to_result(unsafe { bindings::drm_gem_shmem_vmap(self.mut_shmem(), map.as_mut_ptr()) })?;
202+
// SAFETY: drm_gem_shmem_vmap can be called with the DMA reservation lock held
203+
to_result(unsafe {
204+
let resv = self.obj.base.resv as *const _ as *mut _;
205+
bindings::dma_resv_lock(resv, core::ptr::null_mut());
206+
let ret = bindings::drm_gem_shmem_vmap(self.mut_shmem(), map.as_mut_ptr());
207+
bindings::dma_resv_unlock(resv);
208+
ret
209+
})?;
204210

205211
// SAFETY: if drm_gem_shmem_vmap did not fail, map is initialized now
206212
let map = unsafe { map.assume_init() };
@@ -304,9 +310,12 @@ impl<T: DriverObject> VMap<T> {
304310

305311
impl<T: DriverObject> Drop for VMap<T> {
306312
fn drop(&mut self) {
307-
// SAFETY: This function is thread-safe
313+
// SAFETY: This function is safe to call with the DMA reservation lock held
308314
unsafe {
315+
let resv = self.owner.obj.base.resv as *const _ as *mut _;
316+
bindings::dma_resv_lock(resv, core::ptr::null_mut());
309317
bindings::drm_gem_shmem_vunmap(self.owner.mut_shmem(), &mut self.map);
318+
bindings::dma_resv_unlock(resv);
310319
}
311320
}
312321
}

0 commit comments

Comments
 (0)