summaryrefslogtreecommitdiff
path: root/common/board_r.c
diff options
context:
space:
mode:
authorIlias Apalodimas <ilias.apalodimas@linaro.org>2025-02-20 15:54:43 +0200
committerIlias Apalodimas <ilias.apalodimas@linaro.org>2025-03-14 13:37:54 +0200
commitfb553201b67aededdc794f3a0880e386771cbd58 (patch)
tree3050611012b20a57a1e08e1d1d399ae1d6ac2499 /common/board_r.c
parentec1c6cfb1cfce92909a248f10c36bd8b18894d7e (diff)
arm64: Enable RW, RX and RO mappings for the relocated binary
Now that we have everything in place switch the page permissions for .rodata, .text and .data just after we relocate everything in top of the RAM. Unfortunately we can't enable this by default, since we have examples of U-Boot crashing due to invalid access. This usually happens because code defines const variables that it later writes. So hide it behind a Kconfig option until we sort it out. It's worth noting that EFI runtime services are not covered by this patch on purpose. Since the OS can call SetVirtualAddressMap which can relocate runtime services, we need to set them to RX initially but remap them as RWX right before ExitBootServices. Link: https://lore.kernel.org/u-boot/20250129-rockchip-pinctrl-const-v1-0-450ccdadfa7e@cherry.de/ Link: https://lore.kernel.org/u-boot/20250130133646.2177194-1-andre.przywara@arm.com/ Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Diffstat (limited to 'common/board_r.c')
-rw-r--r--common/board_r.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/common/board_r.c b/common/board_r.c
index db0c5cb8032..8d69db1875d 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -170,7 +170,27 @@ static int initr_reloc_global_data(void)
efi_save_gd();
efi_runtime_relocate(gd->relocaddr, NULL);
+
#endif
+ /*
+ * We are done with all relocations change the permissions of the binary
+ * NOTE: __start_rodata etc are defined in arm64 linker scripts and
+ * sections.h. If you want to add support for your platform you need to
+ * add the symbols on your linker script, otherwise they will point to
+ * random addresses.
+ *
+ */
+ if (IS_ENABLED(CONFIG_MMU_PGPROT)) {
+ pgprot_set_attrs((phys_addr_t)(uintptr_t)(__start_rodata),
+ (size_t)(uintptr_t)(__end_rodata - __start_rodata),
+ MMU_ATTR_RO);
+ pgprot_set_attrs((phys_addr_t)(uintptr_t)(__start_data),
+ (size_t)(uintptr_t)(__end_data - __start_data),
+ MMU_ATTR_RW);
+ pgprot_set_attrs((phys_addr_t)(uintptr_t)(__text_start),
+ (size_t)(uintptr_t)(__text_end - __text_start),
+ MMU_ATTR_RX);
+ }
return 0;
}