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@pengutronix.de>
Subject: [PATCH master 36/39] efi: payload: skip ELF MMU handling when booted via stub
Date: Mon, 16 Feb 2026 09:44:36 +0100	[thread overview]
Message-ID: <20260216084758.3548990-37-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20260216084758.3548990-1-a.fatoum@pengutronix.de>

We should not touch the MMU when running as EFI app and must trust
that the EFI firmware has taken care of it.

This was so far realized by skipping MMU setup if MMU is already
enabled, but with the switch to ELF for barebox proper, the same check
can't be repeated in pbl_mmu_setup_from_elf(), so add an explicit check
that barebox wasn't invoked via the PE entry point.

Fixes: 6cb7fc2edbb6 ("ARM: PBL: setup MMU with proper permissions from ELF segments")
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 efi/payload/entry-multi.c | 13 +++++++++++++
 include/efi/mode.h        |  6 +++++-
 pbl/mmu.c                 |  4 ++++
 3 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/efi/payload/entry-multi.c b/efi/payload/entry-multi.c
index ef90ee077622..de977efc50b8 100644
--- a/efi/payload/entry-multi.c
+++ b/efi/payload/entry-multi.c
@@ -7,11 +7,23 @@
 #include <asm/common.h>
 #include <efi/protocol/text.h>
 #include <efi/payload.h>
+#include <efi/mode.h>
 #include <pbl.h>
 #include <pbl/handoff-data.h>
 
 asmlinkage void __efistub_efi_pe_entry(void *image, struct efi_system_table *sys_table);
 
+/*
+ * Put these in the data section so that they survive the clearing of the
+ * BSS segment.
+ */
+static __attribute__ ((section(".data"))) bool is_efi_payload;
+
+bool efi_is_payload(void)
+{
+	return is_efi_payload;
+}
+
 static void efi_putc(void *ctx, int ch)
 {
 	struct efi_system_table *sys_table = ctx;
@@ -30,6 +42,7 @@ void __efistub_efi_pe_entry(void *image, struct efi_system_table *sys_table)
 #endif
 	pbl_set_putc(efi_putc, sys_table);
 
+	is_efi_payload = true;
 	efidata.image = image;
 	efidata.sys_table = sys_table;
 
diff --git a/include/efi/mode.h b/include/efi/mode.h
index d63c47e88dbb..5093e9b2971f 100644
--- a/include/efi/mode.h
+++ b/include/efi/mode.h
@@ -18,10 +18,14 @@ enum efi_loader_state {
 	EFI_LOADER_RUNTIME,
 };
 
+#if IN_PBL && defined(CONFIG_EFI_STUB)
+bool efi_is_payload(void);
+#else
 static inline bool efi_is_payload(void)
 {
-	return IS_ENABLED(CONFIG_EFI_PAYLOAD) && BS;
+	return IS_ENABLED(CONFIG_EFI_PAYLOAD) && IN_PROPER && BS;
 }
+#endif
 
 #ifdef CONFIG_EFI_LOADER
 enum efi_loader_state efi_is_loader(void);
diff --git a/pbl/mmu.c b/pbl/mmu.c
index e7c9b8b1e8e4..897221c53f9b 100644
--- a/pbl/mmu.c
+++ b/pbl/mmu.c
@@ -10,6 +10,7 @@
 #include <asm/mmu.h>
 #include <linux/bits.h>
 #include <linux/sizes.h>
+#include <efi/mode.h>
 
 /*
  * Map ELF segment permissions (p_flags) to architecture MMU flags
@@ -45,6 +46,9 @@ int pbl_mmu_setup_from_elf(struct elf_image *elf, unsigned long membase,
 	void *phdr;
 	int i = -1;
 
+	if (efi_is_payload())
+		return 0;
+
 	pr_debug("Setting up MMU from ELF segments\n");
 
 	/*
-- 
2.47.3




  parent reply	other threads:[~2026-02-16  9:17 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-16  8:44 [PATCH master 00/39] efi: fix bugs Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 01/39] efi: fix potential NULL dereference Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 02/39] efi: trace: fix EFI_EXIT2 to not evaluate output value on error Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 03/39] efi: loader: fix CRC32 computation in table header update Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 04/39] efi: loader: fix pointer vs value comparison in free_efi_only Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 05/39] efi: loader: fix disk write return value check Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 06/39] efi: loader: fix EFI_ENTRY/EFI_EXIT ordering in efi_set_time Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 07/39] efi: runtime: fix missing EFI_EXIT in efirt_query_variable_info Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 08/39] efi: loader: fix file handle leak in efi_file_from_path Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 09/39] efi: loader: fix missing field init in deferred protocol add Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 10/39] efi: loader: fix memory leak in efi_var_to_file Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 11/39] efi: loader: fix multiple bugs in efi_loader_bootm Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 12/39] efi: loader: fix return type and memory leak in efi_smbios_register Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 13/39] efi: loader: fix memory leak in efi_dp_split_file_path Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 14/39] efi: loader: fix HII string table realloc and memset bugs Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 15/39] efi: loader: fix format specifier and missing EFI_EXIT in boot services Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 16/39] efi: fix unreachable free in efi_set_variable_printf Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 17/39] efi: payload: fix missing NULL check after read_file in handover Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 18/39] efi: payload: fix EFI page leak in efi_read_file Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 19/39] efi: payload: fix inverted error check after state_load Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 20/39] efi: fix out-of-bounds read in device path unknown node printing Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 21/39] efi: payload: fix wrong page count in efi_unload_fdt Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 22/39] efi: fix out-of-bounds read in 1394 device path printing Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 23/39] efi: loader: initialize block IO ops before installing protocol Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 24/39] efi: runtime: fix variable store bounds check to account for alignment Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 25/39] efi: fix Fibre Channel device path type vs sub_type comparison Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 26/39] efi: loader: fix file open mode always setting O_RDWR Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 27/39] efi: loader: fix NULL pointer dereference when deleting root volume handle Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 28/39] efi: loader: fix memory leak of variable file buffer on success Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 29/39] efi: loader: fix memory leak in efi_var_collect on buffer overflow Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 30/39] efi: fix signed format specifier for uint64_t timestamp Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 31/39] efi: payload: fix possible memory leaks during init Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 32/39] efi: payload: protect against missing state alias Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 33/39] efi: loader: fix stale return value in console out-of-memory path Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 34/39] efi: loader: fix off-by-one in FAT codepage translation Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 35/39] efi: loader: fix co-existence with EFI payload support Ahmad Fatoum
2026-02-16  8:44 ` Ahmad Fatoum [this message]
2026-02-16  8:44 ` [PATCH master 37/39] efi: payload: register dummy device tree Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 38/39] console: introduce helper for printing binary buffers as-is Ahmad Fatoum
2026-02-16  8:44 ` [PATCH master 39/39] efi: loader: protocol: console: don't turn LF into CRLF Ahmad Fatoum

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=20260216084758.3548990-37-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --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