[PATCH 03/27] libcamera: dma_buf_allocator: Favour udmabuf over cma heap allocations

Laurent Pinchart laurent.pinchart at ideasonboard.com
Wed Apr 23 00:22:31 CEST 2025


Hi Bryan,

Thank you for the patch.

On Tue, Apr 22, 2025 at 10:58:56PM +0100, Bryan O'Donoghue wrote:
> When /dev/dma_heap/linux,cma or /dev/dma_heap/system exist currently we
> favour allocation from this type of heap over /dev/udmabuf.
> 
> We ought to favour udmabuf though
> 
> - udmabuf is the preferred method by various distros for security reasons
> - Contiguous memory is a scarce resource
> 
> Change the ordering of the allocator lookup so that the udmabuf lookup
> comes first.

This means that on a system where CMA allocation is possible from
userspace, the buffers allocated by libcamera for the virtual pipeline
handler and ISP won't be shareable without copies with a consumer that
requires contiguous memory (e.g. most KMS devices on Arm platforms).
Isn't that an issue ? It seems to even count as a regression.

> Fixes: ea4baaacc325 ("libcamera: DmaBufAllocator: Support allocating from /dev/udmabuf")
> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue at linaro.org>
> ---
>  src/libcamera/dma_buf_allocator.cpp | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/libcamera/dma_buf_allocator.cpp b/src/libcamera/dma_buf_allocator.cpp
> index d8c62dd6..722ffd46 100644
> --- a/src/libcamera/dma_buf_allocator.cpp
> +++ b/src/libcamera/dma_buf_allocator.cpp
> @@ -45,10 +45,10 @@ static constexpr std::array<DmaBufAllocatorInfo, 4> providerInfos = { {
>  	 * /dev/dma_heap/linux,cma is the CMA dma-heap. When the cma heap size is
>  	 * specified on the kernel command line, this gets renamed to "reserved".
>  	 */
> +	{ DmaBufAllocator::DmaBufAllocatorFlag::UDmaBuf, "/dev/udmabuf" },
>  	{ DmaBufAllocator::DmaBufAllocatorFlag::CmaHeap, "/dev/dma_heap/linux,cma" },
>  	{ DmaBufAllocator::DmaBufAllocatorFlag::CmaHeap, "/dev/dma_heap/reserved" },
>  	{ DmaBufAllocator::DmaBufAllocatorFlag::SystemHeap, "/dev/dma_heap/system" },
> -	{ DmaBufAllocator::DmaBufAllocatorFlag::UDmaBuf, "/dev/udmabuf" },
>  } };
>  
>  LOG_DEFINE_CATEGORY(DmaBufAllocator)

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list