Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: YoungJun Cho <yj44.cho@samsung.com>
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Reviewed-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rob Clark <robdclark@gmail.com>
Reviewed-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>

authored by

YoungJun Cho and committed by
Dave Airlie
4368dd84 2644ee96

+10
+4
drivers/gpu/drm/drm_gem.c
··· 661 661 * the GEM object is not looked up based on its fake offset. To implement the 662 662 * DRM mmap operation, drivers should use the drm_gem_mmap() function. 663 663 * 664 + * NOTE: This function has to be protected with dev->struct_mutex 665 + * 664 666 * Return 0 or success or -EINVAL if the object size is smaller than the VMA 665 667 * size, or if no gem_vm_ops are provided. 666 668 */ ··· 670 668 struct vm_area_struct *vma) 671 669 { 672 670 struct drm_device *dev = obj->dev; 671 + 672 + lockdep_assert_held(&dev->struct_mutex); 673 673 674 674 /* Check for valid size. */ 675 675 if (obj_size < vma->vm_end - vma->vm_start)
+3
drivers/gpu/drm/drm_gem_cma_helper.c
··· 487 487 { 488 488 struct drm_gem_cma_object *cma_obj = dmabuf->priv; 489 489 struct drm_gem_object *gem_obj = &cma_obj->base; 490 + struct drm_device *dev = gem_obj->dev; 490 491 int ret; 491 492 493 + mutex_lock(&dev->struct_mutex); 492 494 ret = drm_gem_mmap_obj(gem_obj, gem_obj->size, vma); 495 + mutex_unlock(&dev->struct_mutex); 493 496 if (ret < 0) 494 497 return ret; 495 498
+3
drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c
··· 140 140 struct vm_area_struct *vma) 141 141 { 142 142 struct drm_gem_object *obj = buffer->priv; 143 + struct drm_device *dev = obj->dev; 143 144 int ret = 0; 144 145 145 146 if (WARN_ON(!obj->filp)) 146 147 return -EINVAL; 147 148 149 + mutex_lock(&dev->struct_mutex); 148 150 ret = drm_gem_mmap_obj(obj, omap_gem_mmap_size(obj), vma); 151 + mutex_unlock(&dev->struct_mutex); 149 152 if (ret < 0) 150 153 return ret; 151 154