From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web08.2450.1660108829081588907 for ; Tue, 09 Aug 2022 22:20:29 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=aB23/T3F; spf=pass (domain: intel.com, ip: 134.134.136.100, mailfrom: ray.ni@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660108829; x=1691644829; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=p7i0KwFWHoLk8++cGzrJOf+ZnFf39LF614rZDByRVJw=; b=aB23/T3F+Z/2p6opI7xOEtNXoBYLr2eKOY0l3hQEQebncZ+8Nc38ofHC t7f6XihmEt6EfBuE3RUDkz1+MfzzgDZTKEcos26OodV8G6/iEx/KOhKIX s7kgfTwMld1Yq3wXSLfzCbcfgVf80RX9SJMknv5SfDHsaTVaOHee7/Dt8 M0MQ7M+7jtSLGpTfRzQSKxM81/WmyTqyln0lDCk25ewHalgfwrD1B66wg oUC14cTdeRatVoYRfoyFRCM8d8F/TIwvgkgER8CGENnspVgPqPlXebHGq OOnlOUffcTyAXP70qVCTze0HhebrbzFl1J122AYE90+LwSaKp5Ng2qd0d A==; X-IronPort-AV: E=McAfee;i="6400,9594,10434"; a="355000413" X-IronPort-AV: E=Sophos;i="5.93,226,1654585200"; d="scan'208";a="355000413" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2022 22:20:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,226,1654585200"; d="scan'208";a="747307063" Received: from fmsmsx602.amr.corp.intel.com ([10.18.126.82]) by fmsmga001.fm.intel.com with ESMTP; 09 Aug 2022 22:20:27 -0700 Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) by fmsmsx602.amr.corp.intel.com (10.18.126.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Tue, 9 Aug 2022 22:20:27 -0700 Received: from fmsmsx607.amr.corp.intel.com (10.18.126.87) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Tue, 9 Aug 2022 22:20:27 -0700 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx607.amr.corp.intel.com (10.18.126.87) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28 via Frontend Transport; Tue, 9 Aug 2022 22:20:27 -0700 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (104.47.73.169) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2375.28; Tue, 9 Aug 2022 22:20:27 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hdwneR/FrNDQa+akM2N36t9WxzCLz7syq4DcnVT8diyZgKOQKYON4wMKhJ/6ZwLbWVX0F6hcjVgw69zaxmpYYww9k8Uy7f+SydGthdjehMG7RVrgw8dhHnz41XPBXZ6cJ9PllYJqIwKipRkcF0b/ga2EwKestr8sM9LDrvLnlsrY0nGobrnRvLjSgHLMkIpyL2mSkcfKavEsFebYVQo0QdRE4LI3xQo++s8Dmw8+4XT2CB1QlrJjpcOdLpry7++zyawRlLFeiZpAF+0GfA3pEEPQiloIbaXpcTCKbyV3kfqLNMJbxEjfW7mzYcbRQiIu3zTIuBnv99dQLHWhmCbYEA== 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=G6x900zRX+W57eU291DkhyO+O+1ICvHU+7at/9s4u9A=; b=gOuiZ8wIy71Ll6wbaw+fTVKoqzUsuPEeKwjgMOs3OVfvGQAoM4LVXJR5FhH04UDAMGYG1a9bT/3mUYRMhtVF9CkZ7YL54TqcLtcG3Pvn+rjjXwb7mMIonkgdBMEzRwOp54gG8SacPM7yQ+C9BxQ24BPpnN9mUOHMXW2N623NEhmY3Y5zuMm52m5RhDkCT5peU8WZhj+117ihBtjd/BsAMkjDwO+4GwHMIPc7O61Y8wjEd1Bt42ZYGbikM7mD3pcxNftfhow2LOJbOu4fZcDAe3DlQ1vMN0uXyFjkHllZrWZ4B/ITvfLG/YqfA6Azv1kYjq7wkgci8VvjcLwwpmOhhw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from MWHPR11MB1631.namprd11.prod.outlook.com (2603:10b6:301:10::10) by CH2PR11MB4375.namprd11.prod.outlook.com (2603:10b6:610:47::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5525.10; Wed, 10 Aug 2022 05:20:24 +0000 Received: from MWHPR11MB1631.namprd11.prod.outlook.com ([fe80::991b:97a0:7836:5174]) by MWHPR11MB1631.namprd11.prod.outlook.com ([fe80::991b:97a0:7836:5174%10]) with mapi id 15.20.5504.020; Wed, 10 Aug 2022 05:20:24 +0000 From: "Ni, Ray" To: "Tan, Dun" , "devel@edk2.groups.io" CC: "Dong, Eric" , "Kumar, Rahul R" Subject: Re: [PATCH 2/2] UefiCpuPkg/PiSmmCpuDxeSmm: Remove mInternalCr3 in PiSmmCpuDxeSmm Thread-Topic: [PATCH 2/2] UefiCpuPkg/PiSmmCpuDxeSmm: Remove mInternalCr3 in PiSmmCpuDxeSmm Thread-Index: AQHYrFr6CekSuUiQaUWhlOa6NToHR62nmJwg Date: Wed, 10 Aug 2022 05:20:24 +0000 Message-ID: References: <20220810014532.117-1-dun.tan@intel.com> <20220810014532.117-3-dun.tan@intel.com> In-Reply-To: <20220810014532.117-3-dun.tan@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: c552e5ab-9bcf-40f6-c055-08da7a900798 x-ms-traffictypediagnostic: CH2PR11MB4375:EE_ x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: S9CT+a+mO4SpX5G7TBrnxzZIOhjUCbu71SdJRFGnVxQi2roHORaehwYuZqksDd0bxf/fC57EvTGGswaLflGzapJRJDaEsCAFrX3iRflK0df9git1yeijm0LaCP7r9EMgerVJqLjzyF8iA+cXXaB8SMrrYBDp/8GB5EPeqcpz0kqvr56DBUekXNkI/iYcHun6s2hJl8JtLa4Q5r0cDra2muq9icfhOX8iemstrwXQGY6HU6LI+T8KMcdWj66arM4uuKXEG6RpmmSrhFFf4tnnpONVUU9vmQFra/+/toT7g7Gd6f4QpLF/ioYATTeY6kaGPKRzKCYCPyeIUnGfwFY9WiAp3xm/ju1U4KdWdcmR8C05PvNBV21ar6efZHZEk1lnIfYzWAI64o+SNAiV9pOULiw+7Uf2jAmgalDG+k/XguD4iKNJRzib9VN48fz/0Vphll9yIFVxbcdaZyr5UjvodJw+2qFTSJGBJRkg9lviYTP+GbhynCvyu89Ep85m7C3re2VBnsLQEot83mxonmEsCDJFvLEbpqWD9RywC/auiUIYjU+zlIJJRYHMNyiUz/RN1MPf1fLHKsgypxML1b8+IjxjtEtqU5h+TNA4hExByH7eGV3R2mWmeOZYmjrKx+zQnE2Bh+JylcAaxT8TsKFe/P3/9DztAJICVpYccZ1xntrH1r7e8mlbvt89RwKunOqKyb9946fMXFaYCRvSKzGkVd6lIwfIr8dFCFH78Lxqjt0T6HhdJw8xhl9fh5rEeC1/8cx1wyzXYoDlWSGNDPlXxSqOQdczUcIFzhxddnZomk9ZJQtO8Bdcjo8KG5fkDpBw x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR11MB1631.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(6029001)(376002)(396003)(136003)(346002)(366004)(39860400002)(2906002)(478600001)(41300700001)(66476007)(55016003)(66446008)(64756008)(4326008)(8676002)(66946007)(76116006)(30864003)(5660300002)(71200400001)(316002)(19627235002)(33656002)(86362001)(66556008)(26005)(7696005)(6506007)(9686003)(54906003)(110136005)(53546011)(82960400001)(38070700005)(186003)(107886003)(38100700002)(8936002)(52536014)(83380400001)(122000001)(579004);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?AqnAXgS+9AnJs3gYHGvKVbs+XseZAY1APiDCTaUq/3kREv7LGMeflS3r3VWm?= =?us-ascii?Q?jEuVSTYwBjZfICw0bXQ95ebFwOPje+tVPzVCN1T/cRxmeaQf5K/yzdBfSy5q?= =?us-ascii?Q?cqgT8HctLh7g5dYcjp9Pd9eeDTOxLsCI+Qu0oGr0Xa7dCvUOFzGvm/okJ7z4?= =?us-ascii?Q?ysCTkVeLm88mBRnvlMw6WkPSEtpoHjdE8sauip9E41GBsuWgbJTkA9w9LLsk?= =?us-ascii?Q?qZlww6MLLaEabUKjBLhBg/MTPK1fwXUwk9hvxrBF5K6r3DShVR1A82u2n9Y5?= =?us-ascii?Q?0znqmI2lr9B5uMM97rQnzzhzAN4fkNSmtB8FUjftmOFC3gqiJu8DuXgAdMWS?= =?us-ascii?Q?qWMCfJR7Lk4JSPGUVJW628Kvrk5fA+iACSZ1MlDH3xIEEvqGNuAXtdC1V8VI?= =?us-ascii?Q?6bJezL+9uqyE5254gcJg/kuzoXvAAZmn5hM1Edeb7KBBgbkEMveUI500bKY+?= =?us-ascii?Q?hCP49IkXJ8xebYeJ9qrw9sauA2bxLoVxHwrXt7or6nHiKyb/+CsH4bNU2a6+?= =?us-ascii?Q?ouQAUmDTRyfpjj2gtRb8FvGpogiZZdPvFLnuGGksOHaZQu48sspE9LiAsD1K?= =?us-ascii?Q?KK2f6XEt3RpmGN1KKHycuPiPaBUTQ6FXT6t93UmYAgJACj1YdvWqbfh+w2uU?= =?us-ascii?Q?Am9fAZX/Spq4ljhV6V6Z+B3MPjrbOlxIHnTrfr9uxWbyKH6JMLkM3orA8aqo?= =?us-ascii?Q?nA4VU8Qk+xyxq+xdcpJJlLDL2aGMEo+rvyeFBiwR9cS0PEenENsHhUIQQiVj?= =?us-ascii?Q?7qmSHECkWBWFMTOoH8ymQtGJ/8NYvut3NLrCWq9Kg7RfpefsvOiWN4u9j2L8?= =?us-ascii?Q?+9tjseUQXIvxWTdt7aJPq7a6lswo3lTuy5dxLZSqT8J6liHWARceTivUazX+?= =?us-ascii?Q?Sodjg5OryA4esJNWUBe5rcuxmHUr0wDZqlFJSmPQig0b2saeah5LjjhFN3ga?= =?us-ascii?Q?gYv03Qb7wDBNaKYzhfI56rXiCPipBWzZw9f2eSuK0KrTxTvoFUcWYYDlqzXl?= =?us-ascii?Q?760dsfoUWLjQAdGU09hoP5vEdcX+bhdy8kNtuLYZkhKH0EnaYAM0A2Z2yaHZ?= =?us-ascii?Q?9Edtix4Df0sz5LroclAj+l83CyCR4NNwdYQ6FZ4mSy6qDDhUCeNU9ZkQWvDp?= =?us-ascii?Q?DYnxqM/DVC+toYTb1GO4FBz4Dl5LvHb6f4D7XEl3Sd5jrt+8KjylttDmF6Fi?= =?us-ascii?Q?bHSv3EXfPTwPLEC6VW/hsVtSqNfZebWvVgihHrGNCSP5nhF4+6jIQmGymZsy?= =?us-ascii?Q?ztx1ehCr5vaFdlRXbMJBsKrnPvqUkAPh3BIAsyD2/UVtfXJqh4OvmtH/YK6M?= =?us-ascii?Q?nEefXo3FTvR2+SZGCh2pFBRvxJNv6TmFZi6iOeLjN7YJCU02TRzoXJ3D8xCP?= =?us-ascii?Q?uYyaHMdjx2H125+pUdMIGRZZXpXfks0WirecuZSr0pW1q4E+SqQ4aK6ayOBV?= =?us-ascii?Q?Zj+Tld8auMry6KX1NcNDV3GN9TqxO9/ZSKzE9Djjr0FYIxxzbu4va0urZv1g?= =?us-ascii?Q?4yiQuJv0hIDYOJaHKsxAqqPKVFJZb4G8KpDy7HvYe2AVamQePuta4tRsKGWu?= =?us-ascii?Q?JlTiHShoN0Id2STic4A=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MWHPR11MB1631.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: c552e5ab-9bcf-40f6-c055-08da7a900798 X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Aug 2022 05:20:24.7208 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: vd5IVnWzwcyZjn6voPlhlp4yFb+2x2CayGdx8/We5mKtpfrhimch1cOH0Ki0qHqmvQdgU55djkWqxqDFTArPQQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR11MB4375 Return-Path: ray.ni@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Ray Ni > -----Original Message----- > From: Tan, Dun > Sent: Wednesday, August 10, 2022 9:46 AM > To: devel@edk2.groups.io > Cc: Dong, Eric ; Ni, Ray ; Kumar, > Rahul R > Subject: [PATCH 2/2] UefiCpuPkg/PiSmmCpuDxeSmm: Remove mInternalCr3 > in PiSmmCpuDxeSmm >=20 > Remove mInternalCr3 in PiSmmCpuDxe pagetable related code. Currently, > mInternalCr3 is used to pass address of pagetable which is different > from Cr3 register. Now remove it and pass the page table base address > from the root function to simplify the code logic. >=20 > Change-Id: I8f58158b94a01cf829f1b4fb2b8c763dcdda0662 > Signed-off-by: Dun Tan > Cc: Eric Dong > Cc: Ray Ni > Cc: Rahul Kumar > Signed-off-by: Dun Tan > --- > UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c | 30 +++++----------= ---- > ----------- > UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 26 > +++++++++----------------- > UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c | 107 > +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- > ------------------------------------------------ > UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c | 73 > +++++++++++++++++++++++-------------------------------------------------- > 4 files changed, 94 insertions(+), 142 deletions(-) >=20 > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c > b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c > index 8ec8790c05..97058a2810 100644 > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c > @@ -28,26 +28,6 @@ EnableCet ( > VOID > ); >=20 > -/** > - Get page table base address and the depth of the page table. > - > - @param[out] Base Page table base address. > - @param[out] FiveLevels TRUE means 5 level paging. FALSE means 4 level > paging. > -**/ > -VOID > -GetPageTable ( > - OUT UINTN *Base, > - OUT BOOLEAN *FiveLevels OPTIONAL > - ) > -{ > - *Base =3D ((mInternalCr3 =3D=3D 0) ? > - (AsmReadCr3 () & PAGING_4K_ADDRESS_MASK_64) : > - mInternalCr3); > - if (FiveLevels !=3D NULL) { > - *FiveLevels =3D FALSE; > - } > -} > - > /** > Create PageTable for SMM use. >=20 > @@ -297,10 +277,10 @@ SetPageTableAttributes ( > DEBUG ((DEBUG_INFO, "Start...\n")); > PageTableSplitted =3D FALSE; >=20 > - GetPageTable (&PageTableBase, NULL); > - L3PageTable =3D (UINT64 *)PageTableBase; > + PageTableBase =3D AsmReadCr3 () & PAGING_4K_ADDRESS_MASK_64; > + L3PageTable =3D (UINT64 *)PageTableBase; >=20 > - SmmSetMemoryAttributesEx ((EFI_PHYSICAL_ADDRESS)PageTableBase, > SIZE_4KB, EFI_MEMORY_RO, &IsSplitted); > + SmmSetMemoryAttributesEx (PageTableBase, FALSE, > (EFI_PHYSICAL_ADDRESS)PageTableBase, SIZE_4KB, EFI_MEMORY_RO, > &IsSplitted); > PageTableSplitted =3D (PageTableSplitted || IsSplitted); >=20 > for (Index3 =3D 0; Index3 < 4; Index3++) { > @@ -309,7 +289,7 @@ SetPageTableAttributes ( > continue; > } >=20 > - SmmSetMemoryAttributesEx > ((EFI_PHYSICAL_ADDRESS)(UINTN)L2PageTable, SIZE_4KB, EFI_MEMORY_RO, > &IsSplitted); > + SmmSetMemoryAttributesEx (PageTableBase, FALSE, > (EFI_PHYSICAL_ADDRESS)(UINTN)L2PageTable, SIZE_4KB, EFI_MEMORY_RO, > &IsSplitted); > PageTableSplitted =3D (PageTableSplitted || IsSplitted); >=20 > for (Index2 =3D 0; Index2 < SIZE_4KB/sizeof (UINT64); Index2++) { > @@ -323,7 +303,7 @@ SetPageTableAttributes ( > continue; > } >=20 > - SmmSetMemoryAttributesEx > ((EFI_PHYSICAL_ADDRESS)(UINTN)L1PageTable, SIZE_4KB, EFI_MEMORY_RO, > &IsSplitted); > + SmmSetMemoryAttributesEx (PageTableBase, FALSE, > (EFI_PHYSICAL_ADDRESS)(UINTN)L1PageTable, SIZE_4KB, EFI_MEMORY_RO, > &IsSplitted); > PageTableSplitted =3D (PageTableSplitted || IsSplitted); > } > } > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h > b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h > index dfeceec2aa..ef8bf5947d 100644 > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h > @@ -264,7 +264,7 @@ extern UINTN mMaxNumberOfCpus; > extern UINTN mNumberOfCpus; > extern EFI_SMM_CPU_PROTOCOL mSmmCpu; > extern EFI_MM_MP_PROTOCOL mSmmMp; > -extern UINTN mInternalCr3; > +extern BOOLEAN m5LevelPagingNeeded; >=20 > /// > /// The mode of the CPU at the time an SMI occurs > @@ -682,7 +682,6 @@ SmmBlockingStartupThisAp ( >=20 > **/ > EFI_STATUS > -EFIAPI > SmmSetMemoryAttributes ( > IN EFI_PHYSICAL_ADDRESS BaseAddress, > IN UINT64 Length, > @@ -712,7 +711,6 @@ SmmSetMemoryAttributes ( >=20 > **/ > EFI_STATUS > -EFIAPI > SmmClearMemoryAttributes ( > IN EFI_PHYSICAL_ADDRESS BaseAddress, > IN UINT64 Length, > @@ -957,22 +955,12 @@ SetPageTableAttributes ( > VOID > ); >=20 > -/** > - Get page table base address and the depth of the page table. > - > - @param[out] Base Page table base address. > - @param[out] FiveLevels TRUE means 5 level paging. FALSE means 4 level > paging. > -**/ > -VOID > -GetPageTable ( > - OUT UINTN *Base, > - OUT BOOLEAN *FiveLevels OPTIONAL > - ); > - > /** > This function sets the attributes for the memory region specified by > BaseAddress and > Length from their current attributes to the attributes specified by > Attributes. >=20 > + @param[in] PageTableBase The page table base. > + @param[in] EnablePML5Paging If PML5 paging is enabled. > @param[in] BaseAddress The physical address that is the start a= ddress > of a memory region. > @param[in] Length The size in bytes of the memory region. > @param[in] Attributes The bit mask of attributes to set for th= e memory > region. > @@ -993,8 +981,9 @@ GetPageTable ( >=20 > **/ > EFI_STATUS > -EFIAPI > SmmSetMemoryAttributesEx ( > + IN UINTN PageTableBase, > + IN BOOLEAN EnablePML5Paging, > IN EFI_PHYSICAL_ADDRESS BaseAddress, > IN UINT64 Length, > IN UINT64 Attributes, > @@ -1005,6 +994,8 @@ SmmSetMemoryAttributesEx ( > This function clears the attributes for the memory region specified by > BaseAddress and > Length from their current attributes to the attributes specified by > Attributes. >=20 > + @param[in] PageTableBase The page table base. > + @param[in] EnablePML5Paging If PML5 paging is enabled. > @param[in] BaseAddress The physical address that is the start a= ddress > of a memory region. > @param[in] Length The size in bytes of the memory region. > @param[in] Attributes The bit mask of attributes to clear for = the > memory region. > @@ -1025,8 +1016,9 @@ SmmSetMemoryAttributesEx ( >=20 > **/ > EFI_STATUS > -EFIAPI > SmmClearMemoryAttributesEx ( > + IN UINTN PageTableBase, > + IN BOOLEAN EnablePML5Paging, > IN EFI_PHYSICAL_ADDRESS BaseAddress, > IN UINT64 Length, > IN UINT64 Attributes, > diff --git > a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c > b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c > index b369c0c435..ce513c476f 100644 > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c > @@ -32,24 +32,8 @@ PAGE_ATTRIBUTE_TABLE mPageAttributeTable[] =3D { > { Page1G, SIZE_1GB, PAGING_1G_ADDRESS_MASK_64 }, > }; >=20 > -UINTN mInternalCr3; > UINTN IsShadowStack =3D FALSE; >=20 > -/** > - Set the internal page table base address. > - If it is non zero, further MemoryAttribute modification will be on thi= s page > table. > - If it is zero, further MemoryAttribute modification will be on real pa= ge table. > - > - @param Cr3 page table base. > -**/ > -VOID > -SetPageTableBase ( > - IN UINTN Cr3 > - ) > -{ > - mInternalCr3 =3D Cr3; > -} > - > /** > Return length according to page attributes. >=20 > @@ -99,31 +83,31 @@ PageAttributeToMask ( > /** > Return page table entry to match the address. >=20 > - @param[in] Address The address to be checked. > - @param[out] PageAttributes The page attribute of the page entry. > + @param[in] PageTableBase The page table base. > + @param[in] Enable5LevelPaging If PML5 paging is enabled. > + @param[in] Address The address to be checked. > + @param[out] PageAttributes The page attribute of the page entry. >=20 > @return The page entry. > **/ > VOID * > GetPageTableEntry ( > + IN UINTN PageTableBase, > + IN BOOLEAN Enable5LevelPaging, > IN PHYSICAL_ADDRESS Address, > OUT PAGE_ATTRIBUTE *PageAttribute > ) > { > - UINTN Index1; > - UINTN Index2; > - UINTN Index3; > - UINTN Index4; > - UINTN Index5; > - UINT64 *L1PageTable; > - UINT64 *L2PageTable; > - UINT64 *L3PageTable; > - UINT64 *L4PageTable; > - UINT64 *L5PageTable; > - UINTN PageTableBase; > - BOOLEAN Enable5LevelPaging; > - > - GetPageTable (&PageTableBase, &Enable5LevelPaging); > + UINTN Index1; > + UINTN Index2; > + UINTN Index3; > + UINTN Index4; > + UINTN Index5; > + UINT64 *L1PageTable; > + UINT64 *L2PageTable; > + UINT64 *L3PageTable; > + UINT64 *L4PageTable; > + UINT64 *L5PageTable; >=20 > Index5 =3D ((UINTN)RShiftU64 (Address, 48)) & PAGING_PAE_INDEX_MASK; > Index4 =3D ((UINTN)RShiftU64 (Address, 39)) & PAGING_PAE_INDEX_MASK; > @@ -399,6 +383,8 @@ SplitPage ( >=20 > Caller should make sure BaseAddress and Length is at page boundary. >=20 > + @param[in] PageTableBase The page table base. > + @param[in] EnablePML5Paging If PML5 paging is enabled. > @param[in] BaseAddress The physical address that is the start a= ddress > of a memory region. > @param[in] Length The size in bytes of the memory region. > @param[in] Attributes The bit mask of attributes to modify for= the > memory region. > @@ -420,8 +406,9 @@ SplitPage ( > range specified by BaseAddress and Le= ngth. > **/ > RETURN_STATUS > -EFIAPI > ConvertMemoryPageAttributes ( > + IN UINTN PageTableBase, > + IN BOOLEAN EnablePML5Paging, > IN PHYSICAL_ADDRESS BaseAddress, > IN UINT64 Length, > IN UINT64 Attributes, > @@ -475,7 +462,7 @@ ConvertMemoryPageAttributes ( > // Below logic is to check 2M/4K page to make sure we do not waste > memory. > // > while (Length !=3D 0) { > - PageEntry =3D GetPageTableEntry (BaseAddress, &PageAttribute); > + PageEntry =3D GetPageTableEntry (PageTableBase, EnablePML5Paging, > BaseAddress, &PageAttribute); > if (PageEntry =3D=3D NULL) { > return RETURN_UNSUPPORTED; > } > @@ -558,6 +545,8 @@ FlushTlbForAll ( > This function sets the attributes for the memory region specified by > BaseAddress and > Length from their current attributes to the attributes specified by > Attributes. >=20 > + @param[in] PageTableBase The page table base. > + @param[in] EnablePML5Paging If PML5 paging is enabled. > @param[in] BaseAddress The physical address that is the start a= ddress > of a memory region. > @param[in] Length The size in bytes of the memory region. > @param[in] Attributes The bit mask of attributes to set for th= e memory > region. > @@ -578,8 +567,9 @@ FlushTlbForAll ( >=20 > **/ > EFI_STATUS > -EFIAPI > SmmSetMemoryAttributesEx ( > + IN UINTN PageTableBase, > + IN BOOLEAN EnablePML5Paging, > IN EFI_PHYSICAL_ADDRESS BaseAddress, > IN UINT64 Length, > IN UINT64 Attributes, > @@ -589,7 +579,7 @@ SmmSetMemoryAttributesEx ( > EFI_STATUS Status; > BOOLEAN IsModified; >=20 > - Status =3D ConvertMemoryPageAttributes (BaseAddress, Length, Attribute= s, > TRUE, IsSplitted, &IsModified); > + Status =3D ConvertMemoryPageAttributes (PageTableBase, > EnablePML5Paging, BaseAddress, Length, Attributes, TRUE, IsSplitted, > &IsModified); > if (!EFI_ERROR (Status)) { > if (IsModified) { > // > @@ -606,6 +596,8 @@ SmmSetMemoryAttributesEx ( > This function clears the attributes for the memory region specified by > BaseAddress and > Length from their current attributes to the attributes specified by > Attributes. >=20 > + @param[in] PageTableBase The page table base. > + @param[in] EnablePML5Paging If PML5 paging is enabled. > @param[in] BaseAddress The physical address that is the start a= ddress > of a memory region. > @param[in] Length The size in bytes of the memory region. > @param[in] Attributes The bit mask of attributes to clear for = the > memory region. > @@ -626,8 +618,9 @@ SmmSetMemoryAttributesEx ( >=20 > **/ > EFI_STATUS > -EFIAPI > SmmClearMemoryAttributesEx ( > + IN UINTN PageTableBase, > + IN BOOLEAN EnablePML5Paging, > IN EFI_PHYSICAL_ADDRESS BaseAddress, > IN UINT64 Length, > IN UINT64 Attributes, > @@ -637,7 +630,7 @@ SmmClearMemoryAttributesEx ( > EFI_STATUS Status; > BOOLEAN IsModified; >=20 > - Status =3D ConvertMemoryPageAttributes (BaseAddress, Length, Attribute= s, > FALSE, IsSplitted, &IsModified); > + Status =3D ConvertMemoryPageAttributes (PageTableBase, > EnablePML5Paging, BaseAddress, Length, Attributes, FALSE, IsSplitted, > &IsModified); > if (!EFI_ERROR (Status)) { > if (IsModified) { > // > @@ -673,14 +666,20 @@ SmmClearMemoryAttributesEx ( >=20 > **/ > EFI_STATUS > -EFIAPI > SmmSetMemoryAttributes ( > IN EFI_PHYSICAL_ADDRESS BaseAddress, > IN UINT64 Length, > IN UINT64 Attributes > ) > { > - return SmmSetMemoryAttributesEx (BaseAddress, Length, Attributes, > NULL); > + IA32_CR4 Cr4; > + UINTN PageTableBase; > + BOOLEAN Enable5LevelPaging; > + > + PageTableBase =3D AsmReadCr3 () & PAGING_4K_ADDRESS_MASK_64; > + Cr4.UintN =3D AsmReadCr4 (); > + Enable5LevelPaging =3D (BOOLEAN)(Cr4.Bits.LA57 =3D=3D 1); > + return SmmSetMemoryAttributesEx (PageTableBase, Enable5LevelPaging, > BaseAddress, Length, Attributes, NULL); > } >=20 > /** > @@ -706,14 +705,20 @@ SmmSetMemoryAttributes ( >=20 > **/ > EFI_STATUS > -EFIAPI > SmmClearMemoryAttributes ( > IN EFI_PHYSICAL_ADDRESS BaseAddress, > IN UINT64 Length, > IN UINT64 Attributes > ) > { > - return SmmClearMemoryAttributesEx (BaseAddress, Length, Attributes, > NULL); > + IA32_CR4 Cr4; > + UINTN PageTableBase; > + BOOLEAN Enable5LevelPaging; > + > + PageTableBase =3D AsmReadCr3 () & PAGING_4K_ADDRESS_MASK_64; > + Cr4.UintN =3D AsmReadCr4 (); > + Enable5LevelPaging =3D (BOOLEAN)(Cr4.Bits.LA57 =3D=3D 1); > + return SmmClearMemoryAttributesEx (PageTableBase, > Enable5LevelPaging, BaseAddress, Length, Attributes, NULL); > } >=20 > /** > @@ -736,7 +741,7 @@ SetShadowStack ( >=20 > SetPageTableBase (Cr3); > IsShadowStack =3D TRUE; > - Status =3D SmmSetMemoryAttributes (BaseAddress, Length, > EFI_MEMORY_RO); > + Status =3D SmmSetMemoryAttributesEx (Cr3, m5LevelPagingNeeded, > BaseAddress, Length, EFI_MEMORY_RO, NULL); >=20 > SetPageTableBase (0); > IsShadowStack =3D FALSE; > @@ -762,12 +767,7 @@ SetNotPresentPage ( > { > EFI_STATUS Status; >=20 > - SetPageTableBase (Cr3); > - > - Status =3D SmmSetMemoryAttributes (BaseAddress, Length, > EFI_MEMORY_RP); > - > - SetPageTableBase (0); > - > + Status =3D SmmSetMemoryAttributesEx (Cr3, m5LevelPagingNeeded, > BaseAddress, Length, EFI_MEMORY_RP, NULL); > return Status; > } >=20 > @@ -1560,6 +1560,9 @@ EdkiiSmmGetMemoryAttributes ( > UINT64 MemAttr; > PAGE_ATTRIBUTE PageAttr; > INT64 Size; > + UINTN PageTableBase; > + BOOLEAN EnablePML5Paging; > + IA32_CR4 Cr4; >=20 > if ((Length < SIZE_4KB) || (Attributes =3D=3D NULL)) { > return EFI_INVALID_PARAMETER; > @@ -1568,8 +1571,12 @@ EdkiiSmmGetMemoryAttributes ( > Size =3D (INT64)Length; > MemAttr =3D (UINT64)-1; >=20 > + PageTableBase =3D AsmReadCr3 () & PAGING_4K_ADDRESS_MASK_64; > + Cr4.UintN =3D AsmReadCr4 (); > + EnablePML5Paging =3D (BOOLEAN)(Cr4.Bits.LA57 =3D=3D 1); > + > do { > - PageEntry =3D GetPageTableEntry (BaseAddress, &PageAttr); > + PageEntry =3D GetPageTableEntry (PageTableBase, EnablePML5Paging, > BaseAddress, &PageAttr); > if ((PageEntry =3D=3D NULL) || (PageAttr =3D=3D PageNone)) { > return EFI_UNSUPPORTED; > } > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c > b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c > index 538394f239..6e920b32af 100644 > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c > @@ -113,36 +113,6 @@ Is5LevelPagingNeeded ( > } > } >=20 > -/** > - Get page table base address and the depth of the page table. > - > - @param[out] Base Page table base address. > - @param[out] FiveLevels TRUE means 5 level paging. FALSE means 4 level > paging. > -**/ > -VOID > -GetPageTable ( > - OUT UINTN *Base, > - OUT BOOLEAN *FiveLevels OPTIONAL > - ) > -{ > - IA32_CR4 Cr4; > - > - if (mInternalCr3 =3D=3D 0) { > - *Base =3D AsmReadCr3 () & PAGING_4K_ADDRESS_MASK_64; > - if (FiveLevels !=3D NULL) { > - Cr4.UintN =3D AsmReadCr4 (); > - *FiveLevels =3D (BOOLEAN)(Cr4.Bits.LA57 =3D=3D 1); > - } > - > - return; > - } > - > - *Base =3D mInternalCr3; > - if (FiveLevels !=3D NULL) { > - *FiveLevels =3D m5LevelPagingNeeded; > - } > -} > - > /** > Set sub-entries number in entry. >=20 > @@ -1195,20 +1165,21 @@ SetPageTableAttributes ( > VOID > ) > { > - UINTN Index2; > - UINTN Index3; > - UINTN Index4; > - UINTN Index5; > - UINT64 *L1PageTable; > - UINT64 *L2PageTable; > - UINT64 *L3PageTable; > - UINT64 *L4PageTable; > - UINT64 *L5PageTable; > - UINTN PageTableBase; > - BOOLEAN IsSplitted; > - BOOLEAN PageTableSplitted; > - BOOLEAN CetEnabled; > - BOOLEAN Enable5LevelPaging; > + UINTN Index2; > + UINTN Index3; > + UINTN Index4; > + UINTN Index5; > + UINT64 *L1PageTable; > + UINT64 *L2PageTable; > + UINT64 *L3PageTable; > + UINT64 *L4PageTable; > + UINT64 *L5PageTable; > + UINTN PageTableBase; > + BOOLEAN IsSplitted; > + BOOLEAN PageTableSplitted; > + BOOLEAN CetEnabled; > + BOOLEAN Enable5LevelPaging; > + IA32_CR4 Cr4; >=20 > // > // Don't mark page table memory as read-only if > @@ -1258,11 +1229,13 @@ SetPageTableAttributes ( > PageTableSplitted =3D FALSE; > L5PageTable =3D NULL; >=20 > - GetPageTable (&PageTableBase, &Enable5LevelPaging); > + PageTableBase =3D AsmReadCr3 () & PAGING_4K_ADDRESS_MASK_64; > + Cr4.UintN =3D AsmReadCr4 (); > + Enable5LevelPaging =3D (BOOLEAN)(Cr4.Bits.LA57 =3D=3D 1); >=20 > if (Enable5LevelPaging) { > L5PageTable =3D (UINT64 *)PageTableBase; > - SmmSetMemoryAttributesEx ((EFI_PHYSICAL_ADDRESS)PageTableBase, > SIZE_4KB, EFI_MEMORY_RO, &IsSplitted); > + SmmSetMemoryAttributesEx (PageTableBase, Enable5LevelPaging, > (EFI_PHYSICAL_ADDRESS)PageTableBase, SIZE_4KB, EFI_MEMORY_RO, > &IsSplitted); > PageTableSplitted =3D (PageTableSplitted || IsSplitted); > } >=20 > @@ -1276,7 +1249,7 @@ SetPageTableAttributes ( > L4PageTable =3D (UINT64 *)PageTableBase; > } >=20 > - SmmSetMemoryAttributesEx > ((EFI_PHYSICAL_ADDRESS)(UINTN)L4PageTable, SIZE_4KB, EFI_MEMORY_RO, > &IsSplitted); > + SmmSetMemoryAttributesEx (PageTableBase, Enable5LevelPaging, > (EFI_PHYSICAL_ADDRESS)(UINTN)L4PageTable, SIZE_4KB, EFI_MEMORY_RO, > &IsSplitted); > PageTableSplitted =3D (PageTableSplitted || IsSplitted); >=20 > for (Index4 =3D 0; Index4 < SIZE_4KB/sizeof (UINT64); Index4++) { > @@ -1285,7 +1258,7 @@ SetPageTableAttributes ( > continue; > } >=20 > - SmmSetMemoryAttributesEx > ((EFI_PHYSICAL_ADDRESS)(UINTN)L3PageTable, SIZE_4KB, EFI_MEMORY_RO, > &IsSplitted); > + SmmSetMemoryAttributesEx (PageTableBase, Enable5LevelPaging, > (EFI_PHYSICAL_ADDRESS)(UINTN)L3PageTable, SIZE_4KB, EFI_MEMORY_RO, > &IsSplitted); > PageTableSplitted =3D (PageTableSplitted || IsSplitted); >=20 > for (Index3 =3D 0; Index3 < SIZE_4KB/sizeof (UINT64); Index3++) = { > @@ -1299,7 +1272,7 @@ SetPageTableAttributes ( > continue; > } >=20 > - SmmSetMemoryAttributesEx > ((EFI_PHYSICAL_ADDRESS)(UINTN)L2PageTable, SIZE_4KB, EFI_MEMORY_RO, > &IsSplitted); > + SmmSetMemoryAttributesEx (PageTableBase, Enable5LevelPaging, > (EFI_PHYSICAL_ADDRESS)(UINTN)L2PageTable, SIZE_4KB, EFI_MEMORY_RO, > &IsSplitted); > PageTableSplitted =3D (PageTableSplitted || IsSplitted); >=20 > for (Index2 =3D 0; Index2 < SIZE_4KB/sizeof (UINT64); Index2++= ) { > @@ -1313,7 +1286,7 @@ SetPageTableAttributes ( > continue; > } >=20 > - SmmSetMemoryAttributesEx > ((EFI_PHYSICAL_ADDRESS)(UINTN)L1PageTable, SIZE_4KB, EFI_MEMORY_RO, > &IsSplitted); > + SmmSetMemoryAttributesEx (PageTableBase, Enable5LevelPaging, > (EFI_PHYSICAL_ADDRESS)(UINTN)L1PageTable, SIZE_4KB, EFI_MEMORY_RO, > &IsSplitted); > PageTableSplitted =3D (PageTableSplitted || IsSplitted); > } > } > -- > 2.31.1.windows.1