ITS command queues and tables are shared with the host in a confidential-computing guest. The ITS allocator currently assumes that the guest PAGE_SIZE is sufficient for both allocation alignment and private/shared state changes.
Route ITS page allocations through alloc_cc_shared_pages_node(). Keep the tracked table size based on the ITS-requested order. On release, reconstruct the common allocation metadata from the original ITS order and the architecture granule size so the same transitioned range and buddy order are used.
Signed-off-by: Aneesh Kumar K.V (Arm) aneesh.kumar@kernel.org --- drivers/irqchip/irq-gic-v3-its.c | 40 ++++++++++++-------------------- 1 file changed, 15 insertions(+), 25 deletions(-)
diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c index ac5507acb1a0..4814161df02e 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> @@ -214,25 +213,13 @@ static gfp_t gfp_flags_quirk; static struct page *its_alloc_pages_node(int node, gfp_t gfp, unsigned int order) { - struct page *page; - int ret = 0; - - page = alloc_pages_node(node, gfp | gfp_flags_quirk, order); - - if (!page) - return NULL; + struct cc_shared_pages mem;
- 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) + if (alloc_cc_shared_pages_node(node, gfp | gfp_flags_quirk, + PAGE_SIZE << order, &mem)) return NULL;
- return page; + return mem.page; }
static struct page *its_alloc_pages(gfp_t gfp, unsigned int order) @@ -242,13 +229,15 @@ static struct page *its_alloc_pages(gfp_t gfp, unsigned int order)
static void its_free_pages(void *addr, 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)) + struct cc_shared_layout layout; + struct cc_shared_pages mem; + + if (WARN_ON(cc_shared_calc_layout(PAGE_SIZE << order, &layout))) return; - free_pages((unsigned long)addr, order); + + mem.page = virt_to_page(addr); + mem.shared_size = layout.shared_size; + free_cc_shared_pages(&mem); }
static struct gen_pool *itt_pool; @@ -273,7 +262,8 @@ static void *itt_alloc_pool(int node, int size) if (!page) break;
- gen_pool_add(itt_pool, (unsigned long)page_address(page), PAGE_SIZE, node); + gen_pool_add(itt_pool, (unsigned long)page_address(page), + cc_shared_granule_size(), node); } while (!addr);
return (void *)addr;