Marek Szyprowski <[email protected]> writes:

> On 02.12.2026 10:54, Aneesh Kumar K.V (Arm) wrote:
>> Confidential-computing shared DMA allocations require CMA backing memory
>> to be aligned to the architecture shared-memory granule. Passing explicit
>> alignment orders through the DMA allocation stack exposes this derived
>> constraint to callers and requires separate preferred and mandatory values.
>>
>> The DMA core already records whether an allocation needs shared backing in
>> __DMA_ATTR_ALLOC_CC_SHARED. Pass allocation attributes to the DMA-contiguous
>> entry points and derive the mandatory alignment there before calling CMA.
>> Preserve the existing alignment clamping for ordinary allocations, while
>> rejecting shared allocations whose granule exceeds CONFIG_CMA_ALIGNMENT so
>> callers can fall back to the page allocator.
>
> Do we really need to pass the information about required alignment to every
> low-level allocator? I think that all low-level allocator obey the common rule
> that the buffer is aligned to the nearest power-of-2 larger/equal to the
> requested size.
>
> IMHO it would be much easier to ensure that the caller simply aligns the
> requested buffer size to the shared-memory granule size?
>


We already round the size in paths such as dma_direct_alloc(), using
cc_shared_round_size() before passing the rounded size to
__dma_direct_alloc_pages() -> dma_alloc_contiguous().

        if (mark_mem_decrypt) {
                if (cc_shared_round_size(size, &shared_size))
                        return NULL;
        }

        /* we always manually zero the memory once we are done */
        page = __dma_direct_alloc_pages(dev, size, gfp & ~__GFP_ZERO,
                                        allow_highmem, attrs);


But dma_alloc_contiguous() caps the alignment at CONFIG_CMA_ALIGNMENT
(also documented in Kconfig). The rounded size alone cannot tell us the
required minimum alignment. We pass the DMA attribute so the CMA
allocation code can derive that minimum from the shared granule size and
check it against CONFIG_CMA_ALIGNMENT.

When the shared-memory granule's alignment order exceeds
CONFIG_CMA_ALIGNMENT, we need to skip CMA so that the caller can fall
back to the page allocator.

Rather than passing an explicit alignment value through the call chain,
I thought it was clearer to pass the DMA attribute and derive the
required alignment where we check the CMA limit.

-aneesh

Reply via email to