mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Catalin Marinas <catalin.marinas@arm.com>
To: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>
Cc: linux-coco@lists.linux.dev, kvmarm@lists.linux.dev,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, iommu@lists.linux.dev,
	Jason Gunthorpe <jgg@ziepe.ca>, Marc Zyngier <maz@kernel.org>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Robin Murphy <robin.murphy@arm.com>,
	Steven Price <steven.price@arm.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Thomas Gleixner <tglx@kernel.org>, Will Deacon <will@kernel.org>
Subject: Re: [PATCH v6 0/9] coco: guest: Enforce host page-size alignment for shared buffers
Date: Fri, 18 Sep 2026 17:52:31 +0100	[thread overview]
Message-ID: <aq1sT2EDsGaomqST@arm.com> (raw)
In-Reply-To: <20260904103452.1197239-1-aneesh.kumar@kernel.org>

On Fri, Sep 04, 2026 at 04:04:43PM +0530, Aneesh Kumar K.V (Arm) wrote:
> This series tightens the alignment requirements for buffers that are shared
> between confidential-computing guests and the host.
> 
> When a guest runs with private memory, buffers shared with the hypervisor
> are not only accessed by the guest. They are also accessed by the host
> kernel, and the host may manage the corresponding shared/private state at a
> granularity larger than the guest page size.
> 
> This matters for CCA systems where the Realm stage-2 mappings managed by
> the RMM can still operate at 4K granularity, while the non-secure host may
> manage the IPA state change at a larger page size, for example 64K. In that
> case, allowing a guest to convert and share only a 4K subrange of a
> host-managed granule is unsafe.
> 
> Architectures such as Arm can detect incorrect accesses to Realm physical
> address space PFNs through GPC faults. However, relying on that as the only
> line of defence is fragile and can still lead to kernel crashes. The risk
> is especially visible for shared buffers that are later mmapped into
> userspace, such as guest_memfd or dma-buf backed allocations. Once
> userspace can access the mapping, the kernel cannot guarantee that
> applications will only touch the intended 4K region rather than the whole
> host page mapped into their address space. Those userspace addresses may
> also be passed back into the kernel and accessed through the linear map,
> resulting in a GPC fault.
> 
> To avoid this, shared buffers must satisfy two constraints:
> 
>   - the address must be aligned to the CoCo shared-granule size
>   - the size must be a multiple of that granule size
> 
> The series adds generic helpers for this:
> 
>   - mem_cc_shared_granule_size()
>   - mem_cc_align_to_shared_granule()
> 
> The generic implementation defaults to PAGE_SIZE. arm64 CCA overrides this
> by querying the host IPA state change granule size through RHI and exposing that
> value through the arm64 memory-encryption operations.
> 
> The patche series update the main shared-buffer allocation paths that can
> be used by private-memory guests:
> 
>   - arm64 set_memory_encrypted()/set_memory_decrypted() now reject unaligned
>     addresses or sizes.
>   - GIC ITS shared allocations are rounded to the shared granule size.
>   - dma-direct and atomic DMA pool allocations use aligned allocation and
>     conversion sizes.
>   - SWIOTLB pools, including dynamic pools, are allocated and converted at the
>     shared granule size.
>   - restricted-dma-pool regions are checked and rejected if firmware did not
>     provide a base and size aligned to the shared granule size.
>   - dma-buf system heap cc-shared allocations require aligned sizes and use at
>     least the required allocation order.

While I understand why you want it, I think that's maintenance burden
longer term. It's already touching about seven allocators (ITS,
dma-direct, CMA, atomic pool, swiotlb, restricted DMA pools, dma-buf).
Although most are in the DMA code, we still need to keep track of their
changes and what else may be coming. Can we even test all these
combinations in a CCA realm?

I assume for trusted devices we can skip this forced alignment.

TBH, I'm tempted not to support this configuration at all, just fail
gracefully if the realm page size doesn't match the host's. However, if
that's a real world configuration, I wonder whether could we leverage
the swiotlb mechanism but with a separate io_tlb_mem as a shared coco
allocator with the right alignment and use this pool when
force_dma_unencrypted() instead of specific alloc_pages() with adjusted
order.

-- 
Catalin

  parent reply	other threads:[~2026-09-18 16:52 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-04 10:34 Aneesh Kumar K.V (Arm)
2026-09-04 10:34 ` [PATCH v6 1/9] mm/mem_encrypt: Add helpers for shared-buffer alignment Aneesh Kumar K.V (Arm)
2026-09-04 10:34 ` [PATCH v6 2/9] irqchip/gic-v3-its: Align shared ITS allocations to the CoCo shared granule size Aneesh Kumar K.V (Arm)
2026-09-04 10:34 ` [PATCH v6 3/9] dma-mapping: Pass allocation attrs to contiguous allocation helpers Aneesh Kumar K.V (Arm)
2026-09-04 10:34 ` [PATCH v6 4/9] dma-direct: Align CoCo shared DMA allocations to the shared granule size Aneesh Kumar K.V (Arm)
2026-09-18 14:16   ` Catalin Marinas
2026-09-04 10:34 ` [PATCH v6 5/9] swiotlb: Align shared IO TLB pools " Aneesh Kumar K.V (Arm)
2026-09-04 10:34 ` [PATCH v6 6/9] swiotlb: Reject misaligned restricted DMA pools for CoCo guests Aneesh Kumar K.V (Arm)
2026-09-04 10:34 ` [PATCH v6 7/9] dma-buf: system_heap: Enforce shared-granule alignment for cc-shared buffers Aneesh Kumar K.V (Arm)
2026-09-18 15:16   ` Catalin Marinas
2026-09-18 15:23     ` Christian König
2026-09-18 15:36       ` Jason Gunthorpe
2026-09-18 15:39         ` Christian König
2026-09-18 16:53           ` Jason Gunthorpe
2026-09-04 10:34 ` [PATCH v6 8/9] arm64: realm: Add RHI helper to query IPA state change alignment Aneesh Kumar K.V (Arm)
2026-09-16 16:12   ` Suzuki K Poulose
2026-09-18 10:39     ` Aneesh Kumar K.V
2026-09-04 10:34 ` [PATCH v6 9/9] arm64: realm: Expose the CCA shared granule size through mem_encrypt ops Aneesh Kumar K.V (Arm)
2026-09-16 16:17   ` Suzuki K Poulose
2026-09-18 16:52 ` Catalin Marinas [this message]
2026-09-18 16:57   ` [PATCH v6 0/9] coco: guest: Enforce host page-size alignment for shared buffers Jason Gunthorpe
2026-09-18 17:10     ` Catalin Marinas

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=aq1sT2EDsGaomqST@arm.com \
    --to=catalin.marinas@arm.com \
    --cc=aneesh.kumar@kernel.org \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@ziepe.ca \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=maz@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=steven.price@arm.com \
    --cc=suzuki.poulose@arm.com \
    --cc=tglx@kernel.org \
    --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

all inboxes | Powered by JetHome®