Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp891122rwb; Fri, 23 Sep 2022 05:41:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6xzIENM6zY9rrywzvWCBV8HsjC5P+s3UotbCRkj6MagR6ouAAhiXSOiiqnOoi+l2LkHilT X-Received: by 2002:a17:907:3f19:b0:781:e579:46c2 with SMTP id hq25-20020a1709073f1900b00781e57946c2mr6844488ejc.382.1663936892804; Fri, 23 Sep 2022 05:41:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663936892; cv=none; d=google.com; s=arc-20160816; b=q0olnFeyrdPsnbA6d6rPnjisyqF/ZnSpi9b5FQR9OZxNUoJOoHp1G8MRZs9xpuOvPT doB0Ayyd9gh5LUkxvvioW12FuCMzVW6CFJt0wCNxjeX3GKhoSus/UxGiu59UDFMC4zlF +7ez6oaUcfWI/6MG89Xye2w9XbhZot2Lc1iC/KLETW/DSZdSZXmLHH3qUUNpmAnobUij 5z+JcUDKuo380swPGzSjeCkRJzHDMfpjXe2viSB+9+DDMqR0b4ZWDVRPyLX5qsF8uKCy DMt1+GQjyL2cYmf5pKEp6ALaU0ZmDbqeULZI33u/DDjchlEsCgcGiVlKkB7wEVEiATKx 9GRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=qbQ7W0x+UY1iesezie5O9hqvHCE2vvle1PNDgZ97+kU=; b=dvu9aKJn34PkwNOvHhDGGIlUzA0ttr7aolCG7gQSSju5b2rIqjW80tnpljfA1a/uan fdA6U96MhmuZSdDzdR7DSTBRVpd/87TrugydQDkXfscyb8/czwiJeOAsGwGL38/tF6ol Hfr/0N3FHVOsZYjAU3jpzdCRrSVVvfJKY0hYKDz9mT14frU1c6ddRuCDWj0QShqmXGKC oCylL3kbsb8eEYDFsPFdaZo8nR/MoEWIHecQ2amW35mW/Yu6CwSuWTyqkHhm9Nm6v2f5 EXQkIp0HMrWuBTjx0An7S0TShM0RTx9CoRNZ7kjK8Yi1szN0n0J8faS9BaXmh8YDRaPl Z28Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s16-20020a170906455000b00780cb1272eesi6924878ejq.466.2022.09.23.05.40.49; Fri, 23 Sep 2022 05:41:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231578AbiIWM27 (ORCPT + 99 others); Fri, 23 Sep 2022 08:28:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232124AbiIWM20 (ORCPT ); Fri, 23 Sep 2022 08:28:26 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7419513C84D for ; Fri, 23 Sep 2022 05:24:25 -0700 (PDT) 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220922215715.13345-1-will@kernel.org> X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 >