public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Aneesh Kumar K.V <aneesh.kumar@kernel.org>
To: Robin Murphy <robin.murphy@arm.com>,
	iommu@lists.linux.dev, linux-kernel@vger.kernel.org,
	linux-coco@lists.linux.dev
Cc: Marek Szyprowski <m.szyprowski@samsung.com>,
	steven.price@arm.com, Suzuki K Poulose <suzuki.poulose@arm.com>,
	Claire Chang <tientzu@chromium.org>
Subject: Re: [PATCH] dma-direct: swiotlb: Skip encryption toggles for swiotlb allocations
Date: Mon, 12 Jan 2026 21:12:56 +0530	[thread overview]
Message-ID: <yq5acy3eet1b.fsf@kernel.org> (raw)
In-Reply-To: <1290fd7e-bfaf-47ce-b12f-cca0b938b293@arm.com>

Robin Murphy <robin.murphy@arm.com> writes:

> On 2026-01-09 2:51 am, Aneesh Kumar K.V wrote:
>> Robin Murphy <robin.murphy@arm.com> writes:
>> 
>>> On 2026-01-02 3:54 pm, Aneesh Kumar K.V (Arm) wrote:
>>>> Swiotlb backing pages are already mapped decrypted via
>>>> swiotlb_update_mem_attributes(), so dma-direct does not need to call
>>>> set_memory_decrypted() during allocation or re-encrypt the memory on
>>>> free.
>>>>
>>>> Handle swiotlb-backed buffers explicitly: obtain the DMA address and
>>>> zero the linear mapping for lowmem pages, and bypass the decrypt/encrypt
>>>> transitions when allocating/freeing from the swiotlb pool (detected via
>>>> swiotlb_find_pool()).
>>>
>>> swiotlb_update_mem_attributes() only applies to the default SWIOTLB
>>> buffer, while the dma_direct_alloc_swiotlb() path is only for private
>>> restricted pools (because the whole point is that restricted DMA devices
>>> cannot use the regular allocator/default pools). There is no redundancy
>>> here AFAICS.
>>>
>> 
>> But rmem_swiotlb_device_init() is also marking the entire pool decrypted
>> 
>> 	set_memory_decrypted((unsigned long)phys_to_virt(rmem->base),
>> 			     rmem->size >> PAGE_SHIFT);
>
> OK, so why doesn't the commit message mention that instead of saying 
> something which fails to justify the patch at all? ;)
>
> Furthermore, how much does this actually matter? The "real" restricted 
> DMA use-case is on systems where dma_set_decrypted() is a no-op anyway. 
> I know we used restricted DMA as a hack in the early days of CCA 
> prototyping, but is it intended to actually deploy that as a supported 
> and recommended mechanism now?
>
> Note also that the swiotlb_alloc path is essentially an emergency 
> fallback, which doesn't work for all situations anyway - any restricted 
> device that actually needs to make significant coherent allocations (or 
> rather, that firmware cannot assume won't want to do so) should really 
> have a proper coherent pool alongside its restricted one. The expected 
> use-case here is for something like a wifi driver that only needs to 
> allocate one or two small coherent buffers once at startup, then do 
> everything else with streaming DMA.
>


I was aiming to bring more consistency in how swiotlb buffers are
handled, specifically by treating all swiotlb memory as decrypted
buffers, which is also how the current code behaves.

If we are concluding that restricted DMA is not used in conjunction with
memory encryption, then we could, in fact, remove the
set_memory_decrypted() call from rmem_swiotlb_device_init() and
instead add failure conditions for force_dma_unencrypted(dev) in
is_swiotlb_for_alloc(). However, it’s worth noting that the initial
commit did take the memory encryption feature into account
(0b84e4f8b793eb4045fd64f6f514165a7974cd16).

Please let me know if you think this needs to be fixed.

-aneesh

  reply	other threads:[~2026-01-12 15:43 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-02 15:54 [PATCH] dma-direct: swiotlb: Skip encryption toggles for swiotlb allocations Aneesh Kumar K.V (Arm)
2026-01-08 11:01 ` Robin Murphy
2026-01-09  2:51   ` Aneesh Kumar K.V
2026-01-12 13:25     ` Robin Murphy
2026-01-12 15:42       ` Aneesh Kumar K.V [this message]
2026-01-14  9:49         ` Aneesh Kumar K.V
2026-01-19  9:52           ` Marek Szyprowski
2026-01-19 14:28             ` Robin Murphy
2026-01-19 15:53               ` Aneesh Kumar K.V
2026-01-19 16:37                 ` Robin Murphy
2026-01-20  9:33                   ` 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=yq5acy3eet1b.fsf@kernel.org \
    --to=aneesh.kumar@kernel.org \
    --cc=iommu@lists.linux.dev \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=robin.murphy@arm.com \
    --cc=steven.price@arm.com \
    --cc=suzuki.poulose@arm.com \
    --cc=tientzu@chromium.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