[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <yq5a7btvjlfn.fsf@kernel.org>
Date: Tue, 06 Jan 2026 12:07:48 +0530
From: Aneesh Kumar K.V <aneesh.kumar@...nel.org>
To: Jason Gunthorpe <jgg@...pe.ca>
Cc: linux-kernel@...r.kernel.org, iommu@...ts.linux.dev,
linux-coco@...ts.linux.dev,
Catalin Marinas <catalin.marinas@....com>, will@...nel.org,
maz@...nel.org, tglx@...utronix.de, robin.murphy@....com,
suzuki.poulose@....com, akpm@...ux-foundation.org,
steven.price@....com
Subject: Re: [PATCH v2 1/4] swiotlb: dma: its: Enforce host page-size
alignment for shared buffers
Jason Gunthorpe <jgg@...pe.ca> 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
Powered by blists - more mailing lists