* [PATCH] mmu: explicitly map executable non-SDRAM regions with MAP_CODE
@ 2025-06-18 12:36 Ahmad Fatoum
2025-06-20 12:45 ` Sascha Hauer
2025-06-20 12:46 ` Sascha Hauer
0 siblings, 2 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2025-06-18 12:36 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
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>
---
Sascha, I think this should be ordered before your MMU patches to avoid
the known regressions. Let's see what else there is. :)
---
arch/arm/mach-imx/romapi.c | 3 ++-
drivers/firmware/socfpga.c | 3 ++-
drivers/hab/habv4.c | 2 +-
include/mmu.h | 1 +
4 files changed, 6 insertions(+), 3 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..4b10ca009798 100644
--- a/drivers/firmware/socfpga.c
+++ b/drivers/firmware/socfpga.c
@@ -353,7 +353,8 @@ static int socfpga_fpgamgr_program_finish(struct firmware_handler *fh)
return status;
}
- remap_range((void *)CYCLONE5_OCRAM_ADDRESS, PAGE_SIZE, MAP_CACHED);
+ /* TODO: restore uncached mapping once we no longer need this? */
+ remap_range((void *)CYCLONE5_OCRAM_ADDRESS, PAGE_SIZE, MAP_CODE);
dev_dbg(&mgr->dev, "Setting APPLYCFG bit...\n");
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mmu: explicitly map executable non-SDRAM regions with MAP_CODE
2025-06-18 12:36 [PATCH] mmu: explicitly map executable non-SDRAM regions with MAP_CODE Ahmad Fatoum
@ 2025-06-20 12:45 ` Sascha Hauer
2025-06-20 15:45 ` Ahmad Fatoum
2025-06-20 12:46 ` Sascha Hauer
1 sibling, 1 reply; 4+ messages in thread
From: Sascha Hauer @ 2025-06-20 12:45 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Wed, Jun 18, 2025 at 02:36:42PM +0200, Ahmad Fatoum wrote:
> 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>
> ---
> Sascha, I think this should be ordered before your MMU patches to avoid
> the known regressions. Let's see what else there is. :)
> ---
> arch/arm/mach-imx/romapi.c | 3 ++-
> drivers/firmware/socfpga.c | 3 ++-
> drivers/hab/habv4.c | 2 +-
> include/mmu.h | 1 +
> 4 files changed, 6 insertions(+), 3 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..4b10ca009798 100644
> --- a/drivers/firmware/socfpga.c
> +++ b/drivers/firmware/socfpga.c
> @@ -353,7 +353,8 @@ static int socfpga_fpgamgr_program_finish(struct firmware_handler *fh)
> return status;
> }
>
> - remap_range((void *)CYCLONE5_OCRAM_ADDRESS, PAGE_SIZE, MAP_CACHED);
> + /* TODO: restore uncached mapping once we no longer need this? */
> + remap_range((void *)CYCLONE5_OCRAM_ADDRESS, PAGE_SIZE, MAP_CODE);
This is done before the code is copied to this page. I moved it after
the fncpy call to avoid writing to readonly memory.
While at it I also added the remapping to MAP_UNCACHED.
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mmu: explicitly map executable non-SDRAM regions with MAP_CODE
2025-06-18 12:36 [PATCH] mmu: explicitly map executable non-SDRAM regions with MAP_CODE Ahmad Fatoum
2025-06-20 12:45 ` Sascha Hauer
@ 2025-06-20 12:46 ` Sascha Hauer
1 sibling, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2025-06-20 12:46 UTC (permalink / raw)
To: barebox, Ahmad Fatoum
On Wed, 18 Jun 2025 14:36:42 +0200, Ahmad Fatoum wrote:
> 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.
>
> [...]
Applied, thanks!
[1/1] mmu: explicitly map executable non-SDRAM regions with MAP_CODE
https://git.pengutronix.de/cgit/barebox/commit/?id=225fda833a82 (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mmu: explicitly map executable non-SDRAM regions with MAP_CODE
2025-06-20 12:45 ` Sascha Hauer
@ 2025-06-20 15:45 ` Ahmad Fatoum
0 siblings, 0 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2025-06-20 15:45 UTC (permalink / raw)
To: Sascha Hauer, Ahmad Fatoum; +Cc: barebox
On 20.06.25 14:45, Sascha Hauer wrote:
> On Wed, Jun 18, 2025 at 02:36:42PM +0200, Ahmad Fatoum wrote:
>> 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>
>> ---
>> Sascha, I think this should be ordered before your MMU patches to avoid
>> the known regressions. Let's see what else there is. :)
>> ---
>> arch/arm/mach-imx/romapi.c | 3 ++-
>> drivers/firmware/socfpga.c | 3 ++-
>> drivers/hab/habv4.c | 2 +-
>> include/mmu.h | 1 +
>> 4 files changed, 6 insertions(+), 3 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..4b10ca009798 100644
>> --- a/drivers/firmware/socfpga.c
>> +++ b/drivers/firmware/socfpga.c
>> @@ -353,7 +353,8 @@ static int socfpga_fpgamgr_program_finish(struct firmware_handler *fh)
>> return status;
>> }
>>
>> - remap_range((void *)CYCLONE5_OCRAM_ADDRESS, PAGE_SIZE, MAP_CACHED);
>> + /* TODO: restore uncached mapping once we no longer need this? */
>> + remap_range((void *)CYCLONE5_OCRAM_ADDRESS, PAGE_SIZE, MAP_CODE);
>
> This is done before the code is copied to this page. I moved it after
> the fncpy call to avoid writing to readonly memory.
fncpy calls memcpy internally though, so we should either leave the MAP_CACHED
as is and add a further MAP_CODE after the fncpy or introduce a fncpy_toio
that calls memcpy_toio internally.
What do you think?
> While at it I also added the remapping to MAP_UNCACHED.
Thanks,
Ahmad
>
> Sascha
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-06-20 16:15 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-18 12:36 [PATCH] mmu: explicitly map executable non-SDRAM regions with MAP_CODE Ahmad Fatoum
2025-06-20 12:45 ` Sascha Hauer
2025-06-20 15:45 ` Ahmad Fatoum
2025-06-20 12:46 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox