Re: [RFC PATCH v3 5/5] dma-mapping: Fix memory decryption issues
From: Aneesh Kumar K . V
Date: Wed Apr 15 2026 - 08:45:17 EST
Jason Gunthorpe <jgg@xxxxxxxx> writes:
> On Mon, Apr 13, 2026 at 12:49:34PM +0530, Aneesh Kumar K.V wrote:
>> > 2) Using phys_to_dma_unencrypted() is not enlighted about already
>> > decrypted memory and will use the wrong functions for that.
>>
>> Can you split this into a separate patch? I’m finding it difficult to
>> understand what the issue is here. Adding the unencrypted flag multiple
>> times to an address is not a problem in itself. Even so, I still do not
>> follow when we would end up doing that.
>
> I think my comments show how to address it right..
>
>> phys_to_dma_direct should depend on the device state.
>
> No, it depends on what state the CPU address is, which in some flows
> would have depended on the device state, but by the time you get to
> generating a dma_addr_t it should be based 100% on the current state
> of the phys_addr and nothing else.
>
> Assuming that a T=0 device must be presented unencrypted memory is an
> easy hack but it doesn't work when we get to T=1 devices that can
> handle both encryped and decrypted memory. Then we need to track it
> explicitly.
>
> The only places we we should check the device state for T=0 is at the
> very top when we decide if we force it to swiotlb and inside swiotlb
> when we decide if the allocation should be decrypted. Everything else
> should flow from tracking the phy's state, and be tied into the new
> DMA ATTR UNENCRYPTED.
>
For things like
#define dma_map_single(d, a, s, r) dma_map_single_attrs(d, a, s, r, 0)
Where do you suggest DMA_ATTR_CC_DECRYPTED be set?
Right now i have it around
static inline dma_addr_t dma_direct_map_phys(struct device *dev,
phys_addr_t phys, size_t size, enum dma_data_direction dir,
unsigned long attrs)
{
dma_addr_t dma_addr;
if (force_dma_unencrypted(dev))
attrs |= DMA_ATTR_CC_DECRYPTED;
I am wondering whether we should do earlier. But we have only audited
dma-direct for memory encryption.
-aneesh