From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F330246F4BB; Mon, 21 Sep 2026 14:49:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790002186; cv=none; b=RXAh+HyKZ2mbozCwjqEmAfEazA4AjcFNOcu0vMxKI6pGzu8xa96ItRleetNH+xPQU6tc/rfQaKoiz/H08pX5rKnby2cSbsWlzg+QSQWWUgvcFv7aGbtUb4b3q7YhieXKTWpXxgzAChsm1fj8udUTd299Bko0Ub98/dDOLSgvOd0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790002186; c=relaxed/simple; bh=UzoVCxnriQMKM9/Fv4JmiHZNIyxD4P6v8oevkMOlQ0g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fGCh/iVKjCXjjArbrdNiv4XQ5KFi/dB8DXUGd30YtNc4qDkEvoPt+1Ak++yYmG/xSf6MC1d0uPP47nJnPnrLCQf8yhwrNasJha2NqSeTUMlQXijgh+qTAZJrUc2mVxEiFbOAJ5433SpZTsIYKEdTkcU7uUQd6bmv/JWA6RedNrE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Kc8P2140; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Kc8P2140" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 25CA71F00893; Mon, 21 Sep 2026 14:49:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1790002184; bh=HSe1gOHGix6Y2SkfM68PVLIwg5C/r0qNlcWeNP5Fwxs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Kc8P2140ujn+VDpWuuA0syxxlPiR5Dl/sChZvXp0DKgAkTCax/cLTbAp8LB0IWXAB R4hVFA8/L+PQBfe/eKPRAHKK3vjVTVdKREnLY52b3114xvDk3GOmnJLuphnn5R+2sm uOTWUiy5I/4uo1Ehng06km71pPSO/H3d3vc7lO+Gx1bVyxhyybF3v6MrEd5Hy3uB/W f1R2+b/CTIVMQSZLAmFcf1ixeWZgNZEF7GsQ3UxDkz+aw0go90MnrLv0EykJ1GFlpI enwffS8MUCShd5hX7jN0XvuJEjTM/ibsrm8B2tGuAGjBx+1oFq7lO33iYzkp/Ypz4I NeRaMoJfvCMAw== From: "Aneesh Kumar K.V (Arm)" To: linux-coco@lists.linux.dev, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev Cc: "Aneesh Kumar K.V (Arm)" , Andrew Morton , Catalin Marinas , christian.koenig@amd.com, Jason Gunthorpe , Joerg Roedel , Marc Zyngier , Marek Szyprowski , Robin Murphy , Steven Price , Sumit Semwal , Suzuki K Poulose , Thomas Gleixner , Will Deacon , dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH v7 05/13] irqchip/gic-v3-its: Allocate shared tables using CoCo shared memory allocator Date: Mon, 21 Sep 2026 20:18:39 +0530 Message-ID: <20260921144847.501151-6-aneesh.kumar@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260921144847.501151-1-aneesh.kumar@kernel.org> References: <20260921144847.501151-1-aneesh.kumar@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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) --- 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 #include #include +#include #include #include #include @@ -19,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -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; -- 2.43.0