Re: [RFC PATCH v2 3/5] dma-mapping: Decrypt memory on remap
From: Jason Gunthorpe
Date: Mon Mar 30 2026 - 11:33:08 EST
On Mon, Mar 30, 2026 at 02:50:41PM +0000, Mostafa Saleh wrote:
> @@ -265,6 +266,9 @@ void *dma_direct_alloc(struct device *dev, size_t size,
> set_uncached = false;
> }
>
> + if (dma_set_decrypted(dev, page_address(page), size))
> + goto out_leak_pages;
> +
> if (remap) {
> pgprot_t prot = dma_pgprot(dev, PAGE_KERNEL, attrs);
>
> if (force_dma_unencrypted(dev))
> prot = pgprot_decrypted(prot);
It seems confusing, why do we unconditionally call something called
dma_set_decrypted() and then conditionally call pgprot_decrypted()?
So, I think the same remark, lets not sprinkle these tests all over
the place and risk them becoming inconsistent. It should be much more
direct, like:
page = __dma_direct_alloc_pages(dev, size, gfp & ~__GFP_ZERO,
allow_highmem, &flags);
if (!dev_can_dma_from_encrypted(dev) && !(flags & FLAG_DECRYPTED)) {
dma_set_decrypted(dev, page_address(page));
flags = FLAG_DECRYPTED;
}
if (flags & FLAG_DECRYPTED)
prot = pgprot_decrypted(prot);
And so on.
The one place we should see a force_dma_unencrypted() is directly
before setting the flag.
Jason