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

[media] videobuf2: Add support for file access mode flags for DMABUF exporting

Currently it is not possible for userspace to map a DMABUF exported buffer
with write permissions. This patch allows to also pass O_RDONLY/O_RDWR when
exporting the buffer, so that userspace may map it with write permissions.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>

authored by

Philipp Zabel and committed by
Mauro Carvalho Chehab
ea3aba84 d8eec74a

+12 -10
+5 -3
Documentation/DocBook/media/v4l/vidioc-expbuf.xml
··· 73 73 format. For the single-planar API, applications must set <structfield> plane 74 74 </structfield> to zero. Additional flags may be posted in the <structfield> 75 75 flags </structfield> field. Refer to a manual for open() for details. 76 - Currently only O_CLOEXEC is supported. All other fields must be set to zero. 76 + Currently only O_CLOEXEC, O_RDONLY, O_WRONLY, and O_RDWR are supported. All 77 + other fields must be set to zero. 77 78 In the case of multi-planar API, every plane is exported separately using 78 79 multiple <constant> VIDIOC_EXPBUF </constant> calls. </para> 79 80 ··· 171 170 <entry>__u32</entry> 172 171 <entry><structfield>flags</structfield></entry> 173 172 <entry>Flags for the newly created file, currently only <constant> 174 - O_CLOEXEC </constant> is supported, refer to the manual of open() for more 175 - details.</entry> 173 + O_CLOEXEC </constant>, <constant>O_RDONLY</constant>, <constant>O_WRONLY 174 + </constant>, and <constant>O_RDWR</constant> are supported, refer to the manual 175 + of open() for more details.</entry> 176 176 </row> 177 177 <row> 178 178 <entry>__s32</entry>
+4 -4
drivers/media/v4l2-core/videobuf2-core.c
··· 1824 1824 return -EINVAL; 1825 1825 } 1826 1826 1827 - if (eb->flags & ~O_CLOEXEC) { 1828 - dprintk(1, "Queue does support only O_CLOEXEC flag\n"); 1827 + if (eb->flags & ~(O_CLOEXEC | O_ACCMODE)) { 1828 + dprintk(1, "Queue does support only O_CLOEXEC and access mode flags\n"); 1829 1829 return -EINVAL; 1830 1830 } 1831 1831 ··· 1848 1848 1849 1849 vb_plane = &vb->planes[eb->plane]; 1850 1850 1851 - dbuf = call_memop(q, get_dmabuf, vb_plane->mem_priv); 1851 + dbuf = call_memop(q, get_dmabuf, vb_plane->mem_priv, eb->flags & O_ACCMODE); 1852 1852 if (IS_ERR_OR_NULL(dbuf)) { 1853 1853 dprintk(1, "Failed to export buffer %d, plane %d\n", 1854 1854 eb->index, eb->plane); 1855 1855 return -EINVAL; 1856 1856 } 1857 1857 1858 - ret = dma_buf_fd(dbuf, eb->flags); 1858 + ret = dma_buf_fd(dbuf, eb->flags & ~O_ACCMODE); 1859 1859 if (ret < 0) { 1860 1860 dprintk(3, "buffer %d, plane %d failed to export (%d)\n", 1861 1861 eb->index, eb->plane, ret);
+2 -2
drivers/media/v4l2-core/videobuf2-dma-contig.c
··· 393 393 return sgt; 394 394 } 395 395 396 - static struct dma_buf *vb2_dc_get_dmabuf(void *buf_priv) 396 + static struct dma_buf *vb2_dc_get_dmabuf(void *buf_priv, unsigned long flags) 397 397 { 398 398 struct vb2_dc_buf *buf = buf_priv; 399 399 struct dma_buf *dbuf; ··· 404 404 if (WARN_ON(!buf->sgt_base)) 405 405 return NULL; 406 406 407 - dbuf = dma_buf_export(buf, &vb2_dc_dmabuf_ops, buf->size, 0); 407 + dbuf = dma_buf_export(buf, &vb2_dc_dmabuf_ops, buf->size, flags); 408 408 if (IS_ERR(dbuf)) 409 409 return NULL; 410 410
+1 -1
include/media/videobuf2-core.h
··· 83 83 struct vb2_mem_ops { 84 84 void *(*alloc)(void *alloc_ctx, unsigned long size, gfp_t gfp_flags); 85 85 void (*put)(void *buf_priv); 86 - struct dma_buf *(*get_dmabuf)(void *buf_priv); 86 + struct dma_buf *(*get_dmabuf)(void *buf_priv, unsigned long flags); 87 87 88 88 void *(*get_userptr)(void *alloc_ctx, unsigned long vaddr, 89 89 unsigned long size, int write);