From patchwork Wed Feb 5 07:16:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 862166 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:11cb:b0:385:e875:8a9e with SMTP id i11csp800134wrx; Wed, 5 Feb 2025 05:16:23 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCW2k7aElL8Va5lEVB1yrNfpTUJ6wi/ZjYstBUUlUpTfCKUrciiHlPrk5ZXGPX5Gx+Abp+7Xiw==@linaro.org X-Google-Smtp-Source: AGHT+IEMZB3SK/tscZzBb6oQjUqc978JNkfgU73FJvpC0Y8vHbEpeKoP03U3a1mIZKmuNJMpA17D X-Received: by 2002:a17:907:94c7:b0:ab6:f4e0:320a with SMTP id a640c23a62f3a-ab75e265100mr263719166b.21.1738761382942; Wed, 05 Feb 2025 05:16:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1738761382; cv=none; d=google.com; s=arc-20240605; b=igrQ6UUf+8jommcHbWvBOuA2dZXhSVs58zp+InVquUQuG4sZIs9KqgcGQ3HL0jG1S3 bAB7Nge9D+rlFWHL6h1Qny+hwbJjaTNPEfsC6+IFOcr/IJNygOqDB3K/DXI+lwv1GALV Styn+FkgzBTRCwXOmf4/fUjmWMjT2XPn+mCvv7gzd2wxRw2dm8qL/2Rta9lKKaHJ3T49 g5OFs/cAlTL2Ck+Ky13EQ/IFnBi5TsTG3IIGyH+Wu4oKaOto/69Z5ocjBaABb0QjfLp+ /qjQiteoo61GszefiiFyrcRkmNd8VDl7pQZcyXBpC1yB6Ib/GrQI2JbpPIjvyXhssO7z xR+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VUGPK86DWi9+WCYvLPgrYc5wTB8ycSj3VW2D0BfVeDA=; fh=5VI7fLN8pcuuzyzNF8Z0obiI6F8I7YIaqhS+91Jv8PU=; b=k+r87rMVZpZoY6atrJ+0TiJ2R6UouEL95AJMQUkiprA7hVZdMco5VthLBx/v71x0iy PptqfaW0Dezdlbh/BqvH2XvQOILdKw92TqXoFbWd91OzK1K7JvRIIVUgkJKSxqVcmbiu YYKgcwkW/dRzwvpTP1HJXD0WQZ92nunvm1cAyHC9cW6xp12HsgSdQqbIlHT8kXMUX7aV lfHTYamh760igYs0GLGyT29AYNW4YCOA5+ESe0AVMxBh8ppTk2NRCtcODNdmeGseMQby DG7OjjIyLRh4/x6V0H3ri9+pamvgSmr2+n+9tq1SnuWwSHLLO5ZLF8XW2TlmiS8M+g00 qDcQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="khl/pd3i"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id a640c23a62f3a-ab75931fd1asi194490266b.648.2025.02.05.05.16.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Feb 2025 05:16:22 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="khl/pd3i"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C32848081E; Wed, 5 Feb 2025 14:15:29 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="khl/pd3i"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 43067805D7; Wed, 5 Feb 2025 08:17:45 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3B9A380207 for ; Wed, 5 Feb 2025 08:17:43 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-aaeef97ff02so1002361466b.1 for ; Tue, 04 Feb 2025 23:17:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1738739863; x=1739344663; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VUGPK86DWi9+WCYvLPgrYc5wTB8ycSj3VW2D0BfVeDA=; b=khl/pd3igjFLyTCIhwqtPV4ScGWKq7I0Brnfo93lklfVo8PpogD6l5vWnbGARPCCLu gpKUtzT4SbMxFohiXo/JoXXFnUFDbGyzUeEEZqNCINyf43eouDTDZqxeVb0TVSURmbg2 X1r4Y9KmqxLmMTNe/FogE7K3LhSsHEsuhY5QULsbtAZ1PoGXS5HbS1EpjkRhO0oLSRJ0 OchALk7zEyGlT6An8RAma+99zX+55GSYq0bgO8BpIaYvBxtWPxMTRN5L7WqIfr6P4pHb sIppQ+k/jgAFzKdlwQ5QCfwRfGO1AYFlxt9XUKdwEcTeT2WG10/9f547UIMHkTr9q25P QJOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738739863; x=1739344663; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VUGPK86DWi9+WCYvLPgrYc5wTB8ycSj3VW2D0BfVeDA=; b=JNRJUGoMgbFO5wPDF0bSUytveQZxLl1o9Q9fcQIMu9d/BYZ3xZooRSysfRMhG3boNx F+32Fi6tkLBW7j0EzhJmT7CNmNT81VZk7ZdVYZOApllO3TF2+44+XYaqzstBOnkBebCO zWenu08eWDe+5y2gfeg6gwV+JxgfH2bLMNWOmDjx7AoNiEvT4p54w77+n28U4J5PKLmO ym9sdRIX50ZB1rWx7ZZ+m6ykczxjwXWgjWSVNtoRfpYHEUyRwfAmdMVoll9NhfU5wy9u M6vpRGneXjnNpkUaaqMwJ8sdL+fhks+TFLzDaveJ8jk6fnuzi6QAo/VwDvUyhcCgRFo/ i1SA== X-Forwarded-Encrypted: i=1; AJvYcCWT7z4zKGBsaNPO19iPdzbmut6faaY7E0xv9SE1Sf39YIZW9bo+IjFy7cuob/AR6o+Z2Drv/Uk=@lists.denx.de X-Gm-Message-State: AOJu0YypN5e0ysHycA9G9FpHI198m/KGxB+PBbjFNATKaItXo5czobo6 tRxZ+5X9EJcLUgwqhf2tAvhZc/qWGn7+TR9IWNNqX9hsGIXiOlsu+dfE2zXHId4= X-Gm-Gg: ASbGncti6OhEokNzUtRsvQZYH4cA6a+OFHkomrc037u3L2Ycb4ksgBZ6a6ETqaiUVeG oAZSNSftNnFoXGnNXnzGCxFamxHEUhwZm1vczEeS+IPc+lnhx8zDhnwnbpAwoRRiFCu/FY37V78 EIRaZ9NIaMxVJIf7QCXuTClnwJiLx2JTdB2xKIMEvUESThjmb+ppz7sOKc2afLBrQAz5PbwJSqT CW6ktiQSCSjdulo1+xM4resXmTDyjYSZrshf362t3Dkqjj4otMQGtQ4SF15a4j+6KJUim9ArxNh /o/KMz9bvvJAkTydxMmObaLDuYtvSilS5oysRBvugv62B+mK65By/5Kgv8OV06RENf5D X-Received: by 2002:a17:906:f593:b0:aaf:c27e:12e8 with SMTP id a640c23a62f3a-ab75e35dbc2mr190125066b.37.1738739862549; Tue, 04 Feb 2025 23:17:42 -0800 (PST) Received: from localhost.localdomain (ppp176092167070.access.hol.gr. [176.92.167.70]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5dcda28cbcesm1107191a12.43.2025.02.04.23.17.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2025 23:17:42 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de, trini@konsulko.com Cc: Ilias Apalodimas , Jerome Forissier , Alexey Brodkin , Eugeniy Paltsev , Caleb Connolly , Neil Armstrong , Sumit Garg , Huan Wang , Angelo Dureghello , Thomas Chou , Rick Chen , Leo , Marek Vasut , Nobuhiro Iwamatsu , Max Filippov , Simon Glass , Sughosh Ganu , Marc Zyngier , Sam Protsenko , =?utf-8?q?Pierre-Cl=C3=A9ment_Tosi?= , Peng Fan , Richard Henderson , Sam Edwards , Andre Przywara , Peter Hoyes , Patrick Rudolph , Sam Day , Mayuresh Chitale , Mattijs Korpershoek , Stefan Roese , Joshua Watt , Jiaxun Yang , Alex Shumsky , Jagan Teki , Evgeny Bachinin , Rasmus Villemoes , Christian Marangi , Michal Simek , Jonas Jelonek , uboot-snps-arc@synopsys.com, u-boot@lists.denx.de, u-boot-qcom@groups.io Subject: [PATCH v1 3/6] arm: Prepare linker scripts for memory permissions Date: Wed, 5 Feb 2025 09:16:47 +0200 Message-ID: <20250205071714.635518-4-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250205071714.635518-1-ilias.apalodimas@linaro.org> References: <20250205071714.635518-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-Mailman-Approved-At: Wed, 05 Feb 2025 14:15:26 +0100 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Upcoming patches are switching the memory mappings to RW, RO, RX after the U-Boot binary and its data are relocated. Add annotations in the linker scripts to and mark text, data, rodata sections and align them to a page boundary. It's worth noting that efi_runtime relocations are left untouched for now. The efi runtime regions can be relocated by the OS when the latter is calling SetVirtualAddressMap. Which means we have to configure the pages as RX for U-Boot but convert them to RWX just before ExitBootServices. It also needs extra code in efi_tuntime relocation code since R_AARCH64_NONE are emitted as well if we page align the section. Keep it out for now and we can fix it in future patches. Acked-by: Jerome Forissier Signed-off-by: Ilias Apalodimas --- arch/arm/cpu/armv8/u-boot.lds | 29 +++++++++++++++++------------ include/asm-generic/sections.h | 2 ++ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/arch/arm/cpu/armv8/u-boot.lds b/arch/arm/cpu/armv8/u-boot.lds index 857f44412e07..35afc3cbe7ec 100644 --- a/arch/arm/cpu/armv8/u-boot.lds +++ b/arch/arm/cpu/armv8/u-boot.lds @@ -22,7 +22,7 @@ SECTIONS . = ALIGN(8); __image_copy_start = ADDR(.text); - .text : + .text ALIGN(4096): { CPUDIR/start.o (.text*) } @@ -36,9 +36,12 @@ SECTIONS __efi_runtime_stop = .; } - .text_rest : + .text_rest ALIGN(4096) : { + __text_start = .; *(.text*) + . = ALIGN(4096); + __text_end = .; } #ifdef CONFIG_ARMV8_PSCI @@ -98,18 +101,20 @@ SECTIONS } #endif - . = ALIGN(8); - .rodata : { *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*))) } + .rodata ALIGN(4096): { + __start_rodata = .; + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*))) + . = ALIGN(4096); + __end_rodata = .; + } - . = ALIGN(8); - .data : { + .data ALIGN(4096) : { + __start_data = .; *(.data*) + . = ALIGN(4096); + __end_data = .; } - . = ALIGN(8); - - . = .; - . = ALIGN(8); __u_boot_list : { KEEP(*(SORT(__u_boot_list*))); @@ -136,10 +141,10 @@ SECTIONS /* * arch/arm/lib/crt0_64.S assumes __bss_start - __bss_end % 8 == 0 */ - .bss ALIGN(8) : { + .bss ALIGN(4096) : { __bss_start = .; *(.bss*) - . = ALIGN(8); + . = ALIGN(4096); __bss_end = .; } diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h index 3fd5c772a1af..024b1adde270 100644 --- a/include/asm-generic/sections.h +++ b/include/asm-generic/sections.h @@ -23,6 +23,7 @@ extern char __kprobes_text_start[], __kprobes_text_end[]; extern char __entry_text_start[], __entry_text_end[]; extern char __initdata_begin[], __initdata_end[]; extern char __start_rodata[], __end_rodata[]; +extern char __start_data[], __end_data[]; extern char __efi_helloworld_begin[]; extern char __efi_helloworld_end[]; extern char __efi_var_file_begin[]; @@ -63,6 +64,7 @@ static inline int arch_is_kernel_data(unsigned long addr) /* Start of U-Boot text region */ extern char __text_start[]; +extern char __text_end[]; /* This marks the text region which must be relocated */ extern char __image_copy_start[], __image_copy_end[];