From: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>
To: linux-coco@lists.linux.dev
Cc: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Catalin Marinas" <catalin.marinas@arm.com>,
"Christian König" <christian.koenig@amd.com>,
"Jason Gunthorpe" <jgg@ziepe.ca>,
"Joerg Roedel" <joro@8bytes.org>, "Marc Zyngier" <maz@kernel.org>,
"Marek Szyprowski" <m.szyprowski@samsung.com>,
"Robin Murphy" <robin.murphy@arm.com>,
"Steven Price" <steven.price@arm.com>,
"Sumit Semwal" <sumit.semwal@linaro.org>,
"Suzuki K Poulose" <suzuki.poulose@arm.com>,
"Will Deacon" <will@kernel.org>,
"T.J. Mercier" <tjmercier@google.com>,
"Madhavan Srinivasan" <maddy@linux.ibm.com>,
"Heiko Carstens" <hca@linux.ibm.com>,
"Christian Borntraeger" <borntraeger@linux.ibm.com>,
"Sven Schnelle" <svens@linux.ibm.com>,
"Dave Hansen" <dave.hansen@linux.intel.com>,
"Kiryl Shutsemau" <kas@kernel.org>,
"Rick Edgecombe" <rick.p.edgecombe@intel.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Thomas Gleixner" <tglx@kernel.org>,
"Ingo Molnar" <mingo@redhat.com>,
"Borislav Petkov" <bp@alien8.de>,
"Haiyang Zhang" <haiyangz@microsoft.com>,
"Wei Liu" <wei.liu@kernel.org>,
"Dexuan Cui" <decui@microsoft.com>,
"Andy Lutomirski" <luto@kernel.org>,
"Peter Zijlstra" <peterz@infradead.org>,
"Alexander Gordeev" <agordeev@linux.ibm.com>,
"Gerald Schaefer" <gerald.schaefer@linux.ibm.com>,
"Vasily Gorbik" <gor@linux.ibm.com>,
x86@kernel.org, dri-devel@lists.freedesktop.org,
iommu@lists.linux.dev, linaro-mm-sig@lists.linaro.org,
linux-arm-kernel@lists.infradead.org,
linux-media@vger.kernel.org, linux-mm@kvack.org,
kvmarm@lists.linux.dev, patches@lists.linux.dev
Subject: [PATCH v11 14/23] irqchip/gic-v3-its: Allocate shared tables using CoCo shared memory allocator
Date: Wed, 2 Dec 2026 15:24:37 +0530 [thread overview]
Message-ID: <20261202095446.2029567-15-aneesh.kumar@kernel.org> (raw)
In-Reply-To: <20261202095446.2029567-1-aneesh.kumar@kernel.org>
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
next prev parent reply other threads:[~2026-12-02 9:58 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Aneesh Kumar K.V (Arm) [this message]
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)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261202095446.2029567-15-aneesh.kumar@kernel.org \
--to=aneesh.kumar@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=borntraeger@linux.ibm.com \
--cc=bp@alien8.de \
--cc=catalin.marinas@arm.com \
--cc=christian.koenig@amd.com \
--cc=dave.hansen@linux.intel.com \
--cc=decui@microsoft.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=gerald.schaefer@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=haiyangz@microsoft.com \
--cc=hca@linux.ibm.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@ziepe.ca \
--cc=joro@8bytes.org \
--cc=kas@kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-coco@lists.linux.dev \
--cc=linux-media@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=luto@kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=maddy@linux.ibm.com \
--cc=maz@kernel.org \
--cc=mingo@redhat.com \
--cc=patches@lists.linux.dev \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=rick.p.edgecombe@intel.com \
--cc=robin.murphy@arm.com \
--cc=steven.price@arm.com \
--cc=sumit.semwal@linaro.org \
--cc=suzuki.poulose@arm.com \
--cc=svens@linux.ibm.com \
--cc=tglx@kernel.org \
--cc=tjmercier@google.com \
--cc=wei.liu@kernel.org \
--cc=will@kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox