public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Aneesh Kumar K.V <aneesh.kumar@kernel.org>
To: Jason Gunthorpe <jgg@ziepe.ca>
Cc: linux-kernel@vger.kernel.org, iommu@lists.linux.dev,
	linux-coco@lists.linux.dev,
	Catalin Marinas <catalin.marinas@arm.com>,
	will@kernel.org, maz@kernel.org, tglx@linutronix.de,
	robin.murphy@arm.com, suzuki.poulose@arm.com,
	akpm@linux-foundation.org, steven.price@arm.com
Subject: Re: [PATCH v2 1/4] swiotlb: dma: its: Enforce host page-size alignment for shared buffers
Date: Tue, 06 Jan 2026 12:07:48 +0530	[thread overview]
Message-ID: <yq5a7btvjlfn.fsf@kernel.org> (raw)
In-Reply-To: <20260106011636.GQ125261@ziepe.ca>

Jason Gunthorpe <jgg@ziepe.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

  reply	other threads:[~2026-01-06  6:37 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-21 16:09 [PATCH v2 0/4] Enforce host page-size alignment for shared buffers Aneesh Kumar K.V (Arm)
2025-12-21 16:09 ` [PATCH v2 1/4] swiotlb: dma: its: " Aneesh Kumar K.V (Arm)
2025-12-22 14:49   ` Steven Price
2025-12-22 15:42     ` Aneesh Kumar K.V
2026-01-06  1:16   ` Jason Gunthorpe
2026-01-06  6:37     ` Aneesh Kumar K.V [this message]
2025-12-21 16:09 ` [PATCH v2 2/4] coco: guest: arm64: Fetch host IPA change alignment via RHI hostconf Aneesh Kumar K.V (Arm)
2025-12-21 16:09 ` [PATCH v2 3/4] coco: host: arm64: Handle hostconf RHI calls in kernel Aneesh Kumar K.V (Arm)
2025-12-21 20:10   ` Suzuki K Poulose
2025-12-22 14:37     ` Aneesh Kumar K.V
2025-12-23 19:56       ` Suzuki K Poulose
2025-12-21 16:09 ` [PATCH v2 4/4] dma: direct: set decrypted flag for remapped dma allocations Aneesh Kumar K.V (Arm)
2025-12-22 15:05   ` Suzuki K Poulose
2025-12-23  8:18     ` Aneesh Kumar K.V
2025-12-26  8:59       ` Aneesh Kumar K.V
2026-03-11 12:24         ` Mostafa Saleh
2026-01-06  1:11 ` [PATCH v2 0/4] Enforce host page-size alignment for shared buffers Jason Gunthorpe
2026-01-06  6:39   ` Aneesh Kumar K.V

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=yq5a7btvjlfn.fsf@kernel.org \
    --to=aneesh.kumar@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=catalin.marinas@arm.com \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@ziepe.ca \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=steven.price@arm.com \
    --cc=suzuki.poulose@arm.com \
    --cc=tglx@linutronix.de \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox