Commit 4368dd84 authored by YoungJun Cho's avatar YoungJun Cho Committed by Dave Airlie

drm/gem: add mutex lock when using drm_gem_mmap_obj

The drm_gem_mmap_obj() has to be protected with dev->struct_mutex,
but some caller functions do not. So it adds mutex lock to missing
callers and adds assertion to check whether drm_gem_mmap_obj() is
called with mutex lock or not.
Signed-off-by: default avatarYoungJun Cho <yj44.cho@samsung.com>
Signed-off-by: default avatarSeung-Woo Kim <sw0312.kim@samsung.com>
Signed-off-by: default avatarKyungmin Park <kyungmin.park@samsung.com>
Reviewed-by: default avatarMaarten Lankhorst <maarten.lankhorst@canonical.com>
Reviewed-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: default avatarRob Clark <robdclark@gmail.com>
Reviewed-by: default avatarMaarten Lankhorst <maarten.lankhorst@canonical.com>
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
parent 2644ee96
...@@ -661,6 +661,8 @@ EXPORT_SYMBOL(drm_gem_vm_close); ...@@ -661,6 +661,8 @@ EXPORT_SYMBOL(drm_gem_vm_close);
* the GEM object is not looked up based on its fake offset. To implement the * the GEM object is not looked up based on its fake offset. To implement the
* DRM mmap operation, drivers should use the drm_gem_mmap() function. * DRM mmap operation, drivers should use the drm_gem_mmap() function.
* *
* NOTE: This function has to be protected with dev->struct_mutex
*
* Return 0 or success or -EINVAL if the object size is smaller than the VMA * Return 0 or success or -EINVAL if the object size is smaller than the VMA
* size, or if no gem_vm_ops are provided. * size, or if no gem_vm_ops are provided.
*/ */
...@@ -669,6 +671,8 @@ int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size, ...@@ -669,6 +671,8 @@ int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size,
{ {
struct drm_device *dev = obj->dev; struct drm_device *dev = obj->dev;
lockdep_assert_held(&dev->struct_mutex);
/* Check for valid size. */ /* Check for valid size. */
if (obj_size < vma->vm_end - vma->vm_start) if (obj_size < vma->vm_end - vma->vm_start)
return -EINVAL; return -EINVAL;
......
...@@ -487,9 +487,12 @@ static int drm_gem_cma_dmabuf_mmap(struct dma_buf *dmabuf, ...@@ -487,9 +487,12 @@ static int drm_gem_cma_dmabuf_mmap(struct dma_buf *dmabuf,
{ {
struct drm_gem_cma_object *cma_obj = dmabuf->priv; struct drm_gem_cma_object *cma_obj = dmabuf->priv;
struct drm_gem_object *gem_obj = &cma_obj->base; struct drm_gem_object *gem_obj = &cma_obj->base;
struct drm_device *dev = gem_obj->dev;
int ret; int ret;
mutex_lock(&dev->struct_mutex);
ret = drm_gem_mmap_obj(gem_obj, gem_obj->size, vma); ret = drm_gem_mmap_obj(gem_obj, gem_obj->size, vma);
mutex_unlock(&dev->struct_mutex);
if (ret < 0) if (ret < 0)
return ret; return ret;
......
...@@ -140,12 +140,15 @@ static int omap_gem_dmabuf_mmap(struct dma_buf *buffer, ...@@ -140,12 +140,15 @@ static int omap_gem_dmabuf_mmap(struct dma_buf *buffer,
struct vm_area_struct *vma) struct vm_area_struct *vma)
{ {
struct drm_gem_object *obj = buffer->priv; struct drm_gem_object *obj = buffer->priv;
struct drm_device *dev = obj->dev;
int ret = 0; int ret = 0;
if (WARN_ON(!obj->filp)) if (WARN_ON(!obj->filp))
return -EINVAL; return -EINVAL;
mutex_lock(&dev->struct_mutex);
ret = drm_gem_mmap_obj(obj, omap_gem_mmap_size(obj), vma); ret = drm_gem_mmap_obj(obj, omap_gem_mmap_size(obj), vma);
mutex_unlock(&dev->struct_mutex);
if (ret < 0) if (ret < 0)
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment