* [PATCH v11 00/23] coco: guest: Add a shared-granule allocator for host-shared memory
@ 2026-12-02 9:54 Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 01/23] MAINTAINERS: Add CoCo memory sharing and encryption entry Aneesh Kumar K.V (Arm)
` (22 more replies)
0 siblings, 23 replies; 25+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-12-02 9:54 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Andrew Morton, Catalin Marinas,
Christian König, Jason Gunthorpe, Joerg Roedel, Marc Zyngier,
Marek Szyprowski, Robin Murphy, Steven Price, Sumit Semwal,
Suzuki K Poulose, Will Deacon, T.J. Mercier, Madhavan Srinivasan,
Heiko Carstens, Christian Borntraeger, Sven Schnelle, Dave Hansen,
Kiryl Shutsemau, Rick Edgecombe, Paolo Bonzini, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Haiyang Zhang, Wei Liu, Dexuan Cui,
Andy Lutomirski, Peter Zijlstra, Alexander Gordeev,
Gerald Schaefer, Vasily Gorbik, x86, dri-devel, iommu,
linaro-mm-sig, linux-arm-kernel, linux-media, linux-mm, kvmarm,
patches
This series tightens the alignment requirements for buffers that are shared
between confidential-computing guests and the host, and adds a common
allocator for host-shared memory.
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.
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, host-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 a common CoCo shared-memory layer for enforcing these
constraints. It provides shared-granule geometry and range-validation
helpers, byte-oriented private/shared transition helpers, and
alloc_cc_shared() and its node-aware variant. The allocator accepts a byte
count, rounds internally to the sharing granule and a power-of-two number
of pages, and returns a linear-map address. The entire allocation is shared
and zeroed, with its physical base aligned to the allocation size.
cc_shared_alloc_size() reports the actual size from compound-page metadata.
free_cc_shared() restores the complete allocation to private
state before returning it to the buddy allocator. If private state cannot
be restored safely, the allocation is deliberately leaked rather than
returning potentially shared memory for unrelated use.
The series also makes zeroing part of private-to-shared transitions, with
each architecture clearing memory at the appropriate point. Callers must
therefore initialize shared buffers after the transition; existing contents
are not preserved.
The shared-granule size defaults to PAGE_SIZE and can be overridden by an
architecture. The arm64 CCA changes to discover the host's IPA state change
alignment are not included in this series.
GIC ITS command queues and tables and the dma-buf system_cc_shared heap
use the common allocator. DMA direct, atomic DMA pools and SWIOTLB retain
their allocation paths and use checked byte rounding or transition helpers.
Restricted DMA pools are checked for shared-granule alignment.
Hyper-V users of set_memory_encrypted() and set_memory_decrypted() are not
changed to use cc_make_shared() by this series. Those paths are not
currently used by the arm64 CCA code path, and therefore are not part of
the arm64 CCA IPA state change alignment problem addressed here.
Notes:
* Codex assisted with implementation, review and series organization.
Changes from v10:
https://patch.msgid.link/20261116091137.94252-1-aneesh.kumar@kernel.org
* Replace page/size descriptors with byte-based alloc_cc_shared_node() and
alloc_cc_shared(), returning a linear-map address. Recover the full size
from compound metadata in cc_shared_alloc_size() and free_cc_shared().
* Share and zero the entire allocation. Document physical alignment and
low-memory/nonmovable requirements, including without memory encryption.
* Replace layout structures with cc_shared_round_size() for callers that
manage their own backing memory.
* Require a sleepable allocation context regardless of memory encryption.
* Split architecture zeroing changes and caller cleanups into separate
patches. Separate SWIOTLB alignment from transition-helper conversion.
* Add a dedicated MAINTAINERS entry for CoCo memory sharing and
encryption, including the common interfaces and allocator.
Changes from v9:
https://lore.kernel.org/all/20261104164555.3555725-1-aneesh.kumar@kernel.org
* Leak allocations after failed sharing in the common allocator and SWIOTLB.
* Move x86 zeroing from the AMD, TDX and Hyper-V vTOM callbacks to
set_memory_decrypted(), after a successful transition
* Add set_memory_decrypted_nozero() for VGA mappings, which must change
memory attributes without clearing device memory.
* Zero memory even when encryption is inactive in the generic, arm64 and
pSeries implementations of set_memory_decrypted().
* Move pSeries zeroing after sharing. Document why pKVM and s390 must clear
private contents before sharing
* Drop the GIC ITS VPE L1 preallocation patch from this series.
This issue predates the series and will be addressed separately.
* Add mm/cc_shared.c and include/linux/cc_shared.h to the TSM MAINTAINERS
entry.
Changes from v8:
https://lore.kernel.org/all/20260924100529.1398790-1-aneesh.kumar@kernel.org
* Rebase onto the 7.4-rc1
* Move TDX and AMD (including SEV-SNP) zeroing to their finish callbacks
so private-to-shared transitions clear the final shared mapping.
* Clear __GFP_MOVABLE for shared allocations, which cannot be migrated.
* Resolve NUMA_NO_NODE in the common ITS allocation helper to preserve
placement for all ITS callers.
* Stop SWIOTLB allocation retries when the reduced pool would fall below
the shared granule size, avoiding an allocation retry loop.
Changes from v7:
https://lore.kernel.org/all/20260921144847.501151-1-aneesh.kumar@kernel.org
* Add the following new patches:
* "irqchip/gic-v3-its: Preallocate VPE L1 tables"
* "mm: Assert CoCo shared allocations may sleep"
* "mm: Zero memory during shared memory transitions"
* Drop the arm64 RHI and shared granule size patches so that the series can
be rebased on top of upstream to enable Shashiko review.
Changes from v6:
https://lore.kernel.org/all/20260904103452.1197239-1-aneesh.kumar@kernel.org
* Add a common allocator and geometry/transition helpers for CoCo host-shared
memory.
* Convert GIC ITS, dma-direct, atomic DMA pools, and the dma-buf
system_cc_shared heap to the common allocator.
* Limit dma-buf scatterlist entries to the requested buffer size so rounded
backing is not exposed to importers.
Changes from v5:
https://lore.kernel.org/all/20260706060432.1375570-1-aneesh.kumar@kernel.org
* Rebased to latest kernel
* Drop patch arm64: realm: Move Realm memory encryption ops to RSI code
Changes from v4:
https://lore.kernel.org/all/20260427063108.909019-1-aneesh.kumar@kernel.org
* Rename the helpers to use CoCo terminology
(mem_cc_shared_granule_size() / mem_cc_align_to_shared_granule() instead of
mem_decrypt_granule_size() / mem_decrypt_align()).
* Use __DMA_ATTR_ALLOC_CC_SHARED to pass CoCo shared allocation requirements
down to CMA-based allocation helpers.
* Add validation for restricted DMA pools to reject pools that are not aligned
to the shared granule size.
* Add dma-buf system heap handling for cc-shared buffers.
* Split the previous combined DMA/SWIOTLB/ITS change into smaller subsystem
patches covering ITS, DMA direct, SWIOTLB, restricted DMA pools, dma-buf
system heap, and arm64 Realm support.
* Rework arm64 Realm support by moving Realm memory encryption ops into RSI
code and exposing the CCA shared granule size through arm64_mem_crypt_ops.
Changes from v3:
https://lore.kernel.org/all/20260309102625.2315725-1-aneesh.kumar@kernel.org
* Fix build error reported by kernel test robot <lkp@intel.com>
Changes from v2:
https://lore.kernel.org/all/20251221160920.297689-1-aneesh.kumar@kernel.org
* Rebase to latest kernel
* Consider swiotlb always decrypted and don't align when allocating from swiotlb.
Changes from v1:
* Rename the helper to mem_encrypt_align
* Improve the commit message
* Handle DMA allocations from contiguous memory
* Handle DMA allocations from the pool
* swiotlb is still considered unencrypted. Support for an encrypted swiotlb pool
is left as TODO and is independent of this series.
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: "Christian König" <christian.koenig@amd.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Joerg Roedel (AMD) <joro@8bytes.org>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: Steven Price <steven.price@arm.com>
Cc: Sumit Semwal <sumit.semwal@linaro.org>
Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: "T.J. Mercier" <tjmercier@google.com>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Kiryl Shutsemau <kas@kernel.org>
Cc: Rick Edgecombe <rick.p.edgecombe@intel.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Thomas Gleixner <tglx@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Cc: Wei Liu <wei.liu@kernel.org>
Cc: Dexuan Cui <decui@microsoft.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: x86@kernel.org
Cc: dri-devel@lists.freedesktop.org
Cc: iommu@lists.linux.dev
Cc: linaro-mm-sig@lists.linaro.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-media@vger.kernel.org
Cc: linux-mm@kvack.org
Cc: kvmarm@lists.linux.dev
Cc: patches@lists.linux.dev
Aneesh Kumar K.V (Arm) (23):
MAINTAINERS: Add CoCo memory sharing and encryption entry
mm: Add an allocator for CoCo shared memory
x86/mm: Use the non-zeroing decryption helper for VGA mappings
s390/mm: Clear memory before making it shared
powerpc/pseries: Clear memory after making it shared
arm64: Zero memory during private-to-shared transitions
x86/mm: Clear memory after successful decryption transitions
mm: Document zeroing by set_memory_decrypted() and update the fallback
drivers: hv: Remove redundant clearing after decryption
x86/kvmclock: Avoid clearing decrypted clock memory twice
dma-direct: Avoid redundant clearing of shared allocations
mm: Avoid zeroing CoCo shared allocations twice
irqchip/gic-v3-its: Resolve the default NUMA node explicitly
irqchip/gic-v3-its: Allocate shared tables using CoCo shared memory
allocator
dma-contiguous: Derive shared alignment from DMA attributes
dma-pool: Align shared atomic pools to the CoCo sharing granule
dma-direct: Align CoCo shared DMA allocations to the shared granule
size
swiotlb: Align shared IO TLB pools to the shared granule size
swiotlb: Use the common CoCo memory transition helpers
swiotlb: Reject misaligned restricted DMA pools for CoCo guests
dma-buf: system_heap: Limit scatterlist entries to the buffer size
dma-buf: system_heap: Allocate shared buffers using CoCo shared memory
allocator
swiotlb: Make rounded shared pool capacity allocatable
MAINTAINERS | 13 +
arch/arm/mm/dma-mapping.c | 5 +-
arch/arm64/mm/mem_encrypt.c | 8 +-
arch/powerpc/platforms/pseries/svm.c | 13 +-
arch/s390/mm/init.c | 7 +
arch/x86/hyperv/hv_init.c | 1 -
arch/x86/include/asm/set_memory.h | 1 +
arch/x86/include/asm/vga.h | 4 +-
arch/x86/kernel/kvmclock.c | 18 +-
arch/x86/mm/pat/set_memory.c | 19 +-
drivers/dma-buf/heaps/system_heap.c | 125 ++++-----
drivers/firmware/arm_rmm/rsi.c | 9 +
drivers/hv/connection.c | 7 -
drivers/hv/hv.c | 10 +-
drivers/hv/hv_common.c | 2 -
drivers/iommu/dma-iommu.c | 2 +-
drivers/irqchip/irq-gic-v3-its.c | 144 +++++-----
drivers/virt/coco/pkvm-guest/arm-pkvm-guest.c | 11 +
include/linux/cc_shared.h | 25 ++
include/linux/dma-map-ops.h | 9 +-
include/linux/set_memory.h | 8 +-
kernel/dma/contiguous.c | 47 +++-
kernel/dma/direct.c | 78 ++++--
kernel/dma/ops_helpers.c | 2 +-
kernel/dma/pool.c | 29 ++-
kernel/dma/swiotlb.c | 98 ++++---
kernel/kexec_file.c | 3 +-
mm/Makefile | 1 +
mm/cc_shared.c | 245 ++++++++++++++++++
29 files changed, 680 insertions(+), 264 deletions(-)
create mode 100644 include/linux/cc_shared.h
create mode 100644 mm/cc_shared.c
base-commit: 65e4fd942f72a9dba0e4e257290c4fa1aa756854
--
2.43.0
^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH v11 01/23] MAINTAINERS: Add CoCo memory sharing and encryption entry
2026-12-02 9:54 [PATCH v11 00/23] coco: guest: Add a shared-granule allocator for host-shared memory Aneesh Kumar K.V (Arm)
@ 2026-12-02 9:54 ` Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 02/23] mm: Add an allocator for CoCo shared memory Aneesh Kumar K.V (Arm)
` (21 subsequent siblings)
22 siblings, 0 replies; 25+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-12-02 9:54 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Andrew Morton, Catalin Marinas,
Christian König, Jason Gunthorpe, Joerg Roedel, Marc Zyngier,
Marek Szyprowski, Robin Murphy, Steven Price, Sumit Semwal,
Suzuki K Poulose, Will Deacon, T.J. Mercier, Madhavan Srinivasan,
Heiko Carstens, Christian Borntraeger, Sven Schnelle, Dave Hansen,
Kiryl Shutsemau, Rick Edgecombe, Paolo Bonzini, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Haiyang Zhang, Wei Liu, Dexuan Cui,
Andy Lutomirski, Peter Zijlstra, Alexander Gordeev,
Gerald Schaefer, Vasily Gorbik, x86, dri-devel, iommu,
linaro-mm-sig, linux-arm-kernel, linux-media, linux-mm, kvmarm,
patches
include/linux/cc_platform.h and include/linux/mem_encrypt.h do not have
a specific MAINTAINERS entry. Add a CoCo memory sharing and encryption
entry and list both linux-coco and linux-mm for these common interfaces.
The following patch introduces the CoCo shared-memory allocator and adds
its files to this entry, keeping the related interfaces together. For
now, use the same maintainers and reviewer as the TSM entry.
Leave include/linux/set_memory.h out because most of that header covers
page permissions and cacheability.
Link: https://lore.kernel.org/r/awQgDYK2Bq0QGpNU@arm.com
Suggested-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
MAINTAINERS | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index 3ed1991cac46..4cadc468d28d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -6754,6 +6754,17 @@ S: Orphan
W: http://accessrunner.sourceforge.net/
F: drivers/usb/atm/cxacru.c
+CONFIDENTIAL COMPUTING MEMORY SHARING AND ENCRYPTION
+M: Alexey Kardashevskiy <aik@amd.com>
+M: Aneesh Kumar K.V <aneesh.kumar@kernel.org>
+M: Jason Gunthorpe <jgg@nvidia.com>
+R: Lukas Wunner <lukas@wunner.de>
+L: linux-coco@lists.linux.dev
+L: linux-mm@kvack.org
+S: Maintained
+F: include/linux/cc_platform.h
+F: include/linux/mem_encrypt.h
+
CONFIDENTIAL COMPUTING THREAT MODEL FOR X86 VIRTUALIZATION (SNP/TDX)
M: Elena Reshetova <elena.reshetova@intel.com>
M: Carlos Bilbao <carlos.bilbao@kernel.org>
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v11 02/23] mm: Add an allocator for CoCo shared memory
2026-12-02 9:54 [PATCH v11 00/23] coco: guest: Add a shared-granule allocator for host-shared memory Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 01/23] MAINTAINERS: Add CoCo memory sharing and encryption entry Aneesh Kumar K.V (Arm)
@ 2026-12-02 9:54 ` Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 03/23] x86/mm: Use the non-zeroing decryption helper for VGA mappings Aneesh Kumar K.V (Arm)
` (20 subsequent siblings)
22 siblings, 0 replies; 25+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-12-02 9:54 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Andrew Morton, Catalin Marinas,
Christian König, Jason Gunthorpe, Joerg Roedel, Marc Zyngier,
Marek Szyprowski, Robin Murphy, Steven Price, Sumit Semwal,
Suzuki K Poulose, Will Deacon, T.J. Mercier, Madhavan Srinivasan,
Heiko Carstens, Christian Borntraeger, Sven Schnelle, Dave Hansen,
Kiryl Shutsemau, Rick Edgecombe, Paolo Bonzini, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Haiyang Zhang, Wei Liu, Dexuan Cui,
Andy Lutomirski, Peter Zijlstra, Alexander Gordeev,
Gerald Schaefer, Vasily Gorbik, x86, dri-devel, iommu,
linaro-mm-sig, linux-arm-kernel, linux-media, linux-mm, kvmarm,
patches
Confidential-computing guests may require shared memory to be aligned
and transitioned in units larger than PAGE_SIZE. Provide a common
allocator instead of requiring callers to open-code allocation and state
changes.
Add alloc_cc_shared() and alloc_cc_shared_node(), taking a byte count
and returning a linear-map address. Round internally to the sharing
granule and a power-of-two number of pages, and share the entire
allocation. Its physical base is aligned to the allocation size. Always
request compound metadata so cc_shared_alloc_size() and free_cc_shared()
can recover the actual size without a caller-supplied descriptor or
order.
Exclude highmem and movable allocations even without memory encryption:
the returned address must be in the linear map and there is no migration
support. Preserve task NUMA policy for NUMA_NO_NODE. Defer requested
zeroing until after the transition, which may modify memory contents.
Retain allocations if sharing fails or private state cannot be restored.
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
MAINTAINERS | 2 +
include/linux/cc_shared.h | 25 ++++
mm/Makefile | 1 +
mm/cc_shared.c | 240 ++++++++++++++++++++++++++++++++++++++
4 files changed, 268 insertions(+)
create mode 100644 include/linux/cc_shared.h
create mode 100644 mm/cc_shared.c
diff --git a/MAINTAINERS b/MAINTAINERS
index 4cadc468d28d..6e723c6eb31b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -6763,7 +6763,9 @@ L: linux-coco@lists.linux.dev
L: linux-mm@kvack.org
S: Maintained
F: include/linux/cc_platform.h
+F: include/linux/cc_shared.h
F: include/linux/mem_encrypt.h
+F: mm/cc_shared.c
CONFIDENTIAL COMPUTING THREAT MODEL FOR X86 VIRTUALIZATION (SNP/TDX)
M: Elena Reshetova <elena.reshetova@intel.com>
diff --git a/include/linux/cc_shared.h b/include/linux/cc_shared.h
new file mode 100644
index 000000000000..23ba457b5f57
--- /dev/null
+++ b/include/linux/cc_shared.h
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_CC_SHARED_H
+#define _LINUX_CC_SHARED_H
+
+#include <linux/gfp_types.h>
+#include <linux/types.h>
+
+/*
+ * Architectures may override this to return the granule used for transitions
+ * between private and shared memory. The value must be a power of two and no
+ * smaller than PAGE_SIZE.
+ */
+size_t arch_cc_shared_granule_size(void);
+
+size_t cc_shared_granule_size(void);
+int cc_shared_round_size(size_t requested, size_t *size);
+bool cc_shared_range_valid(phys_addr_t base, size_t size);
+int cc_make_shared(void *addr, size_t size);
+int cc_make_private(void *addr, size_t size);
+void *alloc_cc_shared_node(int nid, gfp_t gfp, size_t len);
+void *alloc_cc_shared(gfp_t gfp, size_t len);
+size_t cc_shared_alloc_size(void *addr);
+void free_cc_shared(void *addr);
+
+#endif /* _LINUX_CC_SHARED_H */
diff --git a/mm/Makefile b/mm/Makefile
index 2a3ec53d62ee..a712656449d1 100644
--- a/mm/Makefile
+++ b/mm/Makefile
@@ -57,6 +57,7 @@ obj-y := filemap.o mempool.o oom_kill.o fadvise.o \
interval_tree.o list_lru.o workingset.o \
debug.o gup.o mmap_lock.o vma_init.o char-mem.o \
$(mmu-y)
+obj-y += cc_shared.o
# Give 'page_alloc' its own module-parameter namespace
page-alloc-y := page_alloc.o
diff --git a/mm/cc_shared.c b/mm/cc_shared.c
new file mode 100644
index 000000000000..e60e2269adb6
--- /dev/null
+++ b/mm/cc_shared.c
@@ -0,0 +1,240 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2026 ARM Ltd.
+ */
+#include <linux/align.h>
+#include <linux/cc_platform.h>
+#include <linux/cc_shared.h>
+#include <linux/errno.h>
+#include <linux/export.h>
+#include <linux/gfp.h>
+#include <linux/kernel.h>
+#include <linux/log2.h>
+#include <linux/mm.h>
+#include <linux/mem_encrypt.h>
+#include <linux/numa.h>
+#include <linux/overflow.h>
+#include <linux/set_memory.h>
+
+size_t __weak arch_cc_shared_granule_size(void)
+{
+ return PAGE_SIZE;
+}
+
+size_t cc_shared_granule_size(void)
+{
+ size_t granule = arch_cc_shared_granule_size();
+
+ if (WARN_ON_ONCE(granule < PAGE_SIZE || !is_power_of_2(granule)))
+ return PAGE_SIZE;
+
+ return granule;
+}
+EXPORT_SYMBOL_GPL(cc_shared_granule_size);
+
+/**
+ * cc_shared_round_size - round a byte count to the sharing granule
+ * @requested: nonzero number of bytes
+ * @size: rounded byte count, unchanged on failure
+ *
+ * Return: 0 on success, -EINVAL for a zero request, or -EOVERFLOW.
+ */
+int cc_shared_round_size(size_t requested, size_t *size)
+{
+ size_t granule, rounded;
+
+ if (!requested)
+ return -EINVAL;
+
+ granule = cc_shared_granule_size();
+ if (check_add_overflow(requested, granule - 1, &rounded))
+ return -EOVERFLOW;
+
+ *size = ALIGN_DOWN(rounded, granule);
+ return 0;
+}
+EXPORT_SYMBOL_GPL(cc_shared_round_size);
+
+bool cc_shared_range_valid(phys_addr_t base, size_t size)
+{
+ size_t granule = cc_shared_granule_size();
+
+ if (!size)
+ return false;
+
+ return IS_ALIGNED(base, granule) && IS_ALIGNED(size, granule);
+}
+EXPORT_SYMBOL_GPL(cc_shared_range_valid);
+
+static int cc_validate_transition(void *addr, size_t size)
+{
+ phys_addr_t phys;
+
+ if (!addr || !size || !PAGE_ALIGNED(addr) ||
+ !virt_addr_valid(addr))
+ return -EINVAL;
+
+ phys = page_to_phys(virt_to_page(addr));
+ if (!cc_shared_range_valid(phys, size))
+ return -EINVAL;
+
+ return 0;
+}
+
+int cc_make_shared(void *addr, size_t size)
+{
+ int ret = cc_validate_transition(addr, size);
+
+ if (ret)
+ return ret;
+
+ return set_memory_decrypted((unsigned long)addr, size >> PAGE_SHIFT);
+}
+
+int cc_make_private(void *addr, size_t size)
+{
+ int ret = cc_validate_transition(addr, size);
+
+ if (ret)
+ return ret;
+
+ return set_memory_encrypted((unsigned long)addr, size >> PAGE_SHIFT);
+}
+
+/**
+ * alloc_cc_shared_node - allocate a whole block of shared memory
+ * @nid: NUMA node from which to allocate, or %NUMA_NO_NODE for task policy
+ * @gfp: allocation flags
+ * @len: requested number of bytes; must be nonzero
+ *
+ * Allocate a physically contiguous block of at least @len bytes.
+ * The physical base address is aligned to the full allocation size.
+ * The entire allocation is shared and zeroed.
+ *
+ * The allocation is rounded up to satisfy the platform's sharing granule,
+ * which can make small allocations inefficient. The current implementation
+ * uses compound pages for higher-order allocations to record their size.
+ *
+ * Allocations always have a linear-map address and cannot be migrated.
+ * __GFP_HIGHMEM and __GFP_MOVABLE are ignored. Callers must not split the
+ * allocation or free individual pages. Release the entire allocation with
+ * free_cc_shared().
+ *
+ * Must be called from sleepable context.
+ * Return: The allocation's linear-map address, or NULL on failure.
+ */
+void *alloc_cc_shared_node(int nid, gfp_t gfp, size_t len)
+{
+ bool encrypted = cc_platform_has(CC_ATTR_MEM_ENCRYPT);
+ struct page *page;
+ unsigned int order;
+ void *addr;
+ size_t size;
+
+ might_sleep();
+
+ if (cc_shared_round_size(len, &size))
+ return NULL;
+
+ order = get_order(size);
+ if (order > MAX_PAGE_ORDER)
+ return NULL;
+
+ /*
+ * Returning a linear-map address requires low memory even when memory
+ * encryption is inactive. Callers may retain virtual or physical
+ * addresses, and this allocator provides no migration support, so the
+ * allocation must not be marked movable in either case.
+ */
+ gfp &= ~(__GFP_HIGHMEM | __GFP_MOVABLE);
+ gfp |= __GFP_COMP;
+ gfp &= ~__GFP_ZERO;
+
+ if (nid == NUMA_NO_NODE)
+ page = alloc_pages(gfp, order);
+ else
+ page = alloc_pages_node(nid, gfp, order);
+ if (!page)
+ return NULL;
+
+ addr = page_address(page);
+ size = PAGE_SIZE << order;
+ if (encrypted && cc_make_shared(addr, size)) {
+ /*
+ * A failed transition may leave the range partially shared.
+ * Making already-private pages private again is not safe on
+ * every architecture. Retain the entire allocation rather than
+ * return pages with uncertain state to the page allocator.
+ */
+ pr_warn_ratelimited("leaking %zu bytes with uncertain shared state\n",
+ size);
+ return NULL;
+ }
+
+ memset(addr, 0, size);
+ return addr;
+}
+EXPORT_SYMBOL_GPL(alloc_cc_shared_node);
+
+/**
+ * alloc_cc_shared - allocate a whole block of shared memory
+ * @gfp: allocation flags
+ * @len: requested number of bytes; must be nonzero
+ *
+ * Equivalent to alloc_cc_shared_node() with %NUMA_NO_NODE.
+ *
+ * Return: The allocation's linear-map address, or NULL on failure.
+ */
+void *alloc_cc_shared(gfp_t gfp, size_t len)
+{
+ return alloc_cc_shared_node(NUMA_NO_NODE, gfp, len);
+}
+EXPORT_SYMBOL_GPL(alloc_cc_shared);
+
+/**
+ * cc_shared_alloc_size - get the size of a shared allocation
+ * @addr: original address returned by alloc_cc_shared_node() or
+ * alloc_cc_shared(); must be non-NULL and not yet freed
+ *
+ * Return: The full allocation size recorded in compound-page metadata,
+ * including any rounding performed by the allocator.
+ */
+size_t cc_shared_alloc_size(void *addr)
+{
+ return page_size(virt_to_page(addr));
+}
+EXPORT_SYMBOL_GPL(cc_shared_alloc_size);
+
+/**
+ * free_cc_shared - make an entire shared allocation private and free it
+ * @addr: original address returned by alloc_cc_shared_node() or
+ * alloc_cc_shared(), or NULL
+ *
+ * Use the allocation size from compound-page metadata. Partial frees are
+ * not supported. Retain the allocation if making it private fails.
+ *
+ * Must be called from sleepable context.
+ */
+void free_cc_shared(void *addr)
+{
+ struct page *page;
+ size_t size;
+
+ might_sleep();
+
+ if (!addr)
+ return;
+
+ page = virt_to_page(addr);
+ size = cc_shared_alloc_size(addr);
+ if (cc_platform_has(CC_ATTR_MEM_ENCRYPT)) {
+ if (cc_make_private(addr, size)) {
+ pr_warn_ratelimited("leaking %zu bytes that cannot be made private\n",
+ size);
+ return;
+ }
+ }
+
+ __free_pages(page, compound_order(page));
+}
+EXPORT_SYMBOL_GPL(free_cc_shared);
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v11 03/23] x86/mm: Use the non-zeroing decryption helper for VGA mappings
2026-12-02 9:54 [PATCH v11 00/23] coco: guest: Add a shared-granule allocator for host-shared memory Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 01/23] MAINTAINERS: Add CoCo memory sharing and encryption entry Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 02/23] mm: Add an allocator for CoCo shared memory Aneesh Kumar K.V (Arm)
@ 2026-12-02 9:54 ` Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 04/23] s390/mm: Clear memory before making it shared Aneesh Kumar K.V (Arm)
` (19 subsequent siblings)
22 siblings, 0 replies; 25+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-12-02 9:54 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Andrew Morton, Catalin Marinas,
Christian König, Jason Gunthorpe, Joerg Roedel, Marc Zyngier,
Marek Szyprowski, Robin Murphy, Steven Price, Sumit Semwal,
Suzuki K Poulose, Will Deacon, T.J. Mercier, Madhavan Srinivasan,
Heiko Carstens, Christian Borntraeger, Sven Schnelle, Dave Hansen,
Kiryl Shutsemau, Rick Edgecombe, Paolo Bonzini, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Haiyang Zhang, Wei Liu, Dexuan Cui,
Andy Lutomirski, Peter Zijlstra, Alexander Gordeev,
Gerald Schaefer, Vasily Gorbik, x86, dri-devel, iommu,
linaro-mm-sig, linux-arm-kernel, linux-media, linux-mm, kvmarm,
patches
Add set_memory_decrypted_nozero() with the existing x86 decryption
behavior and use it for VGA_MAP_MEM(). Video memory needs a decrypted
mapping without an explicit memset() of the mapped range.
This prepares the VGA caller for adding zeroing to
set_memory_decrypted().
Cc: Thomas Gleixner <tglx@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: x86@kernel.org
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
arch/x86/include/asm/set_memory.h | 1 +
arch/x86/include/asm/vga.h | 4 ++--
arch/x86/mm/pat/set_memory.c | 7 +++++++
3 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/arch/x86/include/asm/set_memory.h b/arch/x86/include/asm/set_memory.h
index 39271a5ea925..dfac1dde3714 100644
--- a/arch/x86/include/asm/set_memory.h
+++ b/arch/x86/include/asm/set_memory.h
@@ -52,6 +52,7 @@ int set_memory_4k(unsigned long addr, int numpages);
bool set_memory_enc_stop_conversion(void);
int set_memory_encrypted(unsigned long addr, int numpages);
int set_memory_decrypted(unsigned long addr, int numpages);
+int set_memory_decrypted_nozero(unsigned long addr, int numpages);
int set_memory_np_noalias(unsigned long addr, int numpages);
int set_memory_nonglobal(unsigned long addr, int numpages);
diff --git a/arch/x86/include/asm/vga.h b/arch/x86/include/asm/vga.h
index 46f9b2deab4d..e1e91dfa399d 100644
--- a/arch/x86/include/asm/vga.h
+++ b/arch/x86/include/asm/vga.h
@@ -14,7 +14,7 @@
* On the PC, we can just recalculate addresses and then
* access the videoram directly without any black magic.
* To support memory encryption however, we need to access
- * the videoram as decrypted memory.
+ * the videoram as decrypted memory without clearing its contents.
*/
#define VGA_MAP_MEM(x, s) \
@@ -22,7 +22,7 @@
unsigned long start = (unsigned long)phys_to_virt(x); \
\
if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) \
- set_memory_decrypted(start, (s) >> PAGE_SHIFT); \
+ set_memory_decrypted_nozero(start, (s) >> PAGE_SHIFT); \
\
start; \
})
diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c
index b1d5c5a0ffb4..16f3f57f973b 100644
--- a/arch/x86/mm/pat/set_memory.c
+++ b/arch/x86/mm/pat/set_memory.c
@@ -2549,6 +2549,13 @@ int set_memory_decrypted(unsigned long addr, int numpages)
}
EXPORT_SYMBOL_GPL(set_memory_decrypted);
+/* Device memory needs a decrypted mapping without writes to its contents. */
+int set_memory_decrypted_nozero(unsigned long addr, int numpages)
+{
+ return __set_memory_enc_dec(addr, numpages, false);
+}
+EXPORT_SYMBOL_GPL(set_memory_decrypted_nozero);
+
int set_pages_uc(struct page *page, int numpages)
{
unsigned long addr = (unsigned long)page_address(page);
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v11 04/23] s390/mm: Clear memory before making it shared
2026-12-02 9:54 [PATCH v11 00/23] coco: guest: Add a shared-granule allocator for host-shared memory Aneesh Kumar K.V (Arm)
` (2 preceding siblings ...)
2026-12-02 9:54 ` [PATCH v11 03/23] x86/mm: Use the non-zeroing decryption helper for VGA mappings Aneesh Kumar K.V (Arm)
@ 2026-12-02 9:54 ` Aneesh Kumar K.V (Arm)
2026-12-02 9:57 ` Christian Borntraeger
2026-12-02 9:54 ` [PATCH v11 05/23] powerpc/pseries: Clear memory after " Aneesh Kumar K.V (Arm)
` (18 subsequent siblings)
22 siblings, 1 reply; 25+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-12-02 9:54 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Andrew Morton, Catalin Marinas,
Christian König, Jason Gunthorpe, Joerg Roedel, Marc Zyngier,
Marek Szyprowski, Robin Murphy, Steven Price, Sumit Semwal,
Suzuki K Poulose, Will Deacon, T.J. Mercier, Madhavan Srinivasan,
Heiko Carstens, Christian Borntraeger, Sven Schnelle, Dave Hansen,
Kiryl Shutsemau, Rick Edgecombe, Paolo Bonzini, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Haiyang Zhang, Wei Liu, Dexuan Cui,
Andy Lutomirski, Peter Zijlstra, Alexander Gordeev,
Gerald Schaefer, Vasily Gorbik, x86, dri-devel, iommu,
linaro-mm-sig, linux-arm-kernel, linux-media, linux-mm, kvmarm,
patches
The comment in share() warns that sharing operates on whole pages and
can expose unintended data to the hypervisor. Memory whose previous
contents must remain private therefore needs to be cleared before
uv_set_shared() makes it accessible to the host.
The common CoCo allocator masks __GFP_ZERO because a private-to-shared
transition may modify memory contents, and currently clears the
allocation after sharing. On s390, that ordering could expose previous
contents before the clear.
Clear the range in set_memory_decrypted() before calling
uv_set_shared(). This also establishes the zeroing guarantee that
subsequent patches will use to remove redundant caller-side clears.
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
arch/s390/mm/init.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
index be7e009e7b59..fdacd9380286 100644
--- a/arch/s390/mm/init.c
+++ b/arch/s390/mm/init.c
@@ -129,6 +129,13 @@ int set_memory_encrypted(unsigned long vaddr, int numpages)
int set_memory_decrypted(unsigned long vaddr, int numpages)
{
int i;
+
+ /*
+ * uv_set_shared() exposes existing contents to the host; see the data
+ * leakage warning in share() in asm/uv.h. Clear private data first.
+ */
+ memset((void *)vaddr, 0, (size_t)numpages << PAGE_SHIFT);
+
/* make specified pages shared (swiotlb, dma_alloca) */
for (i = 0; i < numpages; ++i) {
uv_set_shared(virt_to_phys((void *)vaddr));
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v11 05/23] powerpc/pseries: Clear memory after making it shared
2026-12-02 9:54 [PATCH v11 00/23] coco: guest: Add a shared-granule allocator for host-shared memory Aneesh Kumar K.V (Arm)
` (3 preceding siblings ...)
2026-12-02 9:54 ` [PATCH v11 04/23] s390/mm: Clear memory before making it shared Aneesh Kumar K.V (Arm)
@ 2026-12-02 9:54 ` Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 06/23] arm64: Zero memory during private-to-shared transitions Aneesh Kumar K.V (Arm)
` (17 subsequent siblings)
22 siblings, 0 replies; 25+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-12-02 9:54 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Andrew Morton, Catalin Marinas,
Christian König, Jason Gunthorpe, Joerg Roedel, Marc Zyngier,
Marek Szyprowski, Robin Murphy, Steven Price, Sumit Semwal,
Suzuki K Poulose, Will Deacon, T.J. Mercier, Madhavan Srinivasan,
Heiko Carstens, Christian Borntraeger, Sven Schnelle, Dave Hansen,
Kiryl Shutsemau, Rick Edgecombe, Paolo Bonzini, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Haiyang Zhang, Wei Liu, Dexuan Cui,
Andy Lutomirski, Peter Zijlstra, Alexander Gordeev,
Gerald Schaefer, Vasily Gorbik, x86, dri-devel, iommu,
linaro-mm-sig, linux-arm-kernel, linux-media, linux-mm, kvmarm,
patches
Clear the final shared mapping after uv_share_page(). Firmware may scrub
memory with nonzero values during conversion, so clearing before sharing
would not guarantee a zeroed result. Also clear the range when memory
encryption is inactive.
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
arch/powerpc/platforms/pseries/svm.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/arch/powerpc/platforms/pseries/svm.c b/arch/powerpc/platforms/pseries/svm.c
index 7a403dbd35ee..0970f1fb76d7 100644
--- a/arch/powerpc/platforms/pseries/svm.c
+++ b/arch/powerpc/platforms/pseries/svm.c
@@ -9,6 +9,7 @@
#include <linux/mm.h>
#include <linux/memblock.h>
#include <linux/mem_encrypt.h>
+#include <linux/string.h>
#include <linux/cc_platform.h>
#include <asm/machdep.h>
#include <asm/svm.h>
@@ -53,13 +54,17 @@ int set_memory_encrypted(unsigned long addr, int numpages)
int set_memory_decrypted(unsigned long addr, int numpages)
{
- if (!cc_platform_has(CC_ATTR_MEM_ENCRYPT))
- return 0;
-
if (!PAGE_ALIGNED(addr))
return -EINVAL;
- uv_share_page(PHYS_PFN(__pa(addr)), numpages);
+ if (cc_platform_has(CC_ATTR_MEM_ENCRYPT))
+ uv_share_page(PHYS_PFN(__pa(addr)), numpages);
+ /*
+ * Firmware may scrub pages with nonzero values during
+ * private-to-shared conversion. Clear the final shared mapping
+ * after the transition so that callers receive zeroed memory.
+ */
+ memset((void *)addr, 0, (size_t)numpages << PAGE_SHIFT);
return 0;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v11 06/23] arm64: Zero memory during private-to-shared transitions
2026-12-02 9:54 [PATCH v11 00/23] coco: guest: Add a shared-granule allocator for host-shared memory Aneesh Kumar K.V (Arm)
` (4 preceding siblings ...)
2026-12-02 9:54 ` [PATCH v11 05/23] powerpc/pseries: Clear memory after " Aneesh Kumar K.V (Arm)
@ 2026-12-02 9:54 ` Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 07/23] x86/mm: Clear memory after successful decryption transitions Aneesh Kumar K.V (Arm)
` (16 subsequent siblings)
22 siblings, 0 replies; 25+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-12-02 9:54 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Andrew Morton, Catalin Marinas,
Christian König, Jason Gunthorpe, Joerg Roedel, Marc Zyngier,
Marek Szyprowski, Robin Murphy, Steven Price, Sumit Semwal,
Suzuki K Poulose, Will Deacon, T.J. Mercier, Madhavan Srinivasan,
Heiko Carstens, Christian Borntraeger, Sven Schnelle, Dave Hansen,
Kiryl Shutsemau, Rick Edgecombe, Paolo Bonzini, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Haiyang Zhang, Wei Liu, Dexuan Cui,
Andy Lutomirski, Peter Zijlstra, Alexander Gordeev,
Gerald Schaefer, Vasily Gorbik, x86, dri-devel, iommu,
linaro-mm-sig, linux-arm-kernel, linux-media, linux-mm, kvmarm,
patches
Zero memory at the point required by each arm64 sharing implementation.
For pKVM, clear and clean the private contents to the point of coherency
before the host gains access
For CCA, clear after successful conversion because the RMM can modify
the contents while returning the pages to the host.
Clear the range on the no-encryption path as well.
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
arch/arm64/mm/mem_encrypt.c | 8 +++++++-
drivers/firmware/arm_rmm/rsi.c | 9 +++++++++
drivers/virt/coco/pkvm-guest/arm-pkvm-guest.c | 11 +++++++++++
3 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/mm/mem_encrypt.c b/arch/arm64/mm/mem_encrypt.c
index ee3c0ab04384..25eb67138b28 100644
--- a/arch/arm64/mm/mem_encrypt.c
+++ b/arch/arm64/mm/mem_encrypt.c
@@ -17,6 +17,7 @@
#include <linux/compiler.h>
#include <linux/err.h>
#include <linux/mm.h>
+#include <linux/string.h>
#include <asm/mem_encrypt.h>
@@ -42,8 +43,13 @@ EXPORT_SYMBOL_GPL(set_memory_encrypted);
int set_memory_decrypted(unsigned long addr, int numpages)
{
- if (likely(!crypt_ops) || WARN_ON(!PAGE_ALIGNED(addr)))
+ if (likely(!crypt_ops)) {
+ memset((void *)addr, 0, (size_t)numpages << PAGE_SHIFT);
return 0;
+ }
+
+ if (WARN_ON(!PAGE_ALIGNED(addr)))
+ return -EINVAL;
return crypt_ops->decrypt(addr, numpages);
}
diff --git a/drivers/firmware/arm_rmm/rsi.c b/drivers/firmware/arm_rmm/rsi.c
index 0fcc4e33bd92..2c1591028b0e 100644
--- a/drivers/firmware/arm_rmm/rsi.c
+++ b/drivers/firmware/arm_rmm/rsi.c
@@ -6,6 +6,7 @@
#include <linux/jump_label.h>
#include <linux/memblock.h>
#include <linux/psci.h>
+#include <linux/string.h>
#include <linux/swiotlb.h>
#include <linux/arm-rsi-cmds.h>
#include <linux/kobject.h>
@@ -146,6 +147,14 @@ static int realm_set_memory_decrypted(unsigned long addr, int numpages)
{
int ret = __set_memory_enc_dec(addr, numpages, false);
+ /*
+ * The RMM may scrub pages with nonzero values before returning them to
+ * the host. Zeroing before conversion would not guarantee zeroed shared
+ * memory, so clear the final shared mapping after the transition.
+ */
+ if (!ret)
+ memset((void *)addr, 0, (size_t)numpages << PAGE_SHIFT);
+
WARN(ret, "Failed to decrypt memory, %d pages will be leaked",
numpages);
diff --git a/drivers/virt/coco/pkvm-guest/arm-pkvm-guest.c b/drivers/virt/coco/pkvm-guest/arm-pkvm-guest.c
index 26fe9c3f22e3..819c26004c99 100644
--- a/drivers/virt/coco/pkvm-guest/arm-pkvm-guest.c
+++ b/drivers/virt/coco/pkvm-guest/arm-pkvm-guest.c
@@ -9,10 +9,12 @@
#include <linux/arm-smccc.h>
#include <linux/array_size.h>
+#include <linux/cacheflush.h>
#include <linux/io.h>
#include <linux/mem_encrypt.h>
#include <linux/mm.h>
#include <linux/pgtable.h>
+#include <linux/string.h>
#include <asm/hypervisor.h>
@@ -61,6 +63,15 @@ static int pkvm_set_memory_encrypted(unsigned long addr, int numpages)
static int pkvm_set_memory_decrypted(unsigned long addr, int numpages)
{
+ size_t size = numpages * PAGE_SIZE;
+
+ /*
+ * The host can read the pages as soon as they are shared, possibly
+ * through a Non-cacheable mapping. Clear them first.
+ */
+ memset((void *)addr, 0, size);
+ dcache_clean_poc(addr, addr + size);
+
return __set_memory_range(ARM_SMCCC_VENDOR_HYP_KVM_MEM_SHARE_FUNC_ID,
addr, numpages);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v11 07/23] x86/mm: Clear memory after successful decryption transitions
2026-12-02 9:54 [PATCH v11 00/23] coco: guest: Add a shared-granule allocator for host-shared memory Aneesh Kumar K.V (Arm)
` (5 preceding siblings ...)
2026-12-02 9:54 ` [PATCH v11 06/23] arm64: Zero memory during private-to-shared transitions Aneesh Kumar K.V (Arm)
@ 2026-12-02 9:54 ` Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 08/23] mm: Document zeroing by set_memory_decrypted() and update the fallback Aneesh Kumar K.V (Arm)
` (15 subsequent siblings)
22 siblings, 0 replies; 25+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-12-02 9:54 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Andrew Morton, Catalin Marinas,
Christian König, Jason Gunthorpe, Joerg Roedel, Marc Zyngier,
Marek Szyprowski, Robin Murphy, Steven Price, Sumit Semwal,
Suzuki K Poulose, Will Deacon, T.J. Mercier, Madhavan Srinivasan,
Heiko Carstens, Christian Borntraeger, Sven Schnelle, Dave Hansen,
Kiryl Shutsemau, Rick Edgecombe, Paolo Bonzini, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Haiyang Zhang, Wei Liu, Dexuan Cui,
Andy Lutomirski, Peter Zijlstra, Alexander Gordeev,
Gerald Schaefer, Vasily Gorbik, x86, dri-devel, iommu,
linaro-mm-sig, linux-arm-kernel, linux-media, linux-mm, kvmarm,
patches
Clear the final mapping after __set_memory_enc_dec() succeeds.
Conversion may change the contents, so zeroing must follow the
successful transition. This applies to the common x86 wrapper, including
when no encryption change is needed.
The VGA caller already uses set_memory_decrypted_nozero() and therefore
does not acquire this new explicit clear. Leave existing caller clears
in place until the subsequent cleanup patches.
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: x86@kernel.org
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
arch/x86/mm/pat/set_memory.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c
index 16f3f57f973b..bf4466ef1220 100644
--- a/arch/x86/mm/pat/set_memory.c
+++ b/arch/x86/mm/pat/set_memory.c
@@ -2545,7 +2545,17 @@ EXPORT_SYMBOL_GPL(set_memory_encrypted);
int set_memory_decrypted(unsigned long addr, int numpages)
{
- return __set_memory_enc_dec(addr, numpages, false);
+ int ret = __set_memory_enc_dec(addr, numpages, false);
+
+ /*
+ * Firmware may scrub pages with nonzero values during private-to-shared
+ * conversion. Clear the final shared mapping after the transition so
+ * that callers receive zeroed memory.
+ */
+ if (!ret)
+ memset((void *)addr, 0, (size_t)numpages << PAGE_SHIFT);
+
+ return ret;
}
EXPORT_SYMBOL_GPL(set_memory_decrypted);
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v11 08/23] mm: Document zeroing by set_memory_decrypted() and update the fallback
2026-12-02 9:54 [PATCH v11 00/23] coco: guest: Add a shared-granule allocator for host-shared memory Aneesh Kumar K.V (Arm)
` (6 preceding siblings ...)
2026-12-02 9:54 ` [PATCH v11 07/23] x86/mm: Clear memory after successful decryption transitions Aneesh Kumar K.V (Arm)
@ 2026-12-02 9:54 ` Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 09/23] drivers: hv: Remove redundant clearing after decryption Aneesh Kumar K.V (Arm)
` (14 subsequent siblings)
22 siblings, 0 replies; 25+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-12-02 9:54 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Andrew Morton, Catalin Marinas,
Christian König, Jason Gunthorpe, Joerg Roedel, Marc Zyngier,
Marek Szyprowski, Robin Murphy, Steven Price, Sumit Semwal,
Suzuki K Poulose, Will Deacon, T.J. Mercier, Madhavan Srinivasan,
Heiko Carstens, Christian Borntraeger, Sven Schnelle, Dave Hansen,
Kiryl Shutsemau, Rick Edgecombe, Paolo Bonzini, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Haiyang Zhang, Wei Liu, Dexuan Cui,
Andy Lutomirski, Peter Zijlstra, Alexander Gordeev,
Gerald Schaefer, Vasily Gorbik, x86, dri-devel, iommu,
linaro-mm-sig, linux-arm-kernel, linux-media, linux-mm, kvmarm,
patches
The architecture implementations now clear memory during successful
private-to-shared transitions. Make the no-encryption generic fallback
clear the supplied range too.
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
include/linux/set_memory.h | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/include/linux/set_memory.h b/include/linux/set_memory.h
index 27c32fbabfec..43ab0d62b87e 100644
--- a/include/linux/set_memory.h
+++ b/include/linux/set_memory.h
@@ -5,6 +5,10 @@
#ifndef _LINUX_SET_MEMORY_H_
#define _LINUX_SET_MEMORY_H_
+#include <linux/string.h>
+
+#include <asm/page.h>
+
/**
* DOC: Kernel page table permissions
*
@@ -21,7 +25,8 @@
*
* When an architecture does not implement these APIs they succeed without
* doing anything, so a return value of 0 does not mean that the permissions
- * were actually changed.
+ * were actually changed. set_memory_decrypted() also clears the range,
+ * including when no encryption change is needed.
*
* Callers that depend on the permissions being applied must ensure that the
* architecture supports the required operation for the target addresses. The
@@ -186,6 +191,7 @@ static inline int set_memory_encrypted(unsigned long addr, int numpages)
static inline int set_memory_decrypted(unsigned long addr, int numpages)
{
+ memset((void *)addr, 0, (size_t)numpages << PAGE_SHIFT);
return 0;
}
#endif /* CONFIG_ARCH_HAS_MEM_ENCRYPT */
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v11 09/23] drivers: hv: Remove redundant clearing after decryption
2026-12-02 9:54 [PATCH v11 00/23] coco: guest: Add a shared-granule allocator for host-shared memory Aneesh Kumar K.V (Arm)
` (7 preceding siblings ...)
2026-12-02 9:54 ` [PATCH v11 08/23] mm: Document zeroing by set_memory_decrypted() and update the fallback Aneesh Kumar K.V (Arm)
@ 2026-12-02 9:54 ` Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 10/23] x86/kvmclock: Avoid clearing decrypted clock memory twice Aneesh Kumar K.V (Arm)
` (13 subsequent siblings)
22 siblings, 0 replies; 25+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-12-02 9:54 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Andrew Morton, Catalin Marinas,
Christian König, Jason Gunthorpe, Joerg Roedel, Marc Zyngier,
Marek Szyprowski, Robin Murphy, Steven Price, Sumit Semwal,
Suzuki K Poulose, Will Deacon, T.J. Mercier, Madhavan Srinivasan,
Heiko Carstens, Christian Borntraeger, Sven Schnelle, Dave Hansen,
Kiryl Shutsemau, Rick Edgecombe, Paolo Bonzini, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Haiyang Zhang, Wei Liu, Dexuan Cui,
Andy Lutomirski, Peter Zijlstra, Alexander Gordeev,
Gerald Schaefer, Vasily Gorbik, x86, dri-devel, iommu,
linaro-mm-sig, linux-arm-kernel, linux-media, linux-mm, kvmarm,
patches
Successful set_memory_decrypted() calls now return zeroed memory. Remove
redundant post-transition clears from the Hyper-V allocation paths. Keep
explicit clearing when a path does not call the transition helper.
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Cc: Wei Liu <wei.liu@kernel.org>
Cc: Dexuan Cui <decui@microsoft.com>
Cc: x86@kernel.org
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
arch/x86/hyperv/hv_init.c | 1 -
drivers/hv/connection.c | 7 -------
drivers/hv/hv.c | 10 ++++++----
drivers/hv/hv_common.c | 2 --
4 files changed, 6 insertions(+), 14 deletions(-)
diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
index b90e6f487533..8b3e34a9d8de 100644
--- a/arch/x86/hyperv/hv_init.c
+++ b/arch/x86/hyperv/hv_init.c
@@ -157,7 +157,6 @@ static int hv_cpu_init(unsigned int cpu)
*/
if (*hvp && !ms_hyperv.paravisor_present && hv_isolation_type_snp()) {
WARN_ON_ONCE(set_memory_decrypted((unsigned long)(*hvp), 1));
- memset(*hvp, 0, PAGE_SIZE);
}
}
diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c
index 818667ef9c74..856b30462a7d 100644
--- a/drivers/hv/connection.c
+++ b/drivers/hv/connection.c
@@ -279,13 +279,6 @@ int vmbus_connect(void)
goto cleanup;
}
- /*
- * Set_memory_decrypted() will change the memory contents if
- * decryption occurs, so zero monitor pages here.
- */
- memset(vmbus_connection.monitor_pages[0], 0x00, HV_HYP_PAGE_SIZE);
- memset(vmbus_connection.monitor_pages[1], 0x00, HV_HYP_PAGE_SIZE);
-
msginfo = kzalloc(sizeof(*msginfo) +
sizeof(struct vmbus_channel_initiate_contact),
GFP_KERNEL);
diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
index fe50090dcc01..9f23c687b57b 100644
--- a/drivers/hv/hv.c
+++ b/drivers/hv/hv.c
@@ -123,12 +123,14 @@ static int hv_alloc_page(void **page, bool decrypt, const char *note)
if (!*page)
return -ENOMEM;
- if (decrypt)
+ if (decrypt) {
ret = set_memory_decrypted((unsigned long)*page, 1);
- if (ret)
- goto failed;
+ if (ret)
+ goto failed;
+ } else {
+ memset(*page, 0, PAGE_SIZE);
+ }
- memset(*page, 0, PAGE_SIZE);
return 0;
failed:
diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
index df2577896271..404d2436346e 100644
--- a/drivers/hv/hv_common.c
+++ b/drivers/hv/hv_common.c
@@ -534,8 +534,6 @@ int hv_common_cpu_init(unsigned int cpu)
/* It may be unsafe to free 'mem' */
return ret;
}
-
- memset(mem, 0x00, pgcount * HV_HYP_PAGE_SIZE);
}
/*
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v11 10/23] x86/kvmclock: Avoid clearing decrypted clock memory twice
2026-12-02 9:54 [PATCH v11 00/23] coco: guest: Add a shared-granule allocator for host-shared memory Aneesh Kumar K.V (Arm)
` (8 preceding siblings ...)
2026-12-02 9:54 ` [PATCH v11 09/23] drivers: hv: Remove redundant clearing after decryption Aneesh Kumar K.V (Arm)
@ 2026-12-02 9:54 ` Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 11/23] dma-direct: Avoid redundant clearing of shared allocations Aneesh Kumar K.V (Arm)
` (12 subsequent siblings)
22 siblings, 0 replies; 25+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-12-02 9:54 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Andrew Morton, Catalin Marinas,
Christian König, Jason Gunthorpe, Joerg Roedel, Marc Zyngier,
Marek Szyprowski, Robin Murphy, Steven Price, Sumit Semwal,
Suzuki K Poulose, Will Deacon, T.J. Mercier, Madhavan Srinivasan,
Heiko Carstens, Christian Borntraeger, Sven Schnelle, Dave Hansen,
Kiryl Shutsemau, Rick Edgecombe, Paolo Bonzini, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Haiyang Zhang, Wei Liu, Dexuan Cui,
Andy Lutomirski, Peter Zijlstra, Alexander Gordeev,
Gerald Schaefer, Vasily Gorbik, x86, dri-devel, iommu,
linaro-mm-sig, linux-arm-kernel, linux-media, linux-mm, kvmarm,
patches
set_memory_decrypted() now clears the range even when memory encryption
is inactive, so call it unconditionally and remove the separate
memset().
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Thomas Gleixner <tglx@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: x86@kernel.org
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
arch/x86/kernel/kvmclock.c | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c
index cb3d0ca1fa22..c7c306275a64 100644
--- a/arch/x86/kernel/kvmclock.c
+++ b/arch/x86/kernel/kvmclock.c
@@ -16,7 +16,6 @@
#include <linux/mm.h>
#include <linux/slab.h>
#include <linux/set_memory.h>
-#include <linux/cc_platform.h>
#include <asm/hypervisor.h>
#include <asm/timer.h>
@@ -247,18 +246,13 @@ static void __init kvmclock_init_mem(void)
* hvclock is shared between the guest and the hypervisor, must
* be mapped decrypted.
*/
- if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) {
- r = set_memory_decrypted((unsigned long) hvclock_mem,
- 1UL << order);
- if (r) {
- __free_pages(p, order);
- hvclock_mem = NULL;
- pr_warn("kvmclock: set_memory_decrypted() failed. Disabling\n");
- return;
- }
+ r = set_memory_decrypted((unsigned long)hvclock_mem, 1UL << order);
+ if (r) {
+ __free_pages(p, order);
+ hvclock_mem = NULL;
+ pr_warn("kvmclock: set_memory_decrypted() failed. Disabling\n");
+ return;
}
-
- memset(hvclock_mem, 0, PAGE_SIZE << order);
}
static int __init kvm_setup_vsyscall_timeinfo(void)
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v11 11/23] dma-direct: Avoid redundant clearing of shared allocations
2026-12-02 9:54 [PATCH v11 00/23] coco: guest: Add a shared-granule allocator for host-shared memory Aneesh Kumar K.V (Arm)
` (9 preceding siblings ...)
2026-12-02 9:54 ` [PATCH v11 10/23] x86/kvmclock: Avoid clearing decrypted clock memory twice Aneesh Kumar K.V (Arm)
@ 2026-12-02 9:54 ` Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 12/23] mm: Avoid zeroing CoCo shared allocations twice Aneesh Kumar K.V (Arm)
` (11 subsequent siblings)
22 siblings, 0 replies; 25+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-12-02 9:54 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Andrew Morton, Catalin Marinas,
Christian König, Jason Gunthorpe, Joerg Roedel, Marc Zyngier,
Marek Szyprowski, Robin Murphy, Steven Price, Sumit Semwal,
Suzuki K Poulose, Will Deacon, T.J. Mercier, Madhavan Srinivasan,
Heiko Carstens, Christian Borntraeger, Sven Schnelle, Dave Hansen,
Kiryl Shutsemau, Rick Edgecombe, Paolo Bonzini, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Haiyang Zhang, Wei Liu, Dexuan Cui,
Andy Lutomirski, Peter Zijlstra, Alexander Gordeev,
Gerald Schaefer, Vasily Gorbik, x86, dri-devel, iommu,
linaro-mm-sig, linux-arm-kernel, linux-media, linux-mm, kvmarm,
patches
A successful decryption transition now clears the shared allocation.
Avoid a second memset() on that path, while retaining explicit zeroing
for allocations that do not undergo a transition.
Keep the explicit clear after remapping for potentially highmem buffers.
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
kernel/dma/direct.c | 23 ++++++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)
diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
index 25e9a86835fd..4d05817d6245 100644
--- a/kernel/dma/direct.c
+++ b/kernel/dma/direct.c
@@ -229,7 +229,8 @@ void *dma_direct_alloc(struct device *dev, size_t size,
if (force_dma_unencrypted(dev))
attrs |= __DMA_ATTR_ALLOC_CC_SHARED;
- if (attrs & __DMA_ATTR_ALLOC_CC_SHARED) {
+ mark_mem_decrypt = attrs & __DMA_ATTR_ALLOC_CC_SHARED;
+ if (mark_mem_decrypt) {
/*
* Unencrypted/shared DMA requires a linear-mapped buffer
* address to look up the PFN and set architecture-required PFN
@@ -237,7 +238,6 @@ void *dma_direct_alloc(struct device *dev, size_t size,
* allocation.
*/
allow_highmem = false;
- mark_mem_decrypt = true;
}
size = PAGE_ALIGN(size);
@@ -341,7 +341,9 @@ void *dma_direct_alloc(struct device *dev, size_t size,
cpu_addr = page_address(page);
}
- memset(cpu_addr, 0, size);
+ /* Zero after remapping because the page may be in HighMem. */
+ if (!mark_mem_decrypt)
+ memset(cpu_addr, 0, size);
if (set_uncached) {
void *uncached_cpu_addr;
@@ -451,10 +453,13 @@ struct page *dma_direct_alloc_pages(struct device *dev, size_t size,
unsigned long attrs = 0;
struct page *page;
void *cpu_addr;
+ bool mark_mem_decrypt;
if (force_dma_unencrypted(dev))
attrs |= __DMA_ATTR_ALLOC_CC_SHARED;
+ mark_mem_decrypt = attrs & __DMA_ATTR_ALLOC_CC_SHARED;
+
if ((attrs & __DMA_ATTR_ALLOC_CC_SHARED) && dma_direct_use_pool(dev, gfp))
return dma_direct_alloc_from_pool(dev, size, dma_handle,
&cpu_addr, gfp, attrs);
@@ -465,6 +470,7 @@ struct page *dma_direct_alloc_pages(struct device *dev, size_t size,
return NULL;
cpu_addr = page_address(page);
+ mark_mem_decrypt = false;
goto setup_page;
}
@@ -473,11 +479,14 @@ struct page *dma_direct_alloc_pages(struct device *dev, size_t size,
return NULL;
cpu_addr = page_address(page);
- if ((attrs & __DMA_ATTR_ALLOC_CC_SHARED) &&
- dma_set_decrypted(dev, cpu_addr, size))
- goto out_leak_pages;
setup_page:
- memset(cpu_addr, 0, size);
+ if (mark_mem_decrypt) {
+ if (dma_set_decrypted(dev, cpu_addr, size))
+ goto out_leak_pages;
+ } else {
+ memset(cpu_addr, 0, size);
+ }
+
*dma_handle = phys_to_dma_direct(dev, page_to_phys(page),
attrs & __DMA_ATTR_ALLOC_CC_SHARED);
return page;
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v11 12/23] mm: Avoid zeroing CoCo shared allocations twice
2026-12-02 9:54 [PATCH v11 00/23] coco: guest: Add a shared-granule allocator for host-shared memory Aneesh Kumar K.V (Arm)
` (10 preceding siblings ...)
2026-12-02 9:54 ` [PATCH v11 11/23] dma-direct: Avoid redundant clearing of shared allocations Aneesh Kumar K.V (Arm)
@ 2026-12-02 9:54 ` Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 13/23] irqchip/gic-v3-its: Resolve the default NUMA node explicitly Aneesh Kumar K.V (Arm)
` (10 subsequent siblings)
22 siblings, 0 replies; 25+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-12-02 9:54 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Andrew Morton, Catalin Marinas,
Christian König, Jason Gunthorpe, Joerg Roedel, Marc Zyngier,
Marek Szyprowski, Robin Murphy, Steven Price, Sumit Semwal,
Suzuki K Poulose, Will Deacon, T.J. Mercier, Madhavan Srinivasan,
Heiko Carstens, Christian Borntraeger, Sven Schnelle, Dave Hansen,
Kiryl Shutsemau, Rick Edgecombe, Paolo Bonzini, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Haiyang Zhang, Wei Liu, Dexuan Cui,
Andy Lutomirski, Peter Zijlstra, Alexander Gordeev,
Gerald Schaefer, Vasily Gorbik, x86, dri-devel, iommu,
linaro-mm-sig, linux-arm-kernel, linux-media, linux-mm, kvmarm,
patches
cc_make_shared() now clears memory as part of the private-to-shared
transition. The subsequent memset() in alloc_cc_shared_node() therefore
clears the same allocation again.
Remove that memset() and leave __GFP_ZERO masked when memory encryption
is active. When encryption is inactive, set __GFP_ZERO so the page
allocator supplies zeroed memory.
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
mm/cc_shared.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/mm/cc_shared.c b/mm/cc_shared.c
index e60e2269adb6..7f114ea68ae4 100644
--- a/mm/cc_shared.c
+++ b/mm/cc_shared.c
@@ -120,6 +120,9 @@ int cc_make_private(void *addr, size_t size)
* allocation or free individual pages. Release the entire allocation with
* free_cc_shared().
*
+ * When memory encryption is active, making the allocation shared always
+ * zeroes it. Clear __GFP_ZERO before allocating to avoid zeroing it twice.
+ *
* Must be called from sleepable context.
* Return: The allocation's linear-map address, or NULL on failure.
*/
@@ -148,7 +151,10 @@ void *alloc_cc_shared_node(int nid, gfp_t gfp, size_t len)
*/
gfp &= ~(__GFP_HIGHMEM | __GFP_MOVABLE);
gfp |= __GFP_COMP;
- gfp &= ~__GFP_ZERO;
+ if (encrypted)
+ gfp &= ~__GFP_ZERO;
+ else
+ gfp |= __GFP_ZERO;
if (nid == NUMA_NO_NODE)
page = alloc_pages(gfp, order);
@@ -171,7 +177,6 @@ void *alloc_cc_shared_node(int nid, gfp_t gfp, size_t len)
return NULL;
}
- memset(addr, 0, size);
return addr;
}
EXPORT_SYMBOL_GPL(alloc_cc_shared_node);
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v11 13/23] irqchip/gic-v3-its: Resolve the default NUMA node explicitly
2026-12-02 9:54 [PATCH v11 00/23] coco: guest: Add a shared-granule allocator for host-shared memory Aneesh Kumar K.V (Arm)
` (11 preceding siblings ...)
2026-12-02 9:54 ` [PATCH v11 12/23] mm: Avoid zeroing CoCo shared allocations twice Aneesh Kumar K.V (Arm)
@ 2026-12-02 9:54 ` Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 14/23] irqchip/gic-v3-its: Allocate shared tables using CoCo shared memory allocator Aneesh Kumar K.V (Arm)
` (9 subsequent siblings)
22 siblings, 0 replies; 25+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-12-02 9:54 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Andrew Morton, Catalin Marinas,
Christian König, Jason Gunthorpe, Joerg Roedel, Marc Zyngier,
Marek Szyprowski, Robin Murphy, Steven Price, Sumit Semwal,
Suzuki K Poulose, Will Deacon, T.J. Mercier, Madhavan Srinivasan,
Heiko Carstens, Christian Borntraeger, Sven Schnelle, Dave Hansen,
Kiryl Shutsemau, Rick Edgecombe, Paolo Bonzini, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Haiyang Zhang, Wei Liu, Dexuan Cui,
Andy Lutomirski, Peter Zijlstra, Alexander Gordeev,
Gerald Schaefer, Vasily Gorbik, x86, dri-devel, iommu,
linaro-mm-sig, linux-arm-kernel, linux-media, linux-mm, kvmarm,
patches
alloc_pages_node() resolves NUMA_NO_NODE to numa_mem_id() internally. In
preparation for switching ITS allocations to the CoCo shared memory
allocator, resolve the default node explicitly in
its_alloc_pages_node().
The CoCo shared memory allocator interprets NUMA_NO_NODE as a request to
apply the current task's memory policy. Resolving it to numa_mem_id() in
the common ITS allocation helper preserves the existing
nearest-memory-node placement for all callers
This patch does not change the current allocation behavior.
Cc: Marc Zyngier <maz@kernel.org>
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
drivers/irqchip/irq-gic-v3-its.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index c952c069f937..ada5c30af41e 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -32,6 +32,7 @@
#include <linux/set_memory.h>
#include <linux/slab.h>
#include <linux/syscore_ops.h>
+#include <linux/topology.h>
#include <linux/irqchip.h>
#include <linux/irqchip/arm-gic-v3.h>
@@ -218,6 +219,9 @@ static struct page *its_alloc_pages_node(int node, gfp_t gfp,
struct page *page;
int ret = 0;
+ if (node == NUMA_NO_NODE)
+ node = numa_mem_id();
+
page = alloc_pages_node(node, gfp | gfp_flags_quirk, order);
if (!page)
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v11 14/23] irqchip/gic-v3-its: Allocate shared tables using CoCo shared memory allocator
2026-12-02 9:54 [PATCH v11 00/23] coco: guest: Add a shared-granule allocator for host-shared memory Aneesh Kumar K.V (Arm)
` (12 preceding siblings ...)
2026-12-02 9:54 ` [PATCH v11 13/23] irqchip/gic-v3-its: Resolve the default NUMA node explicitly Aneesh Kumar K.V (Arm)
@ 2026-12-02 9:54 ` Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 15/23] dma-contiguous: Derive shared alignment from DMA attributes Aneesh Kumar K.V (Arm)
` (8 subsequent siblings)
22 siblings, 0 replies; 25+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-12-02 9:54 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Andrew Morton, Catalin Marinas,
Christian König, Jason Gunthorpe, Joerg Roedel, Marc Zyngier,
Marek Szyprowski, Robin Murphy, Steven Price, Sumit Semwal,
Suzuki K Poulose, Will Deacon, T.J. Mercier, Madhavan Srinivasan,
Heiko Carstens, Christian Borntraeger, Sven Schnelle, Dave Hansen,
Kiryl Shutsemau, Rick Edgecombe, Paolo Bonzini, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Haiyang Zhang, Wei Liu, Dexuan Cui,
Andy Lutomirski, Peter Zijlstra, Alexander Gordeev,
Gerald Schaefer, Vasily Gorbik, x86, dri-devel, iommu,
linaro-mm-sig, linux-arm-kernel, linux-media, linux-mm, kvmarm,
patches
ITS command queues and tables are shared with the host in a confidential
computing guest.
Route allocations through alloc_cc_shared_node(), which rounds the byte
request internally and returns a naturally aligned linear-map address.
Release whole allocations with free_cc_shared(), without reconstructing
metadata.
Use addresses directly where possible and convert to struct page for the
existing property and pending table interfaces. Add the actual allocation
size returned by cc_shared_alloc_size() to the ITT pool.
Cc: Marc Zyngier <maz@kernel.org>
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
drivers/irqchip/irq-gic-v3-its.c | 142 ++++++++++++-------------------
1 file changed, 56 insertions(+), 86 deletions(-)
diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
index ada5c30af41e..cc64384109de 100644
--- a/drivers/irqchip/irq-gic-v3-its.c
+++ b/drivers/irqchip/irq-gic-v3-its.c
@@ -8,6 +8,7 @@
#include <linux/acpi_iort.h>
#include <linux/bitfield.h>
#include <linux/bitmap.h>
+#include <linux/cc_shared.h>
#include <linux/cpu.h>
#include <linux/crash_dump.h>
#include <linux/delay.h>
@@ -19,7 +20,6 @@
#include <linux/irqdomain.h>
#include <linux/list.h>
#include <linux/log2.h>
-#include <linux/mem_encrypt.h>
#include <linux/memblock.h>
#include <linux/mm.h>
#include <linux/msi.h>
@@ -29,7 +29,6 @@
#include <linux/of_pci.h>
#include <linux/of_platform.h>
#include <linux/percpu.h>
-#include <linux/set_memory.h>
#include <linux/slab.h>
#include <linux/syscore_ops.h>
#include <linux/topology.h>
@@ -213,47 +212,18 @@ static DEFINE_IDA(its_vpeid_ida);
static gfp_t gfp_flags_quirk;
-static struct page *its_alloc_pages_node(int node, gfp_t gfp,
- unsigned int order)
+static void *its_alloc_node(int node, gfp_t gfp, unsigned int order)
{
- struct page *page;
- int ret = 0;
-
if (node == NUMA_NO_NODE)
node = numa_mem_id();
- page = alloc_pages_node(node, gfp | gfp_flags_quirk, order);
-
- if (!page)
- return NULL;
-
- ret = set_memory_decrypted((unsigned long)page_address(page),
- 1 << order);
- /*
- * If set_memory_decrypted() fails then we don't know what state the
- * page is in, so we can't free it. Instead we leak it.
- * set_memory_decrypted() will already have WARNed.
- */
- if (ret)
- return NULL;
-
- return page;
-}
-
-static struct page *its_alloc_pages(gfp_t gfp, unsigned int order)
-{
- return its_alloc_pages_node(NUMA_NO_NODE, gfp, order);
+ return alloc_cc_shared_node(node, gfp | gfp_flags_quirk,
+ PAGE_SIZE << order);
}
-static void its_free_pages(void *addr, unsigned int order)
+static void *its_alloc(gfp_t gfp, unsigned int order)
{
- /*
- * If the memory cannot be encrypted again then we must leak the pages.
- * set_memory_encrypted() will already have WARNed.
- */
- if (set_memory_encrypted((unsigned long)addr, 1 << order))
- return;
- free_pages((unsigned long)addr, order);
+ return its_alloc_node(NUMA_NO_NODE, gfp, order);
}
static struct gen_pool *itt_pool;
@@ -261,24 +231,27 @@ static struct gen_pool *itt_pool;
static void *itt_alloc_pool(int node, int size)
{
unsigned long addr;
- struct page *page;
+ void *table_base;
- if (size >= PAGE_SIZE) {
- page = its_alloc_pages_node(node, GFP_KERNEL | __GFP_ZERO, get_order(size));
-
- return page ? page_address(page) : NULL;
- }
+ if (size >= PAGE_SIZE)
+ return its_alloc_node(node, GFP_KERNEL | __GFP_ZERO, get_order(size));
do {
addr = gen_pool_alloc(itt_pool, size);
if (addr)
break;
- page = its_alloc_pages_node(node, GFP_KERNEL | __GFP_ZERO, 0);
- if (!page)
+ table_base = its_alloc_node(node, GFP_KERNEL | __GFP_ZERO, 0);
+ if (!table_base)
break;
- gen_pool_add(itt_pool, (unsigned long)page_address(page), PAGE_SIZE, node);
+ /*
+ * Sharing-granule rounding may allocate more than PAGE_SIZE.
+ * Add the entire shared allocation to the pool so the extra
+ * space can be used for other ITTs.
+ */
+ gen_pool_add(itt_pool, (unsigned long)table_base,
+ cc_shared_alloc_size(table_base), node);
} while (!addr);
return (void *)addr;
@@ -290,7 +263,7 @@ static void itt_free_pool(void *addr, int size)
return;
if (size >= PAGE_SIZE) {
- its_free_pages(addr, get_order(size));
+ free_cc_shared(addr);
return;
}
@@ -2270,21 +2243,20 @@ static void gic_reset_prop_table(void *va)
static struct page *its_allocate_prop_table(gfp_t gfp_flags)
{
- struct page *prop_page;
+ void *addr;
- prop_page = its_alloc_pages(gfp_flags,
- get_order(LPI_PROPBASE_SZ));
- if (!prop_page)
+ addr = its_alloc(gfp_flags, get_order(LPI_PROPBASE_SZ));
+ if (!addr)
return NULL;
- gic_reset_prop_table(page_address(prop_page));
+ gic_reset_prop_table(addr);
- return prop_page;
+ return virt_to_page(addr);
}
static void its_free_prop_table(struct page *prop_page)
{
- its_free_pages(page_address(prop_page), get_order(LPI_PROPBASE_SZ));
+ free_cc_shared(page_address(prop_page));
}
static bool gic_check_reserved_range(phys_addr_t addr, unsigned long size)
@@ -2393,7 +2365,6 @@ static int its_setup_baser(struct its_node *its, struct its_baser *baser,
u64 type = GITS_BASER_TYPE(val);
u64 baser_phys, tmp;
u32 alloc_pages, psz;
- struct page *page;
void *base;
psz = baser->psz;
@@ -2406,11 +2377,10 @@ static int its_setup_baser(struct its_node *its, struct its_baser *baser,
order = get_order(GITS_BASER_PAGES_MAX * psz);
}
- page = its_alloc_pages_node(its->numa_node, GFP_KERNEL | __GFP_ZERO, order);
- if (!page)
+ base = its_alloc_node(its->numa_node, GFP_KERNEL | __GFP_ZERO, order);
+ if (!base)
return -ENOMEM;
- base = (void *)page_address(page);
baser_phys = virt_to_phys(base);
/* Check if the physical address of the memory is above 48bits */
@@ -2419,7 +2389,7 @@ static int its_setup_baser(struct its_node *its, struct its_baser *baser,
/* 52bit PA is supported only when PageSize=64K */
if (psz != SZ_64K) {
pr_err("ITS: no 52bit PA support when psz=%d\n", psz);
- its_free_pages(base, order);
+ free_cc_shared(base);
return -ENXIO;
}
@@ -2475,7 +2445,7 @@ static int its_setup_baser(struct its_node *its, struct its_baser *baser,
pr_err("ITS@%pa: %s doesn't stick: %llx %llx\n",
&its->phys_base, its_base_type_string[type],
val, tmp);
- its_free_pages(base, order);
+ free_cc_shared(base);
return -ENXIO;
}
@@ -2612,7 +2582,7 @@ static void its_free_tables(struct its_node *its)
for (i = 0; i < GITS_BASER_NR_REGS; i++) {
if (its->tables[i].base) {
if (!its->tables[i].shared)
- its_free_pages(its->tables[i].base, its->tables[i].order);
+ free_cc_shared(its->tables[i].base);
its->tables[i].base = NULL;
}
}
@@ -2837,7 +2807,7 @@ static bool allocate_vpe_l2_table(int cpu, u32 id)
void __iomem *base = gic_data_rdist_cpu(cpu)->rd_base;
unsigned int psz, esz, idx, npg, gpsz;
u64 val;
- struct page *page;
+ void *table_base;
__le64 *table;
if (!gic_rdists->has_rvpeid)
@@ -2881,15 +2851,15 @@ static bool allocate_vpe_l2_table(int cpu, u32 id)
/* Allocate memory for 2nd level table */
if (!table[idx]) {
- page = its_alloc_pages(GFP_KERNEL | __GFP_ZERO, get_order(psz));
- if (!page)
+ table_base = its_alloc(GFP_KERNEL | __GFP_ZERO, get_order(psz));
+ if (!table_base)
return false;
/* Flush Lvl2 table to PoC if hw doesn't support coherency */
if (!(val & GICR_VPROPBASER_SHAREABILITY_MASK))
- gic_flush_dcache_to_poc(page_address(page), psz);
+ gic_flush_dcache_to_poc(table_base, psz);
- table[idx] = cpu_to_le64(page_to_phys(page) | GITS_BASER_VALID);
+ table[idx] = cpu_to_le64(virt_to_phys(table_base) | GITS_BASER_VALID);
/* Flush Lvl1 entry to PoC if hw doesn't support coherency */
if (!(val & GICR_VPROPBASER_SHAREABILITY_MASK))
@@ -2908,7 +2878,7 @@ static int allocate_vpe_l1_table(void)
u64 val, gpsz, npg, pa;
unsigned int psz = SZ_64K;
unsigned int np, epp, esz;
- struct page *page;
+ void *table_base;
if (!gic_rdists->has_rvpeid)
return 0;
@@ -3000,12 +2970,12 @@ static int allocate_vpe_l1_table(void)
pr_debug("np = %d, npg = %lld, psz = %d, epp = %d, esz = %d\n",
np, npg, psz, epp, esz);
- page = its_alloc_pages(GFP_ATOMIC | __GFP_ZERO, get_order(np * PAGE_SIZE));
- if (!page)
+ table_base = its_alloc(GFP_ATOMIC | __GFP_ZERO, get_order(np * PAGE_SIZE));
+ if (!table_base)
return -ENOMEM;
- gic_data_rdist()->vpe_l1_base = page_address(page);
- pa = virt_to_phys(page_address(page));
+ gic_data_rdist()->vpe_l1_base = table_base;
+ pa = virt_to_phys(table_base);
WARN_ON(!IS_ALIGNED(pa, psz));
val |= FIELD_PREP(GICR_VPROPBASER_4_1_ADDR, pa >> 12);
@@ -3043,21 +3013,21 @@ static int its_alloc_collections(struct its_node *its)
static struct page *its_allocate_pending_table(gfp_t gfp_flags)
{
- struct page *pend_page;
+ void *addr;
- pend_page = its_alloc_pages(gfp_flags | __GFP_ZERO, get_order(LPI_PENDBASE_SZ));
- if (!pend_page)
+ addr = its_alloc(gfp_flags | __GFP_ZERO, get_order(LPI_PENDBASE_SZ));
+ if (!addr)
return NULL;
/* Make sure the GIC will observe the zero-ed page */
- gic_flush_dcache_to_poc(page_address(pend_page), LPI_PENDBASE_SZ);
+ gic_flush_dcache_to_poc(addr, LPI_PENDBASE_SZ);
- return pend_page;
+ return virt_to_page(addr);
}
static void its_free_pending_table(struct page *pt)
{
- its_free_pages(page_address(pt), get_order(LPI_PENDBASE_SZ));
+ free_cc_shared(page_address(pt));
}
/*
@@ -3372,7 +3342,7 @@ static struct its_baser *its_get_baser(struct its_node *its, u32 type)
static bool its_alloc_table_entry(struct its_node *its,
struct its_baser *baser, u32 id)
{
- struct page *page;
+ void *table_base;
u32 esz, idx;
__le64 *table;
@@ -3390,16 +3360,16 @@ static bool its_alloc_table_entry(struct its_node *its,
/* Allocate memory for 2nd level table */
if (!table[idx]) {
- page = its_alloc_pages_node(its->numa_node, GFP_KERNEL | __GFP_ZERO,
+ table_base = its_alloc_node(its->numa_node, GFP_KERNEL | __GFP_ZERO,
get_order(baser->psz));
- if (!page)
+ if (!table_base)
return false;
/* Flush Lvl2 table to PoC if hw doesn't support coherency */
if (!(baser->val & GITS_BASER_SHAREABILITY_MASK))
- gic_flush_dcache_to_poc(page_address(page), baser->psz);
+ gic_flush_dcache_to_poc(table_base, baser->psz);
- table[idx] = cpu_to_le64(page_to_phys(page) | GITS_BASER_VALID);
+ table[idx] = cpu_to_le64(virt_to_phys(table_base) | GITS_BASER_VALID);
/* Flush Lvl1 entry to PoC if hw doesn't support coherency */
if (!(baser->val & GITS_BASER_SHAREABILITY_MASK))
@@ -5257,7 +5227,7 @@ static int __init its_compute_its_list_map(struct its_node *its)
static int __init its_probe_one(struct its_node *its)
{
u64 baser, tmp;
- struct page *page;
+ void *table_base;
u32 ctlr;
int err;
@@ -5293,14 +5263,14 @@ static int __init its_probe_one(struct its_node *its)
}
}
- page = its_alloc_pages_node(its->numa_node,
+ table_base = its_alloc_node(its->numa_node,
GFP_KERNEL | __GFP_ZERO,
get_order(ITS_CMD_QUEUE_SZ));
- if (!page) {
+ if (!table_base) {
err = -ENOMEM;
goto out_unmap_sgir;
}
- its->cmd_base = (void *)page_address(page);
+ its->cmd_base = table_base;
its->cmd_write = its->cmd_base;
err = its_alloc_tables(its);
@@ -5363,7 +5333,7 @@ static int __init its_probe_one(struct its_node *its)
out_free_tables:
its_free_tables(its);
out_free_cmd:
- its_free_pages(its->cmd_base, get_order(ITS_CMD_QUEUE_SZ));
+ free_cc_shared(its->cmd_base);
out_unmap_sgir:
if (its->sgir_base)
iounmap(its->sgir_base);
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v11 15/23] dma-contiguous: Derive shared alignment from DMA attributes
2026-12-02 9:54 [PATCH v11 00/23] coco: guest: Add a shared-granule allocator for host-shared memory Aneesh Kumar K.V (Arm)
` (13 preceding siblings ...)
2026-12-02 9:54 ` [PATCH v11 14/23] irqchip/gic-v3-its: Allocate shared tables using CoCo shared memory allocator Aneesh Kumar K.V (Arm)
@ 2026-12-02 9:54 ` Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 16/23] dma-pool: Align shared atomic pools to the CoCo sharing granule Aneesh Kumar K.V (Arm)
` (7 subsequent siblings)
22 siblings, 0 replies; 25+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-12-02 9:54 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Andrew Morton, Catalin Marinas,
Christian König, Jason Gunthorpe, Joerg Roedel, Marc Zyngier,
Marek Szyprowski, Robin Murphy, Steven Price, Sumit Semwal,
Suzuki K Poulose, Will Deacon, T.J. Mercier, Madhavan Srinivasan,
Heiko Carstens, Christian Borntraeger, Sven Schnelle, Dave Hansen,
Kiryl Shutsemau, Rick Edgecombe, Paolo Bonzini, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Haiyang Zhang, Wei Liu, Dexuan Cui,
Andy Lutomirski, Peter Zijlstra, Alexander Gordeev,
Gerald Schaefer, Vasily Gorbik, x86, dri-devel, iommu,
linaro-mm-sig, linux-arm-kernel, linux-media, linux-mm, kvmarm,
patches
Confidential-computing shared DMA allocations require CMA backing memory
to be aligned to the architecture shared-memory granule. Passing explicit
alignment orders through the DMA allocation stack exposes this derived
constraint to callers and requires separate preferred and mandatory values.
The DMA core already records whether an allocation needs shared backing in
__DMA_ATTR_ALLOC_CC_SHARED. Pass allocation attributes to the DMA-contiguous
entry points and derive the mandatory alignment there before calling CMA.
Preserve the existing alignment clamping for ordinary allocations, while
rejecting shared allocations whose granule exceeds CONFIG_CMA_ALIGNMENT so
callers can fall back to the page allocator.
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
arch/arm/mm/dma-mapping.c | 5 ++--
drivers/iommu/dma-iommu.c | 2 +-
include/linux/dma-map-ops.h | 9 +++----
kernel/dma/contiguous.c | 47 ++++++++++++++++++++++++++++---------
kernel/dma/direct.c | 2 +-
kernel/dma/ops_helpers.c | 2 +-
kernel/dma/pool.c | 2 +-
kernel/kexec_file.c | 3 ++-
8 files changed, 50 insertions(+), 22 deletions(-)
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index fb2eb0ed7bb8..22888880b832 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -398,7 +398,8 @@ static void *__alloc_from_contiguous(struct device *dev, size_t size,
struct page *page;
void *ptr = NULL;
- page = dma_alloc_from_contiguous(dev, count, order, gfp & __GFP_NOWARN);
+ page = dma_alloc_from_contiguous(dev, count, order, 0,
+ gfp & __GFP_NOWARN);
if (!page)
return NULL;
@@ -866,7 +867,7 @@ static struct page **__iommu_alloc_buffer(struct device *dev, size_t size,
unsigned long order = get_order(size);
struct page *page;
- page = dma_alloc_from_contiguous(dev, count, order,
+ page = dma_alloc_from_contiguous(dev, count, order, 0,
gfp & __GFP_NOWARN);
if (!page)
goto error;
diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index 78742aeba932..2d2781910740 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -1646,7 +1646,7 @@ static void *iommu_dma_alloc_pages(struct device *dev, size_t size,
struct page *page = NULL;
void *cpu_addr;
- page = dma_alloc_contiguous(dev, alloc_size, gfp);
+ page = dma_alloc_contiguous(dev, alloc_size, gfp, 0);
if (!page) {
cpu_addr = alloc_pages_exact_nid(node, alloc_size, gfp);
if (!cpu_addr)
diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h
index afaf2c12189b..7a83942a10f3 100644
--- a/include/linux/dma-map-ops.h
+++ b/include/linux/dma-map-ops.h
@@ -99,10 +99,11 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base,
phys_addr_t limit, struct cma **res_cma, bool fixed);
struct page *dma_alloc_from_contiguous(struct device *dev, size_t count,
- unsigned int order, bool no_warn);
+ unsigned int order, unsigned long attrs, bool no_warn);
bool dma_release_from_contiguous(struct device *dev, struct page *pages,
int count);
-struct page *dma_alloc_contiguous(struct device *dev, size_t size, gfp_t gfp);
+struct page *dma_alloc_contiguous(struct device *dev, size_t size,
+ gfp_t gfp, unsigned long attrs);
void dma_free_contiguous(struct device *dev, struct page *page, size_t size);
void dma_contiguous_early_fixup(phys_addr_t base, unsigned long size);
@@ -125,7 +126,7 @@ static inline int dma_contiguous_reserve_area(phys_addr_t size,
return -ENOSYS;
}
static inline struct page *dma_alloc_from_contiguous(struct device *dev,
- size_t count, unsigned int order, bool no_warn)
+ size_t count, unsigned int order, unsigned long attrs, bool no_warn)
{
return NULL;
}
@@ -136,7 +137,7 @@ static inline bool dma_release_from_contiguous(struct device *dev,
}
/* Use fallback alloc() and free() when CONFIG_DMA_CMA=n */
static inline struct page *dma_alloc_contiguous(struct device *dev, size_t size,
- gfp_t gfp)
+ gfp_t gfp, unsigned long attrs)
{
return NULL;
}
diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c
index 90937dc7c627..cb777c71ee38 100644
--- a/kernel/dma/contiguous.c
+++ b/kernel/dma/contiguous.c
@@ -39,6 +39,7 @@
#include <asm/page.h>
+#include <linux/cc_shared.h>
#include <linux/memblock.h>
#include <linux/err.h>
#include <linux/sizes.h>
@@ -357,19 +358,31 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base,
* dma_alloc_from_contiguous() - allocate pages from contiguous area
* @dev: Pointer to device for which the allocation is performed.
* @count: Requested number of pages.
- * @align: Requested alignment of pages (in PAGE_SIZE order).
+ * @align: Preferred alignment of pages (in PAGE_SIZE order).
+ * @attrs: DMA allocation attributes.
* @no_warn: Avoid printing message about failed allocation.
*
* This function allocates memory buffer for specified device. It uses
* device specific contiguous memory area if available or the default
* global one. Requires architecture specific dev_get_cma_area() helper
* function.
+ *
+ * The preferred alignment is capped at CONFIG_CMA_ALIGNMENT. The internal
+ * shared-allocation attribute requires at least the architecture shared
+ * granule alignment and fails if that exceeds the CMA alignment limit.
*/
struct page *dma_alloc_from_contiguous(struct device *dev, size_t count,
- unsigned int align, bool no_warn)
+ unsigned int align, unsigned long attrs, bool no_warn)
{
- if (align > CONFIG_CMA_ALIGNMENT)
- align = CONFIG_CMA_ALIGNMENT;
+ unsigned int required_align = 0;
+
+ if (attrs & __DMA_ATTR_ALLOC_CC_SHARED)
+ required_align = get_order(cc_shared_granule_size());
+
+ if (required_align > CONFIG_CMA_ALIGNMENT)
+ return NULL;
+
+ align = min(max(align, required_align), CONFIG_CMA_ALIGNMENT);
return cma_alloc(dev_get_cma_area(dev), count, align, no_warn);
}
@@ -390,10 +403,9 @@ bool dma_release_from_contiguous(struct device *dev, struct page *pages,
return cma_release(dev_get_cma_area(dev), pages, count);
}
-static struct page *cma_alloc_aligned(struct cma *cma, size_t size, gfp_t gfp)
+static struct page *cma_alloc_aligned(struct cma *cma, size_t size, gfp_t gfp,
+ unsigned int align)
{
- unsigned int align = min(get_order(size), CONFIG_CMA_ALIGNMENT);
-
return cma_alloc(cma, size >> PAGE_SHIFT, align, gfp & __GFP_NOWARN);
}
@@ -402,6 +414,7 @@ static struct page *cma_alloc_aligned(struct cma *cma, size_t size, gfp_t gfp)
* @dev: Pointer to device for which the allocation is performed.
* @size: Requested allocation size.
* @gfp: Allocation flags.
+ * @attrs: DMA allocation attributes.
*
* tries to use device specific contiguous memory area if available, or it
* tries to use per-numa cma, if the allocation fails, it will fallback to
@@ -412,8 +425,11 @@ static struct page *cma_alloc_aligned(struct cma *cma, size_t size, gfp_t gfp)
* there is no need to waste CMA pages for that kind; it also helps reduce
* fragmentations.
*/
-struct page *dma_alloc_contiguous(struct device *dev, size_t size, gfp_t gfp)
+struct page *dma_alloc_contiguous(struct device *dev, size_t size,
+ gfp_t gfp, unsigned long attrs)
{
+ unsigned int required_align = 0;
+ unsigned int align = get_order(size);
#ifdef CONFIG_DMA_NUMA_CMA
int nid = dev_to_node(dev);
#endif
@@ -421,8 +437,17 @@ struct page *dma_alloc_contiguous(struct device *dev, size_t size, gfp_t gfp)
/* CMA can be used only in the context which permits sleeping */
if (!gfpflags_allow_blocking(gfp))
return NULL;
+
+ if (attrs & __DMA_ATTR_ALLOC_CC_SHARED)
+ required_align = get_order(cc_shared_granule_size());
+
+ if (required_align > CONFIG_CMA_ALIGNMENT)
+ return NULL;
+
+ align = min(max(align, required_align), CONFIG_CMA_ALIGNMENT);
if (dev->cma_area)
- return cma_alloc_aligned(dev->cma_area, size, gfp);
+ return cma_alloc_aligned(dev->cma_area, size, gfp, align);
+
if (size <= PAGE_SIZE)
return NULL;
@@ -431,7 +456,7 @@ struct page *dma_alloc_contiguous(struct device *dev, size_t size, gfp_t gfp)
struct cma *cma = dma_contiguous_numa_area[nid];
struct page *page;
if (cma) {
- page = cma_alloc_aligned(cma, size, gfp);
+ page = cma_alloc_aligned(cma, size, gfp, align);
if (page)
return page;
}
@@ -440,7 +465,7 @@ struct page *dma_alloc_contiguous(struct device *dev, size_t size, gfp_t gfp)
if (!dma_contiguous_default_area)
return NULL;
- return cma_alloc_aligned(dma_contiguous_default_area, size, gfp);
+ return cma_alloc_aligned(dma_contiguous_default_area, size, gfp, align);
}
/**
diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
index 4d05817d6245..77ada1f92ca6 100644
--- a/kernel/dma/direct.c
+++ b/kernel/dma/direct.c
@@ -125,7 +125,7 @@ static struct page *__dma_direct_alloc_pages(struct device *dev, size_t size,
WARN_ON_ONCE(!PAGE_ALIGNED(size));
gfp |= dma_direct_optimal_gfp_mask(dev, &phys_limit);
- page = dma_alloc_contiguous(dev, size, gfp);
+ page = dma_alloc_contiguous(dev, size, gfp, 0);
if (page) {
if (dma_coherent_ok(dev, page_to_phys(page), size) &&
(allow_highmem || !PageHighMem(page)))
diff --git a/kernel/dma/ops_helpers.c b/kernel/dma/ops_helpers.c
index 5cdf3f60cf47..11453e5ee0d3 100644
--- a/kernel/dma/ops_helpers.c
+++ b/kernel/dma/ops_helpers.c
@@ -66,7 +66,7 @@ struct page *dma_common_alloc_pages(struct device *dev, size_t size,
struct page *page;
phys_addr_t phys;
- page = dma_alloc_contiguous(dev, size, gfp);
+ page = dma_alloc_contiguous(dev, size, gfp, 0);
if (!page) {
void *va = alloc_pages_exact_nid(dev_to_node(dev), size, gfp);
diff --git a/kernel/dma/pool.c b/kernel/dma/pool.c
index 5e8cf12e8222..088149b99103 100644
--- a/kernel/dma/pool.c
+++ b/kernel/dma/pool.c
@@ -99,7 +99,7 @@ static int atomic_pool_expand(struct dma_gen_pool *dma_pool, size_t pool_size,
pool_size = 1 << (PAGE_SHIFT + order);
if (cma_in_zone(gfp))
page = dma_alloc_from_contiguous(NULL, 1 << order,
- order, false);
+ order, 0, false);
if (!page)
page = alloc_pages(gfp | __GFP_NOWARN, order);
} while (!page && order-- > 0);
diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c
index b668ce8d68ee..5bcba818f046 100644
--- a/kernel/kexec_file.c
+++ b/kernel/kexec_file.c
@@ -702,7 +702,8 @@ static int kexec_alloc_contig(struct kexec_buf *kbuf)
if (kbuf->image->type == KEXEC_TYPE_CRASH)
return -EPERM;
- p = dma_alloc_from_contiguous(NULL, nr_pages, get_order(kbuf->buf_align), true);
+ p = dma_alloc_from_contiguous(NULL, nr_pages,
+ get_order(kbuf->buf_align), 0, true);
if (!p)
return -ENOMEM;
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v11 16/23] dma-pool: Align shared atomic pools to the CoCo sharing granule
2026-12-02 9:54 [PATCH v11 00/23] coco: guest: Add a shared-granule allocator for host-shared memory Aneesh Kumar K.V (Arm)
` (14 preceding siblings ...)
2026-12-02 9:54 ` [PATCH v11 15/23] dma-contiguous: Derive shared alignment from DMA attributes Aneesh Kumar K.V (Arm)
@ 2026-12-02 9:54 ` Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 17/23] dma-direct: Align CoCo shared DMA allocations to the shared granule size Aneesh Kumar K.V (Arm)
` (6 subsequent siblings)
22 siblings, 0 replies; 25+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-12-02 9:54 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Andrew Morton, Catalin Marinas,
Christian König, Jason Gunthorpe, Joerg Roedel, Marc Zyngier,
Marek Szyprowski, Robin Murphy, Steven Price, Sumit Semwal,
Suzuki K Poulose, Will Deacon, T.J. Mercier, Madhavan Srinivasan,
Heiko Carstens, Christian Borntraeger, Sven Schnelle, Dave Hansen,
Kiryl Shutsemau, Rick Edgecombe, Paolo Bonzini, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Haiyang Zhang, Wei Liu, Dexuan Cui,
Andy Lutomirski, Peter Zijlstra, Alexander Gordeev,
Gerald Schaefer, Vasily Gorbik, x86, dri-devel, iommu,
linaro-mm-sig, linux-arm-kernel, linux-media, linux-mm, kvmarm,
patches
Atomic DMA allocations cannot perform a potentially sleeping
private/shared state transition at allocation time. The atomic DMA pools
avoid this by transitioning their backing allocations in a sleepable
context and suballocating memory that is already shared.
Architectures may require these transitions to use a shared granule size
larger than PAGE_SIZE. The existing fallback loop can reduce the backing
allocation below the order required by that size, producing a range that
cannot be safely transitioned.
For pools marked cc_shared, round the requested pool size up to a multiple
of the shared granule size and prevent allocation fallback below the order
required by that size. Pass __DMA_ATTR_ALLOC_CC_SHARED to
dma_alloc_from_contiguous() so it enforces the mandatory alignment. If CMA
cannot satisfy it, fall back to the buddy allocator. Non-shared pools pass
zero attributes and retain the existing CMA alignment policy.
Use the cc_make_shared() and cc_make_private() helpers to transition the
backing allocation and validate its address and size.
Individual atomic allocations may remain smaller than the shared granule
size because the backing allocation remains owned by the pool and in the
shared state.
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
kernel/dma/pool.c | 29 +++++++++++++++++++++++------
1 file changed, 23 insertions(+), 6 deletions(-)
diff --git a/kernel/dma/pool.c b/kernel/dma/pool.c
index 088149b99103..cd467ee64823 100644
--- a/kernel/dma/pool.c
+++ b/kernel/dma/pool.c
@@ -4,12 +4,12 @@
* Copyright (C) 2020 Google LLC
*/
#include <linux/cma.h>
+#include <linux/cc_shared.h>
#include <linux/debugfs.h>
#include <linux/dma-map-ops.h>
#include <linux/dma-direct.h>
#include <linux/init.h>
#include <linux/genalloc.h>
-#include <linux/set_memory.h>
#include <linux/slab.h>
#include <linux/workqueue.h>
#include <linux/cc_platform.h>
@@ -85,6 +85,9 @@ static bool cma_in_zone(gfp_t gfp)
static int atomic_pool_expand(struct dma_gen_pool *dma_pool, size_t pool_size,
gfp_t gfp)
{
+ size_t shared_size;
+ unsigned long attrs = 0;
+ unsigned int min_order = 0;
unsigned int order;
struct page *page = NULL;
bool leak_pages = false;
@@ -92,6 +95,21 @@ static int atomic_pool_expand(struct dma_gen_pool *dma_pool, size_t pool_size,
int ret = -ENOMEM;
pgprot_t prot __maybe_unused;
+ if (dma_pool->cc_shared) {
+ int err;
+
+ err = cc_shared_round_size(pool_size, &shared_size);
+ if (err)
+ return err;
+
+ pool_size = shared_size;
+ min_order = get_order(cc_shared_granule_size());
+ if (min_order > MAX_PAGE_ORDER)
+ return -E2BIG;
+
+ attrs = __DMA_ATTR_ALLOC_CC_SHARED;
+ }
+
/* Cannot allocate larger than MAX_PAGE_ORDER */
order = min(get_order(pool_size), MAX_PAGE_ORDER);
@@ -99,10 +117,10 @@ static int atomic_pool_expand(struct dma_gen_pool *dma_pool, size_t pool_size,
pool_size = 1 << (PAGE_SHIFT + order);
if (cma_in_zone(gfp))
page = dma_alloc_from_contiguous(NULL, 1 << order,
- order, 0, false);
+ order, attrs, false);
if (!page)
page = alloc_pages(gfp | __GFP_NOWARN, order);
- } while (!page && order-- > 0);
+ } while (!page && order-- > min_order);
if (!page)
goto out;
@@ -111,8 +129,7 @@ static int atomic_pool_expand(struct dma_gen_pool *dma_pool, size_t pool_size,
* shrink so no re-encryption occurs in dma_direct_free().
*/
if (dma_pool->cc_shared) {
- ret = set_memory_decrypted((unsigned long)page_to_virt(page),
- 1 << order);
+ ret = cc_make_shared(page_to_virt(page), pool_size);
/*
* On failure the encryption state of the pages is unknown,
* so they must not be returned to the page allocator or CMA.
@@ -153,7 +170,7 @@ static int atomic_pool_expand(struct dma_gen_pool *dma_pool, size_t pool_size,
encrypt_pages:
#endif
if (dma_pool->cc_shared &&
- set_memory_encrypted((unsigned long)page_to_virt(page), 1 << order))
+ cc_make_private(page_to_virt(page), pool_size))
leak_pages = true;
if (!leak_pages &&
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v11 17/23] dma-direct: Align CoCo shared DMA allocations to the shared granule size
2026-12-02 9:54 [PATCH v11 00/23] coco: guest: Add a shared-granule allocator for host-shared memory Aneesh Kumar K.V (Arm)
` (15 preceding siblings ...)
2026-12-02 9:54 ` [PATCH v11 16/23] dma-pool: Align shared atomic pools to the CoCo sharing granule Aneesh Kumar K.V (Arm)
@ 2026-12-02 9:54 ` Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 18/23] swiotlb: Align shared IO TLB pools " Aneesh Kumar K.V (Arm)
` (5 subsequent siblings)
22 siblings, 0 replies; 25+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-12-02 9:54 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Andrew Morton, Catalin Marinas,
Christian König, Jason Gunthorpe, Joerg Roedel, Marc Zyngier,
Marek Szyprowski, Robin Murphy, Steven Price, Sumit Semwal,
Suzuki K Poulose, Will Deacon, T.J. Mercier, Madhavan Srinivasan,
Heiko Carstens, Christian Borntraeger, Sven Schnelle, Dave Hansen,
Kiryl Shutsemau, Rick Edgecombe, Paolo Bonzini, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Haiyang Zhang, Wei Liu, Dexuan Cui,
Andy Lutomirski, Peter Zijlstra, Alexander Gordeev,
Gerald Schaefer, Vasily Gorbik, x86, dri-devel, iommu,
linaro-mm-sig, linux-arm-kernel, linux-media, linux-mm, kvmarm,
patches
Use the common CoCo shared-memory helpers for allocations backed
directly by CMA or the page allocator. Round the backing allocation to a
whole shared granule and pass the resolved shared-allocation attribute
through the DMA contiguous allocator so it can enforce the mandatory
alignment.
Repeat granule rounding before freeing direct allocations so the
transition back to private memory and dma_free_contiguous() cover
exactly the range acquired by the allocation path.
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
kernel/dma/direct.c | 55 +++++++++++++++++++++++++++++++++++----------
1 file changed, 43 insertions(+), 12 deletions(-)
diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
index 77ada1f92ca6..c877df9873f2 100644
--- a/kernel/dma/direct.c
+++ b/kernel/dma/direct.c
@@ -11,10 +11,10 @@
#include <linux/scatterlist.h>
#include <linux/pfn.h>
#include <linux/vmalloc.h>
-#include <linux/set_memory.h>
#include <linux/slab.h>
#include <linux/pci-p2pdma.h>
#include <linux/cc_platform.h>
+#include <linux/cc_shared.h>
#include "direct.h"
@@ -85,7 +85,7 @@ static int dma_set_decrypted(struct device *dev, void *vaddr, size_t size)
{
int ret;
- ret = set_memory_decrypted((unsigned long)vaddr, PFN_UP(size));
+ ret = cc_make_shared(vaddr, size);
if (ret)
pr_warn_ratelimited("leaking DMA memory that can't be decrypted\n");
return ret;
@@ -95,7 +95,7 @@ static int dma_set_encrypted(struct device *dev, void *vaddr, size_t size)
{
int ret;
- ret = set_memory_encrypted((unsigned long)vaddr, PFN_UP(size));
+ ret = cc_make_private(vaddr, size);
if (ret)
pr_warn_ratelimited("leaking DMA memory that can't be re-encrypted\n");
return ret;
@@ -115,7 +115,7 @@ static struct page *dma_direct_alloc_swiotlb(struct device *dev, size_t size,
}
static struct page *__dma_direct_alloc_pages(struct device *dev, size_t size,
- gfp_t gfp, bool allow_highmem)
+ gfp_t gfp, bool allow_highmem, unsigned long attrs)
{
int node = dev_to_node(dev);
struct page *page;
@@ -125,7 +125,7 @@ static struct page *__dma_direct_alloc_pages(struct device *dev, size_t size,
WARN_ON_ONCE(!PAGE_ALIGNED(size));
gfp |= dma_direct_optimal_gfp_mask(dev, &phys_limit);
- page = dma_alloc_contiguous(dev, size, gfp, 0);
+ page = dma_alloc_contiguous(dev, size, gfp, attrs);
if (page) {
if (dma_coherent_ok(dev, page_to_phys(page), size) &&
(allow_highmem || !PageHighMem(page)))
@@ -202,7 +202,7 @@ static void *dma_direct_alloc_no_mapping(struct device *dev, size_t size,
{
struct page *page;
- page = __dma_direct_alloc_pages(dev, size, gfp & ~__GFP_ZERO, true);
+ page = __dma_direct_alloc_pages(dev, size, gfp & ~__GFP_ZERO, true, 0);
if (!page)
return NULL;
@@ -223,6 +223,7 @@ void *dma_direct_alloc(struct device *dev, size_t size,
bool remap = false, set_uncached = false;
bool mark_mem_decrypt = false;
bool allow_highmem = true;
+ size_t shared_size;
struct page *page;
void *cpu_addr;
@@ -302,8 +303,16 @@ void *dma_direct_alloc(struct device *dev, size_t size,
return NULL;
}
+ if (mark_mem_decrypt) {
+ if (cc_shared_round_size(size, &shared_size))
+ return NULL;
+
+ size = shared_size;
+ }
+
/* we always manually zero the memory once we are done */
- page = __dma_direct_alloc_pages(dev, size, gfp & ~__GFP_ZERO, allow_highmem);
+ page = __dma_direct_alloc_pages(dev, size, gfp & ~__GFP_ZERO,
+ allow_highmem, attrs);
if (!page)
return NULL;
@@ -322,7 +331,7 @@ void *dma_direct_alloc(struct device *dev, size_t size,
void *lm_addr;
lm_addr = page_address(page);
- if (set_memory_decrypted((unsigned long)lm_addr, PFN_UP(size)))
+ if (dma_set_decrypted(dev, lm_addr, size))
goto out_leak_pages;
}
@@ -381,6 +390,7 @@ void dma_direct_free(struct device *dev, size_t size,
phys_addr_t phys;
bool mark_mem_encrypted = false;
struct io_tlb_pool *swiotlb_pool;
+ size_t shared_size;
unsigned int page_order = get_order(size);
/*
@@ -424,6 +434,13 @@ void dma_direct_free(struct device *dev, size_t size,
/* Swiotlb doesn't need a page attribute update on free */
mark_mem_encrypted = false;
+ if (mark_mem_encrypted) {
+ if (WARN_ON_ONCE(cc_shared_round_size(size, &shared_size)))
+ return;
+
+ size = shared_size;
+ }
+
if (is_vmalloc_addr(cpu_addr)) {
vunmap(cpu_addr);
} else {
@@ -435,10 +452,8 @@ void dma_direct_free(struct device *dev, size_t size,
void *lm_addr;
lm_addr = phys_to_virt(phys);
- if (set_memory_encrypted((unsigned long)lm_addr, PFN_UP(size))) {
- pr_warn_ratelimited("leaking DMA memory that can't be re-encrypted\n");
+ if (dma_set_encrypted(dev, lm_addr, size))
return;
- }
}
if (swiotlb_pool)
@@ -451,6 +466,7 @@ struct page *dma_direct_alloc_pages(struct device *dev, size_t size,
dma_addr_t *dma_handle, enum dma_data_direction dir, gfp_t gfp)
{
unsigned long attrs = 0;
+ size_t shared_size;
struct page *page;
void *cpu_addr;
bool mark_mem_decrypt;
@@ -474,7 +490,14 @@ struct page *dma_direct_alloc_pages(struct device *dev, size_t size,
goto setup_page;
}
- page = __dma_direct_alloc_pages(dev, size, gfp, false);
+ if (mark_mem_decrypt) {
+ if (cc_shared_round_size(size, &shared_size))
+ return NULL;
+
+ size = shared_size;
+ }
+
+ page = __dma_direct_alloc_pages(dev, size, gfp, false, attrs);
if (!page)
return NULL;
@@ -501,6 +524,7 @@ void dma_direct_free_pages(struct device *dev, size_t size,
phys_addr_t phys;
void *vaddr = page_address(page);
struct io_tlb_pool *swiotlb_pool;
+ size_t shared_size;
/*
* if the device had requested for an unencrypted buffer,
* convert it to encrypted on free
@@ -517,6 +541,13 @@ void dma_direct_free_pages(struct device *dev, size_t size,
if (swiotlb_pool)
mark_mem_encrypted = false;
+ if (mark_mem_encrypted) {
+ if (WARN_ON_ONCE(cc_shared_round_size(size, &shared_size)))
+ return;
+
+ size = shared_size;
+ }
+
if (mark_mem_encrypted && dma_set_encrypted(dev, vaddr, size))
return;
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v11 18/23] swiotlb: Align shared IO TLB pools to the shared granule size
2026-12-02 9:54 [PATCH v11 00/23] coco: guest: Add a shared-granule allocator for host-shared memory Aneesh Kumar K.V (Arm)
` (16 preceding siblings ...)
2026-12-02 9:54 ` [PATCH v11 17/23] dma-direct: Align CoCo shared DMA allocations to the shared granule size Aneesh Kumar K.V (Arm)
@ 2026-12-02 9:54 ` Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 19/23] swiotlb: Use the common CoCo memory transition helpers Aneesh Kumar K.V (Arm)
` (4 subsequent siblings)
22 siblings, 0 replies; 25+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-12-02 9:54 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Andrew Morton, Catalin Marinas,
Christian König, Jason Gunthorpe, Joerg Roedel, Marc Zyngier,
Marek Szyprowski, Robin Murphy, Steven Price, Sumit Semwal,
Suzuki K Poulose, Will Deacon, T.J. Mercier, Madhavan Srinivasan,
Heiko Carstens, Christian Borntraeger, Sven Schnelle, Dave Hansen,
Kiryl Shutsemau, Rick Edgecombe, Paolo Bonzini, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Haiyang Zhang, Wei Liu, Dexuan Cui,
Andy Lutomirski, Peter Zijlstra, Alexander Gordeev,
Gerald Schaefer, Vasily Gorbik, x86, dri-devel, iommu,
linaro-mm-sig, linux-arm-kernel, linux-media, linux-mm, kvmarm,
patches
Align and size the early memblock pool to the common CoCo shared
granule. Use the same rounded extent when the pool is transitioned and
when it is released. Leave the slot count unchanged: any rounded tail
belongs to the pool allocation but is not advertised as allocatable
SWIOTLB space.
Round late and dynamic shared pool allocations to the sharing granule
and prevent allocation retries from reducing them below that granule.
Apply the same rounding when releasing their backing pages.
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
kernel/dma/swiotlb.c | 35 ++++++++++++++++++++++++++---------
1 file changed, 26 insertions(+), 9 deletions(-)
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 786954bc5e6a..2421efb4436a 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -22,6 +22,7 @@
#include <linux/cache.h>
#include <linux/cc_platform.h>
+#include <linux/cc_shared.h>
#include <linux/ctype.h>
#include <linux/debugfs.h>
#include <linux/dma-direct.h>
@@ -368,7 +369,8 @@ void __init swiotlb_update_mem_attributes(void)
if (!mem->nslabs || mem->late_alloc)
return;
- bytes = PAGE_ALIGN(mem->nslabs << IO_TLB_SHIFT);
+
+ bytes = ALIGN(mem->nslabs << IO_TLB_SHIFT, cc_shared_granule_size());
if (io_tlb_default_mem.cc_shared) {
int ret;
@@ -435,8 +437,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 = ALIGN(nslabs << IO_TLB_SHIFT, cc_shared_granule_size());
/*
* By default allocate the bounce buffer memory from low memory, but
@@ -444,9 +446,9 @@ static void __init *swiotlb_memblock_alloc(unsigned long nslabs,
* memory encryption.
*/
if (flags & SWIOTLB_ANY)
- tlb = memblock_alloc(bytes, PAGE_SIZE);
+ tlb = memblock_alloc(bytes, cc_shared_granule_size());
else
- tlb = memblock_alloc_low(bytes, PAGE_SIZE);
+ tlb = memblock_alloc_low(bytes, cc_shared_granule_size());
if (!tlb) {
pr_warn("%s: Failed to allocate %zu bytes tlb structure\n",
@@ -455,7 +457,7 @@ static void __init *swiotlb_memblock_alloc(unsigned long nslabs,
}
if (remap && remap(tlb, nslabs) < 0) {
- memblock_free(tlb, PAGE_ALIGN(bytes));
+ memblock_free(tlb, bytes);
pr_warn("%s: Failed to remap %zu bytes\n", __func__, bytes);
return NULL;
}
@@ -577,7 +579,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask,
swiotlb_adjust_nareas(num_possible_cpus());
retry:
- order = get_order(nslabs << IO_TLB_SHIFT);
+ order = get_order(ALIGN(nslabs << IO_TLB_SHIFT, cc_shared_granule_size()));
nslabs = SLABS_PER_PAGE << order;
while ((SLABS_PER_PAGE << order) > IO_TLB_MIN_SLABS) {
@@ -586,6 +588,9 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask,
if (vstart)
break;
order--;
+ if (order < get_order(cc_shared_granule_size()))
+ break;
+
nslabs = SLABS_PER_PAGE << order;
retried = true;
}
@@ -599,8 +604,13 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask,
free_pages((unsigned long)vstart, order);
nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
- if (nslabs < IO_TLB_MIN_SLABS)
+ if (nslabs <= IO_TLB_MIN_SLABS)
return rc;
+
+ /* Avoid infinite loop */
+ if (WARN_ON(nslabs < (cc_shared_granule_size() >> IO_TLB_SHIFT)))
+ return rc;
+
retried = true;
goto retry;
}
@@ -677,7 +687,7 @@ void __init swiotlb_exit(void)
io_tlb_default_mem.nslabs = 0;
#endif
tbl_vaddr = (unsigned long)phys_to_virt(mem->start);
- tbl_size = PAGE_ALIGN(mem->end - mem->start);
+ tbl_size = ALIGN(mem->end - mem->start, cc_shared_granule_size());
slots_size = PAGE_ALIGN(array_size(sizeof(*mem->slots), mem->nslabs));
if (io_tlb_default_mem.cc_shared) {
@@ -721,12 +731,16 @@ void __init swiotlb_exit(void)
static struct page *alloc_dma_pages(gfp_t gfp, size_t bytes,
u64 phys_limit, unsigned long attrs)
{
- unsigned int order = get_order(bytes);
bool cc_shared = attrs & __DMA_ATTR_ALLOC_CC_SHARED;
+ unsigned int order;
struct page *page;
phys_addr_t paddr;
void *vaddr;
+ if (cc_shared)
+ bytes = ALIGN(bytes, cc_shared_granule_size());
+
+ order = get_order(bytes);
page = alloc_pages(gfp, order);
if (!page)
return NULL;
@@ -817,6 +831,9 @@ static void swiotlb_free_tlb(void *vaddr, size_t bytes, bool cc_shared)
dma_free_from_pool(NULL, vaddr, bytes))
return;
+ if (cc_shared)
+ bytes = ALIGN(bytes, cc_shared_granule_size());
+
/* Intentional leak if pages cannot be encrypted again. */
if (!cc_shared ||
!set_memory_encrypted((unsigned long)vaddr, PFN_UP(bytes)))
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v11 19/23] swiotlb: Use the common CoCo memory transition helpers
2026-12-02 9:54 [PATCH v11 00/23] coco: guest: Add a shared-granule allocator for host-shared memory Aneesh Kumar K.V (Arm)
` (17 preceding siblings ...)
2026-12-02 9:54 ` [PATCH v11 18/23] swiotlb: Align shared IO TLB pools " Aneesh Kumar K.V (Arm)
@ 2026-12-02 9:54 ` Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 20/23] swiotlb: Reject misaligned restricted DMA pools for CoCo guests Aneesh Kumar K.V (Arm)
` (3 subsequent siblings)
22 siblings, 0 replies; 25+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-12-02 9:54 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Andrew Morton, Catalin Marinas,
Christian König, Jason Gunthorpe, Joerg Roedel, Marc Zyngier,
Marek Szyprowski, Robin Murphy, Steven Price, Sumit Semwal,
Suzuki K Poulose, Will Deacon, T.J. Mercier, Madhavan Srinivasan,
Heiko Carstens, Christian Borntraeger, Sven Schnelle, Dave Hansen,
Kiryl Shutsemau, Rick Edgecombe, Paolo Bonzini, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Haiyang Zhang, Wei Liu, Dexuan Cui,
Andy Lutomirski, Peter Zijlstra, Alexander Gordeev,
Gerald Schaefer, Vasily Gorbik, x86, dri-devel, iommu,
linaro-mm-sig, linux-arm-kernel, linux-media, linux-mm, kvmarm,
patches
Replace set_memory_decrypted() and set_memory_encrypted() calls for the
default and dynamic pools with cc_make_shared() and cc_make_private().
The common helpers validate the alignment and size of each transition.
If sharing a dynamic pool fails, retain the backing pages without
attempting to make them private again. A failed transition can leave a
partially shared range, and making already-private pages private again
is not safe on every architecture.
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
kernel/dma/swiotlb.c | 22 ++++++++--------------
1 file changed, 8 insertions(+), 14 deletions(-)
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 2421efb4436a..83bd825a9a67 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -375,8 +375,7 @@ void __init swiotlb_update_mem_attributes(void)
if (io_tlb_default_mem.cc_shared) {
int ret;
- ret = set_memory_decrypted((unsigned long)mem->vaddr,
- bytes >> PAGE_SHIFT);
+ ret = cc_make_shared(mem->vaddr, bytes);
if (ret) {
pr_warn("Failed to decrypt default memory pool, disabling it\n");
swiotlb_mark_pool_used(mem);
@@ -635,8 +634,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask,
goto error_slots;
if (io_tlb_default_mem.cc_shared) {
- rc = set_memory_decrypted((unsigned long)vstart,
- (nslabs << IO_TLB_SHIFT) >> PAGE_SHIFT);
+ rc = cc_make_shared(vstart, nslabs << IO_TLB_SHIFT);
if (rc) {
leak_pages = true;
goto error_decrypt;
@@ -691,7 +689,7 @@ void __init swiotlb_exit(void)
slots_size = PAGE_ALIGN(array_size(sizeof(*mem->slots), mem->nslabs));
if (io_tlb_default_mem.cc_shared) {
- if (set_memory_encrypted(tbl_vaddr, tbl_size >> PAGE_SHIFT))
+ if (cc_make_private((void *)tbl_vaddr, tbl_size))
leak_pages = true;
}
@@ -752,15 +750,11 @@ static struct page *alloc_dma_pages(gfp_t gfp, size_t bytes,
}
vaddr = phys_to_virt(paddr);
- if (cc_shared && set_memory_decrypted((unsigned long)vaddr, PFN_UP(bytes)))
- goto error;
- return page;
+ if (cc_shared && cc_make_shared(vaddr, bytes))
+ /* leak pages on error */
+ return NULL;
-error:
- /* Intentional leak if pages cannot be encrypted again. */
- if (cc_shared && !set_memory_encrypted((unsigned long)vaddr, PFN_UP(bytes)))
- __free_pages(page, order);
- return NULL;
+ return page;
}
/**
@@ -836,7 +830,7 @@ static void swiotlb_free_tlb(void *vaddr, size_t bytes, bool cc_shared)
/* Intentional leak if pages cannot be encrypted again. */
if (!cc_shared ||
- !set_memory_encrypted((unsigned long)vaddr, PFN_UP(bytes)))
+ !cc_make_private(vaddr, bytes))
__free_pages(virt_to_page(vaddr), get_order(bytes));
}
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v11 20/23] swiotlb: Reject misaligned restricted DMA pools for CoCo guests
2026-12-02 9:54 [PATCH v11 00/23] coco: guest: Add a shared-granule allocator for host-shared memory Aneesh Kumar K.V (Arm)
` (18 preceding siblings ...)
2026-12-02 9:54 ` [PATCH v11 19/23] swiotlb: Use the common CoCo memory transition helpers Aneesh Kumar K.V (Arm)
@ 2026-12-02 9:54 ` Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 21/23] dma-buf: system_heap: Limit scatterlist entries to the buffer size Aneesh Kumar K.V (Arm)
` (2 subsequent siblings)
22 siblings, 0 replies; 25+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-12-02 9:54 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Andrew Morton, Catalin Marinas,
Christian König, Jason Gunthorpe, Joerg Roedel, Marc Zyngier,
Marek Szyprowski, Robin Murphy, Steven Price, Sumit Semwal,
Suzuki K Poulose, Will Deacon, T.J. Mercier, Madhavan Srinivasan,
Heiko Carstens, Christian Borntraeger, Sven Schnelle, Dave Hansen,
Kiryl Shutsemau, Rick Edgecombe, Paolo Bonzini, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Haiyang Zhang, Wei Liu, Dexuan Cui,
Andy Lutomirski, Peter Zijlstra, Alexander Gordeev,
Gerald Schaefer, Vasily Gorbik, x86, dri-devel, iommu,
linaro-mm-sig, linux-arm-kernel, linux-media, linux-mm, kvmarm,
patches
A restricted DMA pool is a firmware-described ownership boundary. Unlike
a pool allocated by SWIOTLB itself, its base cannot be moved and its
size cannot be rounded without claiming memory outside the reserved
region.
Confidential-computing guests may require private/shared state changes
to cover units larger than PAGE_SIZE. Passing a misaligned restricted
region to set_memory_decrypted() can therefore fail.
Validate both the physical base and the complete reserved size with the
common CoCo shared-range helper before allocating SWIOTLB metadata or
performing a state transition. Perform the transition through
cc_make_shared().
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
kernel/dma/swiotlb.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 83bd825a9a67..dbeb600cbf24 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -40,7 +40,6 @@
#include <linux/pfn.h>
#include <linux/rculist.h>
#include <linux/scatterlist.h>
-#include <linux/set_memory.h>
#include <linux/spinlock.h>
#include <linux/string.h>
#include <linux/swiotlb.h>
@@ -2025,6 +2024,14 @@ static int rmem_swiotlb_device_init(struct reserved_mem *rmem,
return -EINVAL;
}
+ if (cc_platform_has(CC_ATTR_MEM_ENCRYPT) &&
+ !cc_shared_range_valid(rmem->base, rmem->size)) {
+ dev_err(dev,
+ "Restricted DMA pool must be aligned to %#zx bytes for memory encryption\n",
+ cc_shared_granule_size());
+ return -EINVAL;
+ }
+
/*
* Since multiple devices can share the same pool, the private data,
* io_tlb_mem struct, will be initialized by the first device attached
@@ -2073,8 +2080,8 @@ static int rmem_swiotlb_device_init(struct reserved_mem *rmem,
int ret;
mem->cc_shared = true;
- ret = set_memory_decrypted((unsigned long)phys_to_virt(rmem->base),
- (nslabs << IO_TLB_SHIFT) >> PAGE_SHIFT);
+ ret = cc_make_shared(phys_to_virt(rmem->base),
+ nslabs << IO_TLB_SHIFT);
if (ret) {
dev_err(dev, "Failed to decrypt restricted DMA pool\n");
kfree(pool->areas);
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v11 21/23] dma-buf: system_heap: Limit scatterlist entries to the buffer size
2026-12-02 9:54 [PATCH v11 00/23] coco: guest: Add a shared-granule allocator for host-shared memory Aneesh Kumar K.V (Arm)
` (19 preceding siblings ...)
2026-12-02 9:54 ` [PATCH v11 20/23] swiotlb: Reject misaligned restricted DMA pools for CoCo guests Aneesh Kumar K.V (Arm)
@ 2026-12-02 9:54 ` Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 22/23] dma-buf: system_heap: Allocate shared buffers using CoCo shared memory allocator Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 23/23] swiotlb: Make rounded shared pool capacity allocatable Aneesh Kumar K.V (Arm)
22 siblings, 0 replies; 25+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-12-02 9:54 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Andrew Morton, Catalin Marinas,
Christian König, Jason Gunthorpe, Joerg Roedel, Marc Zyngier,
Marek Szyprowski, Robin Murphy, Steven Price, Sumit Semwal,
Suzuki K Poulose, Will Deacon, T.J. Mercier, Madhavan Srinivasan,
Heiko Carstens, Christian Borntraeger, Sven Schnelle, Dave Hansen,
Kiryl Shutsemau, Rick Edgecombe, Paolo Bonzini, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Haiyang Zhang, Wei Liu, Dexuan Cui,
Andy Lutomirski, Peter Zijlstra, Alexander Gordeev,
Gerald Schaefer, Vasily Gorbik, x86, dri-devel, iommu,
linaro-mm-sig, linux-arm-kernel, linux-media, linux-mm, kvmarm,
patches
The system heap currently allocates each backing page no larger than the
remaining dma-buf length. It can therefore use the complete
compound-page size for every scatterlist entry while keeping the total
length equal to the buffer size.
Shared backing allocations may need to be rounded up to an architecture
shared granule size. A backing allocation can then be larger than the
remaining buffer length. Describing the complete allocation in the
scatterlist would incorrectly expose the rounded tail to scatterlist
consumers as part of the dma-buf.
Track the remaining buffer length while constructing the scatterlist and
limit each entry to the smaller of the compound-page size and the
remaining length. The complete backing allocation remains owned by the
heap and is still released normally.
This does not change behavior with the current allocation policy, but
prepares the heap for shared-granule-sized backing allocations.
Cc: Sumit Semwal <sumit.semwal@linaro.org>
Cc: "T.J. Mercier" <tjmercier@google.com>
Cc: "Christian König" <christian.koenig@amd.com>
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
drivers/dma-buf/heaps/system_heap.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c
index c8959eadc71d..b5b8cdf65f23 100644
--- a/drivers/dma-buf/heaps/system_heap.c
+++ b/drivers/dma-buf/heaps/system_heap.c
@@ -406,6 +406,7 @@ static struct dma_buf *system_heap_allocate(struct dma_heap *heap,
struct system_heap_buffer *buffer;
DEFINE_DMA_BUF_EXPORT_INFO(exp_info);
unsigned long size_remaining = len;
+ unsigned long sg_remaining = len;
unsigned int max_order = orders[0];
struct system_heap_priv *priv = dma_heap_get_drvdata(heap);
bool cc_shared = priv->cc_shared;
@@ -454,7 +455,11 @@ static struct dma_buf *system_heap_allocate(struct dma_heap *heap,
sg = table->sgl;
list_for_each_entry_safe(page, tmp_page, &pages, lru) {
- sg_set_page(sg, page, page_size(page), 0);
+ unsigned long sg_len;
+
+ sg_len = min_t(unsigned long, page_size(page), sg_remaining);
+ sg_set_page(sg, page, sg_len, 0);
+ sg_remaining -= sg_len;
sg = sg_next(sg);
list_del(&page->lru);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v11 22/23] dma-buf: system_heap: Allocate shared buffers using CoCo shared memory allocator
2026-12-02 9:54 [PATCH v11 00/23] coco: guest: Add a shared-granule allocator for host-shared memory Aneesh Kumar K.V (Arm)
` (20 preceding siblings ...)
2026-12-02 9:54 ` [PATCH v11 21/23] dma-buf: system_heap: Limit scatterlist entries to the buffer size Aneesh Kumar K.V (Arm)
@ 2026-12-02 9:54 ` Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 23/23] swiotlb: Make rounded shared pool capacity allocatable Aneesh Kumar K.V (Arm)
22 siblings, 0 replies; 25+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-12-02 9:54 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Andrew Morton, Catalin Marinas,
Christian König, Jason Gunthorpe, Joerg Roedel, Marc Zyngier,
Marek Szyprowski, Robin Murphy, Steven Price, Sumit Semwal,
Suzuki K Poulose, Will Deacon, T.J. Mercier, Madhavan Srinivasan,
Heiko Carstens, Christian Borntraeger, Sven Schnelle, Dave Hansen,
Kiryl Shutsemau, Rick Edgecombe, Paolo Bonzini, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Haiyang Zhang, Wei Liu, Dexuan Cui,
Andy Lutomirski, Peter Zijlstra, Alexander Gordeev,
Gerald Schaefer, Vasily Gorbik, x86, dri-devel, iommu,
linaro-mm-sig, linux-arm-kernel, linux-media, linux-mm, kvmarm,
patches
The system_cc_shared heap currently allocates its backing pages using
the normal system-heap order policy and changes each resulting compound
page to shared state. This does not accommodate architectures whose
sharing granule is larger than PAGE_SIZE: smaller allocations do not
meet the size and alignment requirements for an independent transition.
Use the common CoCo shared-memory allocator for backing allocation of
the shared heap. Preserve the existing preferred-order search and its
GFP policy: each candidate order is passed to the common allocator as a
byte request, and that allocator rounds it up when the architecture
shared granule is larger.
Calculate a rounded internal backing length but retain the original
length in dma_buf::size. The preceding scatterlist-length change ensures
that the rounded tail is not included in DMA mappings or other
operations. This permits a 4 KiB request on a 64 KiB shared-granule
system without exposing the extra 60 KiB to an importer.
Cc: Sumit Semwal <sumit.semwal@linaro.org>
Cc: "T.J. Mercier" <tjmercier@google.com>
Cc: "Christian König" <christian.koenig@amd.com>
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
drivers/dma-buf/heaps/system_heap.c | 118 ++++++++++++----------------
1 file changed, 51 insertions(+), 67 deletions(-)
diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c
index b5b8cdf65f23..db88b36cd1fd 100644
--- a/drivers/dma-buf/heaps/system_heap.c
+++ b/drivers/dma-buf/heaps/system_heap.c
@@ -11,14 +11,13 @@
*/
#include <linux/cc_platform.h>
+#include <linux/cc_shared.h>
#include <linux/dma-buf.h>
#include <linux/dma-mapping.h>
#include <linux/dma-heap.h>
#include <linux/err.h>
#include <linux/highmem.h>
-#include <linux/mem_encrypt.h>
#include <linux/mm.h>
-#include <linux/set_memory.h>
#include <linux/module.h>
#include <linux/pgtable.h>
#include <linux/scatterlist.h>
@@ -65,34 +64,6 @@ static gfp_t order_flags[] = {HIGH_ORDER_GFP, HIGH_ORDER_GFP, LOW_ORDER_GFP};
static const unsigned int orders[] = {8, 4, 0};
#define NUM_ORDERS ARRAY_SIZE(orders)
-static int system_heap_set_page_decrypted(struct page *page)
-{
- unsigned long addr = (unsigned long)page_address(page);
- unsigned int nr_pages = 1 << compound_order(page);
- int ret;
-
- ret = set_memory_decrypted(addr, nr_pages);
- if (ret)
- pr_warn_ratelimited("dma-buf system heap: failed to decrypt page at %p\n",
- page_address(page));
-
- return ret;
-}
-
-static int system_heap_set_page_encrypted(struct page *page)
-{
- unsigned long addr = (unsigned long)page_address(page);
- unsigned int nr_pages = 1 << compound_order(page);
- int ret;
-
- ret = set_memory_encrypted(addr, nr_pages);
- if (ret)
- pr_warn_ratelimited("dma-buf system heap: failed to re-encrypt page at %p, leaking memory\n",
- page_address(page));
-
- return ret;
-}
-
static int dup_sg_table(struct sg_table *from, struct sg_table *to)
{
struct scatterlist *sg, *new_sg;
@@ -337,6 +308,14 @@ static void system_heap_vunmap(struct dma_buf *dmabuf, struct iosys_map *map)
iosys_map_clear(map);
}
+static void system_heap_free_page(struct page *page, bool cc_shared)
+{
+ if (cc_shared)
+ free_cc_shared(page_address(page));
+ else
+ __free_pages(page, compound_order(page));
+}
+
static void system_heap_dma_buf_release(struct dma_buf *dmabuf)
{
struct system_heap_buffer *buffer = dmabuf->priv;
@@ -345,19 +324,8 @@ static void system_heap_dma_buf_release(struct dma_buf *dmabuf)
int i;
table = &buffer->sg_table;
- for_each_sgtable_sg(table, sg, i) {
- struct page *page = sg_page(sg);
-
- /*
- * Intentionally leak pages that cannot be re-encrypted
- * to prevent shared memory from being reused.
- */
- if (cc_shared_buffer(buffer) &&
- system_heap_set_page_encrypted(page))
- continue;
-
- __free_pages(page, compound_order(page));
- }
+ for_each_sgtable_sg(table, sg, i)
+ system_heap_free_page(sg_page(sg), cc_shared_buffer(buffer));
sg_free_table(table);
kfree(buffer);
}
@@ -375,8 +343,23 @@ static const struct dma_buf_ops system_heap_buf_ops = {
.release = system_heap_dma_buf_release,
};
+static struct page *system_heap_alloc_order(unsigned int order,
+ gfp_t flags, bool cc_shared)
+{
+ void *addr;
+
+ if (!cc_shared)
+ return alloc_pages(flags, order);
+
+ addr = alloc_cc_shared(flags, PAGE_SIZE << order);
+ if (!addr)
+ return NULL;
+
+ return virt_to_page(addr);
+}
+
static struct page *alloc_largest_available(unsigned long size,
- unsigned int max_order)
+ unsigned int max_order, bool cc_shared)
{
struct page *page;
int i;
@@ -390,7 +373,14 @@ static struct page *alloc_largest_available(unsigned long size,
flags = order_flags[i];
if (mem_accounting)
flags |= __GFP_ACCOUNT;
- page = alloc_pages(flags, orders[i]);
+
+ /*
+ * Sharing-granule rounding in system_heap_alloc_order() may
+ * produce the same allocation order as an earlier attempt.
+ * Still try again: the final fallback allows reclaim and
+ * does not set __GFP_NORETRY.
+ */
+ page = system_heap_alloc_order(orders[i], flags, cc_shared);
if (!page)
continue;
return page;
@@ -405,6 +395,7 @@ static struct dma_buf *system_heap_allocate(struct dma_heap *heap,
{
struct system_heap_buffer *buffer;
DEFINE_DMA_BUF_EXPORT_INFO(exp_info);
+ size_t shared_size;
unsigned long size_remaining = len;
unsigned long sg_remaining = len;
unsigned int max_order = orders[0];
@@ -417,6 +408,16 @@ static struct dma_buf *system_heap_allocate(struct dma_heap *heap,
struct page *page, *tmp_page;
int i, ret = -ENOMEM;
+ if (cc_shared) {
+ int err;
+
+ err = cc_shared_round_size(len, &shared_size);
+ if (err)
+ return ERR_PTR(err);
+
+ size_remaining = shared_size;
+ }
+
buffer = kzalloc_obj(*buffer);
if (!buffer)
return ERR_PTR(-ENOMEM);
@@ -439,7 +440,8 @@ static struct dma_buf *system_heap_allocate(struct dma_heap *heap,
goto free_buffer;
}
- page = alloc_largest_available(size_remaining, max_order);
+ page = alloc_largest_available(size_remaining, max_order,
+ cc_shared);
if (!page)
goto free_buffer;
@@ -464,14 +466,6 @@ static struct dma_buf *system_heap_allocate(struct dma_heap *heap,
list_del(&page->lru);
}
- if (cc_shared_buffer(buffer)) {
- for_each_sgtable_sg(table, sg, i) {
- ret = system_heap_set_page_decrypted(sg_page(sg));
- if (ret)
- goto free_pages;
- }
- }
-
/* create the dmabuf */
exp_info.exp_name = dma_heap_get_name(heap);
exp_info.ops = &system_heap_buf_ops;
@@ -486,22 +480,12 @@ static struct dma_buf *system_heap_allocate(struct dma_heap *heap,
return dmabuf;
free_pages:
- for_each_sgtable_sg(table, sg, i) {
- struct page *p = sg_page(sg);
-
- /*
- * Intentionally leak pages that cannot be re-encrypted
- * to prevent shared memory from being reused.
- */
- if (cc_shared_buffer(buffer) &&
- system_heap_set_page_encrypted(p))
- continue;
- __free_pages(p, compound_order(p));
- }
+ for_each_sgtable_sg(table, sg, i)
+ system_heap_free_page(sg_page(sg), cc_shared);
sg_free_table(table);
free_buffer:
list_for_each_entry_safe(page, tmp_page, &pages, lru)
- __free_pages(page, compound_order(page));
+ system_heap_free_page(page, cc_shared);
kfree(buffer);
return ERR_PTR(ret);
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v11 23/23] swiotlb: Make rounded shared pool capacity allocatable
2026-12-02 9:54 [PATCH v11 00/23] coco: guest: Add a shared-granule allocator for host-shared memory Aneesh Kumar K.V (Arm)
` (21 preceding siblings ...)
2026-12-02 9:54 ` [PATCH v11 22/23] dma-buf: system_heap: Allocate shared buffers using CoCo shared memory allocator Aneesh Kumar K.V (Arm)
@ 2026-12-02 9:54 ` Aneesh Kumar K.V (Arm)
22 siblings, 0 replies; 25+ messages in thread
From: Aneesh Kumar K.V (Arm) @ 2026-12-02 9:54 UTC (permalink / raw)
To: linux-coco
Cc: Aneesh Kumar K.V (Arm), Andrew Morton, Catalin Marinas,
Christian König, Jason Gunthorpe, Joerg Roedel, Marc Zyngier,
Marek Szyprowski, Robin Murphy, Steven Price, Sumit Semwal,
Suzuki K Poulose, Will Deacon, T.J. Mercier, Madhavan Srinivasan,
Heiko Carstens, Christian Borntraeger, Sven Schnelle, Dave Hansen,
Kiryl Shutsemau, Rick Edgecombe, Paolo Bonzini, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Haiyang Zhang, Wei Liu, Dexuan Cui,
Andy Lutomirski, Peter Zijlstra, Alexander Gordeev,
Gerald Schaefer, Vasily Gorbik, x86, dri-devel, iommu,
linaro-mm-sig, linux-arm-kernel, linux-media, linux-mm, kvmarm,
patches
CoCo shared memory may need to be allocated and transitioned in units larger
than the requested object. Before this change, users handled the resulting
capacity as follows:
User Rounded capacity reused
dma-buf system heap no
DMA-direct no
regular GIC tables no
small GIC ITTs yes, through a gen_pool
early SWIOTLB pool no
late SWIOTLB pool yes
persistent dynamic SWIOTLB no
transient dynamic SWIOTLB no, one mapping only
atomic DMA pools yes, through a gen_pool
restricted SWIOTLB pool no additional padding
Improve the early and persistent dynamic SWIOTLB pools. They already own
and transition backing rounded to the shared granule size, and SWIOTLB
is itself a suballocator. Advertise the rounded extent as slots, size
the slot metadata to match. This makes the extra capacity available
without reserving more backing memory.
Record the rounded capacity for buddy-backed shared transient pools too.
Keep the original suballocation size for non-blocking shared transient
pools, which allocate from the atomic DMA pools.
With pool start and end recording the rounded backing extent, use the
recorded size for memory transitions and freeing without aligning it
again. Keep the atomic-pool return first in swiotlb_free_tlb(), so those
suballocations are returned using their original size.
Do not attempt the same optimization for dma-buf, DMA-direct or regular
GIC objects. Those allocations have independent caller-visible sizes and
lifetimes. Reusing their padding requires a shared-granule suballocator
with reference counting, per-object mappings and accounting.
Note:
For the current 64 KiB CCA shared granule size, SWIOTLB pool sizes are
already multiples of the 256 KiB IO_TLB segment size. Consequently, the
rounding does not change any runtime values on current CCA systems. It
instead makes the code express the intended invariant that pool metadata
describes the complete shared-granule-aligned backing allocation.
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
kernel/dma/swiotlb.c | 40 +++++++++++++++++++++++++++++-----------
1 file changed, 29 insertions(+), 11 deletions(-)
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index dbeb600cbf24..2ef9cdda4d7b 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -329,6 +329,15 @@ static inline unsigned long nr_slots(u64 val)
return DIV_ROUND_UP(val, IO_TLB_SIZE);
}
+static unsigned long swiotlb_align_nslabs(unsigned long nslabs)
+{
+ unsigned long bytes = nslabs << IO_TLB_SHIFT;
+
+ bytes = ALIGN(bytes, cc_shared_granule_size());
+
+ return bytes >> IO_TLB_SHIFT;
+}
+
static void swiotlb_mark_pool_used(struct io_tlb_pool *pool)
{
unsigned long i;
@@ -369,7 +378,7 @@ void __init swiotlb_update_mem_attributes(void)
if (!mem->nslabs || mem->late_alloc)
return;
- bytes = ALIGN(mem->nslabs << IO_TLB_SHIFT, cc_shared_granule_size());
+ bytes = mem->nslabs << IO_TLB_SHIFT;
if (io_tlb_default_mem.cc_shared) {
int ret;
@@ -432,11 +441,12 @@ static void add_mem_pool(struct io_tlb_mem *mem, struct io_tlb_pool *pool)
}
static void __init *swiotlb_memblock_alloc(unsigned long nslabs,
- unsigned int flags,
+ unsigned long *alloc_nslabs, unsigned int flags,
int (*remap)(void *tlb, unsigned long nslabs))
{
+ unsigned long aligned_nslabs = swiotlb_align_nslabs(nslabs);
+ size_t bytes = aligned_nslabs << IO_TLB_SHIFT;
void *tlb;
- size_t bytes = ALIGN(nslabs << IO_TLB_SHIFT, cc_shared_granule_size());
/*
* By default allocate the bounce buffer memory from low memory, but
@@ -454,12 +464,13 @@ static void __init *swiotlb_memblock_alloc(unsigned long nslabs,
return NULL;
}
- if (remap && remap(tlb, nslabs) < 0) {
+ if (remap && remap(tlb, aligned_nslabs) < 0) {
memblock_free(tlb, bytes);
pr_warn("%s: Failed to remap %zu bytes\n", __func__, bytes);
return NULL;
}
+ *alloc_nslabs = aligned_nslabs;
return tlb;
}
@@ -472,6 +483,7 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
{
struct io_tlb_pool *mem = &io_tlb_default_mem.defpool;
unsigned long nslabs;
+ unsigned long alloc_nslabs;
unsigned int nareas;
size_t alloc_size;
void *tlb;
@@ -496,14 +508,16 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
swiotlb_adjust_nareas(num_possible_cpus());
nslabs = default_nslabs;
- nareas = limit_nareas(default_nareas, nslabs);
- while ((tlb = swiotlb_memblock_alloc(nslabs, flags, remap)) == NULL) {
+ while ((tlb = swiotlb_memblock_alloc(nslabs, &alloc_nslabs, flags,
+ remap)) == NULL) {
if (nslabs <= IO_TLB_MIN_SLABS)
return;
nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
- nareas = limit_nareas(nareas, nslabs);
}
+ nslabs = alloc_nslabs;
+ nareas = limit_nareas(default_nareas, nslabs);
+
if (default_nslabs != nslabs) {
pr_info("SWIOTLB bounce buffer size adjusted %lu -> %lu slabs",
default_nslabs, nslabs);
@@ -684,7 +698,7 @@ void __init swiotlb_exit(void)
io_tlb_default_mem.nslabs = 0;
#endif
tbl_vaddr = (unsigned long)phys_to_virt(mem->start);
- tbl_size = ALIGN(mem->end - mem->start, cc_shared_granule_size());
+ tbl_size = mem->end - mem->start;
slots_size = PAGE_ALIGN(array_size(sizeof(*mem->slots), mem->nslabs));
if (io_tlb_default_mem.cc_shared) {
@@ -824,9 +838,6 @@ static void swiotlb_free_tlb(void *vaddr, size_t bytes, bool cc_shared)
dma_free_from_pool(NULL, vaddr, bytes))
return;
- if (cc_shared)
- bytes = ALIGN(bytes, cc_shared_granule_size());
-
/* Intentional leak if pages cannot be encrypted again. */
if (!cc_shared ||
!cc_make_private(vaddr, bytes))
@@ -883,6 +894,13 @@ static struct io_tlb_pool *swiotlb_alloc_pool(struct device *dev,
tlb_size = nslabs << IO_TLB_SHIFT;
}
+ /* Account for granule rounding in buddy-backed shared allocations. */
+ if (mem->cc_shared &&
+ (!dev || gfpflags_allow_blocking(gfp))) {
+ nslabs = swiotlb_align_nslabs(nslabs);
+ tlb_size = nslabs << IO_TLB_SHIFT;
+ }
+
slot_order = get_order(array_size(sizeof(*pool->slots), nslabs));
pool->slots = (struct io_tlb_slot *)
__get_free_pages(gfp, slot_order);
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH v11 04/23] s390/mm: Clear memory before making it shared
2026-12-02 9:54 ` [PATCH v11 04/23] s390/mm: Clear memory before making it shared Aneesh Kumar K.V (Arm)
@ 2026-12-02 9:57 ` Christian Borntraeger
0 siblings, 0 replies; 25+ messages in thread
From: Christian Borntraeger @ 2026-12-02 9:57 UTC (permalink / raw)
To: Aneesh Kumar K.V (Arm), linux-coco
Cc: Andrew Morton, Catalin Marinas, Christian König,
Jason Gunthorpe, Joerg Roedel, Marc Zyngier, Marek Szyprowski,
Robin Murphy, Steven Price, Sumit Semwal, Suzuki K Poulose,
Will Deacon, T.J. Mercier, Madhavan Srinivasan, Heiko Carstens,
Sven Schnelle, Dave Hansen, Kiryl Shutsemau, Rick Edgecombe,
Paolo Bonzini, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Haiyang Zhang, Wei Liu, Dexuan Cui, Andy Lutomirski,
Peter Zijlstra, Alexander Gordeev, Gerald Schaefer, Vasily Gorbik,
x86, dri-devel, iommu, linaro-mm-sig, linux-arm-kernel,
linux-media, linux-mm, kvmarm, patches
Am 02.12.26 um 10:54 schrieb Aneesh Kumar K.V (Arm):
> The comment in share() warns that sharing operates on whole pages and
> can expose unintended data to the hypervisor. Memory whose previous
> contents must remain private therefore needs to be cleared before
> uv_set_shared() makes it accessible to the host.
>
> The common CoCo allocator masks __GFP_ZERO because a private-to-shared
> transition may modify memory contents, and currently clears the
> allocation after sharing. On s390, that ordering could expose previous
> contents before the clear.
>
> Clear the range in set_memory_decrypted() before calling
> uv_set_shared(). This also establishes the zeroing guarantee that
> subsequent patches will use to remove redundant caller-side clears.
>
> Cc: Alexander Gordeev <agordeev@linux.ibm.com>
> Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
> Cc: Heiko Carstens <hca@linux.ibm.com>
> Cc: Vasily Gorbik <gor@linux.ibm.com>
> Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
Acked-by: Christian Borntraeger <borntraeger@linux.ibm.com>
> ---
> arch/s390/mm/init.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
> index be7e009e7b59..fdacd9380286 100644
> --- a/arch/s390/mm/init.c
> +++ b/arch/s390/mm/init.c
> @@ -129,6 +129,13 @@ int set_memory_encrypted(unsigned long vaddr, int numpages)
> int set_memory_decrypted(unsigned long vaddr, int numpages)
> {
> int i;
> +
> + /*
> + * uv_set_shared() exposes existing contents to the host; see the data
> + * leakage warning in share() in asm/uv.h. Clear private data first.
> + */
> + memset((void *)vaddr, 0, (size_t)numpages << PAGE_SHIFT);
> +
> /* make specified pages shared (swiotlb, dma_alloca) */
> for (i = 0; i < numpages; ++i) {
> uv_set_shared(virt_to_phys((void *)vaddr));
^ permalink raw reply [flat|nested] 25+ messages in thread
end of thread, other threads:[~2026-12-02 10:00 UTC | newest]
Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 9:54 [PATCH v11 00/23] coco: guest: Add a shared-granule allocator for host-shared memory Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 01/23] MAINTAINERS: Add CoCo memory sharing and encryption entry Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 02/23] mm: Add an allocator for CoCo shared memory Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 03/23] x86/mm: Use the non-zeroing decryption helper for VGA mappings Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 04/23] s390/mm: Clear memory before making it shared Aneesh Kumar K.V (Arm)
2026-12-02 9:57 ` Christian Borntraeger
2026-12-02 9:54 ` [PATCH v11 05/23] powerpc/pseries: Clear memory after " Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 06/23] arm64: Zero memory during private-to-shared transitions Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 07/23] x86/mm: Clear memory after successful decryption transitions Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 08/23] mm: Document zeroing by set_memory_decrypted() and update the fallback Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 09/23] drivers: hv: Remove redundant clearing after decryption Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 10/23] x86/kvmclock: Avoid clearing decrypted clock memory twice Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 11/23] dma-direct: Avoid redundant clearing of shared allocations Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 12/23] mm: Avoid zeroing CoCo shared allocations twice Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 13/23] irqchip/gic-v3-its: Resolve the default NUMA node explicitly Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 14/23] irqchip/gic-v3-its: Allocate shared tables using CoCo shared memory allocator Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 15/23] dma-contiguous: Derive shared alignment from DMA attributes Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 16/23] dma-pool: Align shared atomic pools to the CoCo sharing granule Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 17/23] dma-direct: Align CoCo shared DMA allocations to the shared granule size Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 18/23] swiotlb: Align shared IO TLB pools " Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 19/23] swiotlb: Use the common CoCo memory transition helpers Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 20/23] swiotlb: Reject misaligned restricted DMA pools for CoCo guests Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 21/23] dma-buf: system_heap: Limit scatterlist entries to the buffer size Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 22/23] dma-buf: system_heap: Allocate shared buffers using CoCo shared memory allocator Aneesh Kumar K.V (Arm)
2026-12-02 9:54 ` [PATCH v11 23/23] swiotlb: Make rounded shared pool capacity allocatable Aneesh Kumar K.V (Arm)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox