arm: armv8: Flush TLB before enabling MMU
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.
--- arch/arm/cpu/armv8/cache_v8.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm/cpu/armv8/cache_v8.c +3 -2
@@ -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
Quoted 18 lines · Mark Kettenis
Commit
9ebdbbc43e5f("arm: armv8: invalidate dcache entries ondcache_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 themmu_setup()call.Fixes 9ebdbbc43e5f ("arm: armv8: invalidate dcache entries on dcache_enable")Signed-off-by Mark Kettenis <[email protected]>--- arch/arm/cpu/armv8/cache_v8.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)arch/arm/cpu/armv8/cache_v8.c +0
-0
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 ); }
Hi Mark,
Quoted 11 lines · Mark Kettenis
Commit
9ebdbbc43e5f("arm: armv8: invalidate dcache entries ondcache_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 themmu_setup()call.Fixes 9ebdbbc43e5f ("arm: armv8: invalidate dcache entries on dcache_enable")Signed-off-by Mark Kettenis <[email protected]>---
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@@ -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
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 ondcache_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 themmu_setup()call.
Quoted 5 lines
Quoted 3 lines
Fixes 9ebdbbc43e5f ("arm: armv8: invalidate dcache entries on dcache_enable")Signed-off-by Mark Kettenis <[email protected]>---
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
/IliasQuoted 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@@ -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 ); }
Ilias Apalodimas
Reviewed-byQuoted 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 ondcache_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 themmu_setup()call.Fixes 9ebdbbc43e5f ("arm: armv8: invalidate dcache entries on dcache_enable")Signed-off-by Mark Kettenis <[email protected]>---
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 ofmmu_setup()incpu/armv8/fsl-layerscape/cpu.cand 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
/IliasQuoted 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@@ -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 ); }
Quoted 8 lines · Mark Kettenis
Commit
9ebdbbc43e5f("arm: armv8: invalidate dcache entries ondcache_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 themmu_setup()call.[...]
Applied to u-boot/master, thanks!
[1/1] arm: armv8: Flush TLB before enabling MMU
commit: afa8f076db3e4ff322455e4b13b796f39c30eb14
Signature · 1 line
Tom