-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Backport of udmabuf and dma-heaps #3571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
7d6e241
to
9daf453
Compare
8567cd8
to
71d5db1
Compare
Rebased to top of 5.4. |
Hmm, having cherry-picked to my working branch, I'm getting /dev/dma_heap/system and /dev/dma_heap/reserved, but no longer /dev/dma_heap/linux,cma. It may be a build issue, but the option is enabled
...
in dmesg if cma= exists. |
Tested with https://github.com/6by9/userland/tree/clean having a modified user-vcsm library, and dma-heaps work. Not tested udmabuf - it wasn't clear whether they actually help us on the Pi where most dmabuf consumers want contiguous allocations. The backport won't do any harm though. |
Question to @XECDesign. |
I'm guessing copying on of the existing rules and adjusting it in the obvious way didn't work. I'd need to poke around with |
I never managed to get the right runes for vcsm-cma. |
I seem to recall |
If that doesn't work, there is a kernel function you can instrument to log the events on the way out. |
Thanks both. Things to look at. |
Found. Thanks for the guidance
so adding
does the magic. |
Thanks for the update - that's a useful trick. |
Should I add that for the next image? |
@XECDesign I think it's worth adding. I believe it is working with kodi (from logs it can access /dev/dma_heap once permissions are fixed). I think buffers allocated come from here (although I'll see if I can be sure with debugger) and video plays okay. |
@XECDesign Yes please. Now I know the runes, give me a few minutes and I'll see if I can get the runes right for vcsm-cma as well so that we can restrict it a little more than it currently is. |
I have |
so that implies that SUBSYSTEM is not vcsm-cma. DRIVER might be, but that hasn't worked for me. The driver has a nasty hack in it to set permissions to 666 https://github.com/raspberrypi/linux/blob/rpi-5.4.y/drivers/staging/vc04_services/vc-sm-cma/vc_sm.c#L1602 |
Ah yes - it works from the 666 permissions not the ownership. |
Further magic runes (got to love search engines)
So
is the correct line for vcsm-cma. Can we add that one to the default rules as well please? I can then revert the kernel hack. |
Commit 19d32ac upstream. Commit 7f0de8d ("dma-buf: Drop dma_buf_k(un)map") removed map/unmap handlers, but they still existed in udmabuf. Remove them there as well Signed-off-by: Maarten Lankhorst <[email protected]> Fixes: 7f0de8d ("dma-buf: Drop dma_buf_k(un)map") Cc: Sumit Semwal <[email protected]> Cc: Daniel Vetter <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Reviewed-by: Daniel Vetter <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
Commit bc7a71d uptream. The GEM prime helpers do it, so should we. It's also possible to make it optional later. Signed-off-by: Gurchetan Singh <[email protected]> Link: http://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Gerd Hoffmann <[email protected]>
Commit c1bbed6 upstream. Will be used later. v2: rename 'udmabuf_misc' to 'device' (kraxel) Signed-off-by: Gurchetan Singh <[email protected]> Link: http://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Gerd Hoffmann <[email protected]>
Commit 17a7ce2 upstream. These are nice functions and can be re-used. Signed-off-by: Gurchetan Singh <[email protected]> Link: http://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Gerd Hoffmann <[email protected]>
Commit 284562e upstream. With the misc device, we should end up using the result of get_arch_dma_ops(..) or dma-direct ops. This can allow us to have WC mappings in the guest after synchronization. Signed-off-by: Gurchetan Singh <[email protected]> Link: http://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Gerd Hoffmann <[email protected]>
Commit 1ffe095 upstream. I'm just going to put Chia's review comment here since it sums the issue rather nicely: "(1) Semantically, a dma-buf is in DMA domain. CPU access from the importer must be surrounded by {begin,end}_cpu_access. This gives the exporter a chance to move the buffer to the CPU domain temporarily. (2) When the exporter itself has other means to do CPU access, it is only reasonable for the exporter to move the buffer to the CPU domain before access, and to the DMA domain after access. The exporter can potentially reuse {begin,end}_cpu_access for that purpose. Because of (1), udmabuf does need to implement the {begin,end}_cpu_access hooks. But "begin" should mean dma_sync_sg_for_cpu and "end" should mean dma_sync_sg_for_device. Because of (2), if userspace wants to continuing accessing through the memfd mapping, it should call udmabuf's {begin,end}_cpu_access to avoid cache issues." Reported-by: Chia-I Wu <[email protected]> Suggested-by: Chia-I Wu <[email protected]> Fixes: 284562e ("udmabuf: implement begin_cpu_access/end_cpu_access hooks") Signed-off-by: Gurchetan Singh <[email protected]> Link: http://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Gerd Hoffmann <[email protected]>
Commit c02a81f upstream. This framework allows a unified userspace interface for dma-buf exporters, allowing userland to allocate specific types of memory for use in dma-buf sharing. Each heap is given its own device node, which a user can allocate a dma-buf fd from using the DMA_HEAP_IOC_ALLOC. This code is an evoluiton of the Android ION implementation, and a big thanks is due to its authors/maintainers over time for their effort: Rebecca Schultz Zavin, Colin Cross, Benjamin Gaignard, Laura Abbott, and many other contributors! Cc: Laura Abbott <[email protected]> Cc: Benjamin Gaignard <[email protected]> Cc: Sumit Semwal <[email protected]> Cc: Liam Mark <[email protected]> Cc: Pratik Patel <[email protected]> Cc: Brian Starkey <[email protected]> Cc: Vincent Donnefort <[email protected]> Cc: Sudipto Paul <[email protected]> Cc: Andrew F. Davis <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Chenbo Feng <[email protected]> Cc: Alistair Strachan <[email protected]> Cc: Hridya Valsaraju <[email protected]> Cc: Sandeep Patil <[email protected]> Cc: Hillf Danton <[email protected]> Cc: Dave Airlie <[email protected]> Cc: [email protected] Reviewed-by: Brian Starkey <[email protected]> Acked-by: Sandeep Patil <[email protected]> Signed-off-by: Andrew F. Davis <[email protected]> Signed-off-by: John Stultz <[email protected]> Signed-off-by: Sumit Semwal <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
Commit 5248eb1 upstream. Add generic helper dmabuf ops for dma heaps, so we can reduce the amount of duplicative code for the exported dmabufs. This code is an evolution of the Android ION implementation, so thanks to its original authors and maintainters: Rebecca Schultz Zavin, Colin Cross, Laura Abbott, and others! Cc: Laura Abbott <[email protected]> Cc: Benjamin Gaignard <[email protected]> Cc: Sumit Semwal <[email protected]> Cc: Liam Mark <[email protected]> Cc: Pratik Patel <[email protected]> Cc: Brian Starkey <[email protected]> Cc: Vincent Donnefort <[email protected]> Cc: Sudipto Paul <[email protected]> Cc: Andrew F. Davis <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Chenbo Feng <[email protected]> Cc: Alistair Strachan <[email protected]> Cc: Hridya Valsaraju <[email protected]> Cc: Sandeep Patil <[email protected]> Cc: Hillf Danton <[email protected]> Cc: Dave Airlie <[email protected]> Cc: [email protected] Reviewed-by: Benjamin Gaignard <[email protected]> Reviewed-by: Brian Starkey <[email protected]> Acked-by: Sandeep Patil <[email protected]> Acked-by: Laura Abbott <[email protected]> Tested-by: Ayan Kumar Halder <[email protected]> Signed-off-by: John Stultz <[email protected]> Signed-off-by: Sumit Semwal <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
Commit efa04fe upstream. This patch adds system heap to the dma-buf heaps framework. This allows applications to get a page-allocator backed dma-buf for non-contiguous memory. This code is an evolution of the Android ION implementation, so thanks to its original authors and maintainters: Rebecca Schultz Zavin, Colin Cross, Laura Abbott, and others! Cc: Laura Abbott <[email protected]> Cc: Benjamin Gaignard <[email protected]> Cc: Sumit Semwal <[email protected]> Cc: Liam Mark <[email protected]> Cc: Pratik Patel <[email protected]> Cc: Brian Starkey <[email protected]> Cc: Vincent Donnefort <[email protected]> Cc: Sudipto Paul <[email protected]> Cc: Andrew F. Davis <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Chenbo Feng <[email protected]> Cc: Alistair Strachan <[email protected]> Cc: Hridya Valsaraju <[email protected]> Cc: Sandeep Patil <[email protected]> Cc: Hillf Danton <[email protected]> Cc: Dave Airlie <[email protected]> Cc: [email protected] Reviewed-by: Benjamin Gaignard <[email protected]> Reviewed-by: Brian Starkey <[email protected]> Acked-by: Sandeep Patil <[email protected]> Acked-by: Laura Abbott <[email protected]> Tested-by: Ayan Kumar Halder <[email protected]> Signed-off-by: John Stultz <[email protected]> Signed-off-by: Sumit Semwal <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
Commit b61614e upstream. This adds a CMA heap, which allows userspace to allocate a dma-buf of contiguous memory out of a CMA region. This code is an evolution of the Android ION implementation, so thanks to its original author and maintainters: Benjamin Gaignard, Laura Abbott, and others! NOTE: This patch only adds the default CMA heap. We will enable selectively adding other CMA memory regions to the dmabuf heaps interface with a later patch (which requires a dt binding) Cc: Laura Abbott <[email protected]> Cc: Benjamin Gaignard <[email protected]> Cc: Sumit Semwal <[email protected]> Cc: Liam Mark <[email protected]> Cc: Pratik Patel <[email protected]> Cc: Brian Starkey <[email protected]> Cc: Vincent Donnefort <[email protected]> Cc: Sudipto Paul <[email protected]> Cc: Andrew F. Davis <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Chenbo Feng <[email protected]> Cc: Alistair Strachan <[email protected]> Cc: Hridya Valsaraju <[email protected]> Cc: Sandeep Patil <[email protected]> Cc: Hillf Danton <[email protected]> Cc: Dave Airlie <[email protected]> Cc: [email protected] Reviewed-by: Benjamin Gaignard <[email protected]> Reviewed-by: Brian Starkey <[email protected]> Acked-by: Sandeep Patil <[email protected]> Acked-by: Laura Abbott <[email protected]> Tested-by: Ayan Kumar Halder <[email protected]> Signed-off-by: John Stultz <[email protected]> Signed-off-by: Sumit Semwal <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
Commit a877992 upstream. Add very trivial allocation and import test for dma-heaps, utilizing the vgem driver as a test importer. A good chunk of this code taken from: tools/testing/selftests/android/ion/ionmap_test.c Originally by Laura Abbott <[email protected]> Cc: Benjamin Gaignard <[email protected]> Cc: Sumit Semwal <[email protected]> Cc: Liam Mark <[email protected]> Cc: Pratik Patel <[email protected]> Cc: Brian Starkey <[email protected]> Cc: Vincent Donnefort <[email protected]> Cc: Sudipto Paul <[email protected]> Cc: Andrew F. Davis <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Chenbo Feng <[email protected]> Cc: Alistair Strachan <[email protected]> Cc: Hridya Valsaraju <[email protected]> Cc: Sandeep Patil <[email protected]> Cc: Hillf Danton <[email protected]> Cc: Dave Airlie <[email protected]> Cc: [email protected] Reviewed-by: Benjamin Gaignard <[email protected]> Reviewed-by: Brian Starkey <[email protected]> Acked-by: Sandeep Patil <[email protected]> Acked-by: Laura Abbott <[email protected]> Tested-by: Ayan Kumar Halder <[email protected]> Signed-off-by: John Stultz <[email protected]> Signed-off-by: Sumit Semwal <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
Commit b3b4346 upstream. This is more consistent with the DMA and DRM frameworks convention. This patch is only a name change, no logic is changed. Signed-off-by: Andrew F. Davis <[email protected]> Acked-by: John Stultz <[email protected]> Signed-off-by: Sumit Semwal <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
The heaps are already in a directory of heaps, adding _heap to a heap name is redundant. This patch is only a name change, no logic is changed. Signed-off-by: Andrew F. Davis <[email protected]> Acked-by: John Stultz <[email protected]> Signed-off-by: Sumit Semwal <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
Commit f9d3b2c upstream. The -ENOTTY error return path does not free the allocated kdata as it returns directly. Fix this by returning via the error handling label err. Addresses-Coverity: ("Resource leak") Fixes: c02a81f ("dma-buf: Add dma-buf heaps framework") Signed-off-by: Colin Ian King <[email protected]> Acked-by: John Stultz <[email protected]> Signed-off-by: Sumit Semwal <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
Commit 7d411af upstream. Fix the following sparse warning. drivers/dma-buf/dma-heap.c:109:14: warning: symbol 'dma_heap_ioctl_cmds' was not declared. Should it be static? Acked-by: Andrew F. Davis <[email protected]> Acked-by: John Stultz <[email protected]> Signed-off-by: zhong jiang <[email protected]> Signed-off-by: Sumit Semwal <[email protected]> [sumits: rebased over IOCTL rename patches] Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
The CMA dma-heap allocator can be used in place of vcsm-cma doing the allocation side, thereby simplifying that driver. Signed-off-by: Dave Stevenson <[email protected]>
Messages from LibreElec folk say that this works for them, and I've had it working with both libcamera and a hacked user-vcsm (need to push that). |
@popcornmix seems happy (and he can always revert/delete if necessary) - merging. |
See: raspberrypi/linux#3626 kernel: VC4 DRM/KMS - use correct dma-ranges See: raspberrypi/linux#3623 kernel: media: bcm2835-unicam: Retain packing information on G_FMT See: raspberrypi/linux#3622 kernel: Switch to snd_soc_dai_set_bclk_ratio See: raspberrypi/linux#3620 kernel: V4L2 H264 framing fixes See: raspberrypi/linux#3614 kernel: drm/vc4: Fix VIC usage with Broadcast RGB See: raspberrypi/linux#3611 kernel: media: bcm2835-unicam: Always service interrupts See: raspberrypi/linux#3608 kernel: overlays: Fix audio parameter of vc4-kms-v3 See: raspberrypi/linux#2489 kernel: configs: Restore missing NF_TABLES settings See: raspberrypi/linux#3615 kernel: sc16is7xx: Fix for hardware flow control See: raspberrypi/linux#2542 kernel: Use the upstream cpufreq driver on non-BCM2835 Pis See: raspberrypi/linux#3604 kernel: Backport of udmabuf and dma-heaps See: raspberrypi/linux#3571 kernel: imx477 v4l2 driver See: raspberrypi/linux#3605 firmware: isp: fix ISP component to return non-zero focus FoMs firmware: Fix for IMX477 focal length, f_number and aperture firmware: Update firmware for USB MSD boot firmware: platform: Fix overflow on high arm overclocks firmware: video_encode: Add option to include header bytes with frame firmware: DSI display: Close I2C handle if the display doesn't probe firmware: mmal/vc: Add mapping for OMX_IndexConfigBufferStall / MMAL_PARAMETER_VIDEO_STALL_THRESHOLD See: https://www.raspberrypi.org/forums/viewtopic.php?f=70&t=273123&p=1655481 firmware: hdmi: Request an I2C interrupt for EDID reading firmware: i2c: Move using_interrupt flag into periph_setup
See: raspberrypi/linux#3626 kernel: VC4 DRM/KMS - use correct dma-ranges See: raspberrypi/linux#3623 kernel: media: bcm2835-unicam: Retain packing information on G_FMT See: raspberrypi/linux#3622 kernel: Switch to snd_soc_dai_set_bclk_ratio See: raspberrypi/linux#3620 kernel: V4L2 H264 framing fixes See: raspberrypi/linux#3614 kernel: drm/vc4: Fix VIC usage with Broadcast RGB See: raspberrypi/linux#3611 kernel: media: bcm2835-unicam: Always service interrupts See: raspberrypi/linux#3608 kernel: overlays: Fix audio parameter of vc4-kms-v3 See: raspberrypi/linux#2489 kernel: configs: Restore missing NF_TABLES settings See: raspberrypi/linux#3615 kernel: sc16is7xx: Fix for hardware flow control See: raspberrypi/linux#2542 kernel: Use the upstream cpufreq driver on non-BCM2835 Pis See: raspberrypi/linux#3604 kernel: Backport of udmabuf and dma-heaps See: raspberrypi/linux#3571 kernel: imx477 v4l2 driver See: raspberrypi/linux#3605 firmware: isp: fix ISP component to return non-zero focus FoMs firmware: Fix for IMX477 focal length, f_number and aperture firmware: Update firmware for USB MSD boot firmware: platform: Fix overflow on high arm overclocks firmware: video_encode: Add option to include header bytes with frame firmware: DSI display: Close I2C handle if the display doesn't probe firmware: mmal/vc: Add mapping for OMX_IndexConfigBufferStall / MMAL_PARAMETER_VIDEO_STALL_THRESHOLD See: https://www.raspberrypi.org/forums/viewtopic.php?f=70&t=273123&p=1655481 firmware: hdmi: Request an I2C interrupt for EDID reading firmware: i2c: Move using_interrupt flag into periph_setup
As title. dma-heaps can hopefully simplify vcsm-cma, and they're wanted by the Libreelec folk.
They both seem to work in so far as they create /dev/udmabuf and /dev/dma_heap/linux,cma respectively. I haven't tested them from userspace.
Need to add a commit that adds them to the defconfig.