mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH v4 01/13] mmu: explicitly map executable non-SDRAM regions with MAP_CODE
Date: Mon,  4 Aug 2025 19:22:21 +0200	[thread overview]
Message-ID: <20250804172233.2158462-2-a.fatoum@barebox.org> (raw)
In-Reply-To: <20250804172233.2158462-1-a.fatoum@barebox.org>

So far we have been setting eXecute Never on MAP_UNCACHED regions and
left it out for the default MAP_CACHED region.

We have at least three places, which depend on this to remap non-SDRAM
regions executable, so ROM code or newly uploaded code can be run.

Switch them over to use a new MAP_CODE mapping type. For now, this is
equivalent to MAP_CACHED, but with the addition of W^X support in
barebox, this will be required to avoid a prefetch abort when MMU
attributes are used.

Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 arch/arm/mach-imx/romapi.c | 3 ++-
 drivers/firmware/socfpga.c | 4 ++++
 drivers/hab/habv4.c        | 2 +-
 include/mmu.h              | 1 +
 4 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-imx/romapi.c b/arch/arm/mach-imx/romapi.c
index 10af42f28a76..a4143d372ae8 100644
--- a/arch/arm/mach-imx/romapi.c
+++ b/arch/arm/mach-imx/romapi.c
@@ -299,7 +299,8 @@ void imx93_bootsource(void)
 		goto out;
 	}
 
-	arch_remap_range((void *)rom.start, rom.start, resource_size(&rom), MAP_CACHED);
+	/* TODO: restore uncached mapping once we no longer need this? */
+	arch_remap_range((void *)rom.start, rom.start, resource_size(&rom), MAP_CODE);
 
 	OPTIMIZER_HIDE_VAR(rom_api);
 
diff --git a/drivers/firmware/socfpga.c b/drivers/firmware/socfpga.c
index 0f7d11abb588..13ddbe32c30c 100644
--- a/drivers/firmware/socfpga.c
+++ b/drivers/firmware/socfpga.c
@@ -361,11 +361,15 @@ static int socfpga_fpgamgr_program_finish(struct firmware_handler *fh)
 			   &socfpga_sdram_apply_static_cfg,
 			   socfpga_sdram_apply_static_cfg_sz);
 
+	remap_range((void *)CYCLONE5_OCRAM_ADDRESS, PAGE_SIZE, MAP_CODE);
+
 	sync_caches_for_execution();
 
 	ocram_func((void __iomem *) (CYCLONE5_SDR_ADDRESS +
 				     SDR_CTRLGRP_STATICCFG_ADDRESS));
 
+	remap_range((void *)CYCLONE5_OCRAM_ADDRESS, PAGE_SIZE, MAP_UNCACHED);
+
 	return 0;
 }
 
diff --git a/drivers/hab/habv4.c b/drivers/hab/habv4.c
index 4945e8930acb..83ee06a6aa46 100644
--- a/drivers/hab/habv4.c
+++ b/drivers/hab/habv4.c
@@ -689,7 +689,7 @@ int imx8m_hab_print_status(void)
 
 int imx6_hab_print_status(void)
 {
-	remap_range(0x0, SZ_1M, MAP_CACHED);
+	remap_range(0x0, SZ_1M, MAP_CODE);
 
 	imx6_hab_get_status();
 
diff --git a/include/mmu.h b/include/mmu.h
index 84ec6c5efb3e..669959050194 100644
--- a/include/mmu.h
+++ b/include/mmu.h
@@ -8,6 +8,7 @@
 #define MAP_UNCACHED	0
 #define MAP_CACHED	1
 #define MAP_FAULT	2
+#define MAP_CODE	MAP_CACHED	/* until support added */
 
 /*
  * Depending on the architecture the default mapping can be
-- 
2.39.5




  reply	other threads:[~2025-08-04 18:29 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-04 17:22 [PATCH v4 00/13] ARM: Map sections RO/XN Ahmad Fatoum
2025-08-04 17:22 ` Ahmad Fatoum [this message]
2025-08-04 17:22 ` [PATCH v4 02/13] ARM: pass barebox base to mmu_early_enable() Ahmad Fatoum
2025-08-04 17:22 ` [PATCH v4 03/13] ARM: mmu: move ARCH_MAP_WRITECOMBINE to header Ahmad Fatoum
2025-08-04 17:22 ` [PATCH v4 04/13] ARM: mmu: map memory for barebox proper pagewise Ahmad Fatoum
2025-08-04 17:22 ` [PATCH v4 05/13] ARM: mmu: skip TLB invalidation if remapping zero bytes Ahmad Fatoum
2025-08-04 17:22 ` [PATCH v4 06/13] ARM: mmu: provide setup_trap_pages for both 32- and 64-bit Ahmad Fatoum
2025-08-04 17:22 ` [PATCH v4 07/13] ARM: mmu: share common memory bank remapping code Ahmad Fatoum
2025-08-04 17:22 ` [PATCH v4 08/13] ARM: mmu: make mmu_remap_memory_banks clearer with helper Ahmad Fatoum
2025-08-04 17:22 ` [PATCH v4 09/13] partition: rename region_overlap_end to region_overlap_end_inclusive Ahmad Fatoum
2025-08-04 17:22 ` [PATCH v4 10/13] partition: define new region_overlap_end_exclusive helper Ahmad Fatoum
2025-08-04 17:22 ` [PATCH v4 11/13] ARM: mmu: map text segment ro and data segments execute never Ahmad Fatoum
2025-08-04 17:22 ` [PATCH v4 12/13] ARM: mmu64: map memory for barebox proper pagewise Ahmad Fatoum
2025-08-04 17:22 ` [PATCH v4 13/13] ARM: mmu64: map text segment ro and data segments execute never Ahmad Fatoum
2025-08-05 10:18 ` [PATCH v4 00/13] ARM: Map sections RO/XN 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=20250804172233.2158462-2-a.fatoum@barebox.org \
    --to=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