On Thu, Dec 03, 2026 at 02:13:21PM +0100, Marek Szyprowski wrote:
> 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.
The CMA API is a little weird and doesn't do that..
dma_alloc_from_contiguous() is probably the wrong API for the users,
all of them are doing like this:
page = dma_alloc_from_contiguous(NULL, 1 << order,
order,
false);
Which effectively makes everything aligned to the size in the first
place.
I don't really understand why we have both
static inline struct page *dma_alloc_contiguous(struct device *dev, size_t size,
gfp_t gfp, unsigned long attrs)
And
static inline struct page *dma_alloc_from_contiguous(struct device *dev,
size_t count, unsigned int order, unsigned long attrs,
bool no_warn)
Can't the atomic pool just use dma_alloc_contiguous with a size
instead of the other API?
I say this because:
> IMHO it would be much easier to ensure that the caller simply aligns the
> requested buffer size to the shared-memory granule size?
The overal design of this series is to hide the set_memory_decrypted()
inside the allocators.
So, IMHO, it is a mistake that cma_alloc() or related isn't calling
the set_memory_decrypted, and all the remaing calls to
cc_make_shared() look misplaced to me because they are not immediately
linked to a low level allocator.
dma_alloc_contiguous() has attrs in this series, and it can be updated
to call shared versions of both the plain and CMA allocators and just
return already shared memory directly.
This would eliminate the rest of the open coding of cc_make_shared(),
I think.
With another little fix to allow the NULL dev we can just use it in
the atomic pools directly. For example a little helper like this:
static struct page *atomic_pool_alloc_single(struct dma_gen_pool *dma_pool,
unsigned int order, gfp_t gfp)
{
unsigned long attrs = dma_pool->cc_shared ? __DMA_ATTR_ALLOC_CC_SHARED
: 0;
struct page *page;
void *addr;
if (cma_in_zone(gfp)) {
page = dma_alloc_contiguous(NULL, PAGE_SIZE << order, gfp,
attrs);
if (page)
return page;
}
if (dma_pool->cc_shared) {
addr = alloc_cc_shared(gfp | __GFP_NOWARN, PAGE_SIZE << order);
return addr ? virt_to_page(addr) : NULL;
}
return alloc_pages(gfp | __GFP_NOWARN, order);
}
Shows how it would be organized.
This helper is quite close to what __dma_direct_alloc_pages() does, so
perhaps there is some room for further sharing in this twisty maze of
allocator paths we have :\
Jason