From patchwork Sat Mar 1 16:49:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 869715 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1561:b0:38f:210b:807b with SMTP id 1csp1644402wrz; Sun, 2 Mar 2025 04:40:52 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWh+pkRg6Y/p/9zJrrfULpYk0p0w6HqXj0ZiqzK+hVTeuv6i8rq6z4CB2XaGx4r7kdsDcd7sw==@linaro.org X-Google-Smtp-Source: AGHT+IHroNkWbz8+g7yNhEu/4JFZSMl2+mPv7C+cW7hyNZb81Z5GazOMr5BhHE6IUee6dnS+ABjV X-Received: by 2002:a05:6000:2ce:b0:38d:b52d:e11c with SMTP id ffacd0b85a97d-390ec155366mr10263619f8f.15.1740919251796; Sun, 02 Mar 2025 04:40:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1740919251; cv=none; d=google.com; s=arc-20240605; b=dQbdPhTz+kUQaihfRkOZlfLRLUAsEKO/DkvkN8QHGC/ha/oMLr9ju2WlGf0AOcsYk/ w9liU2/il4KzP9iDII0LDCCwCi6qgKXvz+c6pxYvla+X7vepcOM4a6hlbhmYUIgALjOF grT68ojUVMIUmukqGbUFq32Zmd7oNR/2x3Lr8iWT5gnOGtpadhv9lmkEm3L69C2A10vi oDelNGXBHW1yKn1csZXtn/q5pYlt8bNQyz4iThLORQpOnHuXggukBBAmNDsNfFynaGOL pkuFX1mczWT8DqRqu4INUAVKO7pwgHBYOJz+tZappfhq5/TTvpC6WXKbL0CPuybSC3cA dVvA== 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=5qSeBQm8rIiofeh7plKeu/pk/Zyacx6XzEy5fwctVGo=; fh=U7e/tr90HC7sVSZXlPWdZF/HQr5ji5LnTldcznHZK/0=; b=Yy689wWJjF25lOAMdE1ULTbcLJwCvvfiU3RhmY5DXaLfPiT/Acq7dnCVbZ4IMS8ji0 bA5GqyHSDNE/yD5kPmoj4+q9chT2YqdbHTsPeN9Q1sJmpju66czXzPho/I5idgViJlPu 2GFElDn5e4rqAXzNhn2TpPOrfWVwZ7hK0gL/9hPtzXsnGmm5E2UjI3+WctZYO/5ZIPN5 2M8SDbkWm4n6d/Re3LMUeRZG0Pq7MGqA86hvSFBtNMlPX/g8IoBYe2pASPQFtxKOgkmW zwS6MKFLVuiUJW3GZTsgzYhTGVy+jfnCXCTJwDKVfAxSACYjK+QmbDGbR4BZbjD08SoV CMOA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mknH8YN3; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id ffacd0b85a97d-390e48260e4si5850633f8f.470.2025.03.02.04.40.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Mar 2025 04:40:51 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mknH8YN3; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 07E3F811B3; Sun, 2 Mar 2025 13:40:26 +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="mknH8YN3"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 23DAD81111; Sat, 1 Mar 2025 17:50:06 +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-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) (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 C0D94810F6 for ; Sat, 1 Mar 2025 17:50:02 +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-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-5e4ce6e3b8cso4135368a12.1 for ; Sat, 01 Mar 2025 08:50:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740847802; x=1741452602; 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=5qSeBQm8rIiofeh7plKeu/pk/Zyacx6XzEy5fwctVGo=; b=mknH8YN3fX/phRXTi12biSqFTrW0gRKQ+VDc8lQMX20KJ+m/D5hlw+wYQo2+jc+lXR D8xZBjMCCMvlJUU3e7m8unlOzq9Fnv39YLKXiqDtDZEFMf3oVhjB5cKJMbNLfMDQSCut E8Wk7s2YbEMYvccVUbac2ph4Kzmi+700BfZMqPXwXjdH8rE+bpMBGfr0DBtG7oi/oIYb BfTjlja2GLZuc1ONrA4/oxN629aW7GsA4clHbw4dyiOmiwV4i7d+HBO2g1HJtVSNRY35 vbb1wtL7fw0sLZoOJQto7CbeodUfyOITGYLCUJOq4VGtTsjA1GeLZfHOgad0EsDLNP3I Gfsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740847802; x=1741452602; 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=5qSeBQm8rIiofeh7plKeu/pk/Zyacx6XzEy5fwctVGo=; b=tDpBvH9HvgGyRsaMQJ23a2YNj/qPtAE29Y4hWmaZRuFfjVk95M9q1iGIL3g/D5kepD hpFRlru/y6AOVZjosVUdm9Xxsj3L5/4UdaD8bJsxiG5H9l/JZ5nYJQ+L5GXlB2ot4/0G Emjfp8m4H0ushlHhylvQNFmVDcfoYtwG5TVwtHm//HF9s6edAm5Q66mPyaAp1/vZxBX0 miQrmupikLDPRuHQXH1AdZOZye8wN4qu7wda5oUrUpISx5kdwccL35cf731O6o6MXJ4t 2jAiXrcVkyyYCBmfDbJG38xK2h7GUXLnjbU31Pp/4r6V9wmcfWHOjh1JJjdXoX1PhBe0 KYFw== X-Forwarded-Encrypted: i=1; AJvYcCXhA34i/r9O2o1TsZtDsU+QTK9L4VaxKFD411pT1S4TiTjzFX8LUaYHSBgVDDCiDfN7o4pfKRM=@lists.denx.de X-Gm-Message-State: AOJu0Yx6plio0ZmRWDM4Hk3GUy6FE+rp2Rw24+FzMBBqBZm1K4RehfYs 3BaZikcYiAlGpFg6WzJ74F3vT0SXHC340z7pj6pmyc3pd6k1hGkfM3uhz2oK/Ss= X-Gm-Gg: ASbGncsIr15tFRTJLPh8iXZxLMBsuEfgDlPrgsFYPHMpvbDclSWghlLuz9f4+2gak8u pRVp2yXbtJzdaH7borTRiFu/NnnkbYsrcSK9zBD3fPQfhoXqXAkrBPTwqeihBOO2nPLRAajssz4 I7bUnJV6SrRmlFIPxgqFH9bNX/aEz6qHfsK9ed8WB51673iPiIGU/cauRxq3AbkFUzboRpBRdCP FjEqJkIc7n/uXBRflGcxgShXT7H54fkZjUGxot7Cq7ysWjip9QYhCyK7/w+qJCbFl5CI1zv5aqD V04PVLyMAZmir8bOOWU/U8j+3Bb4cDB8sGhQ+9GjcR2zki1UANL91QdG9n/D5zRr9UNeYwtIoQX GCayvBI4rCf6osI+m7SWfMIQ= X-Received: by 2002:a05:6402:1e91:b0:5dc:eb2:570d with SMTP id 4fb4d7f45d1cf-5e4d52ac8b1mr9819986a12.2.1740847802125; Sat, 01 Mar 2025 08:50:02 -0800 (PST) Received: from localhost.localdomain (ppp176092191135.access.hol.gr. [176.92.191.135]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5e4c3fb5927sm4257231a12.53.2025.03.01.08.49.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Mar 2025 08:50:01 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de, mark.kettenis@xs4all.nl Cc: Ilias Apalodimas , Jerome Forissier , Neil Armstrong , Richard Henderson , Alexey Brodkin , Eugeniy Paltsev , Tom Rini , Huan Wang , Angelo Dureghello , Thomas Chou , Rick Chen , Leo , Marek Vasut , Nobuhiro Iwamatsu , Max Filippov , Simon Glass , Sughosh Ganu , Caleb Connolly , Marc Zyngier , Sam Protsenko , =?utf-8?q?Pierre-Cl=C3=A9ment_T?= =?utf-8?q?osi?= , Sam Edwards , Andre Przywara , Peter Hoyes , Patrick Rudolph , Mayuresh Chitale , Mattijs Korpershoek , Stefan Roese , Joshua Watt , Jiaxun Yang , Alex Shumsky , Jagan Teki , Evgeny Bachinin , Christian Marangi , Michal Simek , Jonas Jelonek , uboot-snps-arc@synopsys.com, u-boot@lists.denx.de Subject: [PATCH v4 3/6] arm: Prepare linker scripts for memory permissions Date: Sat, 1 Mar 2025 18:49:01 +0200 Message-ID: <20250301164922.397441-4-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250301164922.397441-1-ilias.apalodimas@linaro.org> References: <20250301164922.397441-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-Mailman-Approved-At: Sun, 02 Mar 2025 13:40:23 +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 memory permissions are left untouched for now. There's two problems with EFI currently. The first problem is that we bundle data, rodata and text in a single .efi_runtime section which also must be close to .text for now. As a result we also dont change the permissions for anything contained in CPUDIR/start.o. In order to fix that we have to decoule .text_rest, .text and .efi_runtime and have the runtime services on their own section with proper memory permission annotations (efi_rodata etc). The efi runtime regions (.efi_runtime_rel) can be relocated by the OS when the latter is calling SetVirtualAddressMap. Which means we have to configure those 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. Due to the above ignore EFI for now and fix it later once we have the rest in place. Acked-by: Jerome Forissier Tested-by: Neil Armstrong # on AML-S905X-CC Reviewed-by: Richard Henderson Signed-off-by: Ilias Apalodimas --- arch/arm/cpu/armv8/u-boot.lds | 59 +++++++++++++++++++++++----------- include/asm-generic/sections.h | 2 ++ 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/arch/arm/cpu/armv8/u-boot.lds b/arch/arm/cpu/armv8/u-boot.lds index 857f44412e07..f4ce98c82c8d 100644 --- a/arch/arm/cpu/armv8/u-boot.lds +++ b/arch/arm/cpu/armv8/u-boot.lds @@ -36,9 +36,18 @@ SECTIONS __efi_runtime_stop = .; } +#ifdef CONFIG_MMU_PGPROT + .text_rest ALIGN(CONSTANT(COMMONPAGESIZE)) : +#else .text_rest : +#endif { + __text_start = .; *(.text*) +#ifdef CONFIG_MMU_PGPROT + . = ALIGN(CONSTANT(COMMONPAGESIZE)); +#endif + __text_end = .; } #ifdef CONFIG_ARMV8_PSCI @@ -97,35 +106,43 @@ SECTIONS LONG(0x1d1071c); /* Must output something to reset LMA */ } #endif - - . = ALIGN(8); - .rodata : { *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*))) } - - . = ALIGN(8); - .data : { - *(.data*) + .efi_runtime_rel : { + __efi_runtime_rel_start = .; + *(.rel*.efi_runtime) + *(.rel*.efi_runtime.*) + __efi_runtime_rel_stop = .; } - . = ALIGN(8); - - . = .; +#ifdef CONFIG_MMU_PGPROT + .rodata ALIGN(CONSTANT(COMMONPAGESIZE)): { +#else + .rodata ALIGN(8) : { +#endif + __start_rodata = .; + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*))) + } - . = ALIGN(8); - __u_boot_list : { + __u_boot_list ALIGN(8) : { KEEP(*(SORT(__u_boot_list*))); +#ifdef CONFIG_MMU_PGPROT + . = ALIGN(CONSTANT(COMMONPAGESIZE)); +#endif + __end_rodata = .; } - .efi_runtime_rel : { - __efi_runtime_rel_start = .; - *(.rel*.efi_runtime) - *(.rel*.efi_runtime.*) - __efi_runtime_rel_stop = .; +#ifdef CONFIG_MMU_PGPROT + .data ALIGN(CONSTANT(COMMONPAGESIZE)) : { +#else + .data ALIGN(8) : { +#endif + __start_data = .; + *(.data*) } . = ALIGN(8); __image_copy_end = .; - .rela.dyn : { + .rela.dyn ALIGN(8) : { __rel_dyn_start = .; *(.rela*) __rel_dyn_end = .; @@ -136,11 +153,15 @@ SECTIONS /* * arch/arm/lib/crt0_64.S assumes __bss_start - __bss_end % 8 == 0 */ - .bss ALIGN(8) : { + .bss ADDR(.rela.dyn) (OVERLAY) : { __bss_start = .; *(.bss*) . = ALIGN(8); __bss_end = .; +#ifdef CONFIG_MMU_PGPROT + . = ALIGN(CONSTANT(COMMONPAGESIZE)); +#endif + __end_data = .; } /DISCARD/ : { *(.dynsym) } 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[];