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 D3A91392C36; Mon, 6 Jul 2026 14:44:58 +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=1783349100; cv=none; b=Nto5ZCsn1skLF2Ffj4zsYIBJLlM1397/FnoLOm7BE1jzziJi6zwKLtpCDUHmrBZ9szZtqwNsLGhu3Id68/fQujuFgBI6zrLGmsD12YZvoZ9wBHu8PXNlcVgGsA9qDymtot5nWjKXB39f56xJqnJp3zPLdRVTgTeDvG0Ha7beL/A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783349100; c=relaxed/simple; bh=PH56BOtAy+0dmr/EksHt/OZDeCD+2GMl65NDITOxSrI=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=nj1GDJT6/idlve4W21VNUDaWZQEvzYWXxK341HZA4jRxFMA/M7lKAIIwoQvVC/eU+Cbr/O4ufJVrvpIHdJ6mkcrk7mP7onyCSELCu9+sdBkFpsFAaiYHL0Z3CjHmZAq3292jfhK8I3pBF5WCL7Rrc0mU/MZb7lMTasX07CsQ9C4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TjMOwfDM; 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="TjMOwfDM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 748561F00A3F; Mon, 6 Jul 2026 14:44:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1783349098; bh=0/x/qPU/Mc5BG2XPfLPZ5NC8qJYbU07GVymxY/B1eeU=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=TjMOwfDMZifMw3H2/8ppID+L8d/jyr9SeYD1M3fCMWNCqLc4SdT7FtiXFUC+MRf5Z nVVfCX7YGNBKvN8WwuubQqppAk5qoUeshcJXP0yZosi9Q78MXBtLv2zUnmyOHJOU9e 6zClMZTdBiB/FsW3AcAptE5qUQIYha35SNzednw9dSfqygAiRDOmj9SNTzxgRdD4X5 Ue49tvXg+5IZsw9dlB/871oEUsIsPjaAVqBbczl6tRGs+4mFhHW6ez1+Ank5rsbHLr /rObu0dZpclZ1eCHPSi9r5ebQtEM1DAP/xep9DsdB8qtE+I78yCJ7GhjKU0gyg5lGK Sk4axVoKxCFtA== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wgkZ6-00000001zfe-2hmG; Mon, 06 Jul 2026 14:44:56 +0000 Date: Mon, 06 Jul 2026 15:44:56 +0100 Message-ID: <86fr1wp47r.wl-maz@kernel.org> From: Marc Zyngier To: Aneesh Kumar K.V Cc: linux-coco@lists.linux.dev, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, Catalin Marinas , Jason Gunthorpe , Marek Szyprowski , Robin Murphy , Steven Price , Suzuki K Poulose , Thomas Gleixner , Will Deacon Subject: Re: [PATCH v5 02/10] irqchip/gic-v3-its: Align shared ITS allocations to the CoCo shared granule size In-Reply-To: References: <20260706060432.1375570-1-aneesh.kumar@kernel.org> <20260706060432.1375570-3-aneesh.kumar@kernel.org> <86ik6sp7fc.wl-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: aneesh.kumar@kernel.org, linux-coco@lists.linux.dev, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, catalin.marinas@arm.com, jgg@ziepe.ca, m.szyprowski@samsung.com, robin.murphy@arm.com, steven.price@arm.com, suzuki.poulose@arm.com, tglx@kernel.org, will@kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Mon, 06 Jul 2026 14:42:17 +0100, Aneesh Kumar K.V wrote: > > Marc Zyngier writes: > > > On Mon, 06 Jul 2026 07:04:24 +0100, > > "Aneesh Kumar K.V (Arm)" wrote: > >> > >> ITS tables allocated by the coco guest are shared with the hypervisor. > >> These allocations must satisfy the host shared-buffer granule size so that > >> the full converted range is safe for host access. > >> > >> Allocate ITS pages using a size rounded up to the shared granule size and > >> use the same allocation order when encrypting, decrypting and freeing the > >> memory. Also grow the ITT cache in shared-granule sized chunks instead of > >> assuming PAGE_SIZE is sufficient. > >> > >> Signed-off-by: Aneesh Kumar K.V (Arm) > >> --- > >> drivers/irqchip/irq-gic-v3-its.c | 17 +++++++++++------ > >> 1 file changed, 11 insertions(+), 6 deletions(-) > >> > >> diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c > >> index b57d81ad33a0..5d6d38aa0dae 100644 > >> --- a/drivers/irqchip/irq-gic-v3-its.c > >> +++ b/drivers/irqchip/irq-gic-v3-its.c > >> @@ -213,16 +213,17 @@ static gfp_t gfp_flags_quirk; > >> static struct page *its_alloc_pages_node(int node, gfp_t gfp, > >> unsigned int order) > >> { > >> + unsigned int alloc_order; > >> struct page *page; > >> int ret = 0; > >> > >> - page = alloc_pages_node(node, gfp | gfp_flags_quirk, order); > >> - > >> + alloc_order = get_order(mem_cc_align_to_shared_granule(PAGE_SIZE << order)); > >> + page = alloc_pages_node(node, gfp | gfp_flags_quirk, alloc_order); > >> if (!page) > >> return NULL; > >> > >> ret = set_memory_decrypted((unsigned long)page_address(page), > >> - 1 << order); > >> + 1 << alloc_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. > >> @@ -241,13 +242,16 @@ static struct page *its_alloc_pages(gfp_t gfp, unsigned int order) > >> > >> static void its_free_pages(void *addr, unsigned int order) > >> { > >> + int alloc_order; > >> + > >> + alloc_order = get_order(mem_cc_align_to_shared_granule(PAGE_SIZE << 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)) > >> + if (set_memory_encrypted((unsigned long)addr, 1 << alloc_order)) > >> return; > >> - free_pages((unsigned long)addr, order); > >> + free_pages((unsigned long)addr, alloc_order); > > > > The comments I had in [1] are still applicable. > > > > M. > > > > [1] https://lore.kernel.org/all/86zf2ozrb8.wl-maz@kernel.org/ > > > > I renamed it to alloc_order to make it clear that it refers to the > allocation order rather than the requested order. If you feel strongly > about not introducing another variable, I'll drop the new variable. I do. At the very least, to avoid you changing the type of the order in its_free_pages(). These things do matter. M. -- Without deviation from the norm, progress is not possible.