On Thu, Jun 04, 2026 at 02:09:43PM +0530, Aneesh Kumar K.V (Arm) wrote:
>  struct page *dma_alloc_from_pool(struct device *dev, size_t size,
> -             void **cpu_addr, gfp_t gfp,
> +             void **cpu_addr, gfp_t gfp, unsigned long attrs,
>               bool (*phys_addr_ok)(struct device *, phys_addr_t, size_t))
>  {
> -     struct gen_pool *pool = NULL;
> +     struct dma_gen_pool *dma_pool = NULL;
>       struct page *page;
>       bool pool_found = false;
>  
> -     while ((pool = dma_guess_pool(pool, gfp))) {
> +     while ((dma_pool = dma_guess_pool(dma_pool, gfp))) {
> +
> +             if (dma_pool->unencrypted != !!(attrs & DMA_ATTR_CC_SHARED))
> +                     continue;

I don't think you should be overloading DMA_ATTR_CC_SHARED like this.

        /*
         * DMA_ATTR_CC_SHARED is not a caller-visible dma_alloc_*()
         * attribute. The direct allocator uses it internally after it has
         * decided that the backing pages must be shared/decrypted, so the
         * rest of the allocation path can consistently select DMA addresses,
         * choose compatible pools and restore encryption on free.
         */
        if (attrs & DMA_ATTR_CC_SHARED)
                return NULL;

        if (force_dma_unencrypted(dev)) {
                attrs |= DMA_ATTR_CC_SHARED;
                mark_mem_decrypt = true;
        }

It is fine to have a bit inside the attrs that is only used by the
internal logic, but it needs to have a clearer name
__DMA_ATTR_REQUIRE_CC_SHARED perhaps.

The sashiko note does look legit though:

        if (IS_ENABLED(CONFIG_DMA_DIRECT_REMAP) &&
            !gfpflags_allow_blocking(gfp) && !coherent) {
                page = dma_alloc_from_pool(dev, PAGE_ALIGN(size), &cpu_addr,
                                           gfp, attrs, NULL);
                if (!page)
                        return NULL;

I don't see anything doing the force_dma_unencrypted test along this
callchain..

I guess it should be done one step up in dma_alloc_attrs() instead of
in dma_direct_alloc()?

Jason

Reply via email to