From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 167C4606A330 for ; Fri, 4 Dec 2026 11:53:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=Qn4+2POJ; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ip4tdjMX DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=aJpsxJtLmJQ1t5ISZNBI/tJB5lfF4votenB/JzjkAMI=; b=Qn4+2POJTMc6Hn3Cc6J2r1Kuu1 4Wc3roLhc6tGV5UoI5+KtfADUT5cr8vTdqOTurYx4oisJnshjudql+4f9bTsLeY3nF+NYlJXu0m+S Dtnr+MP3vBoZ2chXW5h+p9wKsCfSYM1XFS1n22KxfP6HTLy1bv2oDWfifm1x+Fw2qCDeHlYOOEFr+ bcT9etOlZF05d5EUjqtpG1dJEN/6HPft21/skG6NVNrm2iqR2AbSJ+xJGFlKml/sPYKurM10oXDnf t68i4PegrkmiuYsoQslBygMt1ZV8kN2Opzcy7XJYB0emPWDpPNGkNV+E4y8oy7FPI2zBPuDIin97O WgnVCmug==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZRql-00000000B9x-02Sj; Fri, 04 Dec 2026 11:53:15 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZRij-00000000ASE-3Cy6 for linux-arm-kernel@lists.infradead.org; Fri, 04 Dec 2026 11:47:04 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 8FE5963070; Fri, 4 Dec 2026 11:44:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6DDFE1F00897; Fri, 4 Dec 2026 11:44:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796384696; bh=aJpsxJtLmJQ1t5ISZNBI/tJB5lfF4votenB/JzjkAMI=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=ip4tdjMXzZlZjTpAkiWnsNvavgxt5Hws+fOiP8AmHuntm1B9fQpiTSLvvExD2GBU/ Bv+YAZd3WXBX1lRcfUFI6bUA9lJaxofmoMdEs+LPyMObWTXBnsfILMexc0GAI0jfxT F+enRysOSLk/vFrZlBGfPiaHPxeMQ1O4clWgAB5L5AhehpeS8Wc1d/rE811CWGsJgV TuvoScuZCsVTvSwvuTyqs2y/qroM3cTpne+j60gIhCe6x1nMIFTKeA0OJuFHqPQ6N1 4M7cpsE/t5Qc0aqFmb4dxYWSa2sn8cXORkLpMQXLtZMS5jNdY3QMbt/w5DPUHxwOqg SQc48V6Vs6AmQ== Date: Fri, 4 Dec 2026 12:44:52 +0100 From: Lorenzo Pieralisi To: Zenghui Yu Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, maz@kernel.org, tglx@kernel.org, radu@rendec.net, wangzhigang17@huawei.com Subject: Re: [PATCH] irqchip/gic-v5: Replace the dead linear IST ID cap with a build-time check Message-ID: References: <20261204092042.1457-1-yuzenghui@huawei.com> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261204092042.1457-1-yuzenghui@huawei.com> X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-16.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Fri, Dec 04, 2026 at 05:20:42PM +0800, Zenghui Yu wrote: > gicv5_irs_init_ist_linear() has a cap intended to keep the linear IST > within the kmalloc() limit. It is broken in two ways: > > (a) It adds @istsz instead of subtracting it when computing the ID bits; > > (b) and it only updates its local lpi_id_bits, so the caller keeps using > the original, uncapped value when publishing the LPI ID space > (gicv5_init_lpis()). Bah. See below. Thank you for spotting it and fixing it. > The branch is dead code, though. With the current LPI_ID_BITS_LINEAR (12), Yep, that's a symptom of how useless the current check is, (a) and (b) are the obvious consequences. > a linear IST is used with at most 14 LPI ID bits. On 1-level-only HW, > lpi_id_bits is at most max(LPI_ID_BITS_LINEAR, MIN_LPI_ID_BITS), and > MIN_LPI_ID_BITS is at most 14 as per the specification. On 2-level-capable > HW, a linear table is used only when lpi_id_bits fits in > ((10-ISTSZ) + (2*L2SZ)), which is at most 14 as well. A table with 14 LPI > ID bits and 16-byte ISTEs is 256KB, while KMALLOC_MAX_SIZE is 4MB on arm64 > with 4K pages and larger with 16K/64K pages. > > Rather than fixing the dead code, remove the cap and add a build-time > assertion: the maximum possible linear table, derived from > GICV5_IRS_LINEAR_MAX_ID_BITS and the largest ISTE, must fit in > KMALLOC_MAX_SIZE. This catches a future increase of LPI_ID_BITS_LINEAR or a > page/MAX_ORDER configuration that would make the table too large. > > Signed-off-by: Zenghui Yu > --- > drivers/irqchip/irq-gic-v5-irs.c | 46 +++++++++++++++++------------- > include/linux/irqchip/arm-gic-v5.h | 2 ++ > 2 files changed, 28 insertions(+), 20 deletions(-) > > diff --git a/drivers/irqchip/irq-gic-v5-irs.c b/drivers/irqchip/irq-gic-v5-irs.c > index 9d60f474aa4f..79176a9a7c2f 100644 > --- a/drivers/irqchip/irq-gic-v5-irs.c > +++ b/drivers/irqchip/irq-gic-v5-irs.c > @@ -7,7 +7,6 @@ > > #include > #include > -#include > #include > #include > > @@ -16,11 +15,32 @@ > > /* > * Hardcoded ID_BITS limit for systems supporting only a 1-level IST > - * table. Systems supporting only a 1-level IST table aren't expected > - * to require more than 2^12 LPIs. Tweak as required. > + * table. Such systems aren't expected to require more than 2^12 LPIs. > + * Tweak as required; raising it above 14 also raises the size bound > + * checked below. Nit: 14 seems to come out of thin air. Maybe we can move the two defines below together with the single comment (very clear) that you wrote below explaining the reasoning as a whole. > */ > #define LPI_ID_BITS_LINEAR 12 > > +/* > + * Upper bound of LPI ID bits used by a linear IST. > + * > + * On hardware that only supports a 1-level IST, gicv5_irs_init_ist() > + * asks for at most max(LPI_ID_BITS_LINEAR, MIN_LPI_ID_BITS) LPI ID > + * bits; MIN_LPI_ID_BITS is at most 14 as per the architecture. On > + * hardware with 2-level IST support, it uses a linear table only when > + * ((10-ISTSZ) + (2*L2SZ)) covers the ID space, which is at most 14 as > + * well. > + * > + * LPI_ID_BITS_LINEAR may ask for more than 14; the assertion makes sure > + * the maximum possible table fits in one kmalloc() chunk. > + */ > +#define GICV5_IRS_LINEAR_MAX_ID_BITS \ > + ((LPI_ID_BITS_LINEAR) > 14 ? (LPI_ID_BITS_LINEAR) : 14) > + > +static_assert(BIT(GICV5_IRS_LINEAR_MAX_ID_BITS + 2 + > + GICV5_IRS_IST_CFGR_ISTSZ_MAX) <= KMALLOC_MAX_SIZE, > + "GICv5 linear IST does not fit in KMALLOC_MAX_SIZE"); Nit: if I really had to be picky this caters for the worst case where MIN_LPI_ID_BITS is at its max level and so is ISTSZ, which I don't necessarily expect but this patch makes sense to me, certainly more than current code. Thanks, Lorenzo