From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.65]) by mx.groups.io with SMTP id smtpd.web12.3842.1645592865726882430 for ; Tue, 22 Feb 2022 21:07:46 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@nvidia.com header.s=selector2 header.b=ea1xbzSO; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: nvidia.com, ip: 40.107.220.65, mailfrom: ashishsingha@nvidia.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lOMyMpMrm6dDT6RUqBkAsNit1+TU2uzP7aiVdYCEGnYfAt2xjsi/J1vQYAU6YqqrWDDO66ceHtRzC8lWQd0mtT8r9YQbHbPQ/tSyE4ff+CCbSNlYQ5S5uXPf1C9w4L+mi89KwuLCV+T7NtzzZWUAxeYy6Nnpd1Vu7MyUeiRSSyr5jFnfDn86nK6cCENaZ48SsrDu+/7qQthiOuo7G/OoOKBN1iPle5CFQUjxwva3OAui0hAVvcPi0ze19lM+Pv93osX74xW9huwkx5fIrApPTqRBxSvfEJk6pG0MrOlyz30XrpXaAdgbEyaBYry4ssKDhppPyp/XDH5003gVAlUfRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=SdQbez5/vU4o/KuzuM6/EBNVTZOlnX/m5lGeluekHY0=; b=eGWZsKqwWDCOdpf1mKS2ezAAg2VfF82cndpkARzOVdJaK1AS12s13lS79BymzUL+HxXwtCs05qxjTOyU/8thgArAYEtZ9/w6p3Mi7SXYmZzv+2fheCis8/Ei0TT1m8Tg4TGli9pSNcZhz6V9QeL/w8cZvxcaKee33/8XemdxBIGEUGDsXZqgQyhOX4qhxvcyqrcjL397xnM/9DMGFUN+TlAZYer3kYqVJ5+uTXgpomC/KLXIoxr+C8u2aqRxoGkDYWlx7MaQFU9uqctZd2O4dEADYZomdQ0s8mSmfLC6U8KDjtmHZGtSGMvY658iO0/uiwZx4iTq+Z9Lu+Uns7NJ7A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SdQbez5/vU4o/KuzuM6/EBNVTZOlnX/m5lGeluekHY0=; b=ea1xbzSOzQIf5MgVgRYOZNsP2HJvbtAZj1/XpANbgt+d6+fNmlEJl9VThoon5+5ith0dr6zql3EOKxwhPepNiTyWEo75RTDvEjdlX51BrdJFfVAZ/H417nZZ4mCAjz6Y/ztcpSncyT6Lyyczru3SpTTlqQXeRYu8sGepsf3kDaXjHAqN/FwHObYpvJ0rpTS6O51KlGBDKzIfThLKZzeqJ76MWcYv3yC/qi75zPql5I7pbcX3Gyk0zn7vFFnGrsauLu4u/ODJrNignAr+p+uEPUGntKjncfqnNVJ9J2g9mxODdM8Yn5IErTwtYmxqNkj4I72Er7w6Nn86IK/eQFbmSA== Received: from CH2PR12MB5546.namprd12.prod.outlook.com (2603:10b6:610:63::14) by BL1PR12MB5223.namprd12.prod.outlook.com (2603:10b6:208:315::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.21; Wed, 23 Feb 2022 05:07:43 +0000 Received: from CH2PR12MB5546.namprd12.prod.outlook.com ([fe80::2003:f63d:1875:ff76]) by CH2PR12MB5546.namprd12.prod.outlook.com ([fe80::2003:f63d:1875:ff76%8]) with mapi id 15.20.4995.027; Wed, 23 Feb 2022 05:07:43 +0000 From: "Ashish Singhal" To: "devel@edk2.groups.io" , "sami.mujawar@arm.com" , "ardb+tianocore@kernel.org" , "quic_llindhol@quicinc.com" , Samer El-Haj-Mahmoud Subject: Re: [PATCH] ArmPkg: Invalidate Instruction Cache On MMU Enable Thread-Topic: [PATCH] ArmPkg: Invalidate Instruction Cache On MMU Enable Thread-Index: AQHYJ5XQvRPcrKvPP0GmL2mPrc+CGKyglx8e Date: Wed, 23 Feb 2022 05:07:43 +0000 Message-ID: References: <122c32bb19ed0730ef166b9f46d3b112bc9ed937.1645497637.git.ashishsingha@nvidia.com> In-Reply-To: <122c32bb19ed0730ef166b9f46d3b112bc9ed937.1645497637.git.ashishsingha@nvidia.com> Accept-Language: en-US X-Mentions: Samer.El-Haj-Mahmoud@arm.com X-MS-Has-Attach: X-MS-TNEF-Correlator: suggested_attachment_session_id: 1599d660-aa87-3f51-2041-2bfe1c4cae75 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: b9613d00-6eac-4c01-6649-08d9f68a6caf x-ms-traffictypediagnostic: BL1PR12MB5223:EE_ x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: w7ssVGNo0P5YqJydmhZGG9PGGSoopOCo09TmJ6we8X6wEedGGio1pT+3h/BcL5GnjBp1gZ+WjAi3C+zwTdTKE8U9Qr1tvRONEVX/98YhBy6vPhrfP2PsAEc8nS24akkaESlrHd7CW1UxB6zw9hkxZx6mpoWYi64wHxN3hDJymhzQHyydnlV/yWr+5NGo92+aCEOHjKOEnCuRH38u8IfE+oX56ueCAXITOBEvLkKbnI8Oh/VoCsU96OnUr1HGBvsJMbh4BmVBrdwDtvmtEmxJBFJKCQ2BM5G1Ajw1INHqWa0phxnI5W3ex84bGZGUTFnkxOlrXAwMmES9BrignkdEcsJ7Xbyqga9FkMWM5waS8JaFWCnb4M54o8ZYTN/v313AZcbJdjvRWDeoPMneYBYWOBiLbS42Xs1iLMKJLMquQrKwetOZQhJn789RMErcsJ3XsiUBKq9IbLmZ0682jXAizi1Fz9DBnUo3fbm7fcsD9sprXQFM2rg4nAQ69UzS8HU1+IqZpGBaV9GxC2KsWt5EzndGxfky0z8wOchtoD4MwflWK0xg8h7srqoHZHAeqQnDSCXC39pX65wztMYqd2XV4iboRdMs9riirmrFeACJe/7YXzcXxnzz+I262DOYwkgjyfGYz0t0qZsu5Spy1da4FvMQ53TRH0rfPpew5Nuj/QH57u/RdMDTdBawRLmFQbYGyCaGJyh+SRAwpCg39zsqEQ== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH2PR12MB5546.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(83380400001)(33656002)(38070700005)(186003)(86362001)(26005)(38100700002)(71200400001)(122000001)(110136005)(19627235002)(508600001)(53546011)(7696005)(316002)(9686003)(91956017)(66946007)(66556008)(66476007)(66446008)(64756008)(5660300002)(52536014)(8936002)(19627405001)(76116006)(2906002)(6506007)(8676002)(55016003);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?vSxS+5msi9VKMuYmisEM9b/90kI4LfLdIibuAf9RnPh+cWTTSd78gj3Kztdt?= =?us-ascii?Q?XaBXC+q+wfGCLdUxcOlGkXOdWHuP5XnpwZqOhpiGyOYFeuvdyeSFVJXNqG5y?= =?us-ascii?Q?aC23Dz0QsnvO2TFft3MymGY2or+k5iQ+7vmk49KifuwY592MdeQ6cQ4Yb7n2?= =?us-ascii?Q?2cEs1qfyoPaJNeYMjw4dF34r5tJB/nU/52iaCJdn3OdisSXx9plfINanyyLC?= =?us-ascii?Q?z+I9jmu9MVidcniPKVp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N?= =?us-ascii?Q?jKETsb4ucNBmqEnfBQ0BS21XB//W/tGjKQ1bOHyoLF8+Rn5a9LfYUdVYXoSn?= =?us-ascii?Q?d+1Q8WRQUgFPA08l6zG55JRxC7b010b6Z9ttf8bcLTM+yOhv1JsvCdx8PJ8c?= =?us-ascii?Q?zzsX5teYxFqgB7FR7HjAEVQId94RuFDNsDtWACjAhVlmd2ItrzciCgryojLY?= =?us-ascii?Q?+RjOUVqoQsSLXW8cDysdJsGPhGAR1yZxC8lrBHtIi2rQhwd3nsqCCj7PjeS2?= =?us-ascii?Q?KDxu2w2/vvrkv3Zt1gj5o2u9RAMu4aybR2X1ec8GBWUgB23sY9/3LOCGClrW?= =?us-ascii?Q?1qogSCft6n1T3cYffZmRCapTSbhIU2tt3xfKVCOl0g/xpb2diI1nYER0s+Ml?= =?us-ascii?Q?rBhUPIrEFh30AMdRYXwcxTLYgkjVlLbyIT0AJ9WkM+3lGxu4nD/imFPZEHkC?= =?us-ascii?Q?0ASqkYo9J4N5TGq8VhMsLqAC8liBMB2bb1pxF35ZcbdUWSp+8k7awb3sW8D/?= =?us-ascii?Q?xhB8/t4T2Q/nNQC5rWVHza0=3D?= MIME-Version: 1.0 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CH2PR12MB5546.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: b9613d00-6eac-4c01-6649-08d9f68a6caf X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Feb 2022 05:07:43.8364 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: uZEN42K0+hDovtbZs9YCSiwsOqTWpsmmwjPkKvZ4cNtRu/EYuQBYNLtDdCTq0rOni7YwMMzeafZ6rBouWzjHJQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5223 Content-Language: en-US Content-Type: multipart/alternative; boundary="_000_CH2PR12MB554678277E5ADF1474EB5BAEBA3C9CH2PR12MB5546namp_" --_000_CH2PR12MB554678277E5ADF1474EB5BAEBA3C9CH2PR12MB5546namp_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable + @Samer El-Haj-Mahmoud Hello Leif/Ard/Sami/Samer, Can you please look at this patch and provide some feedback? Thanks Ashish ________________________________ From: Ashish Singhal Sent: Monday, February 21, 2022 7:42 PM To: devel@edk2.groups.io ; sami.mujawar@arm.com ; ardb+tianocore@kernel.org ; q= uic_llindhol@quicinc.com Cc: Ashish Singhal 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 --- 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/Librar= y/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/Arm= Pkg/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 --_000_CH2PR12MB554678277E5ADF1474EB5BAEBA3C9CH2PR12MB5546namp_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Hello Leif/Ard/Sami/Samer,

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

Thanks
Ashish

From: Ashish Singhal <as= hishsingha@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+ti= anocore@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<= /font>
 
Even with MMU turned off, instruction cache can sp= eculate
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/Librar= y/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  &nb= sp;    // Write back
-4: isb
+4: ic      iallu
+   dsb     sy
+   isb
    ret
 
 
diff --git a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibReplaceEntry.S b/Arm= Pkg/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

--_000_CH2PR12MB554678277E5ADF1474EB5BAEBA3C9CH2PR12MB5546namp_--