From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 21D58C6FA8B for ; Fri, 23 Sep 2022 12:25:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Cf3PiLP46wVjlPMXBWasYKMmZkk1iUieqxD8kJG/sdM=; b=dQTU9k40cyeW6O lOUtOIUY/ZULxdBlMjVrUYip8vN2N+vPzl8NAPkGDAKRMwvMcYhSxbiF52C/baCbjEXlmgpBqWcjQ n0Jm3J6GSoVbecUebcGAfaa9RkxDVOrgmv5z1WZBpGeEy+jhug5TRxY9T+n3Cw41/xRdl+9C/sOBH gosiHeyn1N1LS/BscE1/iVSZWirwQ+ifMMIBrUXSjb6X8urLE/Kv3/UHGzRkO9AkFLqeTjKqxxTEe 6zwYk83HLF/IH6wLpXgn9jKEiM/gZACYoaosyd7u+8VniXIwSC8TTGJCt4wrJuW9naUbygSTlEoAm k9pLk9AwD6AhBQTZigJQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1obhjJ-0048t4-Ni; Fri, 23 Sep 2022 12:24:29 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1obhjG-0048s2-NL for linux-arm-kernel@lists.infradead.org; Fri, 23 Sep 2022 12:24:28 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 56DEA1042; Fri, 23 Sep 2022 05:24:31 -0700 (PDT) Received: from FVFF77S0Q05N (unknown [10.57.80.223]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8B5E63F73D; Fri, 23 Sep 2022 05:24:23 -0700 (PDT) Date: Fri, 23 Sep 2022 13:24:20 +0100 From: Mark Rutland To: Will Deacon Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Sami Tolvanen , "Mohan Rao .vanimina" , Kees Cook , Nathan Chancellor Subject: Re: [PATCH] vmlinux.lds.h: CFI: Reduce alignment of jump-table to function alignment Message-ID: References: <20220922215715.13345-1-will@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220922215715.13345-1-will@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220923_052426_830655_3A62F3DC X-CRM114-Status: GOOD ( 20.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Sep 22, 2022 at 10:57:15PM +0100, Will Deacon wrote: > Due to undocumented, hysterical raisins on x86, the CFI jump-table > sections in .text are needlessly aligned to PMD_SIZE in the vmlinux > linker script. When compiling a CFI-enabled arm64 kernel with a 64KiB > page-size, a PMD maps 512MiB of virtual memory and so the .text section > increases to a whopping 940MiB and blows the final Image up to 960MiB. > Others report a link failure. > > Since the CFI jump-table requires only instruction alignment, reduce the > alignment directives to function alignment for parity with other parts > of the .text section. This reduces the size of the .text section for the > aforementioned 64KiB page size arm64 kernel to 19MiB for a much more > reasonable total Image size of 39MiB. > > Cc: Sami Tolvanen > Cc: Mark Rutland > Cc: "Mohan Rao .vanimina" > Cc: Kees Cook > Cc: Nathan Chancellor > Link: https://lore.kernel.org/all/CAL_GTzigiNOMYkOPX1KDnagPhJtFNqSK=1USNbS0wUL4PW6-Uw@mail.gmail.com/ > Fixes: cf68fffb66d60 ("add support for Clang CFI") > Signed-off-by: Will Deacon Thanks for this! I gave this a spin atop v6.-rc3 defconfig with: * CONFIG_ARM64_64K_PAGES=y * CONFIG_LTO_CLANG_THIN=y * CONFIG_CFI_CLANG=y The sizes clearly speak for themselves: | % ls -al *-v6.0-rc3-64K-CFI* | -rwxr-xr-x 1 mark mark 959693312 Sep 23 13:13 Image-v6.0-rc3-64K-CFI | -rwxr-xr-x 1 mark mark 38781440 Sep 23 13:19 Image-v6.0-rc3-64K-CFI-patched | -rwxr-xr-x 1 mark mark 1378631080 Sep 23 13:13 vmlinux-v6.0-rc3-64K-CFI | -rwxr-xr-x 1 mark mark 453015376 Sep 23 13:19 vmlinux-v6.0-rc3-64K-CFI-patched ... and before and after applying the patch, the kernel booted fine under QEMU (in TCG mode, as Cortex-A53). I see that in scripts/module.lds.S we place the CFI bits into the .text section, and that's only aligned to PAGE_SIZE, so we don't have a similar issue for modules. FWIW: Reviewed-by: Mark Rutland Tested-by: Mark Rutland Mark. > --- > include/asm-generic/vmlinux.lds.h | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h > index 7515a465ec03..7c90b1ab3e00 100644 > --- a/include/asm-generic/vmlinux.lds.h > +++ b/include/asm-generic/vmlinux.lds.h > @@ -543,10 +543,9 @@ > */ > #ifdef CONFIG_CFI_CLANG > #define TEXT_CFI_JT \ > - . = ALIGN(PMD_SIZE); \ > + ALIGN_FUNCTION(); \ > __cfi_jt_start = .; \ > *(.text..L.cfi.jumptable .text..L.cfi.jumptable.*) \ > - . = ALIGN(PMD_SIZE); \ > __cfi_jt_end = .; > #else > #define TEXT_CFI_JT > -- > 2.37.3.998.g577e59143f-goog > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel