Skip to contentSkip to conversation

arm: armv8: Flush TLB before enabling MMU

PATCH In review Mark Kettenis 5 participants 6 messages Jan 10 – Feb 24 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm: armv8: Flush TLB before enabling MMU

Commit 9ebdbbc43e5f ("arm: armv8: invalidate dcache entries on dcache_enable") broke Apple Silicon machines in certain scenarios. If the MMU is currently not enabled we need to flush the TLB before we enable it to prevent stale TLB entries from becoming active again. So move the __asm_invalidate_tlb_all() back immediately before the mmu_setup() call.

Fixes 9ebdbbc43e5f ("arm: armv8: invalidate dcache entries on dcache_enable")
---
 arch/arm/cpu/armv8/cache_v8.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm/cpu/armv8/cache_v8.c +3 -2
index 0309da6d397..39479df7b21 100644
@@ -878,15 +878,16 @@ void flush_dcache_range(unsigned long start, unsigned long stop)
 void dcache_enable(void)
 {
 	/* The data cache is not active unless the mmu is enabled */
-	if (!mmu_status())
+	if (!mmu_status()) {
+		__asm_invalidate_tlb_all();
 		mmu_setup();
+	}
 
 	/* Set up page tables only once (it is done also by mmu_setup()) */
 	if (!gd->arch.tlb_fillptr)
 		setup_all_pgtables();
 
 	invalidate_dcache_all();
-	__asm_invalidate_tlb_all();
 	set_sctlr(get_sctlr() | CR_C);
 }
 
Signature · 1 line
2.52.0
#1 lore raw
Quoted 18 lines · Mark Kettenis

Commit 9ebdbbc43e5f ("arm: armv8: invalidate dcache entries on dcache_enable") broke Apple Silicon machines in certain scenarios. If the MMU is currently not enabled we need to flush the TLB before we enable it to prevent stale TLB entries from becoming active again. So move the __asm_invalidate_tlb_all() back immediately before the mmu_setup() call.

Fixes 9ebdbbc43e5f ("arm: armv8: invalidate dcache entries on dcache_enable")
---
 arch/arm/cpu/armv8/cache_v8.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm/cpu/armv8/cache_v8.c +0 -0
index 0309da6d397..39479df7b21 100644

arch/arm/cpu/armv8/cache_v8.c void flush_dcache_range(unsigned long start, unsigned long stop) · line 883

Quoted 7 lines
arch/arm/cpu/armv8/cache_v8.c +2 -1
@@ -878,15 +878,16 @@ void flush_dcache_range(unsigned long start, unsigned long stop)
 void dcache_enable(void)
 {
 	/* The data cache is not active unless the mmu is enabled */
-	if (!mmu_status())
+	if (!mmu_status()) {
+		__asm_invalidate_tlb_all();
 		mmu_setup();

So, if I understand correctly the problem is that the TLB is enabled by mmu_setup which happened before we invalidated the existing TLB entries?

Quoted 11 lines
arch/arm/cpu/armv8/cache_v8.c +1 -1
+	}
 
 	/* Set up page tables only once (it is done also by mmu_setup()) */
 	if (!gd->arch.tlb_fillptr)
 		setup_all_pgtables();
 
 	invalidate_dcache_all();
-	__asm_invalidate_tlb_all();
 	set_sctlr(get_sctlr() | CR_C);
 }
 
#2 lore raw
In reply to Mark Kettenis

Hi Mark,

Quoted 11 lines · Mark Kettenis

Commit 9ebdbbc43e5f ("arm: armv8: invalidate dcache entries on dcache_enable") broke Apple Silicon machines in certain scenarios. If the MMU is currently not enabled we need to flush the TLB before we enable it to prevent stale TLB entries from becoming active again. So move the __asm_invalidate_tlb_all() back immediately before the mmu_setup() call.

Fixes 9ebdbbc43e5f ("arm: armv8: invalidate dcache entries on dcache_enable")

---

Should we keep the check here or mayber move it in mmu_setup()?

Thanks
/Ilias

Quoted 29 lines
 arch/arm/cpu/armv8/cache_v8.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm/cpu/armv8/cache_v8.c +3 -3
index 0309da6d397..39479df7b21 100644
@@ -878,15 +878,16 @@ void flush_dcache_range(unsigned long start, unsigned long stop)
 void dcache_enable(void)
 {
        /* The data cache is not active unless the mmu is enabled */
-       if (!mmu_status())
+       if (!mmu_status()) {
+               __asm_invalidate_tlb_all();
                mmu_setup();
+       }
 
        /* Set up page tables only once (it is done also by mmu_setup()) */
        if (!gd->arch.tlb_fillptr)
                setup_all_pgtables();
 
        invalidate_dcache_all();
-       __asm_invalidate_tlb_all();
        set_sctlr(get_sctlr() | CR_C);
 }
 
