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 2564BC77B61 for ; Fri, 28 Apr 2023 18:59:17 +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-Type: Content-Transfer-Encoding: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=9dIpRx6rFA/H3Znh9vyyjrEUprNUa3C69zIiE5yYqFk=; b=PkbjQSNjTW1hGERGzpvalBH4Cs rOb4+BodwRoYoEAJ6zsfuEV49VCl/bAIqnWBRFJcJkD0pFHEJ9JvkwuwkcWe7YyhMFGtlAe2roon5 pZoj/Z4EJV16SwOO1uzS4kbMcUm2hV9AC1Jbu+xV+lB7hoqJXz0IJGw8oYE+Nzq1a1uAAh4UmRVNN qxKsXcYV34J5BanmjsFooqXWjdzyt7V0mGRF9eOqP6f1SsZJ38gUUYllnZySNzTEi5coq0suvOtBj RsNnLmdVPhb2pZjgcFq4H2wrYawc8Jxn1YIkmdWkMiC++qjFQDrYvjit4XIDHna2TMA25qcQv5UBZ 8ukQu2ZQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1psTIa-00BZTh-2i; Fri, 28 Apr 2023 18:58:28 +0000 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1psTIW-00BZRU-2J for linux-arm-kernel@lists.infradead.org; Fri, 28 Apr 2023 18:58:26 +0000 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1a7ff4a454eso557015ad.0 for ; Fri, 28 Apr 2023 11:58:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682708298; x=1685300298; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=HWv7yMEpyQoEe4U7b9znrOaiU21oK5MGaoZZWk9b61k=; b=mHJf/vRsxzIbrsWPHnWcur9NXpHbxre+RNm1R0jSsB1HV9e+qgYGsnabCuOKuMBkdl glBr04imslXb11CooqamPIOJxZpO02LUcuU7UZrf3WAtVJ9FrSJYUz3SdK8qU+7imZj9 uzBUz6M++X5VcqmqzffnPFss0WFhULX+DdwPemtpobY5aHIYlutJio9Tme6VKbwY5KKD XGBeeGYFkU5jFxH8o+hoSICxyLKbIXb0M/yBjD6E0Wq+WSFpxJxszt7C31o8mcIVVsBO 0ZOwUFuVvQ0tlQUdXQmO2DEexdAzgWM6AkOFAB8xBtPgIO9qozuLQe16/vcdx6KklGzs 5V/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682708298; x=1685300298; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=HWv7yMEpyQoEe4U7b9znrOaiU21oK5MGaoZZWk9b61k=; b=PgZG4/XjgfE2VBju3/CSucDi1TgANhrMQygK/wvqCAqSK4A/EhkVqBM/l0bKsjxVy9 lXR3AWI1frVodjVmUfqnAc9AT3DQuVV99oJ/3W+iAvlRQpeI2T/VtAeZfYA46ipXTnzm F/bSDh693vABnvGjQICuZ2eKwieDFLKMMglS/zF9R9MuLDER54tVxK69cQg9hgxAklt5 SJ+fs56rj8L2tl5LCydtYwEOSMA+DdzO/f92Ew7wxG+8sKiDhtSUXvCX0VDfvvBG/ImW wp+6OiKMsrSeeruUZgpNYmztqtOVP2075b6t1kem0TouWJlT5JxPSWJU5sXaqCuUX/Pi gjZA== X-Gm-Message-State: AC+VfDx2MHBdfsSaNWyXu8RABp+xakTl4ADO8yzmR8rAxEFLz8eO7ACf tzaUICEZpPKuyVfNXeBnagXxEQ== X-Google-Smtp-Source: ACHHUZ4NfddWa+12nWfyZP9HV+HNaMWf1B5NzO1GgLklmNC/tYXEeCS4jisgnpTvqBLG28RpcAGMBg== X-Received: by 2002:a17:902:e809:b0:19a:5a9d:3c with SMTP id u9-20020a170902e80900b0019a5a9d003cmr27368plg.16.1682708297588; Fri, 28 Apr 2023 11:58:17 -0700 (PDT) Received: from google.com (25.11.145.34.bc.googleusercontent.com. [34.145.11.25]) by smtp.gmail.com with ESMTPSA id y3-20020a634943000000b0051b460fd90fsm13426512pgk.8.2023.04.28.11.58.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Apr 2023 11:58:17 -0700 (PDT) Date: Fri, 28 Apr 2023 18:58:14 +0000 From: Fangrui Song To: Ard Biesheuvel Cc: Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Bill Wendling , Nick Desaulniers Subject: Re: [PATCH] arm64: lds: move .got section out of .text Message-ID: <20230428185814.mmnb3jafp7fnwdrh@google.com> References: <20230428050442.180913-1-maskray@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230428_115824_758106_36B203F5 X-CRM114-Status: GOOD ( 21.57 ) 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-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 2023-04-28, Ard Biesheuvel wrote: >Hello Fangrui, Hello Ard, thank you for the rapid response. >On Fri, 28 Apr 2023 at 06:05, Fangrui Song wrote: >> >> Currently, the .got section is placed within the output section .text. >> However, when .got is non-empty, the SHF_WRITE flag is set when linked >> by lld. GNU ld recognizes .text as a special section and ignores the >> SHF_WRITE flag. By renaming .text, we can also get the SHF_WRITE flag. >> >> Conventionally, the .got section is placed just before .got.plt (which >> should be empty and omitted in the kernel). Therefore, we move the .got >> section to a conventional location (between .text and .data) and remove >> the unneeded `. = ALIGN(16)`. >> >> Signed-off-by: Fangrui Song >> --- >> arch/arm64/kernel/vmlinux.lds.S | 20 ++++++++++---------- >> 1 file changed, 10 insertions(+), 10 deletions(-) >> >> diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S >> index b9202c2ee18e..2bcb3b30db41 100644 >> --- a/arch/arm64/kernel/vmlinux.lds.S >> +++ b/arch/arm64/kernel/vmlinux.lds.S >> @@ -181,18 +181,8 @@ SECTIONS >> KPROBES_TEXT >> HYPERVISOR_TEXT >> *(.gnu.warning) >> - . = ALIGN(16); >> - *(.got) /* Global offset table */ >> } >> >> - /* >> - * Make sure that the .got.plt is either completely empty or it >> - * contains only the lazy dispatch entries. >> - */ >> - .got.plt : { *(.got.plt) } >> - ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18, >> - "Unexpected GOT/PLT entries detected!") >> - >> . = ALIGN(SEGMENT_ALIGN); >> _etext = .; /* End of text section */ >> >> @@ -247,6 +237,16 @@ SECTIONS >> >> . = ALIGN(SEGMENT_ALIGN); >> __inittext_end = .; >> + >> + .got : { *(.got) } > >This is the .init region, which gets freed and unmapped after boot. If >the GOT is non-empty, it needs to remain mapped, so we cannot place it >here. Thanks. I did not know the constraint. >We have the same issue with the .rodata section, which incorporates >variables marked as __ro_after_init, which are not const qualified. So >given that .rodata is already emitted as WA, and we cannot do anything >about that, let's move the GOT in there. Yes, writable .data..ro_after_init and __jump_table sections in include/asm-generic/vmlinux.lds.h (#define RO_DATA(align)) makes the output section .rodata writable. Perhaps this is very difficult to fix, and we will have writable .rodata for a long time. What do you think of moving .got/.got.plt immediately before .data? I want to place .got/.got.plt before the guaranteed-writable sections, not some sections which are "unfortunately" writable (.rodata, __modver, .hyp.rodata, .rodata.text, etc). For userspace programs, either linked with GNU ld or lld, .got/.got.plt are usually immediately before .data . diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S index b9202c2ee18e..48bd7c25b6ab 100644 --- a/arch/arm64/kernel/vmlinux.lds.S +++ b/arch/arm64/kernel/vmlinux.lds.S @@ -181,18 +181,8 @@ SECTIONS KPROBES_TEXT HYPERVISOR_TEXT *(.gnu.warning) - . = ALIGN(16); - *(.got) /* Global offset table */ } - /* - * Make sure that the .got.plt is either completely empty or it - * contains only the lazy dispatch entries. - */ - .got.plt : { *(.got.plt) } - ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18, - "Unexpected GOT/PLT entries detected!") - . = ALIGN(SEGMENT_ALIGN); _etext = .; /* End of text section */ @@ -286,6 +276,15 @@ SECTIONS __initdata_end = .; __init_end = .; + .got : { *(.got) } + /* + * Make sure that the .got.plt is either completely empty or it + * contains only the lazy dispatch entries. + */ + .got.plt : { *(.got.plt) } + ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18, + "Unexpected GOT/PLT entries detected!") + _data = .; _sdata = .; RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN) -- 2.40.1.495.gc816e09b53d-goog >> + /* >> + * Make sure that the .got.plt is either completely empty or it >> + * contains only the lazy dispatch entries. >> + */ >> + .got.plt : { *(.got.plt) } >> + ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18, >> + "Unexpected GOT/PLT entries detected!") >> + >> __initdata_begin = .; >> >> init_idmap_pg_dir = .; >> -- >> 2.40.1.495.gc816e09b53d-goog >> _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel