Skip to contentSkip to conversation

Fix speculative access to firewalled regions on AM62 SoCs

PATCH Superseded Anshul Dalal 2 participants 6 messages May 18 – May 20

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Fix speculative access to firewalled regions on AM62 SoCs

Hi all,

This patch series fixes firewall exceptions observed on AM62 family of devices due to speculative accesses made by the A53 core to secure DDR regions.

For testing, I had used an AM62p with the following diff to enable logging from TIFS:

--- a/board/ti/am62px/board-cfg.yaml
+++ b/board/ti/am62px/board-cfg.yaml
@@ -33,5 +33,5 @@ board-cfg:

           subhdr:
               magic: 0x020C
               size: 8
  -        trace_dst_enables: 0x00
  -        trace_src_enables: 0x00
  +        trace_dst_enables: 0xd
  +        trace_src_enables: 0x3f

Without this patch an exception[1] similar to the following is observed at A53 SPL stage:

FWL Bit 0x1
Exception addr 0x45B08000
FWL Exception 0x1000100
0x60000
0x80002880
0x0
0x141201
0x40

[1]: https://software-dl.ti.com/tisci/esd/latest/6_topic_user_guides/firewall_faq.html#how-do-i-debug-firewall-issues

---
Changes in v2:
- Added Reported-by from Suhaas
- Modify ARMv8's mmu_setup instead of overriding it only for mach-k3
- Add mmu_enable to give boards more control over MMU configruation
- Link to v1: https://patch.msgid.link/[email protected]

---
Anshul Dalal (2):
arm: armv8: mmu: move mmu enablement out of mmu_setup
mach-k3: enable mmu after reserved memory is unmapped

 arch/arm/cpu/armv8/cache_v8.c    | 5 ++++-
 arch/arm/include/asm/armv8/mmu.h | 5 +++++
 arch/arm/mach-k3/common.c        | 2 ++
 3 files changed, 11 insertions(+), 1 deletion(-)

---
base-commit: 13c1e13cc7fb1fa07867f835ccf25913594c71ec
change-id: 20260512-am62_firewall_exception_fix-20a335cca769

Best regards,

Signature · 1 line
Anshul Dalal <[email protected]>
#1 lore raw

PATCH v2 1/2 arm: armv8: mmu: move mmu enablement out of mmu_setup

Currently mmu_setup for ARMv8 performs two functions, first it sets up the page tables based the memory map provided by the board and then it enables the MMU.

However for some platforms runtime fixes to the generated page tables are required before the MMU can be enabled, such as K3 family of SoCs.

Therefore this patch moves the enablement of the MMU out of mmu_setup and to a standalone mmu_enable function to give more granular control to the platforms.

Note that no functional changes are intended from this patch.

---
 arch/arm/cpu/armv8/cache_v8.c    | 5 ++++-
 arch/arm/include/asm/armv8/mmu.h | 5 +++++
 arch/arm/mach-k3/common.c        | 1 +
 3 files changed, 10 insertions(+), 1 deletion(-)
arch/arm/cpu/armv8/cache_v8.c +4 -1
index 39479df7b21..7c0e3f6d055 100644
@@ -810,8 +810,10 @@ __weak void mmu_setup(void)
 	el = current_el();
 	set_ttbr_tcr_mair(el, gd->arch.tlb_addr, get_tcr(NULL, NULL),
 			  MEMORY_ATTRIBUTES);
+}
 
-	/* enable the mmu */
+void mmu_enable(void)
+{
 	set_sctlr(get_sctlr() | CR_M);
 }
 
@@ -881,6 +883,7 @@ void dcache_enable(void)
 	if (!mmu_status()) {
 		__asm_invalidate_tlb_all();
 		mmu_setup();
+		mmu_enable();
 	}
 
 	/* Set up page tables only once (it is done also by mmu_setup()) */
arch/arm/include/asm/armv8/mmu.h +5 -0
index 8aa5f9721c4..5359b2ad87b 100644
@@ -222,6 +222,11 @@ u64 get_tcr(u64 *pips, u64 *pva_bits);
  * mmu_setup() - Sets up the mmu page tables as per mem_map
  */
 void mmu_setup(void);
+
+/**
+ * mmu_enable() - Enable the MMU by setting 'M' bit in SCTLR register
+ */
+void mmu_enable(void);
 #endif
 
 #endif /* _ASM_ARMV8_MMU_H_ */
