From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.100; helo=mga07.intel.com; envelope-from=jian.j.wang@intel.com; receiver=edk2-devel@lists.01.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 01BAC2217CE4B for ; Thu, 21 Dec 2017 20:21:54 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Dec 2017 20:26:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,439,1508828400"; d="scan'208";a="4779255" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by orsmga008.jf.intel.com with ESMTP; 21 Dec 2017 20:26:32 -0800 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 21 Dec 2017 20:26:32 -0800 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.213]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.218]) with mapi id 14.03.0319.002; Fri, 22 Dec 2017 12:26:30 +0800 From: "Wang, Jian J" To: "Wang, Jian J" , "edk2-devel@lists.01.org" CC: Laszlo Ersek , "Yao, Jiewen" , "Dong, Eric" Thread-Topic: [edk2] [PATCH] UefiCpuPkg/MpInitLib: Fix incorrect Guard page setup for APs Thread-Index: AQHTefr35N1D5hjqNEuJ0x1uCkzFQqNOxfoQ Date: Fri, 22 Dec 2017 04:26:29 +0000 Message-ID: References: <20171221012712.3480-1-jian.j.wang@intel.com> In-Reply-To: <20171221012712.3480-1-jian.j.wang@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZGQ3ZjBhODItOTUwNS00YmZjLWI0NzctOWEyZDcyZGI2NGIzIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjIuNS4xOCIsIlRydXN0ZWRMYWJlbEhhc2giOiJmeWRpaE9JYU5CYzhvWDFoZDZ0NWFCeGxlWjdLRXFiVmVCa0R1OXJ3RkM2ZXJmdHdyM1lJXC9LQjRLSlVHYjZQWSJ9 x-ctpclassification: CTP_IC dlp-product: dlpe-windows dlp-version: 11.0.0.116 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH] UefiCpuPkg/MpInitLib: Fix incorrect Guard page setup for APs X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Dec 2017 04:21:55 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi, Anyone has any comments on this? Regards, Jian > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Ji= an J > Wang > Sent: Thursday, December 21, 2017 9:27 AM > To: edk2-devel@lists.01.org > Cc: Laszlo Ersek ; Yao, Jiewen ; > Dong, Eric > Subject: [edk2] [PATCH] UefiCpuPkg/MpInitLib: Fix incorrect Guard page se= tup > for APs >=20 > AP has its own stack for code execution. If PcdCpuStackGuard is enabled, > the page at the bottom of stack of AP will be disabled (NOT PRESENT) to > monitor the stack overflow issue. This requires PcdCpuApStackSize to be > set with value more than one page of memory. >=20 > Cc: Jiewen Yao > Cc: Eric Dong > Cc: Laszlo Ersek > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Jian J Wang > --- > UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf | 1 + > UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 34 > ++++++++++++++++++++++++--- > 2 files changed, 32 insertions(+), 3 deletions(-) >=20 > diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf > b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf > index 805641b516..e7b9eb4462 100644 > --- a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf > +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf > @@ -73,4 +73,5 @@ > gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchRegionSize ## > CONSUMES > gUefiCpuPkgTokenSpaceGuid.PcdCpuApLoopMode ## CO= NSUMES > gUefiCpuPkgTokenSpaceGuid.PcdCpuApTargetCstate ## > SOMETIMES_CONSUMES > + gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ## > CONSUMES >=20 > diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c > b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c > index 479f8189f6..40c1bf407a 100644 > --- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c > +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c > @@ -17,6 +17,7 @@ > #include > #include > #include > +#include >=20 > #include >=20 > @@ -288,9 +289,12 @@ InitMpGlobalData ( > IN CPU_MP_DATA *CpuMpData > ) > { > - EFI_STATUS Status; > - EFI_PHYSICAL_ADDRESS Address; > - UINTN ApSafeBufferSize; > + EFI_STATUS Status; > + EFI_PHYSICAL_ADDRESS Address; > + UINTN ApSafeBufferSize; > + UINTN Index; > + EFI_GCD_MEMORY_SPACE_DESCRIPTOR MemDesc; > + UINTN StackBase; >=20 > SaveCpuMpData (CpuMpData); >=20 > @@ -301,6 +305,30 @@ InitMpGlobalData ( > return; > } >=20 > + if (PcdGetBool (PcdCpuStackGuard)) { > + // > + // One extra page at the bottom of the stack is needed for Guard pag= e. > + // > + if (CpuMpData->CpuApStackSize <=3D EFI_PAGE_SIZE) { > + DEBUG ((DEBUG_ERROR, "PcdCpuApStackSize is not big enough for Stac= k > Guard!\n")); > + ASSERT (FALSE); > + } > + > + for (Index =3D 0; Index < CpuMpData->CpuCount; ++Index) { > + StackBase =3D CpuMpData->Buffer + Index * CpuMpData->CpuApStackSiz= e; > + > + Status =3D gDS->GetMemorySpaceDescriptor (StackBase, &MemDesc); > + ASSERT_EFI_ERROR (Status); > + > + Status =3D gDS->SetMemorySpaceAttributes ( > + StackBase, > + EFI_PAGES_TO_SIZE (1), > + MemDesc.Attributes | EFI_MEMORY_RP > + ); > + ASSERT_EFI_ERROR (Status); > + } > + } > + > // > // Avoid APs access invalid buffer data which allocated by BootService= s, > // so we will allocate reserved data for AP loop code. We also need to > -- > 2.15.1.windows.2 >=20 > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel