Hello,
Recently, dma-buf got a common locking convention for importers and
exporters. All the dma-buf functions were moved to the new locking
convention, apart from the dma_buf_mmap_internal() that was missed out
by accident. This series moves dma_buf_mmap_internal() to the dynamic
locking specification and updates drivers that support mmaping of
dma-bufs to use the debug-assert of the lock.
Thanks to Daniel Vetter for spotting the missed function!
Dmitry Osipenko (6):
dma-buf: Move dma_buf_mmap_internal() to dynamic locking specification
drm: Assert held reservation lock for dma-buf mmapping
udmabuf: Assert held reservation lock for dma-buf mmapping
dma-buf/heaps: Assert held reservation lock for dma-buf mmapping
media: videobuf2: Assert held reservation lock for dma-buf mmapping
fastrpc: Assert held reservation lock for dma-buf mmapping
drivers/dma-buf/dma-buf.c | 7 ++++++-
drivers/dma-buf/heaps/cma_heap.c | 3 +++
drivers/dma-buf/heaps/system_heap.c | 3 +++
drivers/dma-buf/udmabuf.c | 3 +++
drivers/gpu/drm/drm_prime.c | 2 ++
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c | 2 ++
drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c | 2 ++
drivers/gpu/drm/tegra/gem.c | 2 ++
drivers/media/common/videobuf2/videobuf2-dma-contig.c | 3 +++
drivers/media/common/videobuf2/videobuf2-dma-sg.c | 3 +++
drivers/media/common/videobuf2/videobuf2-vmalloc.c | 3 +++
drivers/misc/fastrpc.c | 3 +++
12 files changed, 35 insertions(+), 1 deletion(-)
--
2.37.3
When userspace mmaps dma-buf's fd, the dma-buf reservation lock must be
held. Add locking sanity check to the dma-buf mmaping callback to ensure
that the locking assumption won't regress in the future.
Suggested-by: Daniel Vetter <[email protected]>
Signed-off-by: Dmitry Osipenko <[email protected]>
---
drivers/dma-buf/udmabuf.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
index 2bcdb935a3ac..283816fbd72f 100644
--- a/drivers/dma-buf/udmabuf.c
+++ b/drivers/dma-buf/udmabuf.c
@@ -2,6 +2,7 @@
#include <linux/cred.h>
#include <linux/device.h>
#include <linux/dma-buf.h>
+#include <linux/dma-resv.h>
#include <linux/highmem.h>
#include <linux/init.h>
#include <linux/kernel.h>
@@ -49,6 +50,8 @@ static int mmap_udmabuf(struct dma_buf *buf, struct vm_area_struct *vma)
{
struct udmabuf *ubuf = buf->priv;
+ dma_resv_assert_held(buf->resv);
+
if ((vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) == 0)
return -EINVAL;
--
2.37.3
On 11/10/22 23:13, Dmitry Osipenko wrote:
> Hello,
>
> Recently, dma-buf got a common locking convention for importers and
> exporters. All the dma-buf functions were moved to the new locking
> convention, apart from the dma_buf_mmap_internal() that was missed out
> by accident. This series moves dma_buf_mmap_internal() to the dynamic
> locking specification and updates drivers that support mmaping of
> dma-bufs to use the debug-assert of the lock.
>
> Thanks to Daniel Vetter for spotting the missed function!
>
> Dmitry Osipenko (6):
> dma-buf: Move dma_buf_mmap_internal() to dynamic locking specification
> drm: Assert held reservation lock for dma-buf mmapping
> udmabuf: Assert held reservation lock for dma-buf mmapping
> dma-buf/heaps: Assert held reservation lock for dma-buf mmapping
> media: videobuf2: Assert held reservation lock for dma-buf mmapping
> fastrpc: Assert held reservation lock for dma-buf mmapping
>
> drivers/dma-buf/dma-buf.c | 7 ++++++-
> drivers/dma-buf/heaps/cma_heap.c | 3 +++
> drivers/dma-buf/heaps/system_heap.c | 3 +++
> drivers/dma-buf/udmabuf.c | 3 +++
> drivers/gpu/drm/drm_prime.c | 2 ++
> drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c | 2 ++
> drivers/gpu/drm/omapdrm/omap_gem_dmabuf.c | 2 ++
> drivers/gpu/drm/tegra/gem.c | 2 ++
> drivers/media/common/videobuf2/videobuf2-dma-contig.c | 3 +++
> drivers/media/common/videobuf2/videobuf2-dma-sg.c | 3 +++
> drivers/media/common/videobuf2/videobuf2-vmalloc.c | 3 +++
> drivers/misc/fastrpc.c | 3 +++
> 12 files changed, 35 insertions(+), 1 deletion(-)
>
Applied to drm-misc-next
--
Best regards,
Dmitry