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.web09.5098.1647479097071909758 for ; Wed, 16 Mar 2022 18:04:57 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=VXBjKXbu; spf=pass (domain: intel.com, ip: 134.134.136.100, mailfrom: ted.kuo@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1647479097; x=1679015097; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=nh2vTXLtSpvgCs+DDnCjcL3Mv6LtfkvO4VuFSvJTbPU=; b=VXBjKXbuLH4omyerMwfX8epeQbgKa97R59zf1QyaxtDVfMiYN+pGbFDL hPdmZtc8mQqNWqjPNEdahQ4nOPZkKT6B/t0apL134wpCruD3BXf5YMRDR LIXaT1tf9yNsLnC7+ARXxlMiuwCjv3i0BgOqh4sNwjTqaXFjxoB5Ril36 KROeCuSZ08XN7+VP2HPnl2lXIFLMY9OJ/Xj2PS40Qdb6QRm3CLIlFY1Ju MZSozUN+Dqb3RrTbbBsUA31vnIPdkTab1UUbO/Z95Eax1ghn8mGOx8mi5 LrbGbIxOLwYg5WTCqOtmWcQpOfTBUoO1E40lu+jDZ7TjJB4kC/OukaJhZ w==; X-IronPort-AV: E=McAfee;i="6200,9189,10288"; a="319964459" X-IronPort-AV: E=Sophos;i="5.90,188,1643702400"; d="scan'208";a="319964459" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2022 18:04:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,188,1643702400"; d="scan'208";a="557706313" Received: from fmsmsx602.amr.corp.intel.com ([10.18.126.82]) by orsmga008.jf.intel.com with ESMTP; 16 Mar 2022 18:04:56 -0700 Received: from fmsmsx601.amr.corp.intel.com (10.18.126.81) 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.2308.21; Wed, 16 Mar 2022 18:04:55 -0700 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21 via Frontend Transport; Wed, 16 Mar 2022 18:04:55 -0700 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (104.47.66.43) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.21; Wed, 16 Mar 2022 18:04:55 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PK0H0gZ86mN3XPoWr3uQwTfzEJEK6Oa07KZvC0NIQTKj1wmgm6lViIY+NnEujInDI6ecmgbPH3ZJrHO1Ot76l1wA8dT/wNzexI9RUktUd3xczGXI4+A3EMd9KtiBv29QbUXzWDfZKyBG0x2mRSil8+mf/JqG/PK2ioaV+0q9YOvzRHpDGSAZQorce5rgDEE1SI9KPbrA8GGBxRzpuYAIisGa2cAGci+pNIk71QWSJThkkLK0dK5B2p+FsuzCshzwz+uLDR905uSnDRhuYXCxdWLBa1ZjuZSyKyPkVAtVSp60ILxjq/FOZpjvk6R8azTM8nSdXcQcugLsY62M5hxnqQ== 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=jmiEJwbOE8Vh1ZjU38ZG1CLn7/lciAysN3CY4Tti5cs=; b=C4sarZ32Yt5z6RWNIPSLl22W4OY2oCjm7yqty6Wy92q7f7uHfn7CBeXOsDFq8cyUSUR9bA5efgHMf3N6KbLAy2+Fi/NiN/FZ4OW1t2nObatS7Y7HDlPqDwUerqINDGjLYtNChRB5ShOpKs0ADey8fXCwoDLrFMRMeyQnXJi5aNuKPBbeyM9iJH9W9+fbZ2TdNIkI+xM1oap77fFjdHpDCVC918O8Qa1BlQ3Tio1vLgD8q8ZEyah4pCbS32EHU9OL75j6JzDghppMqYvz+l12X2kG5fBIyF8//+AiZ3h+n508pVJDrx4u+80TNmqXD9m2CWU4aWiqoyGHSVNGp0/I3A== 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 MW5PR11MB5932.namprd11.prod.outlook.com (2603:10b6:303:1a2::5) by DM6PR11MB2778.namprd11.prod.outlook.com (2603:10b6:5:c0::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.14; Thu, 17 Mar 2022 01:04:52 +0000 Received: from MW5PR11MB5932.namprd11.prod.outlook.com ([fe80::99c1:4af2:442d:4ffa]) by MW5PR11MB5932.namprd11.prod.outlook.com ([fe80::99c1:4af2:442d:4ffa%5]) with mapi id 15.20.5061.028; Thu, 17 Mar 2022 01:04:52 +0000 From: "Kuo, Ted" To: "devel@edk2.groups.io" , "Kuo, Ted" CC: "Bi, Dandan" , "Gao, Liming" , "De, Debkumar" , "Han, Harry" , "West, Catharine" , "Wang, Jian J" , "S, Ashraf Ali" , "Kinney, Michael D" Subject: Re: [edk2-devel][PATCH] MdeModulePkg: Make RSP 16-byte boundary aligned for PEI 64bit Thread-Topic: [edk2-devel][PATCH] MdeModulePkg: Make RSP 16-byte boundary aligned for PEI 64bit Thread-Index: AQHYNEcKlxHMUsGQNkC1F+OqRR5bjazCzPYA Date: Thu, 17 Mar 2022 01:04:52 +0000 Message-ID: References: <16DAF0B16C1B1922.28111@groups.io> In-Reply-To: <16DAF0B16C1B1922.28111@groups.io> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.6.401.20 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: ba8fc4ef-e203-4906-ddeb-08da07b224bc x-ms-traffictypediagnostic: DM6PR11MB2778:EE_ x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr 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: DbMDnyFrRlnWpOHJPjJksSGKLZtRfWaToLaOvwk5r5jtSroykXkOE0TjHUvQ7w8ejVGsDZzIKMLBqLOfLurwQeQAYSqiF7NmHHlVJwW6WNKWnKapUE9SQV0N12mCdaXPMoTNbExGz+FwBTLT3Fx8foLQutdqi4ycr3I7jENkad5YBqlw9hbGHyNmOzewqYO1utUid6f40SIUsrRA8QSIC8moITzonAR3wX1k0p52AXUqW0DfXbPG+fT6TZLm2mgCIdvtRvCOYBFwkVUqn2NuHHwMq5rJ4+e5ZvGONGRWpHbImUItaI5mzVqeTTb4+prS/gddxmiS1vmCoxohZnM2SFZYxzR8C+QMaUf8IWjQSl7ECrNv5axnn+XYke26Vlw0QyA/A8One7ikO+UYn2cVMEVvnw+yK6B6Xb5uYZNzu+y+3uUkWKrapIVIRVkONz64FU8SDrlBwsbAvj7IAE4iGbWuE2Vf8iONPqCAECMdG7uGlzS/fbygFk3BP4DLNkB5g2og/S60eCY3UOrVEP2S420UkUsON62sKf05WlQny4pXxpruMpuBdp+2kOgiK1FDYcI7xQBEccM1QE0zC4KooGNRWdQsg4U1BdfCNsl/wrT9462Dpr7UfzCoCkMgC+YdkDFw+VqP6Yb6+PTy00pWrddL26xUAK1iQnRkkKabR/Syn0XCMR0y2Mkp7uaDckympMr6na799c08ejodVOD7mmcd/+LTmdcsK9UjU63qzINz2mxZ8FhgXtSA4ccWQSjXg9578yP8xz4tOMAc7LpXzeqQ48wKBTlOc/G2F988B5GZn40PAHP0NWALSCnwuiweialLV4J2SIna+J/RT+WhEg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW5PR11MB5932.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(71200400001)(82960400001)(508600001)(966005)(52536014)(8936002)(107886003)(8676002)(33656002)(4326008)(66556008)(66446008)(64756008)(66476007)(66946007)(5660300002)(55016003)(76116006)(122000001)(86362001)(186003)(38100700002)(7696005)(6506007)(53546011)(83380400001)(54906003)(110136005)(19627235002)(316002)(2906002)(38070700005)(9686003)(26005);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?NiC8/MahZvWbLrwIdYi687MsaF+J5Ynzyultzb5SQ63MebjHYrwZATPvM54z?= =?us-ascii?Q?9vXIFDqPhET7BRFXJzoXae5ST4Gcx5fpzqr4fqMAhvFsWU7ioXpk6aLUFJwy?= =?us-ascii?Q?vRwgRlqrLubFRCDKRttmh1PtWl0rM8r1xKOnlWT/T8wT4T5TkJIoyfiRNRqO?= =?us-ascii?Q?BZJjbTf+0wNEInCFsMIurH4ukJfJsCo6LZeV3PUWndC7hKfmbjYEQoynkgDJ?= =?us-ascii?Q?Rnwka66EJcX6gEAc/p8WsZQMQYD9ktjWExarEKIEqaTCteWqH9Pq2LDiAqtJ?= =?us-ascii?Q?3BGIVsyrQXofxBnz9pz/ZRwyG/dCmPbahJw3D5TcPDk/BahvRzQ9ekjaPUEE?= =?us-ascii?Q?bD0f86vlhL0RriEuESLwvrNcQV5M1n1HuwGOvqKAd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ii?Q?PFgp4V6yoruGLaZugNjojRYaewFQUsdy3FYou7Id+unqUcjoLhAhc1/Pf+Vh?= =?us-ascii?Q?Kg7hvRjDMomHGY1iSIjfabovr5C4m0nnRw+28T1s8aKEiF0jzIxc0CO7ZwN6?= =?us-ascii?Q?SlKF7pFLZuVg/A9X1Bj29OkdfwA1aRurw7okg4/2ztPOmwFgvfcgtVtfjQvn?= =?us-ascii?Q?fBvvfrlZcceFnBhCgac3Sx118ucNCzEH?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MW5PR11MB5932.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: ba8fc4ef-e203-4906-ddeb-08da07b224bc X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Mar 2022 01:04:52.6871 (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: klKSTWfj7Q/G93JnY4GVJ9/KnOJRjyQ0lufbDMhan0eMC1OVmm478AhncHMacOLPASPO688hm5mph0AbFvvW0w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR11MB2778 Return-Path: ted.kuo@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Liming and Mike, Can you please review the change? Thanks, Ted -----Original Message----- From: devel@edk2.groups.io On Behalf Of Kuo, Ted Sent: Thursday, March 10, 2022 2:21 PM To: devel@edk2.groups.io Cc: Bi, Dandan ; Gao, Liming ; De, Debkumar ; Han, Harry ; = West, Catharine ; Wang, Jian J ; S, Ashraf Ali Subject: [edk2-devel][PATCH] MdeModulePkg: Make RSP 16-byte boundary aligne= d for PEI 64bit REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D3865 Use SwitchPeiCore instead of calling PeiCore directly when switching PeiCor= e from temporary memory to permanent memory. For PEI 32bit, SwitchPeiCore a= lways calls PeiCore without any additional step. For PEI 64bit, SwitchPeiCo= re makes RSP 16-byte boundary aligned and then allocate 32 bytes as a shado= w store on call stack before calling PeiCore. Cc: Dandan Bi Cc: Liming Gao Cc: Debkumar De Cc: Harry Han Cc: Catharine West Cc: Jian J Wang Cc: Ashraf Ali S Signed-off-by: Ted Kuo --- MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c | 2 +- MdeModulePkg/Core/P= ei/Ia32/SwitchPeiCore.nasm | 33 +++++++++++++++++++++++ MdeModulePkg/Core/Pei/PeiMain.h | 25 ++++++++++++++++++ MdeModulePkg/Core/Pei/PeiMain.inf | 6 +++++ MdeModulePkg/Core/Pei/X64/SwitchPeiCore.nasm | 38 +++++++++++++++++++++++= ++++ 5 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 MdeM= odulePkg/Core/Pei/Ia32/SwitchPeiCore.nasm create mode 100644 MdeModulePkg/Core/Pei/X64/SwitchPeiCore.nasm diff --git a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c b/MdeModulePkg/C= ore/Pei/Dispatcher/Dispatcher.c index 3552feda8f..5af6e6e86f 100644 --- a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c +++ b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c @@ -871,7 +871,7 @@ PeiCheckAndSwitchStack ( // // Entry PEI Phase 2 // - PeiCore (SecCoreData, NULL, Private); + SwitchPeiCore (SecCoreData, NULL, Private); } else { // // Migrate memory pages allocated in pre-memory phase. diff --git a/MdeModulePkg/Core/Pei/Ia32/SwitchPeiCore.nasm b/MdeModulePkg/C= ore/Pei/Ia32/SwitchPeiCore.nasm new file mode 100644 index 0000000000..23cfb5090b --- /dev/null +++ b/MdeModulePkg/Core/Pei/Ia32/SwitchPeiCore.nasm @@ -0,0 +1,33 @@ +;---------------------------------------------------------------------- +-------- +; +; Copyright (c) 2022, Intel Corporation. All rights reserved.
;=20 +SPDX-License-Identifier: BSD-2-Clause-Patent ; ; Abstract: +; +; Switch PeiCore from temporary memory to permanent memory. +; +;---------------------------------------------------------------------- +-------- + + SECTION .text + +extern ASM_PFX(PeiCore) + +;---------------------------------------------------------------------- +-------- +; VOID +; EFIAPI +; SwitchPeiCore ( +; EFI_SEC_PEI_HAND_OFF *SecCoreDataPtr, +; EFI_PEI_PPI_DESCRIPTOR *PpiList, +; VOID *Data +; ); +;---------------------------------------------------------------------- +-------- +global ASM_PFX(SwitchPeiCore) +ASM_PFX(SwitchPeiCore): + push DWORD [esp + 12] + push DWORD [esp + 12] + push DWORD [esp + 12] + call ASM_PFX(PeiCore) + jmp $ ; Should never reach here + ret + diff --git a/MdeModulePkg/Core/Pei/PeiMain.h b/MdeModulePkg/Core/Pei/PeiMai= n.h index 556beddad5..8e8ed3dadf 100644 --- a/MdeModulePkg/Core/Pei/PeiMain.h +++ b/MdeModulePkg/Core/Pei/PeiMain.h @@ -2038,4 +2038,29 @@ PeiReinitializeFv ( IN PEI_CORE_INSTANCE *PrivateData ); =20 +/** + This routine is invoked by main entry of PeiMain module during=20 +transition + from temporary memory to permanent memory. + + @param SecCoreDataPtr Points to a data structure containing information= about the PEI core's operating + environment, such as the size and location of tem= porary RAM, the stack location and + the BFV location. + @param PpiList Points to a list of one or more PPI descriptors t= o be installed initially by the PEI core. + An empty PPI list consists of a single descriptor= with the end-tag + EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST. As part of= its initialization + phase, the PEI Foundation will add these SEC-host= ed PPIs to its PPI database such + that both the PEI Foundation and any modules can = leverage the associated service + calls and/or code in these early PPIs + @param Data Pointer to old core data that is used to initiali= ze the + core's data areas. + If NULL, it is first PeiCore entering. + +**/ +VOID +EFIAPI +SwitchPeiCore ( + IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreDataPtr, + IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList, + IN VOID *Data + ); #endif diff --git a/MdeModulePkg/Core/Pei/PeiMain.inf b/MdeModulePkg/Core/Pei/PeiM= ain.inf index 0cf357371a..b597aed8f6 100644 --- a/MdeModulePkg/Core/Pei/PeiMain.inf +++ b/MdeModulePkg/Core/Pei/PeiMain.inf @@ -47,6 +47,12 @@ PciCfg2/PciCfg2.c PeiMain.h =20 +[Sources.IA32] + Ia32/SwitchPeiCore.nasm + +[Sources.X64] + X64/SwitchPeiCore.nasm + [Packages] MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec diff --git a/MdeModulePkg/Core/Pei/X64/SwitchPeiCore.nasm b/MdeModulePkg/Co= re/Pei/X64/SwitchPeiCore.nasm new file mode 100644 index 0000000000..94e09be757 --- /dev/null +++ b/MdeModulePkg/Core/Pei/X64/SwitchPeiCore.nasm @@ -0,0 +1,38 @@ +;---------------------------------------------------------------------- +-------- +; +; Copyright (c) 2022, Intel Corporation. All rights reserved.
;=20 +SPDX-License-Identifier: BSD-2-Clause-Patent ; ; Abstract: +; +; Switch PeiCore from temporary memory to permanent memory. +; +;---------------------------------------------------------------------- +-------- + + SECTION .text + +extern ASM_PFX(PeiCore) + +;---------------------------------------------------------------------- +-------- +; VOID +; EFIAPI +; SwitchPeiCore ( +; EFI_SEC_PEI_HAND_OFF *SecCoreDataPtr, +; EFI_PEI_PPI_DESCRIPTOR *PpiList, +; VOID *Data +; ); +;---------------------------------------------------------------------- +-------- +global ASM_PFX(SwitchPeiCore) +ASM_PFX(SwitchPeiCore): + ; + ; Per X64 calling convention, make sure RSP is 16-byte aligned. + ; + mov rax, rsp + and rax, 0fh + sub rsp, rax + + sub rsp, 20h ; Allocate 32 bytes as a shadow store on call st= ack + call ASM_PFX(PeiCore) + jmp $ ; Should never reach here + ret + -- 2.16.2.windows.1