[RFC PATCH v7 06/13] dma-contiguous: Accept an explicit minimum alignment
Catalin Marinas
catalin.marinas at arm.com
Wed Sep 23 06:49:07 PDT 2026
On Wed, Sep 23, 2026 at 05:19:52PM +0530, Aneesh Kumar K.V wrote:
> Catalin Marinas <catalin.marinas at arm.com> writes:
> > On Mon, Sep 21, 2026 at 08:18:40PM +0530, Aneesh Kumar K.V (Arm) wrote:
> >> @@ -125,7 +126,8 @@ static inline int dma_contiguous_reserve_area(phys_addr_t size,
> >> return -ENOSYS;
> >> }
> >> static inline struct page *dma_alloc_from_contiguous(struct device *dev,
> >> - size_t count, unsigned int order, bool no_warn)
> >> + size_t count, unsigned int order, unsigned int required_order,
> >> + bool no_warn)
> >> {
> >> return NULL;
> >> }
> >> @@ -136,7 +138,7 @@ static inline bool dma_release_from_contiguous(struct device *dev,
> >> }
> >> /* Use fallback alloc() and free() when CONFIG_DMA_CMA=n */
> >> static inline struct page *dma_alloc_contiguous(struct device *dev, size_t size,
> >> - gfp_t gfp)
> >> + gfp_t gfp, unsigned int align_order)
> >
> > Can we not just bake the alignment further down in these functions
> > rather than getting the callers to pass the {required,align}_order?
> >
>
> But, we need this to be conditional on CoCo shared allocations. We could
> derive that from attrs and pass attrs instead of align_order, i.e.
> something like:
>
>
> struct page *dma_alloc_from_contiguous(struct device *dev, size_t count,
> - unsigned int align, unsigned int required_align, bool no_warn)
> + unsigned int align, unsigned long attrs, bool no_warn)
> {
> - if (required_align > CONFIG_CMA_ALIGNMENT)
> + if (!dma_contiguous_resolve_alignment(attrs, &align))
> return NULL;
> - align = min(max(align, required_align), CONFIG_CMA_ALIGNMENT);
>
> return cma_alloc(dev_get_cma_area(dev), count, align, no_warn);
> }
>
>
> with
>
> +static bool dma_contiguous_resolve_alignment(unsigned long attrs,
> + unsigned int *align)
> +{
> + unsigned int required_align = 0;
> +
> + if (attrs & __DMA_ATTR_ALLOC_CC_SHARED)
> + required_align = get_order(cc_shared_granule_size());
> + if (required_align > CONFIG_CMA_ALIGNMENT)
> + return false;
> +
> + *align = min(max(*align, required_align), CONFIG_CMA_ALIGNMENT);
> + return true;
> +}
Yes, I think this would work.
--
Catalin
More information about the linux-arm-kernel
mailing list