Re: [PATCH v2 1/4] swiotlb: dma: its: Enforce host page-size alignment for shared buffers

From: Aneesh Kumar K . V
Date: Tue Jan 06 2026 - 01:38:13 EST


Jason Gunthorpe <jgg@xxxxxxxx> writes:

> On Sun, Dec 21, 2025 at 09:39:17PM +0530, Aneesh Kumar K.V (Arm) wrote:
>> +#define mem_encrypt_align mem_encrypt_align
>> +static inline size_t mem_encrypt_align(size_t size)
>> +{
>> + return size;
>> +}
>> +
>
> IMHO this is the wrong API.
>
> The issue here is not about alignment, it is about the permitted
> granule size for shared/private.
>
> On X86 this will be PAGE_SIZE on ARM64 it is
> max(hypervisor_page_size, PAGE_SIZE)
>
> So think the arch helper should simply be
>
> __pure size_T mem_encrypt_granule_size(void);
>
>> + if (WARN_ON(!IS_ALIGNED(addr, mem_encrypt_align(PAGE_SIZE))))
>> + return 0;
>> +
>> + if (WARN_ON(!IS_ALIGNED(numpages << PAGE_SHIFT, mem_encrypt_align(PAGE_SIZE))))
>> + return 0;
>
> And then we don't end up with weiro reading stuff like this..
>
> if (WARN_ON(!IS_ALIGNED(addr, mem_encrypt_granule_size())) ||
> WARN_ON(!IS_ALIGNED(numpages, mem_encrypt_granule_size() / PAGE_SIZE)))
>
> Is much more readable..
>

I added this helper

>> @@ -319,8 +319,8 @@ static void __init *swiotlb_memblock_alloc(unsigned long nslabs,
>> unsigned int flags,
>> int (*remap)(void *tlb, unsigned long nslabs))
>> {
>> - size_t bytes = PAGE_ALIGN(nslabs << IO_TLB_SHIFT);
>> void *tlb;
>> + size_t bytes = mem_encrypt_align(nslabs << IO_TLB_SHIFT);
>
> The stuff like this is just ALING(nslabs << IO_TLB_SHIFT, mem_encrypt_granule_size())
>

I guess we can still keep mem_encrypt_align so that changes like below
becomes simpler.

- int page_order = get_order(min_size);
+ int page_order = get_order(mem_encrypt_align(min_size));

-aneesh