public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] ArmPkg: Invalidate Instruction Cache On MMU Enable
@ 2022-02-22  2:42 Ashish Singhal
  2022-02-23  5:07 ` Ashish Singhal
  2022-02-23  7:02 ` Ard Biesheuvel
  0 siblings, 2 replies; 10+ messages in thread
From: Ashish Singhal @ 2022-02-22  2:42 UTC (permalink / raw)
  To: devel, sami.mujawar, ardb+tianocore, quic_llindhol; +Cc: Ashish Singhal

Even with MMU turned off, instruction cache can speculate
and fetch instructions. This can cause a crash if region
being executed has been modified recently. With this patch,
we ensure that instruction cache is invalidated right after
MMU has been enabled and any potentially stale instruction
fetched earlier has been discarded.

This is specially helpful when the memory attributes of a
region in MMU are being changed and some instructions
operating on the region are prefetched in the instruction
cache.

Signed-off-by: Ashish Singhal <ashishsingha@nvidia.com>
---
 ArmPkg/Library/ArmLib/AArch64/AArch64Support.S           | 4 +++-
 ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibReplaceEntry.S | 2 ++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/ArmPkg/Library/ArmLib/AArch64/AArch64Support.S b/ArmPkg/Library/ArmLib/AArch64/AArch64Support.S
index d3cc1e8671..9648245182 100644
--- a/ArmPkg/Library/ArmLib/AArch64/AArch64Support.S
+++ b/ArmPkg/Library/ArmLib/AArch64/AArch64Support.S
@@ -89,7 +89,9 @@ ASM_FUNC(ArmEnableMmu)
    dsb     nsh
    isb
    msr     sctlr_el3, x0       // Write back
-4: isb
+4: ic      iallu
+   dsb     sy
+   isb
    ret
 
 
diff --git a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibReplaceEntry.S b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibReplaceEntry.S
index 66ebca571e..56cc2dd73f 100644
--- a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibReplaceEntry.S
+++ b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibReplaceEntry.S
@@ -37,6 +37,8 @@
 
   // re-enable the MMU
   msr   sctlr_el\el, x8
+  ic    iallu
+  dsb   sy
   isb
   .endm
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-02-26  4:46 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-22  2:42 [PATCH] ArmPkg: Invalidate Instruction Cache On MMU Enable Ashish Singhal
2022-02-23  5:07 ` Ashish Singhal
2022-02-23  7:02 ` Ard Biesheuvel
2022-02-23  8:58   ` Marc Zyngier
2022-02-23 17:36     ` Ashish Singhal
2022-02-23 17:40       ` [edk2-devel] " Ard Biesheuvel
2022-02-23 18:13         ` Ashish Singhal
2022-02-23 22:54           ` Ard Biesheuvel
2022-02-24  6:01             ` Ashish Singhal
2022-02-26  4:46               ` Ashish Singhal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox