From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from hqnvemgate26.nvidia.com (hqnvemgate26.nvidia.com [216.228.121.65]) by mx.groups.io with SMTP id smtpd.web12.14640.1585151267217885416 for ; Wed, 25 Mar 2020 08:47:47 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@nvidia.com header.s=n1 header.b=pgcpPo/S; spf=pass (domain: nvidia.com, ip: 216.228.121.65, mailfrom: ashishsingha@nvidia.com) Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Wed, 25 Mar 2020 08:47:33 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Wed, 25 Mar 2020 08:47:46 -0700 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Wed, 25 Mar 2020 08:47:46 -0700 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 25 Mar 2020 15:47:45 +0000 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.168) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Wed, 25 Mar 2020 15:47:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G7AboU3+HuKTxnkEBgsjbFM4Z9wQ4eVBmWnHdJi5QQRXlaRocRVJYuwiopjWTH1/Cfyr0jLvNu89G+0TyE9btS9irG01w6aULE2LMaNDaeeJr5JUwELiy+Qp/2dY0S5y7hu0Z0HLGmulnKN1TvOzDWhUwpr5cOigZIsXAGEjVrH6MFMcr/QEKyXUMXQNbasKdzQ6PbVGfsZu6RGOpUkQ4BXaxwXuiyLhtmA0nHC3QpACbJIGkcmT4oh6/i0kPZIPSNttPSlUscl5deCc7OoQjSiOa3eU9HspgqS5dNlM2pyeXYJb57ZR9dnfwogKIuxtyNu13AzsKpDwOyT1PEfM9A== 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-SenderADCheck; bh=QZ3FqSNCHKnE5SfqwhqSsnorpbz96K+kSNCpH8sBmRs=; b=I97XWugBwMYclJle+ozR2VmzvoJRF7NUcDqktRYlWzMfSA8x2BDeNt8c/+fhs9ZNlaSvvOQedyGUS378BT3bVxfzZlOv20gYLXUJc4BTjg2/x0aprqhlNrRhwPsCZl6vyySR0V4etXm3iiXN8sfprm/jzpQEraLw4jZHgxAFuwUKipkZc/Aj7sXyk/ljLW9+8HQ6VgZodJXKPYNxm3OetyXyUZ8n775oGO1Aa7IBigITKgbgO0a8oycD57GBhNEyKDdKIrt1CRFkt9woWGNdyGqXDcw7d1tr0YENgedA4V2ZWzhv2sZE5SGgcjbdVh9zIyZSgeQVJHRSbfa6OSJ7Tg== 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 Received: from MW3PR12MB4457.namprd12.prod.outlook.com (2603:10b6:303:2e::20) by MW3PR12MB4474.namprd12.prod.outlook.com (2603:10b6:303:2e::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2835.20; Wed, 25 Mar 2020 15:47:44 +0000 Received: from MW3PR12MB4457.namprd12.prod.outlook.com ([fe80::d477:5c8e:2e4e:5481]) by MW3PR12MB4457.namprd12.prod.outlook.com ([fe80::d477:5c8e:2e4e:5481%4]) with mapi id 15.20.2835.023; Wed, 25 Mar 2020 15:47:44 +0000 From: "Ashish Singhal" To: Ard Biesheuvel , "devel@edk2.groups.io" CC: Laszlo Ersek , Leif Lindholm Subject: Re: [PATCH v3 2/3] ArmPkg/ArmMmuLib AARCH64: use helpers to determine table entry types Thread-Topic: [PATCH v3 2/3] ArmPkg/ArmMmuLib AARCH64: use helpers to determine table entry types Thread-Index: AQHWAro6wFGRPXUQiUaaw3EiPmNhqKhZc/v7 Date: Wed, 25 Mar 2020 15:47:43 +0000 Message-ID: References: <20200325152940.1492-1-ard.biesheuvel@linaro.org>,<20200325152940.1492-3-ard.biesheuvel@linaro.org> In-Reply-To: <20200325152940.1492-3-ard.biesheuvel@linaro.org> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=ashishsingha@nvidia.com; x-originating-ip: [216.228.112.22] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 397ebaf9-ad2e-48db-d6b3-08d7d0d3dbc7 x-ms-traffictypediagnostic: MW3PR12MB4474: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4502; x-forefront-prvs: 0353563E2B x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(376002)(366004)(39860400002)(396003)(136003)(346002)(5660300002)(110136005)(19627405001)(52536014)(54906003)(33656002)(76116006)(7696005)(66476007)(66556008)(316002)(19627235002)(8676002)(66946007)(81166006)(71200400001)(86362001)(81156014)(478600001)(4326008)(186003)(9686003)(55016002)(26005)(6506007)(53546011)(64756008)(2906002)(8936002)(66446008);DIR:OUT;SFP:1101;SCL:1;SRVR:MW3PR12MB4474;H:MW3PR12MB4457.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords; received-spf: None (protection.outlook.com: nvidia.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: wsGl+5U9Acwp+4AspX6cDRqqYuy46MVMJtxsDQoTHF4/BvArZvuecfiEDVfFpkgHlZ6ttATtW90ErVBz/MhyCf+iz900n8VCboIZrCONIwAqPpRE+/6PQ4pfGWLnW/4jz7ve3Agq1MuNRXqS18X+bfDZmVW8AO40VnBSof2Z6pD98D095298MPv9QAsgn04e0LZfOgre91GNdvfMXI31fA4TXAlLOM/Ngxoii5h2QnCYo8ZIexzKv2SsROQwNhVGzOUfyJfWwJajipSB0IIlL2QKWRE/WcANK2EtbsJMm/as23tF9Cm58ZQtGw1/rZ8/yy4tbJtNtlycDIKSkSiU1mvvC2Td78uy1NdjO51SFhR1YyD7FHFvs43t3cmq7y3/z1l+zOnycWFIH0/fLJAZndguw5fY9ubzdUV6fHMDQSSKGeYCoIdBGOv4IxGFh+Ws x-ms-exchange-antispam-messagedata: nxTQL8uY8EcGN9sSoaRNE6HNNYis6IrGcYdLptCqFrqzDaq+3/QAd/7R7z8tMzUwzXGbVMobPFGQkap85LysY7iykqoF78T2dZY15qyMPuJw3PgQZBCwooO+MB5QNPRJXKUNx6HyC4aoICCIQYa7OA== x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 397ebaf9-ad2e-48db-d6b3-08d7d0d3dbc7 X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Mar 2020 15:47:43.8864 (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: YQmbAaMTdeRXxUfOAOWOlFIW/dYDNuSRHNSodSgiJHwCbTp39MQ2P3pdQyTPVJ5vQIveKUF26X+o40HywL6jIw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4474 Return-Path: ashishsingha@nvidia.com X-OriginatorOrg: Nvidia.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1585151253; bh=piQ/Tl7ZULJwQUyZHTAb2E1Nn8OCwVNl2NEPiuGQAmU=; h=X-PGP-Universal:ARC-Seal:ARC-Message-Signature: ARC-Authentication-Results:From:To:CC:Subject:Thread-Topic: Thread-Index:Date:Message-ID:References:In-Reply-To: Accept-Language:X-MS-Has-Attach:X-MS-TNEF-Correlator: authentication-results:x-originating-ip:x-ms-publictraffictype: x-ms-office365-filtering-correlation-id:x-ms-traffictypediagnostic: x-microsoft-antispam-prvs:x-ms-oob-tlc-oobclassifiers: x-forefront-prvs:x-forefront-antispam-report:received-spf: x-ms-exchange-senderadcheck:x-microsoft-antispam: x-microsoft-antispam-message-info: x-ms-exchange-antispam-messagedata:x-ms-exchange-transport-forked: MIME-Version:X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-originalarrivaltime: X-MS-Exchange-CrossTenant-fromentityheader: X-MS-Exchange-CrossTenant-id:X-MS-Exchange-CrossTenant-mailboxtype: X-MS-Exchange-CrossTenant-userprincipalname: X-MS-Exchange-Transport-CrossTenantHeadersStamped:X-OriginatorOrg: Content-Language:Content-Type; b=pgcpPo/StK6S++FrVy0n1zdqGFsGQRdB0ZB47LWG3NLLi6VOh1/OHX560xfrNMUMf H98YAjjZAI17Ce9fAwnUHikXNNuXFYxaM32iJOolwNv/7Hlwk6FQl0VvxSUv0f4VlF e8A6Fi6YStd1qnH8UlEAYWCe8rtuuZqyfpD7zWjO//5NpJCMKs+jGNO0dI0lZaLZ9P 6ydV8GZmVD/m1KCxfsS1VVxGLYYLiB2K3xwhSNqq8/LpuR1CiQoXdi+Mtt+K36X0m5 iuRKTwtjMlLk7OMf5tF5M3ptAEBrj/USq7rRkTnHIdv6+3gJ7y4rJ778V0jiQWXPbY GQAMvZ7QGnPJw== Content-Language: en-US Content-Type: multipart/alternative; boundary="_000_MW3PR12MB4457B8BB315EBF51FFE3F747BACE0MW3PR12MB4457namp_" --_000_MW3PR12MB4457B8BB315EBF51FFE3F747BACE0MW3PR12MB4457namp_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Ashish Singhal Tested-by: Ashish Singhal ________________________________ From: Ard Biesheuvel Sent: Wednesday, March 25, 2020 9:29 AM To: devel@edk2.groups.io Cc: Ard Biesheuvel ; Laszlo Ersek ; Leif Lindholm ; Ashish Singhal Subject: [PATCH v3 2/3] ArmPkg/ArmMmuLib AARCH64: use helpers to determin= e table entry types External email: Use caution opening links or attachments Given how the meaning of the attribute bits for page table entry types is slightly awkward, and changes between levels, add some helpers to abstract from this. Signed-off-by: Ard Biesheuvel Reviewed-by: Leif Lindholm --- =20ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c | 40 ++++++++++++++++= +--- =201 file changed, 35 insertions(+), 5 deletions(-) diff --git a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c b/ArmPkg/Li= brary/ArmMmuLib/AArch64/ArmMmuLibCore.c index d78918cf7ba8..0680ba36d907 100644 --- a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c +++ b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c @@ -162,6 +162,36 @@ FreePageTablesRecursive ( =20 FreePages (TranslationTable, 1); =20} +STATIC +BOOLEAN +IsBlockEntry ( + IN UINT64 Entry, + IN UINTN Level + ) +{ + if (Level =3D=3D 3) { + return (Entry & TT_TYPE_MASK) =3D=3D TT_TYPE_BLOCK_ENTRY_LEVEL3; + } + return (Entry & TT_TYPE_MASK) =3D=3D TT_TYPE_BLOCK_ENTRY; +} + +STATIC +BOOLEAN +IsTableEntry ( + IN UINT64 Entry, + IN UINTN Level + ) +{ + if (Level =3D=3D 3) { + // + // TT_TYPE_TABLE_ENTRY aliases TT_TYPE_BLOCK_ENTRY_LEVEL3 + // so we need to take the level into account as well. + // + return FALSE; + } + return (Entry & TT_TYPE_MASK) =3D=3D TT_TYPE_TABLE_ENTRY; +} + =20STATIC =20EFI_STATUS =20UpdateRegionMappingRecursive ( @@ -203,7 +233,7 @@ UpdateRegionMappingRecursive ( =20 if (Level =3D=3D 0 || ((RegionStart | BlockEnd) & BlockMask) !=3D = 0) { =20 ASSERT (Level < 3); - if ((*Entry & TT_TYPE_MASK) !=3D TT_TYPE_TABLE_ENTRY) { + if (!IsTableEntry (*Entry, Level)) { =20 // =20 // No table entry exists yet, so we need to allocate a page ta= ble =20 // for the next level. @@ -221,7 +251,7 @@ UpdateRegionMappingRecursive ( =20 InvalidateDataCacheRange (TranslationTable, EFI_PAGE_SIZE); =20 } - if ((*Entry & TT_TYPE_MASK) =3D=3D TT_TYPE_BLOCK_ENTRY) { + if (IsBlockEntry (*Entry, Level)) { =20 // =20 // We are splitting an existing block entry, so we have to p= opulate =20 // the new table with the attributes of the block entry it r= eplaces. @@ -252,7 +282,7 @@ UpdateRegionMappingRecursive ( =20 AttributeSetMask, AttributeClearMask, TranslationTabl= e, =20 Level + 1); =20 if (EFI_ERROR (Status)) { - if ((*Entry & TT_TYPE_MASK) !=3D TT_TYPE_TABLE_ENTRY) { + if (!IsTableEntry (*Entry, Level)) { =20 // =20 // We are creating a new table entry, so on failure, we can = free all =20 // allocations we made recursively, given that the whole sub= hierarchy @@ -265,10 +295,10 @@ UpdateRegionMappingRecursive ( =20 return Status; =20 } - if ((*Entry & TT_TYPE_MASK) !=3D TT_TYPE_TABLE_ENTRY) { + if (!IsTableEntry (*Entry, Level)) { =20 EntryValue =3D (UINTN)TranslationTable | TT_TYPE_TABLE_ENTRY; =20 ReplaceTableEntry (Entry, EntryValue, RegionStart, - (*Entry & TT_TYPE_MASK) =3D=3D TT_TYPE_BLOCK_= ENTRY); + IsBlockEntry (*Entry, Level)); =20 } =20 } else { =20 EntryValue =3D (*Entry & AttributeClearMask) | AttributeSetMask;= -- 2.17.1 -------------------------------------------------------------------------= ---------- This email message is for the sole use of the intended recipient(s) and m= ay contain confidential information. Any unauthorized review, use, disclosure or di= stribution is prohibited. If you are not the intended recipient, please contact the= =20sender by reply email and destroy all copies of the original message. -------------------------------------------------------------------------= ---------- --_000_MW3PR12MB4457B8BB315EBF51FFE3F747BACE0MW3PR12MB4457namp_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable
Reviewed-by: =20Ashish Singhal <ashishsingha@nvidia.com>
Tested-by: =20Ashish Singhal <ashishsingha@nvidia.com>


From: Ard Biesheuvel &l= t;ard.biesheuvel@linaro.org>
Sent: Wednesday, March 25, 2020 9:29 AM
To: devel@edk2.groups.io <devel@edk2.groups.io>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>; Laszlo Ersek= =20<lersek@redhat.com>; Leif Lindholm <leif@nuviainc.com>; As= hish Singhal <ashishsingha@nvidia.com>
Subject: [PATCH v3 2/3] ArmPkg/ArmMmuLib AARCH64: use helpers to d= etermine table entry types
 
External email: Use caution opening links or att= achments


Given how the meaning of the attribute bits for page table entry types is slightly awkward, and changes between levels, add some helpers to
abstract from this.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif@nuviainc.com>
---
 ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c | 40 ++= 3;++++++++++++++-= --
 1 file changed, 35 insertions(+), 5 deletions(-)

diff --git a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c b/ArmPkg/Li= brary/ArmMmuLib/AArch64/ArmMmuLibCore.c
index d78918cf7ba8..0680ba36d907 100644
--- a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c
+++ b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c
@@ -162,6 +162,36 @@ FreePageTablesRecursive (
   FreePages (TranslationTable, 1);
 }

+STATIC
+BOOLEAN
+IsBlockEntry (
+  IN  UINT64  Entry,
+  IN  UINTN   Level
+  )
+{
+  if (Level =3D=3D 3) {
+    return (Entry & TT_TYPE_MASK) =3D=3D TT_TYPE_= BLOCK_ENTRY_LEVEL3;
+  }
+  return (Entry & TT_TYPE_MASK) =3D=3D TT_TYPE_BLOCK_ENTRY;=
+}
+
+STATIC
+BOOLEAN
+IsTableEntry (
+  IN  UINT64  Entry,
+  IN  UINTN   Level
+  )
+{
+  if (Level =3D=3D 3) {
+    //
+    // TT_TYPE_TABLE_ENTRY aliases TT_TYPE_BLOCK_ENTR= Y_LEVEL3
+    // so we need to take the level into account as w= ell.
+    //
+    return FALSE;
+  }
+  return (Entry & TT_TYPE_MASK) =3D=3D TT_TYPE_TABLE_ENTRY;=
+}
+
 STATIC
 EFI_STATUS
 UpdateRegionMappingRecursive (
@@ -203,7 +233,7 @@ UpdateRegionMappingRecursive (
     if (Level =3D=3D 0 || ((RegionStart | BlockEnd) = & BlockMask) !=3D 0) {
       ASSERT (Level < 3);

-      if ((*Entry & TT_TYPE_MASK) !=3D TT_T= YPE_TABLE_ENTRY) {
+      if (!IsTableEntry (*Entry, Level)) {<= br>          //
         // No table entry exists= =20yet, so we need to allocate a page table
         // for the next level. @@ -221,7 +251,7 @@ UpdateRegionMappingRecursive (
           InvalidateDa= taCacheRange (TranslationTable, EFI_PAGE_SIZE);
         }

-        if ((*Entry & TT_TYPE_MAS= K) =3D=3D TT_TYPE_BLOCK_ENTRY) {
+        if (IsBlockEntry (*Entry,= =20Level)) {
           //
           // We are sp= litting an existing block entry, so we have to populate
           // the new t= able with the attributes of the block entry it replaces.
@@ -252,7 +282,7 @@ UpdateRegionMappingRecursive (
            &= nbsp;     AttributeSetMask, AttributeClearMask, Trans= lationTable,
            &= nbsp;     Level + 1);
       if (EFI_ERROR (Status)) {
-        if ((*Entry & TT_TYPE_MAS= K) !=3D TT_TYPE_TABLE_ENTRY) {
+        if (!IsTableEntry (*Entry= , Level)) {
           //
           // We are cr= eating a new table entry, so on failure, we can free all
           // allocatio= ns we made recursively, given that the whole subhierarchy
@@ -265,10 +295,10 @@ UpdateRegionMappingRecursive (
         return Status;
       }

-      if ((*Entry & TT_TYPE_MASK) !=3D TT_T= YPE_TABLE_ENTRY) {
+      if (!IsTableEntry (*Entry, Level)) {<= br>          EntryValue =3D (UINTN)Tr= anslationTable | TT_TYPE_TABLE_ENTRY;
         ReplaceTableEntry (Entry= , EntryValue, RegionStart,
-            =             &= nbsp;  (*Entry & TT_TYPE_MASK) =3D=3D TT_TYPE_BLOCK_ENTRY);
+          IsBlockEntry = (*Entry, Level));
       }
     } else {
       EntryValue =3D (*Entry & Attribu= teClearMask) | AttributeSetMask;
--
2.17.1


This email message is for the sole use of the intended recipient(s) = and may=20 contain confidential information.  Any unauthorized review, use, dis= closure=20 or distribution is prohibited.  If you are not the intended recipien= t,=20 please contact the sender by reply email and destroy all copies of the or= iginal=20 message.

--_000_MW3PR12MB4457B8BB315EBF51FFE3F747BACE0MW3PR12MB4457namp_--