drm/msm: Replace custom dumb_map_offset with generic helper
PATCH 1/1 drm/msm: Replace custom dumb_map_offset with generic helper
The msm driver implements a custom dumb_map_offset callback. This implementation acquires the msm_gem_lock, but the underlying drm_gem_create_mmap_offset() function is already thread-safe regarding the VMA offset manager (it acquires the mgr->vm_lock internally).
Switching to the generic drm_gem_dumb_map_offset() helper provides several benefits:
1. Removes the unnecessary locking overhead (locking leftovers).
2. Adds a missing check to reject mapping of imported objects, which is invalid for dumb buffers.
3. Allows for the removal of the msm_gem_dumb_map_offset() wrapper and the msm_gem_mmap_offset() helper function.
The logic from msm_gem_mmap_offset() has been inlined into msm_ioctl_gem_info() to maintain functionality without the separate helper.
This addresses the TODO:
"Documentation/gpu/todo.rst: Remove custom dumb_map_offset implementations"
---
Compile-tested only.
drivers/gpu/drm/msm/msm_drv.c | 8 +++--- drivers/gpu/drm/msm/msm_gem.c | 49 ----------------------------------- drivers/gpu/drm/msm/msm_gem.h | 3 --- 3 files changed, 5 insertions(+), 55 deletions(-)
drivers/gpu/drm/msm/msm_drv.c +5 -3
@@ -588,7 +588,9 @@ static int msm_ioctl_gem_info(struct drm_device *dev, void *data,switch (args->info) {case MSM_INFO_GET_OFFSET : - args->value =msm_gem_mmap_offset (obj); + ret =drm_gem_create_mmap_offset (obj); +if (ret ==0 ) + args->value =drm_vma_node_offset_addr (&obj->vma_node);break ;case MSM_INFO_GET_IOVA : ret =msm_ioctl_gem_info_iova (dev, file, obj, &args->value);
@@ -836,7 +838,7 @@ static const struct drm_driver msm_driver = { .open = msm_open, .postclose = msm_postclose, .dumb_create = msm_gem_dumb_create, - .dumb_map_offset = msm_gem_dumb_map_offset, + .dumb_map_offset = drm_gem_dumb_map_offset, .gem_prime_import = msm_gem_prime_import, .gem_prime_import_sg_table = msm_gem_prime_import_sg_table, #ifdef CONFIG_DEBUG_FS
@@ -859,7 +861,7 @@ static const struct drm_driver msm_kms_driver = { .open = msm_open, .postclose = msm_postclose, .dumb_create = msm_gem_dumb_create, - .dumb_map_offset = msm_gem_dumb_map_offset, + .dumb_map_offset = drm_gem_dumb_map_offset, .gem_prime_import_sg_table = msm_gem_prime_import_sg_table, #ifdef CONFIG_DEBUG_FS .debugfs_init = msm_debugfs_init,
drivers/gpu/drm/msm/msm_gem.c +0 -49
61 lines not on this page · raw message
drivers/gpu/drm/msm/msm_gem.h +0 -3
@@ -262,7 +262,6 @@ struct msm_gem_object {void msm_gem_vma_get (struct drm_gem_object *obj);void msm_gem_vma_put (struct drm_gem_object *obj); -uint64_t msm_gem_mmap_offset (struct drm_gem_object *obj);int msm_gem_prot (struct drm_gem_object *obj);int msm_gem_pin_vma_locked (struct drm_gem_object *obj,struct drm_gpuva *vma);void msm_gem_unpin_locked (struct drm_gem_object *obj);
@@ -285,8 +284,6 @@ struct page **msm_gem_pin_pages_locked(struct drm_gem_object *obj);void msm_gem_unpin_pages_locked (struct drm_gem_object *obj);int msm_gem_dumb_create (struct drm_file *file,struct drm_device *dev,struct drm_mode_create_dumb *args); -int msm_gem_dumb_map_offset (struct drm_file *file,struct drm_device *dev, -uint32_t handle,uint64_t *offset);void *msm_gem_get_vaddr_locked (struct drm_gem_object *obj);void *msm_gem_get_vaddr (struct drm_gem_object *obj);void *msm_gem_get_vaddr_active (struct drm_gem_object *obj);
base-commit: 8f0b4cce4481fb22653697cced8d0d04027cb1e8 --
2.52.0
Quoted 4 lines · Swaraj Gaikwad
The msm driver implements a custom
dumb_map_offsetcallback. This implementation acquires themsm_gem_lock, but the underlyingdrm_gem_create_mmap_offset()function is already thread-safe regarding the VMA offset manager (it acquires themgr->vm_lockinternally).
Other pieces are using msm_gem_lock() / msm_gem_unlock(), which translates to dma_resv_lock() / dma_resv_unlock(), so you need to describe, why it's still safe wrt. that code.
Quoted 21 lines
Switching to the generic
drm_gem_dumb_map_offset()helper provides several benefits:
1. Removes the unnecessary locking overhead (locking leftovers).
2. Adds a missing check to reject mapping of imported objects, which is invalid for dumb buffers.
3. Allows for the removal of themsm_gem_dumb_map_offset()wrapper and themsm_gem_mmap_offset()helper function.The logic from
msm_gem_mmap_offset()has been inlined intomsm_ioctl_gem_info()to maintain functionality without the separate helper.This addresses the TODO:
"Documentation/gpu/todo.rst: Remove customdumb_map_offsetimplementations"Signed-off-by Swaraj Gaikwad <[email protected]>---
Compile-tested only.
Signature · 2 lines
With best wishes Dmitry