compat: backport kernel dma-buf implementation
PATCH 1/1 compat: backport kernel dma-buf implementation
From: "Luis R. Rodriguez" <[email protected]>
dma-buf was added via commit d15bd7ee on v3.3 but completed in a more sound fassion in later kernels, you should preferably be at v3.5 a least, so we take the latest dma-buf implementation and port it for usage on kernels [3.0-3.4]. We take the implementation as of next-20130328.
This is implemented as a non modular solution upstream but we can carry the implementation into our compat module.
Note that although commit f23513e8d was added on v2.6.23 that allowed the kernel to call get_unused_fd_flags(flags) for O_CLOEXEC setting, this routine was not exported until v3.7. dma-buf makes use of it, and since our backported dma-buf implementation is modular it means we have to work around the lack of get_unused_fd_flags() exported symbol on older kernels. Due to the security concerns noted by Ulrich on f23513e8 we need to ensure the operatin is atomic so we fix this on our port of dma-buf for older kernels by adding our own dma_buf_fd_set_flag() to be called when dma_buf_fd() is used. This implementation is available for usage on kernels >= 3.0. We disable it for v3.5 as we're happy with that implementation.
mcgrof@frijol ~/linux-next (git::master)$ git describe --contains \ d15bd7ee445d0702ad801fdaece348fdb79e6581
v3.3-rc1~161^2~2
mcgrof@frijol ~/linux-next (git::master)$ git describe --contains \ f23513e8d96cf5e6cf8d2ff0cb5dd6bbc33995e4
v2.6.23-rc1~894
mcgrof@frijol ~/linux-stable (git::linux-3.2.y)$ git describe --contains \ 1a7bd226
v3.7-rc1~134^2~69
Carried over the implementation from linux-next next-20130328
commit d15bd7ee445d0702ad801fdaece348fdb79e6581
Author: Sumit Semwal <[email protected]> Date: Mon Dec 26 14:53:15 2011 +0530
dma-buf: Introduce dma buffer sharing mechanism
This is the first step in defining a dma buffer sharing mechanism.
A new buffer object dma_buf is added, with operations and API to allow easy sharing of this buffer object across devices.
The framework allows:
- creation of a buffer object, its association with a file pointer, and associated allocator-defined operations on that buffer. This operation is called the 'export' operation.
- different devices to 'attach' themselves to this exported buffer object, to facilitate backing storage negotiation, using dma_buf_attach() API.
- the exported buffer object to be shared with the other entity by asking for its 'file-descriptor (fd)', and sharing the fd across.
- a received fd to get the buffer object back, where it can be accessed using the associated exporter-defined operations.
- the exporter and user to share the scatterlist associated with this buffer object using map_dma_buf and unmap_dma_buf operations.
Atleast one 'attach()' call is required to be made prior to calling the map_dma_buf() operation.
Couple of building blocks in map_dma_buf() are added to ease introduction of sync'ing across exporter and users, and late allocation by the exporter.
For this first version, this framework will work with certain conditions:
- *ONLY* exporter will be allowed to mmap to userspace (outside of this framework - mmap is not a buffer object operation),
- currently, *ONLY* users that do not need CPU access to the buffer are allowed.
More details are there in the documentation patch.
This is based on design suggestions from many people at the mini-summits[1], most notably from Arnd Bergmann <[email protected]>, Rob Clark <[email protected]> and Daniel Vetter <[email protected]>.
The implementation is inspired from proof-of-concept patch-set from Tomasz Stanislawski <[email protected]>, who demonstrated buffer sharing between two v4l2 devices. [2]
[1]: https://wiki.linaro.org/OfficeofCTO/MemoryManagement
[2]: http://lwn.net/Articles/454389
1 2.6.24 [ OK ] 2 2.6.25 [ OK ] 3 2.6.26 [ OK ] 4 2.6.27 [ OK ] 5 2.6.28 [ OK ] 6 2.6.29 [ OK ] 7 2.6.30 [ OK ] 8 2.6.31 [ OK ] 9 2.6.32 [ OK ] 10 2.6.33 [ OK ] 11 2.6.34 [ OK ] 12 2.6.35 [ OK ] 13 2.6.36 [ OK ] 14 2.6.37 [ OK ] 15 2.6.38 [ OK ] 16 2.6.39 [ OK ] 17 3.0.65 [ OK ] 18 3.1.10 [ OK ] 19 3.2.38 [ OK ] 20 3.3.8 [ OK ] 21 3.4.32 [ OK ] 22 3.5.7 [ OK ] 23 3.6.11 [ OK ] 24 3.7.9 [ OK ] 25 3.8.0 [ OK ] 26 3.9-rc1 [ OK ]
--- compat/Makefile | 1 + compat/dma-buf.c | 578 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/dma-buf.h | 215 ++++++++++++++++++ 3 files changed, 794 insertions(+) create mode 100644 compat/dma-buf.c create mode 100644 include/linux/dma-buf.h
compat/Makefile +1 -0
@@ -48,6 +48,7 @@ compat-$(CONFIG_COMPAT_KERNEL_3_3) += \ compat-$(CONFIG_COMPAT_KERNEL_3_4) += compat-3.4.o compat-$(CONFIG_COMPAT_KERNEL_3_5) += \ compat-3.5.o \ + dma-buf.o \ user_namespace.o compat-$(CONFIG_COMPAT_KERNEL_3_6) += compat-3.6.o compat-$(CONFIG_COMPAT_KERNEL_3_7) += compat-3.7.o
compat/dma-buf.c new file +578 -0
578 lines not on this page · raw message
include/linux/dma-buf.h new file +215 -0
215 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Quoted 6 lines
dma-buf was added via commit
d15bd7eeon v3.3 but completed in a more sound fassion in later kernels, you should preferably be at v3.5 a least, so we take the latest dma-buf implementation and port it for usage on kernels [3.0-3.4]. We take the implementation as of next-20130328.
I'm curious about that approach -- I noticed it a few times already, e.g. with CONFIG_AVERAGE, however...
If you don't mangle symbols (you don't), then wouldn't this cause linking errors when you try to load compat.ko on say kernel 3.0?
johannes
Quoted 7 lines · Johannes Berg
Quoted 6 lines
dma-buf was added via commit
d15bd7eeon v3.3 but completed in a more sound fassion in later kernels, you should preferably be at v3.5 a least, so we take the latest dma-buf implementation and port it for usage on kernels [3.0-3.4]. We take the implementation as of next-20130328.
Quoted 5 lines
I'm curious about that approach -- I noticed it a few times already, e.g. with
CONFIG_AVERAGE, however...If you don't mangle symbols (you don't), then wouldn't this cause linking errors when you try to load compat.ko on say kernel 3.0?
Did you see the usage of LINUX_BACKPORT() on the header file? That would rename the exported symbols, and the header we carry makes sure the kernel's original is not used, that means that our DRM code would use our backport_*() symbols instead. Not sure, perhaps I'm missing something?
Luis
Quoted 5 lines · Luis R. Rodriguez
Did you see the usage of
LINUX_BACKPORT()on the header file? That would rename the exported symbols, and the header we carry makes sure the kernel's original is not used, that means that our DRM code would use our backport_*() symbols instead. Not sure, perhaps I'm missing something?
Ah no, I missed that, sorry.
johannes