mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 1/4] ARM: lds: place EFI runtime code and data in separate PT_LOAD segments
Date: Mon, 24 Aug 2026 09:29:51 +0200	[thread overview]
Message-ID: <20260824073005.3267576-1-a.fatoum@pengutronix.de> (raw)

From: Ahmad Fatoum <a.fatoum@barebox.org>

EFI runtime services support was added before barebox proper was made an
ELF and back then it proved too cumbersome to have two non-adjacent text
areas for each of the boot-time and run-time portions.

Now that barebox proper is an ELF, let's move the EFI runtime data and
text each into its own segment with the appropriate segment flags, so
pbl_mmu_setup_from_elf() can apply the correct protections.

The runtime sections are also moved between rodata and data rather than
at the end of the image: sections in a PT_LOAD must be contiguous, so in
the old position .bss would have had to move into the efirt_data
segment, inflating its p_memsz by all of barebox's bss, which would make
a BSS worth of memory unusable by the running kernel.

This does not yet introduce a functional change:
without ARM_MMU_PERMISSIONS, all cached mappings remain RWX.

Assisted-by: Claude:fable-5
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 arch/arm/lib32/barebox.lds.S      | 12 +++++++++---
 arch/arm/lib64/barebox.lds.S      | 12 +++++++++---
 include/asm-generic/barebox.lds.h |  6 ++++--
 3 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/arch/arm/lib32/barebox.lds.S b/arch/arm/lib32/barebox.lds.S
index 02db3b9790b7..e5ef2d045218 100644
--- a/arch/arm/lib32/barebox.lds.S
+++ b/arch/arm/lib32/barebox.lds.S
@@ -13,6 +13,10 @@ PHDRS
 	text PT_LOAD FLAGS(5);		/* PF_R | PF_X */
 	rodata PT_LOAD FLAGS(4);	/* PF_R */
 	dynamic PT_DYNAMIC FLAGS(4);	/* PF_R */
+#ifdef CONFIG_EFI_RUNTIME
+	efirt_text PT_LOAD FLAGS(5);	/* PF_R | PF_X */
+	efirt_data PT_LOAD FLAGS(6);	/* PF_R | PF_W */
+#endif
 	data PT_LOAD FLAGS(6);		/* PF_R | PF_W */
 }
 
@@ -63,6 +67,9 @@ SECTIONS
 
 	__end_rodata = .;
 	_etext = .;
+
+	BAREBOX_EFI_RUNTIME
+
 	_sdata = .;
 
 	.data : { *(.data*) } :data
@@ -73,8 +80,6 @@ SECTIONS
 
 	_edata = .;
 
-	BAREBOX_EFI_RUNTIME
-
 	.image_end : { *(.__image_end) } :data
 
 	. = ALIGN(4);
@@ -94,4 +99,5 @@ SECTIONS
 	_barebox_image_size = __bss_start;
 }
 
-NOCROSSREFS_FROM(.efi_runtime)
+NOCROSSREFS_FROM(.efi_runtime.text)
+NOCROSSREFS_FROM(.efi_runtime.data)
diff --git a/arch/arm/lib64/barebox.lds.S b/arch/arm/lib64/barebox.lds.S
index 1dddd6d1a942..a06a078d4142 100644
--- a/arch/arm/lib64/barebox.lds.S
+++ b/arch/arm/lib64/barebox.lds.S
@@ -12,6 +12,10 @@ PHDRS
 	text PT_LOAD FLAGS(5);		/* PF_R | PF_X */
 	rodata PT_LOAD FLAGS(4);	/* PF_R */
 	dynamic PT_DYNAMIC FLAGS(4);	/* PF_R */
+#ifdef CONFIG_EFI_RUNTIME
+	efirt_text PT_LOAD FLAGS(5);	/* PF_R | PF_X */
+	efirt_data PT_LOAD FLAGS(6);	/* PF_R | PF_W */
+#endif
 	data PT_LOAD FLAGS(6);		/* PF_R | PF_W */
 }
 
@@ -43,14 +47,15 @@ SECTIONS
 
 	__end_rodata = .;
 	_etext = .;
+
+	BAREBOX_EFI_RUNTIME
+
 	_sdata = .;
 
 	.data : { *(.data*) } :data
 
 	_edata = .;
 
-	BAREBOX_EFI_RUNTIME
-
 	.image_end : { *(.__image_end) } :data
 
 	. = ALIGN(4);
@@ -61,4 +66,5 @@ SECTIONS
 	_barebox_image_size = __bss_start;
 }
 
-NOCROSSREFS_FROM(.efi_runtime)
+NOCROSSREFS_FROM(.efi_runtime.text)
+NOCROSSREFS_FROM(.efi_runtime.data)
diff --git a/include/asm-generic/barebox.lds.h b/include/asm-generic/barebox.lds.h
index 008217e808cb..c672894ad502 100644
--- a/include/asm-generic/barebox.lds.h
+++ b/include/asm-generic/barebox.lds.h
@@ -157,7 +157,7 @@
 #ifdef CONFIG_EFI_RUNTIME
 #define BAREBOX_EFI_RUNTIME			\
 	. = ALIGN(4096);			\
-	.efi_runtime : {			\
+	.efi_runtime.text : {			\
 		__efi_runtime_start = .;	\
 		__efi_runtime_text_start = .;	\
 		*(.efi_runtime.text*)		\
@@ -166,12 +166,14 @@
 		*(.efi_runtime.rodata*)		\
 		__efi_runtime_rodata_stop = .;	\
 		. = ALIGN(4096);		\
+	} :efirt_text				\
+	.efi_runtime.data : {			\
 		__efi_runtime_data_start = .;	\
 		*(.efi_runtime.data*)		\
 		*(.efi_runtime.bss*)		\
 		__efi_runtime_data_stop = .;	\
 		__efi_runtime_stop = .;		\
-	}					\
+	} :efirt_data				\
 	. = ALIGN(4096);
 #else
 #define BAREBOX_EFI_RUNTIME
-- 
2.47.3




             reply	other threads:[~2026-08-24  7:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-24  7:29 Ahmad Fatoum [this message]
2026-08-24  7:29 ` [PATCH 2/4] efi: loader: map code-type page allocations executable Ahmad Fatoum
2026-08-24  7:29 ` [PATCH 3/4] ARM: allow CONFIG_ARM_MMU_PERMISSIONS together with EFI_RUNTIME Ahmad Fatoum
2026-08-24  7:29 ` [PATCH 4/4] test: py: efiloader: test EFI ResetSystem from booted Linux Ahmad Fatoum
2026-08-24 12:28 ` [PATCH 1/4] ARM: lds: place EFI runtime code and data in separate PT_LOAD segments Sascha Hauer
2026-08-25 13:49 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260824073005.3267576-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=a.fatoum@barebox.org \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox