mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: chalianis1@gmail.com
To: s.hauer@pengutronix.de
Cc: barebox@lists.infradead.org, Chali Anis <chalianis1@gmail.com>
Subject: [PATCH] efi: payload: early-mem: add memory type on early mem allocation
Date: Fri, 22 Aug 2025 01:37:17 -0400	[thread overview]
Message-ID: <20250822053717.1050752-1-chalianis1@gmail.com> (raw)

From: Chali Anis <chalianis1@gmail.com>

Add the ability to specify the memory type which mendatory for the
recent efi versions that have MMU, this will fix a permission fault
on second level when trying to relocate the barebox or even execting
the memory code. see the snapshot error log below.

 SP 0x000000007C6CFF80  ELR 0x000000006C6EA4FC  SPSR 0x60000205  FPSR 0x00000000
 ESR 0x8600000E          FAR 0x000000006C6EA4FC
 ESR : EC 0x21  IL 0x1  ISS 0x0000000E
 Instruction abort: Permission fault, second level

Fixes: c937ad266413 ("efi: return pointer from efi_earlymem_alloc")
Signed-off-by: Chali Anis <chalianis1@gmail.com>
---
 efi/payload/early-mem.c    | 4 ++--
 efi/payload/entry-multi.c  | 2 +-
 efi/payload/entry-single.c | 2 +-
 include/efi/efi-payload.h  | 4 +++-
 4 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/efi/payload/early-mem.c b/efi/payload/early-mem.c
index 6229fd43a587..0f79a8c30694 100644
--- a/efi/payload/early-mem.c
+++ b/efi/payload/early-mem.c
@@ -6,7 +6,7 @@
 #include <efi/efi-payload.h>
 
 void *efi_earlymem_alloc(const struct efi_system_table *sys_table,
-			 size_t *memsize)
+			 size_t *memsize, enum efi_memory_type mem_type)
 {
 	struct efi_boot_services *bs = sys_table->boottime;
 	enum efi_allocate_type alloc_type = EFI_ALLOCATE_ANY_PAGES;
@@ -20,7 +20,7 @@ void *efi_earlymem_alloc(const struct efi_system_table *sys_table,
 	}
 
 	for (*memsize = SZ_256M; *memsize >= SZ_8M; *memsize /= 2) {
-		efiret  = bs->allocate_pages(alloc_type, EFI_LOADER_DATA,
+		efiret  = bs->allocate_pages(alloc_type, mem_type,
 					     *memsize / EFI_PAGE_SIZE, &mem);
 		if (!EFI_ERROR(efiret) || efiret != EFI_OUT_OF_RESOURCES)
 			break;
diff --git a/efi/payload/entry-multi.c b/efi/payload/entry-multi.c
index 2eb9dccc08a0..d5d54cdf70a1 100644
--- a/efi/payload/entry-multi.c
+++ b/efi/payload/entry-multi.c
@@ -37,7 +37,7 @@ void __efistub_efi_pe_entry(void *image, struct efi_system_table *sys_table)
 
 	handoff_data_add(HANDOFF_DATA_EFI, &efidata, sizeof(efidata));
 
-	mem = efi_earlymem_alloc(sys_table, &memsize);
+	mem = efi_earlymem_alloc(sys_table, &memsize, EFI_LOADER_CODE);
 
 	barebox_pbl_entry((uintptr_t)mem, memsize, NULL);
 }
diff --git a/efi/payload/entry-single.c b/efi/payload/entry-single.c
index c95672b9fe66..b7171bb24bfa 100644
--- a/efi/payload/entry-single.c
+++ b/efi/payload/entry-single.c
@@ -37,7 +37,7 @@ void efi_main(efi_handle_t image, struct efi_system_table *sys_table)
 		BS->handle_protocol(efi_loaded_image->device_handle,
 				&efi_device_path_protocol_guid, (void **)&efi_device_path);
 
-	mem = efi_earlymem_alloc(sys_table, &memsize);
+	mem = efi_earlymem_alloc(sys_table, &memsize, EFI_LOADER_CODE);
 
 	mem_malloc_init(mem, mem + memsize - 1);
 
diff --git a/include/efi/efi-payload.h b/include/efi/efi-payload.h
index 22cdceb71fe2..fe45864dd8a7 100644
--- a/include/efi/efi-payload.h
+++ b/include/efi/efi-payload.h
@@ -4,6 +4,7 @@
 
 #include <efi/types.h>
 #include <efi/efi-util.h>
+#include <efi/memtype.h>
 
 struct efi_system_table;
 struct efi_loaded_image;
@@ -30,6 +31,7 @@ int efi_set_variable(char *name, efi_guid_t *vendor, uint32_t attributes,
 		     void *buf, size_t size);
 int efi_set_variable_usec(char *name, efi_guid_t *vendor, uint64_t usec);
 
-void *efi_earlymem_alloc(const struct efi_system_table *sys_table, size_t *memsize);
+void *efi_earlymem_alloc(const struct efi_system_table *sys_table,
+			 size_t *memsize, enum efi_memory_type mem_type);
 
 #endif
-- 
2.34.1




                 reply	other threads:[~2025-08-22 14:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20250822053717.1050752-1-chalianis1@gmail.com \
    --to=chalianis1@gmail.com \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    /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