[edk2-devel] [PATCH] ArmPkg: Invalidate Instruction Cache On MMU Enable

Ashish Singhal via groups.io ashishsingha=nvidia.com at groups.io
Wed Feb 23 05:07:43 UTC 2022


+ @Samer El-Haj-Mahmoud<mailto:Samer.El-Haj-Mahmoud at arm.com>

Hello Leif/Ard/Sami/Samer,

Can you please look at this patch and provide some feedback?

Thanks
Ashish
________________________________
From: Ashish Singhal <ashishsingha at nvidia.com>
Sent: Monday, February 21, 2022 7:42 PM
To: devel at edk2.groups.io <devel at edk2.groups.io>; sami.mujawar at arm.com <sami.mujawar at arm.com>; ardb+tianocore at kernel.org <ardb+tianocore at kernel.org>; quic_llindhol at quicinc.com <quic_llindhol at quicinc.com>
Cc: Ashish Singhal <ashishsingha at nvidia.com>
Subject: [PATCH] ArmPkg: Invalidate Instruction Cache On MMU Enable

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 at 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



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#86881): https://edk2.groups.io/g/devel/message/86881
Mute This Topic: https://groups.io/mt/89309504/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/edk2-devel-archive/attachments/20220223/63a2ac0f/attachment.htm>


More information about the edk2-devel-archive mailing list