arch/arm/mach-k3/common.c +1 -0
index b0a75988714..396018b7a7a 100644
@@ -279,6 +279,7 @@ void enable_caches(void)
 		       __func__, fdt_strerror(ret));
 
 	mmu_setup();
+	mmu_enable();
 
 	if (CONFIG_K3_ATF_LOAD_ADDR >= CFG_SYS_SDRAM_BASE) {
 		ret = mmu_unmap_reserved_mem("tfa", true);
Signature · 1 line
2.53.0
Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH master v2 1/2] arm: armv8: mmu: move mmu enablement out of mmu_setup

Quoted 8 lines · Anshul Dalal

Currently mmu_setup for ARMv8 performs two functions, first it sets up the page tables based the memory map provided by the board and then it enables the MMU.

However for some platforms runtime fixes to the generated page tables are required before the MMU can be enabled, such as K3 family of SoCs.

Quoted 8 lines

Therefore this patch moves the enablement of the MMU out of mmu_setup and to a standalone mmu_enable function to give more granular control to the platforms.

Note that no functional changes are intended from this patch.

---

Quoted 61 lines
 arch/arm/cpu/armv8/cache_v8.c    | 5 ++++-
 arch/arm/include/asm/armv8/mmu.h | 5 +++++
 arch/arm/mach-k3/common.c        | 1 +
 3 files changed, 10 insertions(+), 1 deletion(-)
arch/arm/cpu/armv8/cache_v8.c +4 -1
index 39479df7b21..7c0e3f6d055 100644
@@ -810,8 +810,10 @@ __weak void mmu_setup(void)
        el = current_el();
        set_ttbr_tcr_mair(el, gd->arch.tlb_addr, get_tcr(NULL, NULL),
                          MEMORY_ATTRIBUTES);
+}
 
-       /* enable the mmu */
+void mmu_enable(void)
+{
        set_sctlr(get_sctlr() | CR_M);
 }
 
@@ -881,6 +883,7 @@ void dcache_enable(void)
        if (!mmu_status()) {
                __asm_invalidate_tlb_all();
                mmu_setup();
+               mmu_enable();
        }
 
        /* Set up page tables only once (it is done also by mmu_setup()) */
arch/arm/include/asm/armv8/mmu.h +5 -0
index 8aa5f9721c4..5359b2ad87b 100644
@@ -222,6 +222,11 @@ u64 get_tcr(u64 *pips, u64 *pva_bits);
  * mmu_setup() - Sets up the mmu page tables as per mem_map
  */
 void mmu_setup(void);
+
+/**
+ * mmu_enable() - Enable the MMU by setting 'M' bit in SCTLR register
+ */
+void mmu_enable(void);
 #endif
 
 #endif /* _ASM_ARMV8_MMU_H_ */
arch/arm/mach-k3/common.c +1 -1
index b0a75988714..396018b7a7a 100644
@@ -279,6 +279,7 @@ void enable_caches(void)
                       __func__, fdt_strerror(ret));
 
        mmu_setup();
+       mmu_enable();
 
        if (CONFIG_K3_ATF_LOAD_ADDR >= CFG_SYS_SDRAM_BASE) {
                ret = mmu_unmap_reserved_mem("tfa", true);
 
--

2.53.0

#3 lore raw

PATCH v2 2/2 mach-k3: enable mmu after reserved memory is unmapped

In reply to Anshul Dalal

Currently the sequence to enable caches for the A53/A72 core on K3 devices looks as follows:

1. Map entire DDR banks
2. Setup page tables (done by mmu_setup)
3. Enable MMU
4. Unmap reserved-memory regions
5. Enable caches

However there is a brief period of execution between #3 and #4 where the core can issue speculative accesses to the entire DDR space (including the reserved-memory regions) despite the caches being disabled.

A firewall exception is triggered whenever such speculative access is made to secure DDR region of TFA or OP-TEE. This patch fixes the issue by re-ordering the sequence as follows:

1. Map entire DDR banks
2. Setup page tables
3. Unmap reserved-memory regions
4. Enable MMU
5. Enable caches

Fixes f1c694b8fdde ("mach-k3: map all banks using mem_map_from_dram_banks")
---
 arch/arm/mach-k3/common.c | 1 +
 1 file changed, 1 insertion(+)
arch/arm/mach-k3/common.c +1 -0
index 396018b7a7a..9bebc0b1106 100644
@@ -295,6 +295,7 @@ void enable_caches(void)
 			       __func__, ret);
 	}
 
