Re: [PATCH v2 4/4] dma: direct: set decrypted flag for remapped dma allocations

From: Aneesh Kumar K . V

Date: Tue Dec 23 2025 - 03:18:18 EST


Suzuki K Poulose <suzuki.poulose@xxxxxxx> writes:

> On 21/12/2025 16:09, Aneesh Kumar K.V (Arm) wrote:
>> Devices that are DMA non-coherent and need a remap were skipping
>> dma_set_decrypted(), leaving buffers encrypted even when the device
>> requires unencrypted access. Move the call after the remap
>> branch so both paths mark the allocation decrypted (or fail cleanly)
>> before use.
>>
>> Fixes: f3c962226dbe ("dma-direct: clean up the remapping checks in dma_direct_alloc")
>> Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@xxxxxxxxxx>
>> ---
>> kernel/dma/direct.c | 8 +++-----
>> 1 file changed, 3 insertions(+), 5 deletions(-)
>>
>> diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
>> index 3448d877c7c6..a62dc25524cc 100644
>> --- a/kernel/dma/direct.c
>> +++ b/kernel/dma/direct.c
>> @@ -271,9 +271,6 @@ void *dma_direct_alloc(struct device *dev, size_t size,
>> if (remap) {
>> pgprot_t prot = dma_pgprot(dev, PAGE_KERNEL, attrs);
>>
>> - if (force_dma_unencrypted(dev))
>> - prot = pgprot_decrypted(prot);
>
> This would be problematic, isn't it ? We don't support decrypted on a
> vmap area for arm64. If we move this down, we might actually use the
> vmapped area. Not sure if other archs are fine with "decrypting" a
> "vmap" address.
>
> If we map the "vmap" address with pgprot_decrypted, we could go ahead
> and further map the linear map (i.e., page_address(page)) decrypted
> and get everything working.

We still have the problem w.r.t free

dma_direct_free():

if (is_vmalloc_addr(cpu_addr)) {
vunmap(cpu_addr);
} else {
if (dma_set_encrypted(dev, cpu_addr, size))
return;
}

-aneesh