[PATCH v4 2/3] swiotlb: dma: its: Enforce host page-size alignment for shared buffers
Aneesh Kumar K.V
aneesh.kumar at kernel.org
Tue Apr 28 05:22:59 PDT 2026
Jason Gunthorpe <jgg at ziepe.ca> writes:
> On Mon, Apr 27, 2026 at 12:01:07PM +0530, Aneesh Kumar K.V (Arm) wrote:
>> When running private-memory guests, the guest kernel must apply additional
>> constraints when allocating buffers that are shared with the hypervisor.
>
> This patch has way too much stuff in it.
>
> I think your patch structure should be changed around
>
> 1) Patch to add mem_decrypt_granule_size(), and explain it as
> the alignment & size of what can be passed to
> set_memory_encrypted/decrypted()
>
> 2) Add support for mem_decrypt_granule_size() to ARM
>
> Then patches going caller by caller of set_memory_decrypted() to make
> them follow the new rule:
>
> 3) its
>
> 4) swiotlb
>
> 3) dma_alloc_coherent
>
> etc.
>
> don't forget about the new dma buf heaps too:
>
> drivers/dma-buf/heaps/system_heap.c: ret = set_memory_decrypted(addr, nr_pages);
>
> It is worth calling out in the cover letter that all the ARM CCA
> relevant places are fixed but drivers/hv/ is left for future.
>
>> @@ -33,18 +32,30 @@ int arm64_mem_crypt_ops_register(const struct arm64_mem_crypt_ops *ops)
>>
>> int set_memory_encrypted(unsigned long addr, int numpages)
>> {
>> - if (likely(!crypt_ops) || WARN_ON(!PAGE_ALIGNED(addr)))
>> + if (likely(!crypt_ops))
>> return 0;
>>
>> + if (WARN_ON(!IS_ALIGNED(addr, mem_decrypt_granule_size())))
>> + return -EINVAL;
>> +
>> + if (WARN_ON(!IS_ALIGNED(numpages << PAGE_SHIFT, mem_decrypt_granule_size())))
>> + return -EINVAL;
>> +
>> return crypt_ops->encrypt(addr, numpages);
>> }
>> EXPORT_SYMBOL_GPL(set_memory_encrypted);
>>
>> int set_memory_decrypted(unsigned long addr, int numpages)
>> {
>> - if (likely(!crypt_ops) || WARN_ON(!PAGE_ALIGNED(addr)))
>> + if (likely(!crypt_ops))
>> return 0;
>>
>> + if (WARN_ON(!IS_ALIGNED(addr, mem_decrypt_granule_size())))
>> + return -EINVAL;
>> +
>> + if (WARN_ON(!IS_ALIGNED(numpages << PAGE_SHIFT, mem_decrypt_granule_size())))
>> + return -EINVAL;
>> +
>> return crypt_ops->decrypt(addr, numpages);
>> }
>> EXPORT_SYMBOL_GPL(set_memory_decrypted);
>
> This should go in the ARM patch adding mem_decrypt_granule_size() to CCA
>
>> diff --git a/include/linux/mem_encrypt.h b/include/linux/mem_encrypt.h
>> index 07584c5e36fb..1e01c9ac697f 100644
>> --- a/include/linux/mem_encrypt.h
>> +++ b/include/linux/mem_encrypt.h
>> @@ -11,6 +11,8 @@
>> #define __MEM_ENCRYPT_H__
>>
>> #ifndef __ASSEMBLY__
>> +#include <linux/align.h>
>> +#include <vdso/page.h>
>>
>> #ifdef CONFIG_ARCH_HAS_MEM_ENCRYPT
>>
>> @@ -54,6 +56,18 @@
>> #define dma_addr_canonical(x) (x)
>> #endif
>>
>> +#ifndef mem_decrypt_granule_size
>> +static inline size_t mem_decrypt_granule_size(void)
>> +{
>> + return PAGE_SIZE;
>> +}
>> +#endif
>> +
>> +static inline size_t mem_decrypt_align(size_t size)
>> +{
>> + return ALIGN(size, mem_decrypt_granule_size());
>> +}
>> +
>> #endif /* __ASSEMBLY__ */
>>
>> #endif /* __MEM_ENCRYPT_H__ */
>
> I know it seems a bit small, but put this in its own patch and explain
> how it works. I'd also like to see a kdoc here, and add a kdoc to
> set_memory_decrypted() that links back so people have a better chance
> to know about this.
>
Okay, I’ll update all the above in the next revision.
-aneesh
More information about the linux-arm-kernel
mailing list