Re: [PATCH v6 00/20] dma-mapping: Use DMA_ATTR_CC_SHARED through direct, pool and swiotlb paths
From: Jason Gunthorpe <jgg@ziepe.ca>
Date: 2026-06-19 14:06:19
Also in:
linux-coco, linux-iommu, linux-s390, linuxppc-dev, lkml
On Fri, Jun 19, 2026 at 02:36:19PM +0100, Aneesh Kumar K.V wrote:
quoted
quoted
Agreed. If the device can do encrypted DMA and requires bouncing, it should bounce through encrypted pools. We don't support encrypted pools now and that means, we mark the option ("mem_encrypt=on iommu=pt swiotlb=force") not supported for now??? if you don't have a CC system then the swiotlb is "encrypted" meaning ordinary struct page system memory. The hypervisor should not be triggering any CC special stuff here, it is not a CC guest. Agree we don't need to worry about swiotlb=force with a trusted device in the GUEST for now, but it should be something to fix eventually.If i understand this correctly, the setup Alexey is referring to here is bare metal system with memory encryption enabled and dma address doesn't need C bit cleared because it is handled in iommu.
This is how I understand it too, if the iommu is turned on then it can take the high PA with the C bit set and map it to an IOVA that matches the device's dma limit.
( I consider this as memory encryption that is handled transparently, device can access any address because that encryption details are now managed by iommu).
Compared to the guest side there are some important host side differences: - On the host the iommu can fix it because this is only a matter of IOVA range not access control. On a guest even a IOMMU cannot permit access to private memory - On the host the state of the device is driven by the dma limit which is not set until after the driver probes. On guest the state is set by the tsm and device security level before the driver probes - Both flows end up using pgprot_decrypted and set_memory_decrypted() to create their special pools, but for completely different reasons. - The memory coming from the special swiotlb pool must NOT be used by a trusted device on a CC guest, while there is no problem for any device to use it on the host.
Thinking about this more, I guess we should mark the swiotlb as cc_shared only with CC_ATTR_GUEST_MEM_ENCRYPT instead of CC_ATTR_MEM_ENCRYPT as we have below.
The name cc_shared should be used for GUEST scenarios only. I guess there is some merit in keeping swiotlb using "decrypted" to mean it usinig pgprot_decrypted and set_memory_decyped() which AMD gives meaning to on both host and guest. IDK what AMD should do on the host by default. I guess it should setup a swiotlb pool of low dma addrs "unencrypted", but not "cc_shared"? But if we are operating on the host then this pool is not limited to only T=0 devices, every device can "safely" use it. (ignoring this destroys the security memory encryption on bare metal was supposed to provide)
Now we have the case of host memory encryption where the C-bit needs to be cleared in dma_addr_t. That requires special handling in the kernel, and I believe we need to mark swiotlb as unencrypted in this configuration.
I think we need to split the two things up, they have different behaviors and need different flags and labels to make it all work right.
I am still not clear whether there is a config option or runtime check we can use to identify this case.
The dma api has to detect, after the driver sets the dma limit, that none of system memory is usable when: - The direct path is being used - phys to dma for 0 is outside the dma limit Then it should assume the arch has setup a swiotlb pool for it to use to fix the high memory problem. Similar hackery would be needed in the dma alloc path to know that decrypted can be used to fix the high memory problem like for GUEST. I guess some 'dev_cannot_reach_memory(dev)' sort of test in a few key places? Setup with a static branch to be a nop on everything but AMD, compiled out on every other arch. Jason