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 95185606A330 for ; Fri, 4 Dec 2026 09:21:08 +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=RTAbgVoy; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.a=rsa-sha256 header.s=dkim header.b=YsiMqNfl 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:Content-Type: Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject:CC:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Unsubscribe-Post:List-Owner; bh=zOZnbMMxpV+2WnQDUddqDVX8c445CBOB3A+Rn/v1kbU=; b=RTAbgVoyklxiUyUGz7E2PwTokH ZVGL7VPYJZu5YjwTswO3sncbz+CxWHIFPhl/BfyQ4ZhNle+bThWce+qPtrKIRn7XNZxFWjVWpavlw c4HuK5tl8KwyDVZ8XdHnfrPgJor+CwR5gHhFMtj+IsmfAtnCt+cfd44165WpudwD5pkeRmnOCln+6 Qbr5JRLoqokWr1EjnT6oPyCzImS8Y4D0mT1r9yWLjh8VxgKiv7LhWjtcYz09jYvSoFqYA6yNEHF7U TVKKTQFIwrW2ZuJMBwUaUBmRXfjBkdIhgDvIbPiDRZBtY+7TRIpJpgvLEi7fCi482kokXJjGCd/zD AaTiMIPw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZPTR-0000000HKxa-2Ysq; Fri, 04 Dec 2026 09:21:01 +0000 Received: from canpmsgout10.his.huawei.com ([113.46.200.225]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZPTO-0000000HKvM-15nl for linux-arm-kernel@lists.infradead.org; Fri, 04 Dec 2026 09:21:00 +0000 dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=zOZnbMMxpV+2WnQDUddqDVX8c445CBOB3A+Rn/v1kbU=; b=YsiMqNfldLMuRSkJ5c+BRhDNHRCKFhgh2ecDTILU+hmHANYBErMXwrVTdQk+PC3pzM/MtNwM3 g7MXwtMjGJCZuCa3v5H8QrYvlHz3DgprlFngXvdHsBbBr0h0/aU9VssUtLIb/scfNDHb7BbuB39 ELnHL2BorrRKOGcNUfi2XQg= Received: from mail.maildlp.com (unknown [172.19.163.214]) by canpmsgout10.his.huawei.com (SkyGuard) with ESMTPS id 4jgmCZ5j7Cz1K9WT; Fri, 4 Dec 2026 17:19:22 +0800 (CST) Received: from whupemo200006.china.huawei.com (unknown [7.152.185.252]) by mail.maildlp.com (Postfix) with ESMTPS id 9880F4056C; Fri, 4 Dec 2026 17:20:47 +0800 (CST) Received: from DESKTOP-8RFUVS3.china.huawei.com (10.174.178.219) by whupemo200006.china.huawei.com (7.152.185.252) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.56; Fri, 4 Dec 2026 17:20:46 +0800 From: Zenghui Yu To: , CC: , , , , , Zenghui Yu Subject: [PATCH] irqchip/gic-v5: Replace the dead linear IST ID cap with a build-time check Date: Fri, 4 Dec 2026 17:20:42 +0800 Message-ID: <20261204092042.1457-1-yuzenghui@huawei.com> X-Mailer: git-send-email 2.23.0.windows.1 X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: kwepems200002.china.huawei.com (7.221.188.68) To whupemo200006.china.huawei.com (7.152.185.252) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261204_012059_027178_6CDED217 X-CRM114-Status: GOOD ( 21.87 ) X-Spam-Score: -2.8 (--) 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=-19.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,USER_AGENT_GIT 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 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()). The branch is dead code, though. With the current LPI_ID_BITS_LINEAR (12), 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. */ #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"); + static DEFINE_PER_CPU_READ_MOSTLY(struct gicv5_irs_chip_data *, per_cpu_irs_data); static LIST_HEAD(irs_nodes); @@ -78,20 +98,6 @@ static int __init gicv5_irs_init_ist_linear(struct gicv5_irs_chip_data *irs_data n = max(5, lpi_id_bits + 1 + istsz); l2istsz = BIT(n + 1); - /* - * Check memory requirements. For a linear IST we cap the - * number of ID bits to a value that should never exceed - * kmalloc interface memory allocation limits, so this - * check is really belt and braces. - */ - if (l2istsz > KMALLOC_MAX_SIZE) { - u8 lpi_id_cap = ilog2(KMALLOC_MAX_SIZE) - 2 + istsz; - - pr_warn("Limiting LPI ID bits from %u to %u\n", - lpi_id_bits, lpi_id_cap); - lpi_id_bits = lpi_id_cap; - l2istsz = KMALLOC_MAX_SIZE; - } ist = kzalloc(l2istsz, GFP_KERNEL); if (!ist) @@ -317,9 +323,9 @@ static int __init gicv5_irs_init_ist(struct gicv5_irs_chip_data *irs_data) * number of IDs. * * For 1-level tables, we should support a number of bits that - * is >= min_lpi_id_bits but cap it to LPI_ID_BITS_LINEAR lest - * the level 1-table gets too large and its memory allocation - * may fail. + * is >= min_lpi_id_bits but cap it to LPI_ID_BITS_LINEAR to keep + * the table small; the worst case is checked at build time, see + * GICV5_IRS_LINEAR_MAX_ID_BITS. */ if (two_levels) { lpi_id_bits = idr2_id_bits; diff --git a/include/linux/irqchip/arm-gic-v5.h b/include/linux/irqchip/arm-gic-v5.h index 299e75bc9525..1210c6de8452 100644 --- a/include/linux/irqchip/arm-gic-v5.h +++ b/include/linux/irqchip/arm-gic-v5.h @@ -252,6 +252,8 @@ #define GICV5_IRS_IST_CFGR_ISTSZ_8 0b01 #define GICV5_IRS_IST_CFGR_ISTSZ_16 0b10 +#define GICV5_IRS_IST_CFGR_ISTSZ_MAX GICV5_IRS_IST_CFGR_ISTSZ_16 + #define GICV5_IRS_IST_CFGR_L2SZ_4K 0b00 #define GICV5_IRS_IST_CFGR_L2SZ_16K 0b01 #define GICV5_IRS_IST_CFGR_L2SZ_64K 0b10 -- 2.33.0