--

2.52.0

#3 lore raw
In reply to Mark Kettenis
Quoted 1 line

Hi Mark,

Hi Ilias,

Sorry for the late reply. I was a bit busy the last weeks...

Quoted 9 lines · Mark Kettenis
Quoted 8 lines

Commit 9ebdbbc43e5f ("arm: armv8: invalidate dcache entries on dcache_enable") broke Apple Silicon machines in certain scenarios. If the MMU is currently not enabled we need to flush the TLB before we enable it to prevent stale TLB entries from becoming active again. So move the __asm_invalidate_tlb_all() back immediately before the mmu_setup() call.

Quoted 5 lines
Quoted 3 lines
Fixes 9ebdbbc43e5f ("arm: armv8: invalidate dcache entries on dcache_enable")

---

Should we keep the check here or mayber move it in mmu_setup()?

It would make sense to move it to mmu_setup(), but I went for a partial revert as there is an alternative implementation of mmu_setup() in cpu/armv8/fsl-layerscape/cpu.c and I couldn't test that code.

Hope this can still make the next release.

Quoted 28 lines

Thanks
/Ilias

Quoted 25 lines
 arch/arm/cpu/armv8/cache_v8.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm/cpu/armv8/cache_v8.c +3 -2
index 0309da6d397..39479df7b21 100644
@@ -878,15 +878,16 @@ void flush_dcache_range(unsigned long start, unsigned long stop)
 void dcache_enable(void)
 {
        /* The data cache is not active unless the mmu is enabled */
-       if (!mmu_status())
+       if (!mmu_status()) {
+               __asm_invalidate_tlb_all();
                mmu_setup();
+       }
 
        /* Set up page tables only once (it is done also by mmu_setup()) */
        if (!gd->arch.tlb_fillptr)
                setup_all_pgtables();
 
        invalidate_dcache_all();
-       __asm_invalidate_tlb_all();
        set_sctlr(get_sctlr() | CR_C);
 }
Reviewed-by
#4 lore raw
Quoted 20 lines · Mark Kettenis
Quoted 2 lines

Hi Mark,

Hi Ilias,

Sorry for the late reply. I was a bit busy the last weeks...

Quoted 13 lines · Mark Kettenis
Quoted 11 lines

Commit 9ebdbbc43e5f ("arm: armv8: invalidate dcache entries on dcache_enable") broke Apple Silicon machines in certain scenarios. If the MMU is currently not enabled we need to flush the TLB before we enable it to prevent stale TLB entries from becoming active again. So move the __asm_invalidate_tlb_all() back immediately before the mmu_setup() call.

Fixes 9ebdbbc43e5f ("arm: armv8: invalidate dcache entries on dcache_enable")

---

Quoted 8 lines
Quoted 1 line

Should we keep the check here or mayber move it in mmu_setup()?

It would make sense to move it to mmu_setup(), but I went for a partial revert as there is an alternative implementation of mmu_setup() in cpu/armv8/fsl-layerscape/cpu.c and I couldn't test that code.

Hope this can still make the next release.

Ok that's unfortunate. Let's get it in now since it's a fix

Quoted 29 lines
Quoted 29 lines

Thanks
/Ilias

Quoted 25 lines
 arch/arm/cpu/armv8/cache_v8.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm/cpu/armv8/cache_v8.c +3 -2
index 0309da6d397..39479df7b21 100644
@@ -878,15 +878,16 @@ void flush_dcache_range(unsigned long start, unsigned long stop)
 void dcache_enable(void)
 {
        /* The data cache is not active unless the mmu is enabled */
-       if (!mmu_status())
+       if (!mmu_status()) {
+               __asm_invalidate_tlb_all();
                mmu_setup();
+       }
 
        /* Set up page tables only once (it is done also by mmu_setup()) */
        if (!gd->arch.tlb_fillptr)
                setup_all_pgtables();
 
        invalidate_dcache_all();
-       __asm_invalidate_tlb_all();
        set_sctlr(get_sctlr() | CR_C);
 }
#5 lore raw
In reply to Mark Kettenis
Quoted 8 lines · Mark Kettenis

Commit 9ebdbbc43e5f ("arm: armv8: invalidate dcache entries on dcache_enable") broke Apple Silicon machines in certain scenarios. If the MMU is currently not enabled we need to flush the TLB before we enable it to prevent stale TLB entries from becoming active again. So move the __asm_invalidate_tlb_all() back immediately before the mmu_setup() call.

[...]

Applied to u-boot/master, thanks!

[1/1] arm: armv8: Flush TLB before enabling MMU

      commit: afa8f076db3e4ff322455e4b13b796f39c30eb14
Signature · 1 line
Tom