From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web11.3185.1664330652889759147 for ; Tue, 27 Sep 2022 19:04:13 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=ETXk6mLs; spf=pass (domain: intel.com, ip: 192.55.52.151, mailfrom: jiewen.yao@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664330652; x=1695866652; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=SFJX1JyHsPrqohXzKAPEWDfxH6Ah1dvOoUWEggat3Rs=; b=ETXk6mLsaXzMyZvvCbKfXoHH7OuMVX+wCB4NuLZKln4dg/eUGQP8ctXB Lx0AYG0eokaJQ0HID7yZXKd+fpyM6suZQnxqNaE5hT6r31B4YE+6Xfk42 8FXI8zO+AYa+NHZVen+/nd3jW/3X2OmCaka9+BUB9zCFVf8Zd9LmOWQcS 2WtDvmFIz7u0zz03OIBZrbJ2Fm7+cKaC92H+3Qx4UT3oUGQsU++Kkd1cK ZJpEUj3eOpdscsRt1URJCSA0GhcU1/uaSKD0RWLxrXxxVTZD6oUwixKc2 5EgNALnyIgLaCDNGGzq0ZQpzU/B8j4y3jfty7rfS7xaUfDXhCb3EaF6KM A==; X-IronPort-AV: E=McAfee;i="6500,9779,10483"; a="281851600" X-IronPort-AV: E=Sophos;i="5.93,350,1654585200"; d="scan'208";a="281851600" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Sep 2022 19:04:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10483"; a="617037860" X-IronPort-AV: E=Sophos;i="5.93,350,1654585200"; d="scan'208";a="617037860" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by orsmga007.jf.intel.com with ESMTP; 27 Sep 2022 19:04:03 -0700 Received: from orsmsx608.amr.corp.intel.com (10.22.229.21) by ORSMSX603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 27 Sep 2022 19:04:03 -0700 Received: from orsmsx603.amr.corp.intel.com (10.22.229.16) by ORSMSX608.amr.corp.intel.com (10.22.229.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 27 Sep 2022 19:04:03 -0700 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31 via Frontend Transport; Tue, 27 Sep 2022 19:04:03 -0700 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (104.47.51.43) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2375.31; Tue, 27 Sep 2022 19:04:02 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nk6IDjMnVDPsVUKmNZHvvF3zAOc75t4igYIi3QWcsWjiZWR/EAKj9b+hmQTYA3e4hVbSPeNwD67mn9+/cNiTdWVuEf8e6rK8Uy2a4GyGcv90H6XLWOAbLZWpZgf5DcRS9zjw7Z3EMnlE0u1h989Ow+w0BtWk9kIo/To3dE2G1Imw93bMPeM2O2d0ZFnqUE0REpYH3BW+L+v1F8miI3u5A1IQAAi9LR8E01jhQnKhPUEKHlSPji5loCmjofzBlK3k3ivMhm+LJQT38ovl6R+t/Fay6SdXVLVOUueGgqBK7JVV9CY90/i5hCXDxYMZJ8WIQqGHNLejQpkzkLpocpDpNQ== 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=kINHxdArdxpmjTDZ3fkoZeF4VniZZfDetMXuVJS6EWQ=; b=AohyPMXcX2it5CUI77WDMSD8qBs5VyuYLeAsNwXNqxJLst1XLTvcRjdYp7YMVhRl1WW+TVT0NWaFjJQy5rZm4ogeOC28so2KNI5CmGkbl8hKs+eiSLMQmjxT1iHJ3FCrkwRvGDhTEFg+6KEnE4DhjsbS/PcSzeYPPci8Fgu+mEktGnvmuTgQ/id0OpoBpZ6adwdRivvgJc4dmIjaeo5diTgZlawesjcwLaK1HHcbMRO12kdH6dHVWzgdDyl3e2waHFzZL5AS9OKprLopX67uIndTyYDiVgwMxWo5qrqLj40X+UvolAk+uGklWLDAV8tMFLrm4Z0KaPyuUIuX/jrRmw== 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 MW4PR11MB5872.namprd11.prod.outlook.com (2603:10b6:303:169::14) by PH8PR11MB6609.namprd11.prod.outlook.com (2603:10b6:510:1cc::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.26; Wed, 28 Sep 2022 02:03:59 +0000 Received: from MW4PR11MB5872.namprd11.prod.outlook.com ([fe80::c17d:f1c9:e958:b5e]) by MW4PR11MB5872.namprd11.prod.outlook.com ([fe80::c17d:f1c9:e958:b5e%6]) with mapi id 15.20.5654.025; Wed, 28 Sep 2022 02:03:59 +0000 From: "Yao, Jiewen" To: "Xu, Min M" , "devel@edk2.groups.io" CC: "Aktas, Erdem" , Gerd Hoffmann , James Bottomley Subject: Re: [PATCH V2 1/1] OvmfPkg/PeilessStartupLib: move mPageTablePool to stack Thread-Topic: [PATCH V2 1/1] OvmfPkg/PeilessStartupLib: move mPageTablePool to stack Thread-Index: AQHY0j/pmUaOjUn78UGKA6Bxv3y5x63y789ggAEozcA= Date: Wed, 28 Sep 2022 02:03:59 +0000 Message-ID: References: <20220927070753.470-1-min.m.xu@intel.com> In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-version: 11.6.500.17 dlp-product: dlpe-windows dlp-reaction: no-action authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MW4PR11MB5872:EE_|PH8PR11MB6609:EE_ x-ms-office365-filtering-correlation-id: 3b8ed0b5-5c37-46b4-b25a-08daa0f5b544 x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: gx6j/MB/7WuhHdSmUzsZpn7rEwWdSxzq6OjYOe83a6cfPtESY4lh+pfg3+9xHD+Y5skzCksdlzmJ6FP8OQl65sxmpOFWCQDNt5eMkfAgr5nzpv8KZvck79eIRRBS41FooO35FfUmzQ1K831aCqq+Yh5pHRNLIEaSHS2GQr22174WFReKq+y6aoHBw3FRIAv+Rv85vkh97VrH1oZiTEUzeAU3007NTVAn8m+XCfz8ItO+FA4Iq8eVYPLDrpoUtTPVts9aY/O26ZK0xsXRoSZXWcDyQMAwbeoH2TGM3xiozo/uS7Zh26Oqhmh1Pxg9WJKF9URgHk6b9XIgzVoqGMZZv9KEi7sXK6Bf0xunF+7Z3z0X2JcuQ+t18E/HJZncV/mkqJYHGYLwIjloHbBtMRzBJ7oDlqk79UM1Lw3PVg3mut7fRCgKFVabsb9538l0iiaowiWXu42CaT6o8s8dx+GuaeojTGUBUsh039YrBZ6+RI0ClPxNWX9JM3ddtrWF5TLJ0ek3cbyMW0y57hKvxbR03DTHWWPx9gSCnb/tE3pTzPftZ69mgiwhZedwY/b2mv+XKR9b3pLo0nI5RxKqdngXhwGtAgvjcAr6NyDE6z0vf8AlbtVda2BjXqVA7sz9l6Td9AmnH5Ej9feSVpcsSHlYwjDRMYs5BEoZ5Xz3QKaXf3bt50HEbhAEKm8ctGDXS2gxa1ha3ikSjtSNOsPWTgoAZWgnKFgZGPkLIrl8BhoMwtjtQG0pvPFfrpq6NoioT5aRel4o1dnOZOal9J2OkvX2xRnXBpj0290DPvQlklN9n0VPFoiIUSrGJzyHM86WHWcb x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW4PR11MB5872.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(136003)(346002)(396003)(366004)(39860400002)(376002)(451199015)(186003)(83380400001)(64756008)(38100700002)(66946007)(19627235002)(4326008)(8676002)(76116006)(71200400001)(66446008)(66476007)(33656002)(41300700001)(66556008)(316002)(122000001)(55016003)(478600001)(86362001)(110136005)(966005)(82960400001)(38070700005)(5660300002)(54906003)(2906002)(26005)(6506007)(8936002)(53546011)(9686003)(7696005)(30864003)(52536014)(145543001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?Rx7CeOCVwjFkTksuIscMYwmjPBaMZa3yTZo9sGOBqf6i06TXbyWSPCLVsPQV?= =?us-ascii?Q?BsqaaE8/4YqKc9oBz1aQru07TRm9FHy18G3F2w0m1J8sydz1TTxKW9mTxSlc?= =?us-ascii?Q?9s6xfB0c2oDQLS2OjUS6M8TuE9/r9ToUjLL6dYFV+bEVPdVkngbAfWpnrfOz?= =?us-ascii?Q?dQwzzfIM5ptAi+seGy/gf0JCXVcheeo65Fsx0PTaGcIa17y97xP7YFdtFomO?= =?us-ascii?Q?K5ETCLK/kW378zjtc32lmJxbrRN6i91E/NHVlMptrTo4mywPzV4XXQjx4vkd?= =?us-ascii?Q?E+sdcV+1SQzERAkx/E+wnKKejwah1FplH1Pvw0x5lI2o6kEbygYmrWAJt9ro?= =?us-ascii?Q?dYkCEg/ZFv51qLHgA8y7AgetOU1U5mCMh52u8v51GDog9EgeYqermReYUTRk?= =?us-ascii?Q?YCd/APRSAf/GgV6JNYgFGOCz/CtYGbw4ySx9p60i2dE3GIIbh97QqMp2sdoZ?= =?us-ascii?Q?VrTUNodRGgYslC/8G+/Cz+m01DIAWg0Y2DXDSwomYXpbqlgGXSd39hKZxL5L?= =?us-ascii?Q?u4NGXQyAmyxry80c7JTbFKa5SlTldWgMXdgsXa4vDlbmTxoIevV2qzyIcm9+?= =?us-ascii?Q?Z/1ROzkFG481A0qaiAqPDufwooXtx1xh1oXSHMbO1XxLiYITciOa9sjoyrZG?= =?us-ascii?Q?gThE+wwmdGxnKxQpIX+jDoornshGeuK++pR2Eykprwx/9AsO+cG1w0i7bBaF?= =?us-ascii?Q?0/8ASd14Luu2ePVHSJ022Iqj3uVBEbxaF7D13itZaxUNFd0u3hjoxrv8yLaJ?= =?us-ascii?Q?7e9TYmgQxCbAn7G7Exti3tr452BG5Y0OHoRGCN+uFOJijex/0WQ5OICq6Cqe?= =?us-ascii?Q?747JIFwnJukJGJOvr0BuN6J+MJZnpO+VUYdM+BwDKF0aMaThuVucRRaYDDww?= =?us-ascii?Q?BZt9SeX/JngSI9F/HCA51+hY0JbglZTe7mzsBLNCL3xzFS1w1nPcXxm4U+Ty?= =?us-ascii?Q?ZCg3PIdjc2Q2Uk5DUIpYKxqXBFSUvFXEVRsCrn6VHXSMLzNHeYdPucLgyh0y?= =?us-ascii?Q?DSzqaxZyARKP+XG+x/9ldH0f6niascZQsltHpkscmcg2u2Fk1Cy2IWI9Mnm2?= =?us-ascii?Q?jCrQHT2Fn803rT47mpDsEnl1fW6BqZtf0XGxmOTYG8X9EZFck7k8N3K5+TyE?= =?us-ascii?Q?QTNf1FeDenVqQYMmflsqU2DrrAxN7+G2i8cgdwjKfCgpF1xDzbhTBdcSbOTj?= =?us-ascii?Q?whp9SDmgKn5+WD5f1jUzIenuEkODahp19tezTvhd9HAOS484Q72t5dGcErSI?= =?us-ascii?Q?6lJMa215qpuG8u/1bNBoWbNhRVjvzitgQHDMLpYdMiAAx8DTyE97/gvM6acW?= =?us-ascii?Q?CzTwZmElNDtX3KUH0lB51jxglRtZeCvLs7eg+Fq/r+W3WLCLisGTQvGpCnm+?= =?us-ascii?Q?3CimtQSso7BloFmtPkrRXyqPHwNYPmo3TbnzN+tXXlkBp9ei+R7ryAU1hiRU?= =?us-ascii?Q?EJV3W6rHpCJqLThlItaRoSBGEdWR5QCb/xa/Wk5ZwAhlCE6uBQr6GG9zeDQ5?= =?us-ascii?Q?Fkju6Xnsx/bfofpME//3rckegEoKOHm+MYnVXUIpBD1XnwhGVrlmPJ2SKa3v?= =?us-ascii?Q?tznsYwayJJo75p23YORaFgUnL0A2gJDaIM8/hEUu?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MW4PR11MB5872.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3b8ed0b5-5c37-46b4-b25a-08daa0f5b544 X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Sep 2022 02:03:59.4331 (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: KbX6JFzjx0K4NGVpjTL2VmNCVYLsWXjtJCp1/cG54gdLTjKPxZKEl889GMwjlaOaaJ+wBny9NxdvyMf8eoPMAQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR11MB6609 Return-Path: jiewen.yao@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Merged https://github.com/tianocore/edk2/pull/3420 > -----Original Message----- > From: Yao, Jiewen > Sent: Tuesday, September 27, 2022 4:22 PM > To: Xu, Min M ; devel@edk2.groups.io > Cc: Aktas, Erdem ; Gerd Hoffmann > ; James Bottomley > Subject: RE: [PATCH V2 1/1] OvmfPkg/PeilessStartupLib: move > mPageTablePool to stack >=20 > Reviewed-by: Jiewen Yao >=20 > > -----Original Message----- > > From: Xu, Min M > > Sent: Tuesday, September 27, 2022 3:08 PM > > To: devel@edk2.groups.io > > Cc: Xu, Min M ; Aktas, Erdem > > ; Gerd Hoffmann ; > James > > Bottomley ; Yao, Jiewen > > Subject: [PATCH V2 1/1] OvmfPkg/PeilessStartupLib: move > mPageTablePool > > to stack > > > > From: Min M Xu > > > > PeilessStartupLib is running in SEC phase. In this phase global variabl= e > > is not allowed to be modified. This patch moves mPageTablePool to stack > > and pass it as input parameter between functions. > > > > Cc: Erdem Aktas > > Cc: Gerd Hoffmann > > Cc: James Bottomley > > Cc: Jiewen Yao > > Signed-off-by: Min Xu > > --- > > .../PeilessStartupLib/X64/VirtualMemory.c | 117 ++++++++++-------- > > 1 file changed, 68 insertions(+), 49 deletions(-) > > > > diff --git a/OvmfPkg/Library/PeilessStartupLib/X64/VirtualMemory.c > > b/OvmfPkg/Library/PeilessStartupLib/X64/VirtualMemory.c > > index 6877e521e485..b444c052d1bf 100644 > > --- a/OvmfPkg/Library/PeilessStartupLib/X64/VirtualMemory.c > > +++ b/OvmfPkg/Library/PeilessStartupLib/X64/VirtualMemory.c > > @@ -21,11 +21,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent > > #include > > #include "PageTables.h" > > > > -// > > -// Global variable to keep track current available memory used as page > > table. > > -// > > -PAGE_TABLE_POOL *mPageTablePool =3D NULL; > > - > > UINTN mLevelShift[5] =3D { > > 0, > > PAGING_L1_ADDRESS_SHIFT, > > @@ -273,14 +268,17 @@ ToSplitPageTable ( > > reserve at least another PAGE_TABLE_POOL_UNIT_PAGES. But usually > > this won't > > happen in practice. > > > > - @param PoolPages The least page number of the pool to be created. > > + @param[in] PoolPages The least page number of the pool to = be > > created. > > + @param[in, out] PageTablePool Pointer of Pointer to the current > > available memory > > + used as page table. > > > > @retval TRUE The pool is initialized successfully. > > @retval FALSE The memory is out of resource. > > **/ > > BOOLEAN > > InitializePageTablePool ( > > - IN UINTN PoolPages > > + IN UINTN PoolPages, > > + IN OUT PAGE_TABLE_POOL **PageTablePool > > ) > > { > > VOID *Buffer; > > @@ -303,20 +301,20 @@ InitializePageTablePool ( > > // > > // Link all pools into a list for easier track later. > > // > > - if (mPageTablePool =3D=3D NULL) { > > - mPageTablePool =3D Buffer; > > - mPageTablePool->NextPool =3D mPageTablePool; > > + if (*PageTablePool =3D=3D NULL) { > > + *(UINT64 *)(UINTN)PageTablePool =3D (UINT64)(UINTN)Buffer; > > + (*PageTablePool)->NextPool =3D *PageTablePool; > > } else { > > - ((PAGE_TABLE_POOL *)Buffer)->NextPool =3D mPageTablePool- > >NextPool; > > - mPageTablePool->NextPool =3D Buffer; > > - mPageTablePool =3D Buffer; > > + ((PAGE_TABLE_POOL *)Buffer)->NextPool =3D (*PageTablePool)- > >NextPool; > > + (*PageTablePool)->NextPool =3D Buffer; > > + *PageTablePool =3D Buffer; > > } > > > > // > > // Reserve one page for pool header. > > // > > - mPageTablePool->FreePages =3D PoolPages - 1; > > - mPageTablePool->Offset =3D EFI_PAGES_TO_SIZE (1); > > + (*PageTablePool)->FreePages =3D PoolPages - 1; > > + (*PageTablePool)->Offset =3D EFI_PAGES_TO_SIZE (1); > > > > return TRUE; > > } > > @@ -333,14 +331,17 @@ InitializePageTablePool ( > > If there is not enough memory remaining to satisfy the request, then > > NULL is > > returned. > > > > - @param Pages The number of 4 KB pages to allocate. > > + @param[in] Pages The number of 4 KB pages to al= locate. > > + @param[in, out] PageTablePool Pointer of pointer to the curr= ent > > available > > + memory used as page table. > > > > @return A pointer to the allocated buffer or NULL if allocation fail= s. > > > > **/ > > VOID * > > AllocatePageTableMemory ( > > - IN UINTN Pages > > + IN UINTN Pages, > > + IN OUT PAGE_TABLE_POOL **PageTablePool > > ) > > { > > VOID *Buffer; > > @@ -349,30 +350,31 @@ AllocatePageTableMemory ( > > return NULL; > > } > > > > - DEBUG ((DEBUG_INFO, "AllocatePageTableMemory. > mPageTablePool=3D%p, > > Pages=3D%d\n", mPageTablePool, Pages)); > > + DEBUG ((DEBUG_INFO, "AllocatePageTableMemory. PageTablePool=3D%p, > > Pages=3D%d\n", *PageTablePool, Pages)); > > // > > // Renew the pool if necessary. > > // > > - if ((mPageTablePool =3D=3D NULL) || > > - (Pages > mPageTablePool->FreePages)) > > + if ((*PageTablePool =3D=3D NULL) || > > + (Pages > (*PageTablePool)->FreePages)) > > { > > - if (!InitializePageTablePool (Pages)) { > > + if (!InitializePageTablePool (Pages, PageTablePool)) { > > return NULL; > > } > > } > > > > - Buffer =3D (UINT8 *)mPageTablePool + mPageTablePool->Offset; > > + Buffer =3D (UINT8 *)(*PageTablePool) + (*PageTablePool)->Offset; > > > > - mPageTablePool->Offset +=3D EFI_PAGES_TO_SIZE (Pages); > > - mPageTablePool->FreePages -=3D Pages; > > + (*PageTablePool)->Offset +=3D EFI_PAGES_TO_SIZE (Pages); > > + (*PageTablePool)->FreePages -=3D Pages; > > > > DEBUG (( > > DEBUG_INFO, > > - "%a:%a: Buffer=3D0x%Lx Pages=3D%ld\n", > > + "%a:%a: Buffer=3D0x%Lx Pages=3D%ld, PageTablePool=3D%p\n", > > gEfiCallerBaseName, > > __FUNCTION__, > > Buffer, > > - Pages > > + Pages, > > + *PageTablePool > > )); > > > > return Buffer; > > @@ -385,6 +387,8 @@ AllocatePageTableMemory ( > > @param[in, out] PageEntry2M Pointer to 2M page entry. > > @param[in] StackBase Stack base address. > > @param[in] StackSize Stack size. > > + @param[in, out] PageTablePool Pointer to the current availab= le > > memory used as > > + page table. > > > > **/ > > VOID > > @@ -392,7 +396,8 @@ Split2MPageTo4K ( > > IN EFI_PHYSICAL_ADDRESS PhysicalAddress, > > IN OUT UINT64 *PageEntry2M, > > IN EFI_PHYSICAL_ADDRESS StackBase, > > - IN UINTN StackSize > > + IN UINTN StackSize, > > + IN OUT PAGE_TABLE_POOL *PageTablePool > > ) > > { > > EFI_PHYSICAL_ADDRESS PhysicalAddress4K; > > @@ -401,7 +406,7 @@ Split2MPageTo4K ( > > > > DEBUG ((DEBUG_INFO, "Split2MPageTo4K\n")); > > > > - PageTableEntry =3D AllocatePageTableMemory (1); > > + PageTableEntry =3D AllocatePageTableMemory (1, &PageTablePool); > > > > if (PageTableEntry =3D=3D NULL) { > > ASSERT (FALSE); > > @@ -448,6 +453,8 @@ Split2MPageTo4K ( > > @param[in, out] PageEntry1G Pointer to 1G page entry. > > @param[in] StackBase Stack base address. > > @param[in] StackSize Stack size. > > + @param[in, out] PageTablePool Pointer to the current availab= le > > memory used as > > + page table. > > > > **/ > > VOID > > @@ -455,14 +462,16 @@ Split1GPageTo2M ( > > IN EFI_PHYSICAL_ADDRESS PhysicalAddress, > > IN OUT UINT64 *PageEntry1G, > > IN EFI_PHYSICAL_ADDRESS StackBase, > > - IN UINTN StackSize > > + IN UINTN StackSize, > > + IN OUT PAGE_TABLE_POOL *PageTablePool > > ) > > { > > EFI_PHYSICAL_ADDRESS PhysicalAddress2M; > > UINTN IndexOfPageDirectoryEntries; > > PAGE_TABLE_ENTRY *PageDirectoryEntry; > > > > - PageDirectoryEntry =3D AllocatePageTableMemory (1); > > + DEBUG ((DEBUG_INFO, "Split1GPageTo2M\n")); > > + PageDirectoryEntry =3D AllocatePageTableMemory (1, &PageTablePool); > > > > if (PageDirectoryEntry =3D=3D NULL) { > > ASSERT (FALSE); > > @@ -480,7 +489,7 @@ Split1GPageTo2M ( > > // > > // Need to split this 2M page that covers NULL or stack range. > > // > > - Split2MPageTo4K (PhysicalAddress2M, (UINT64 *)PageDirectoryEntry= , > > StackBase, StackSize); > > + Split2MPageTo4K (PhysicalAddress2M, (UINT64 > *)PageDirectoryEntry, > > StackBase, StackSize, PageTablePool); > > } else { > > // > > // Fill in the Page Directory entries > > @@ -496,16 +505,19 @@ Split1GPageTo2M ( > > /** > > Set one page of page table pool memory to be read-only. > > > > - @param[in] PageTableBase Base address of page table (CR3). > > - @param[in] Address Start address of a page to be set as rea= d-only. > > - @param[in] Level4Paging Level 4 paging flag. > > + @param[in] PageTableBase Base address of page table (CR3). > > + @param[in] Address Start address of a page to be set a= s read- > > only. > > + @param[in] Level4Paging Level 4 paging flag. > > + @param[in, out] PageTablePool Pointer to the current available > > memory used as > > + page table. > > > > **/ > > VOID > > SetPageTablePoolReadOnly ( > > IN UINTN PageTableBase, > > IN EFI_PHYSICAL_ADDRESS Address, > > - IN BOOLEAN Level4Paging > > + IN BOOLEAN Level4Paging, > > + IN OUT PAGE_TABLE_POOL *PageTablePool > > ) > > { > > UINTN Index; > > @@ -573,7 +585,8 @@ SetPageTablePoolReadOnly ( > > // > > ASSERT (Level > 1); > > > > - NewPageTable =3D AllocatePageTableMemory (1); > > + DEBUG ((DEBUG_INFO, "SetPageTablePoolReadOnly\n")); > > + NewPageTable =3D AllocatePageTableMemory (1, &PageTablePool); > > > > if (NewPageTable =3D=3D NULL) { > > ASSERT (FALSE); > > @@ -604,14 +617,17 @@ SetPageTablePoolReadOnly ( > > /** > > Prevent the memory pages used for page table from been overwritten. > > > > - @param[in] PageTableBase Base address of page table (CR3). > > - @param[in] Level4Paging Level 4 paging flag. > > + @param[in] PageTableBase Base address of page table (CR3). > > + @param[in] Level4Paging Level 4 paging flag. > > + @param[in, out] PageTablePool Pointer to the current available > > memory used as > > + page table. > > > > **/ > > VOID > > EnablePageTableProtection ( > > - IN UINTN PageTableBase, > > - IN BOOLEAN Level4Paging > > + IN UINTN PageTableBase, > > + IN BOOLEAN Level4Paging, > > + IN OUT PAGE_TABLE_POOL *PageTablePool > > ) > > { > > PAGE_TABLE_POOL *HeadPool; > > @@ -621,7 +637,7 @@ EnablePageTableProtection ( > > > > DEBUG ((DEBUG_INFO, "EnablePageTableProtection\n")); > > > > - if (mPageTablePool =3D=3D NULL) { > > + if (PageTablePool =3D=3D NULL) { > > return; > > } > > > > @@ -632,10 +648,10 @@ EnablePageTableProtection ( > > AsmWriteCr0 (AsmReadCr0 () & ~CR0_WP); > > > > // > > - // SetPageTablePoolReadOnly might update mPageTablePool. It's safer > to > > + // SetPageTablePoolReadOnly might update PageTablePool. It's safer t= o > > // remember original one in advance. > > // > > - HeadPool =3D mPageTablePool; > > + HeadPool =3D PageTablePool; > > Pool =3D HeadPool; > > do { > > Address =3D (EFI_PHYSICAL_ADDRESS)(UINTN)Pool; > > @@ -647,7 +663,7 @@ EnablePageTableProtection ( > > // protection to them one by one. > > // > > while (PoolSize > 0) { > > - SetPageTablePoolReadOnly (PageTableBase, Address, Level4Paging); > > + SetPageTablePoolReadOnly (PageTableBase, Address, Level4Paging, > > PageTablePool); > > Address +=3D PAGE_TABLE_POOL_UNIT_SIZE; > > PoolSize -=3D PAGE_TABLE_POOL_UNIT_SIZE; > > } > > @@ -700,6 +716,7 @@ CreateIdentityMappingPageTables ( > > BOOLEAN Page1GSupport; > > PAGE_TABLE_1G_ENTRY *PageDirectory1GEntry; > > IA32_CR4 Cr4; > > + PAGE_TABLE_POOL *PageTablePool; > > > > // > > // Set PageMapLevel5Entry to suppress incorrect compiler/analyzer > > warnings > > @@ -785,13 +802,14 @@ CreateIdentityMappingPageTables ( > > (UINT64)TotalPagesNum > > )); > > > > - BigPageAddress =3D (UINTN)AllocatePageTableMemory (TotalPagesNum); > > + PageTablePool =3D NULL; > > + BigPageAddress =3D (UINTN)AllocatePageTableMemory (TotalPagesNum, > > &PageTablePool); > > if (BigPageAddress =3D=3D 0) { > > ASSERT (FALSE); > > return 0; > > } > > > > - DEBUG ((DEBUG_INFO, "BigPageAddress =3D 0x%llx\n", BigPageAddress)); > > + DEBUG ((DEBUG_INFO, "BigPageAddress =3D 0x%llx, > PageTablePool=3D%p\n", > > BigPageAddress, PageTablePool)); > > > > // > > // By architecture only one PageMapLevel4 exists - so lets allocate > storage > > for it. > > @@ -856,7 +874,8 @@ CreateIdentityMappingPageTables ( > > PageAddress, > > (UINT64 *)PageDirectory1GEntry, > > StackBase, > > - StackSize > > + StackSize, > > + PageTablePool > > ); > > } else { > > // > > @@ -892,7 +911,7 @@ CreateIdentityMappingPageTables ( > > // > > // Need to split this 2M page that covers NULL or stack = range. > > // > > - Split2MPageTo4K (PageAddress, (UINT64 *)PageDirectoryEnt= ry, > > StackBase, StackSize); > > + Split2MPageTo4K (PageAddress, (UINT64 *)PageDirectoryEnt= ry, > > StackBase, StackSize, PageTablePool); > > } else { > > // > > // Fill in the Page Directory entries > > @@ -929,7 +948,7 @@ CreateIdentityMappingPageTables ( > > // Protect the page table by marking the memory used for page table = to > > be > > // read-only. > > // > > - EnablePageTableProtection ((UINTN)PageMap, TRUE); > > + EnablePageTableProtection ((UINTN)PageMap, TRUE, PageTablePool); > > > > return (UINTN)PageMap; > > } > > -- > > 2.29.2.windows.2