public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ashish Singhal" <ashishsingha@nvidia.com>
To: "devel@edk2.groups.io" <devel@edk2.groups.io>,
	"sami.mujawar@arm.com" <sami.mujawar@arm.com>,
	"ardb+tianocore@kernel.org" <ardb+tianocore@kernel.org>,
	"quic_llindhol@quicinc.com" <quic_llindhol@quicinc.com>,
	Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>
Subject: Re: [PATCH] ArmPkg: Invalidate Instruction Cache On MMU Enable
Date: Wed, 23 Feb 2022 05:07:43 +0000	[thread overview]
Message-ID: <CH2PR12MB554678277E5ADF1474EB5BAEBA3C9@CH2PR12MB5546.namprd12.prod.outlook.com> (raw)
In-Reply-To: <122c32bb19ed0730ef166b9f46d3b112bc9ed937.1645497637.git.ashishsingha@nvidia.com>

[-- Attachment #1: Type: text/plain, Size: 2253 bytes --]

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

Hello Leif/Ard/Sami/Samer,

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

Thanks
Ashish
________________________________
From: Ashish Singhal <ashishsingha@nvidia.com>
Sent: Monday, February 21, 2022 7:42 PM
To: devel@edk2.groups.io <devel@edk2.groups.io>; sami.mujawar@arm.com <sami.mujawar@arm.com>; ardb+tianocore@kernel.org <ardb+tianocore@kernel.org>; quic_llindhol@quicinc.com <quic_llindhol@quicinc.com>
Cc: Ashish Singhal <ashishsingha@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@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


[-- Attachment #2: Type: text/html, Size: 4451 bytes --]

  reply	other threads:[~2022-02-23  5:07 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-22  2:42 [PATCH] ArmPkg: Invalidate Instruction Cache On MMU Enable Ashish Singhal
2022-02-23  5:07 ` Ashish Singhal [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CH2PR12MB554678277E5ADF1474EB5BAEBA3C9@CH2PR12MB5546.namprd12.prod.outlook.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox