|
@@ -46,6 +46,48 @@ The buffer-user
|
|
same area of memory. This interface is provided by :c:type:`struct
|
|
same area of memory. This interface is provided by :c:type:`struct
|
|
dma_buf_attachment <dma_buf_attachment>`.
|
|
dma_buf_attachment <dma_buf_attachment>`.
|
|
|
|
|
|
|
|
+Any exporters or users of the dma-buf buffer sharing framework must have a
|
|
|
|
+'select DMA_SHARED_BUFFER' in their respective Kconfigs.
|
|
|
|
+
|
|
|
|
+Userspace Interface Notes
|
|
|
|
+~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
+
|
|
|
|
+Mostly a DMA buffer file descriptor is simply an opaque object for userspace,
|
|
|
|
+and hence the generic interface exposed is very minimal. There's a few things to
|
|
|
|
+consider though:
|
|
|
|
+
|
|
|
|
+- Since kernel 3.12 the dma-buf FD supports the llseek system call, but only
|
|
|
|
+ with offset=0 and whence=SEEK_END|SEEK_SET. SEEK_SET is supported to allow
|
|
|
|
+ the usual size discover pattern size = SEEK_END(0); SEEK_SET(0). Every other
|
|
|
|
+ llseek operation will report -EINVAL.
|
|
|
|
+
|
|
|
|
+ If llseek on dma-buf FDs isn't support the kernel will report -ESPIPE for all
|
|
|
|
+ cases. Userspace can use this to detect support for discovering the dma-buf
|
|
|
|
+ size using llseek.
|
|
|
|
+
|
|
|
|
+- In order to avoid fd leaks on exec, the FD_CLOEXEC flag must be set
|
|
|
|
+ on the file descriptor. This is not just a resource leak, but a
|
|
|
|
+ potential security hole. It could give the newly exec'd application
|
|
|
|
+ access to buffers, via the leaked fd, to which it should otherwise
|
|
|
|
+ not be permitted access.
|
|
|
|
+
|
|
|
|
+ The problem with doing this via a separate fcntl() call, versus doing it
|
|
|
|
+ atomically when the fd is created, is that this is inherently racy in a
|
|
|
|
+ multi-threaded app[3]. The issue is made worse when it is library code
|
|
|
|
+ opening/creating the file descriptor, as the application may not even be
|
|
|
|
+ aware of the fd's.
|
|
|
|
+
|
|
|
|
+ To avoid this problem, userspace must have a way to request O_CLOEXEC
|
|
|
|
+ flag be set when the dma-buf fd is created. So any API provided by
|
|
|
|
+ the exporting driver to create a dmabuf fd must provide a way to let
|
|
|
|
+ userspace control setting of O_CLOEXEC flag passed in to dma_buf_fd().
|
|
|
|
+
|
|
|
|
+- Memory mapping the contents of the DMA buffer is also supported. See the
|
|
|
|
+ discussion below on `CPU Access to DMA Buffer Objects`_ for the full details.
|
|
|
|
+
|
|
|
|
+- The DMA buffer FD is also pollable, see `Fence Poll Support`_ below for
|
|
|
|
+ details.
|
|
|
|
+
|
|
Basic Operation and Device DMA Access
|
|
Basic Operation and Device DMA Access
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
@@ -58,6 +100,12 @@ CPU Access to DMA Buffer Objects
|
|
.. kernel-doc:: drivers/dma-buf/dma-buf.c
|
|
.. kernel-doc:: drivers/dma-buf/dma-buf.c
|
|
:doc: cpu access
|
|
:doc: cpu access
|
|
|
|
|
|
|
|
+Fence Poll Support
|
|
|
|
+~~~~~~~~~~~~~~~~~~
|
|
|
|
+
|
|
|
|
+.. kernel-doc:: drivers/dma-buf/dma-buf.c
|
|
|
|
+ :doc: fence polling
|
|
|
|
+
|
|
Kernel Functions and Structures Reference
|
|
Kernel Functions and Structures Reference
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|