Commit 39ce2529 authored by Dmitry Osipenko's avatar Dmitry Osipenko

drm: Assert held reservation lock for dma-buf mmapping

When userspace mmaps dma-buf's fd, the dma-buf reservation lock must be
held. Add locking sanity checks to the dma-buf mmaping callbacks of DRM
drivers to ensure that the locking assumptions won't regress in future.
Suggested-by: default avatarDaniel Vetter <daniel@ffwll.ch>
Signed-off-by: default avatarDmitry Osipenko <dmitry.osipenko@collabora.com>
Acked-by: default avatarChristian König <christian.koenig@amd.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20221110201349.351294-3-dmitry.osipenko@collabora.com
parent 8526e973
...@@ -781,6 +781,8 @@ int drm_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct *vma) ...@@ -781,6 +781,8 @@ int drm_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct *vma)
struct drm_gem_object *obj = dma_buf->priv; struct drm_gem_object *obj = dma_buf->priv;
struct drm_device *dev = obj->dev; struct drm_device *dev = obj->dev;
dma_resv_assert_held(dma_buf->resv);
if (!dev->driver->gem_prime_mmap) if (!dev->driver->gem_prime_mmap)
return -ENOSYS; return -ENOSYS;
......
...@@ -97,6 +97,8 @@ static int i915_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct * ...@@ -97,6 +97,8 @@ static int i915_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct *
struct drm_i915_private *i915 = to_i915(obj->base.dev); struct drm_i915_private *i915 = to_i915(obj->base.dev);
int ret; int ret;
dma_resv_assert_held(dma_buf->resv);
if (obj->base.size < vma->vm_end - vma->vm_start) if (obj->base.size < vma->vm_end - vma->vm_start)
return -EINVAL; return -EINVAL;
......
...@@ -66,6 +66,8 @@ static int omap_gem_dmabuf_mmap(struct dma_buf *buffer, ...@@ -66,6 +66,8 @@ static int omap_gem_dmabuf_mmap(struct dma_buf *buffer,
struct drm_gem_object *obj = buffer->priv; struct drm_gem_object *obj = buffer->priv;
int ret = 0; int ret = 0;
dma_resv_assert_held(buffer->resv);
ret = drm_gem_mmap_obj(obj, omap_gem_mmap_size(obj), vma); ret = drm_gem_mmap_obj(obj, omap_gem_mmap_size(obj), vma);
if (ret < 0) if (ret < 0)
return ret; return ret;
......
...@@ -694,6 +694,8 @@ static int tegra_gem_prime_mmap(struct dma_buf *buf, struct vm_area_struct *vma) ...@@ -694,6 +694,8 @@ static int tegra_gem_prime_mmap(struct dma_buf *buf, struct vm_area_struct *vma)
struct drm_gem_object *gem = buf->priv; struct drm_gem_object *gem = buf->priv;
int err; int err;
dma_resv_assert_held(buf->resv);
err = drm_gem_mmap_obj(gem, gem->size, vma); err = drm_gem_mmap_obj(gem, gem->size, vma);
if (err < 0) if (err < 0)
return err; return err;
......
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