+	mmu_enable();
 	icache_enable();
 	dcache_enable();
 }
Signature · 1 line
2.53.0
#4 lore raw

Re: [PATCH master v2 2/2] mach-k3: enable mmu after reserved memory is unmapped

Quoted 36 lines · Anshul Dalal

Currently the sequence to enable caches for the A53/A72 core on K3 devices looks as follows:

1. Map entire DDR banks
2. Setup page tables (done by mmu_setup)
3. Enable MMU
4. Unmap reserved-memory regions
5. Enable caches

However there is a brief period of execution between #3 and #4 where the core can issue speculative accesses to the entire DDR space (including the reserved-memory regions) despite the caches being disabled.

A firewall exception is triggered whenever such speculative access is made to secure DDR region of TFA or OP-TEE. This patch fixes the issue by re-ordering the sequence as follows:

1. Map entire DDR banks
2. Setup page tables
3. Unmap reserved-memory regions
4. Enable MMU
5. Enable caches

Fixes f1c694b8fdde ("mach-k3: map all banks using mem_map_from_dram_banks")
---
 arch/arm/mach-k3/common.c | 1 +
 1 file changed, 1 insertion(+)
arch/arm/mach-k3/common.c +0 -0
index 396018b7a7a..9bebc0b1106 100644

arch/arm/mach-k3/common.c void enable_caches(void) · line 298

Quoted 4 lines
arch/arm/mach-k3/common.c +1 -0
@@ -295,6 +295,7 @@ void enable_caches(void)
                               __func__, ret);
        }
 
+       mmu_enable();

You added mm_enable() on the previous patch a few lines above. I assumed it was to keep the code changes confined to one patch without changing the behavior, but you have to remove it now. You can even skip it entirely since dcache_enable() will do it, but I don't mind having the explicit call.

Cheers
/Ilias

Quoted 7 lines
arch/arm/mach-k3/common.c +0 -1
        icache_enable();
        dcache_enable();
 }
 
--

2.53.0

#5 lore raw

Re: [PATCH master v2 2/2] mach-k3: enable mmu after reserved memory is unmapped

Quoted 40 lines · Ilias Apalodimas
Quoted 39 lines · Anshul Dalal

Currently the sequence to enable caches for the A53/A72 core on K3 devices looks as follows:

1. Map entire DDR banks
2. Setup page tables (done by mmu_setup)
3. Enable MMU
4. Unmap reserved-memory regions
5. Enable caches

However there is a brief period of execution between #3 and #4 where the core can issue speculative accesses to the entire DDR space (including the reserved-memory regions) despite the caches being disabled.

A firewall exception is triggered whenever such speculative access is made to secure DDR region of TFA or OP-TEE. This patch fixes the issue by re-ordering the sequence as follows:

1. Map entire DDR banks
2. Setup page tables
3. Unmap reserved-memory regions
4. Enable MMU
5. Enable caches

Fixes f1c694b8fdde ("mach-k3: map all banks using mem_map_from_dram_banks")
---
 arch/arm/mach-k3/common.c | 1 +
 1 file changed, 1 insertion(+)
arch/arm/mach-k3/common.c +0 -0
index 396018b7a7a..9bebc0b1106 100644
@@ -295,6 +295,7 @@ void enable_caches(void)
                               __func__, ret);
        }
 
Quoted 7 lines

arch/arm/mach-k3/common.c void enable_caches(void) · line 298

Quoted 1 line
arch/arm/mach-k3/common.c +1 -0
+       mmu_enable();

You added mm_enable() on the previous patch a few lines above. I assumed it was to keep the code changes confined to one patch without changing the behavior, but you have to remove it now. You can even skip it entirely since dcache_enable() will do it, but I don't mind having the explicit call.

I indeed meant to remove the mmu_enable call added earlier, will fix in the next revision.

Thanks for the review,
Anshul

Quoted 11 lines

Cheers
/Ilias

Quoted 7 lines
arch/arm/mach-k3/common.c +0 -1
        icache_enable();
        dcache_enable();
 }
 
--

2.53.0