[PATCH v6 03/20] dma-direct: use DMA_ATTR_CC_SHARED in alloc/free paths
Alexey Kardashevskiy
aik at amd.com
Wed Jun 17 19:39:21 PDT 2026
On 18/6/26 01:41, Jason Gunthorpe wrote:
> On Wed, Jun 17, 2026 at 10:50:39AM +1000, Alexey Kardashevskiy wrote:
>>> @@ -193,16 +193,31 @@ void *dma_direct_alloc(struct device *dev, size_t size,
>>> dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs)
>>> {
>>> bool remap = false, set_uncached = false;
>>> - bool mark_mem_decrypt = true;
>>> + bool mark_mem_decrypt = false;
>>> struct page *page;
>>> void *ret;
>>> + /*
>>> + * DMA_ATTR_CC_SHARED is not a caller-visible dma_alloc_*()
>>> + * attribute. The direct allocator uses it internally after it has
>>> + * decided that the backing pages must be shared/decrypted, so the
>>> + * rest of the allocation path can consistently select DMA addresses,
>>> + * choose compatible pools and restore encryption on free.
>>
>> Why this limit?
>>
>> Context: I am looking for a memory pool for a few shared pages (to
>> do some guest<->host communication), SWIOTLB seems like the right
>> fit but swiotlb_alloc() is not exported and
>> dma_direct_alloc(DMA_ATTR_CC_SHARED) is not allowed. Thanks,
>
> Then setup your struct device so that the DMA API knows the
> guest<->host channel requires unecrypted and it will work correctly.
>
> I think this is a reasonable API to use for that, and I was just
> advocating that hyperv should be using it too.
>
> But it all relies on a properly setup struct device.
Sounds good but how do I do that in practice? DMA_ATTR_CC_SHARED is not externally available so I'll have to trick the DMA layer into using SWIOTLB (which is still all shared, right?) as I specifically want to skip page conversions. Setting low DMA mask won't guarantee that the DMA layer won't allocate a page outside of SWIOTLB and convert it. Manually do
dev->dma_io_tlb_mem->force_bounce = true;
dev->dma_io_tlb_mem->for_allow = true;
?
Or follow the Aneesh'es genpool approach? Thanks,
>
> Jason
--
Alexey
More information about the linux-arm-kernel
mailing list