From patchwork Thu Feb 27 12:14:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 868962 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1561:b0:38f:210b:807b with SMTP id 1csp247150wrz; Thu, 27 Feb 2025 04:57:40 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWu0//I0SFLsu/endT8JjHiiU5UR4n9rOK0X0ai5tb2uuNWrgAEU6mzy9UPQ5a8/jRFNMq0DA==@linaro.org X-Google-Smtp-Source: AGHT+IFzbujc6exkVWbTexJbj8SjlQ+f8zQWKOU+YysyrNij/0Xt3/rX+4+FHF1kC3k6PJ6K/jyr X-Received: by 2002:a5d:6d07:0:b0:38f:3f65:2ea3 with SMTP id ffacd0b85a97d-390cc602127mr8265878f8f.17.1740661060084; Thu, 27 Feb 2025 04:57:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1740661060; cv=none; d=google.com; s=arc-20240605; b=aQpYJqU14jkMGDFLuwJGM3SMcgpYNf/ltjw2nj6XlGLz/dZkhfiLnytLkuNpjO5KW/ nF3Agf7e4764YC1MW6F02MsYs0CkDxAZtyHir/cHbpVvN9R/NZ0wHF+f729kfbgUahst uqZk//ghy2Wj+jDiRmU7OlEsaUO+ZFHUOl7pAETe2N2GmOK472/or3ml3XFi+MsBvoNC pITx/zkI4QWpfBTODvngITPshRZyVH9y/otEx5ZxoTtK4jY2IUV99hoXkPl+In+5MF7w PJt+rBcF7WvhsfHocz0MUnf+ChztxHMdxmZZoVc+jZpsk+FvBFN/ndi6bc73ioMBQKG5 HVbw== 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=kkXx8zhK7uZMdTX03n+IWXECBgmzC7X3Q5ZcQhxoAPE=; b=COb6FJQmLnDn/XktZIYIGzcq5/edWGjMAFOp7pRBDf3JzSqZv+lwMkl2bFs6HTo7an eOdBPdfiC1dodxDM5hukpk7rZckbtncAVQ1J3kbrdnlNJGgpi1eD9k4AFv3a/Nsw6zFN ksim0LBG9hTEEzYb/7YDIHGO7TNZk6IweM1VOlSReVzCYl16piRT+a1FOoqjWEimPPg1 5XZk8G9doR+ukO/3TuW3T2SPLKSmyTthJdsHzcH8AUoMNYq6E8R1X2gOmGFucslzh8yx r0eUHq6pIAbcmxAzy6IfXTf8gmLlrgDk7K4pVHzVHCwAIh2R9J/Ii3YEozExdm7nWpQa AWvg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Vz3RmQBY; 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 5b1f17b1804b1-43b7a267f9bsi10593375e9.126.2025.02.27.04.57.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 04:57:40 -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=Vz3RmQBY; 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 DFBA881120; Thu, 27 Feb 2025 13:56:57 +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="Vz3RmQBY"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E51F7810EA; Thu, 27 Feb 2025 13:15:47 +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-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) (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 C6EC1801FB for ; Thu, 27 Feb 2025 13:15:45 +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-x62f.google.com with SMTP id a640c23a62f3a-abb7f539c35so158230066b.1 for ; Thu, 27 Feb 2025 04:15:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740658545; x=1741263345; 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=Vz3RmQBYTILp8QCodnkZCARKpp2BzjCMAridH7xaWiO4X9fZ2sTJuxtfzvgsEXYN+H ic8pYB8SYmx34x3oin9kufKuRNybxcXbbgfdom+Q4iSgcrSjALyKASydqRxIi99HG16X jJa3u93gczFfmJ1jZNr4j1gfamztcAiMQ9bU9wecXQVomnVwqa4ZZd2bDzJh6pydZaUb h4MPQFTFvrOxEyxKeaFMKFbZziPq3p/7V/nCq9GEWNrL3lFQwqIKmNmAGrjeptadim/Y EkTbCbYBB41CQvjETdBk6OfmEkz3/R73PLQQzw3648IwUjstM6lCgz1fPhGLsHS/tZSA kBEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740658545; x=1741263345; 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=lSPmGaAJJuR/gGXhcYVR+/Z2FHch3oxui5pQOEKT3Did4F2+PVzHazYchFLmt0e113 /R/0r9iRetbIy6khmy315HymH6xHn4Z1ZJPzoxZU4QEPzXNAglPTvsz7y/JLFt+LXFHD 1T6CqWjIzWCh7i3aoQYDv6YeZ2hPT1iEiOPXITxkwITSYCFMUa5FSLcrc8il4tLo231X JGZG4zohgPmIZaJYfruWlA51fd3Lt3B9+7zYS3GKyi7OzVgWkTDWe4kwaT/VJxAb5Ivh yvlR33cSLqFxbV1MtFpUv+vgBw4Vz83hScW+ySoWUFtit+SfokZHuZRelREAUhW71/Pu PhmA== X-Forwarded-Encrypted: i=1; AJvYcCWhydjJpMJ8bycYz4u81e9/xyi637ah2OtvVdX0tviIhTC5cG9p5Nih9Jyi2ayqaFCyQJmuxuM=@lists.denx.de X-Gm-Message-State: AOJu0Yx0iW8NHx1oYEw8cKut9JLtaChxeMNB2bB9r1K+4PX8LDJOr4qa sl5bwhm75a8HW22dq+UsS2fB/nlIuSx5H4kkr6VBrcKJwhrCn0cJDQjGFomJc78= X-Gm-Gg: ASbGncteL6yHanPBzMOkx1YRXHfiP3oaowf01qRd6tlqLgbe3w6Af4tyburJ8XRitMB jlKRcULDe9zIw1BX14/2ZpGM39i+JxKRXD6ng8y2F3QJqw9rzfpuBbnrzO5aDfQU2lQNREqwRFC c9dSokKV5R2OKwBL35Tro5TsLdz7d5/3a4IwO4IxQ8/brjc4E0riUs4NZJ31kiNbtCna6hZl86r YNbl3kP0UoqiAPqkjYhmQ7aE5XnNQL3mXfgqutOT54Dx77PslftQipd5t3D53KRLKteiZWTRDdg wr+zXw9oUhuj63eoF3Rv/KIaa6N+mFXqzCtd5/+WhDKnZdiEOToeh0mjkYqeLgbtEwZB2EbmnHR yOga/ X-Received: by 2002:a17:906:31c6:b0:aba:7a3a:e267 with SMTP id a640c23a62f3a-abed101d92fmr1207034366b.45.1740658545038; Thu, 27 Feb 2025 04:15:45 -0800 (PST) Received: from localhost.localdomain (ppp176092191135.access.hol.gr. [176.92.191.135]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-abf0c0dc168sm114736566b.70.2025.02.27.04.15.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2025 04:15:44 -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 , Peter Hoyes , Andre Przywara , Patrick Rudolph , Mayuresh Chitale , Mattijs Korpershoek , Harrison Mutai , Alex Shumsky , Joshua Watt , Raymond Mao , Jagan Teki , Evgeny Bachinin , Peter Robinson , Christian Marangi , Michal Simek , Rasmus Villemoes , Jonas Jelonek , uboot-snps-arc@synopsys.com, u-boot@lists.denx.de Subject: [PATCH v3 3/6] arm: Prepare linker scripts for memory permissions Date: Thu, 27 Feb 2025 14:14:53 +0200 Message-ID: <20250227121515.232996-4-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250227121515.232996-1-ilias.apalodimas@linaro.org> References: <20250227121515.232996-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 27 Feb 2025 13:56:54 +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[];