Re: [rfc v2 4/6] dma-direct: atomic allocations must come from atomic coherent pools
From: Christoph Hellwig
Date: Tue Apr 14 2020 - 02:43:58 EST
> + /*
> + * Unencrypted memory must come directly from DMA atomic pools if
> + * blocking is not allowed.
> + */
> + if (IS_ENABLED(CONFIG_DMA_COHERENT_POOL) &&
> + force_dma_unencrypted(dev) && !gfpflags_allow_blocking(gfp)) {
> + ret = dma_alloc_from_pool(dev, PAGE_ALIGN(size), &page, gfp);
> + if (!ret)
> + return NULL;
> + goto done;
> + }
> +
> if (IS_ENABLED(CONFIG_DMA_DIRECT_REMAP) &&
> dma_alloc_need_uncached(dev, attrs) &&
> !gfpflags_allow_blocking(gfp)) {
Can we keep a single conditional for the pool allocations? Maybe
add a new dma_alloc_from_pool helper ala:
static inline bool dma_alloc_from_pool(struct device *dev, gfp_t gfp)
{
if (!IS_ENABLED(CONFIG_DMA_COHERENT_POOL))
return false;
if (gfpflags_allow_blocking(gfp))
return false;
if (force_dma_unencrypted(dev))
return true;
if (dma_alloc_need_uncached(dev))
return true;
}
}
> @@ -203,6 +215,10 @@ void dma_direct_free_pages(struct device *dev, size_t size, void *cpu_addr,
> {
> unsigned int page_order = get_order(size);
>
> + if (IS_ENABLED(CONFIG_DMA_COHERENT_POOL) &&
> + dma_free_from_pool(dev, cpu_addr, PAGE_ALIGN(size)))
> + return;
> +
Similarly I think we should have a single conditional to free from the
pool instead.