From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 1CAF2AC1246 for ; Fri, 3 Nov 2023 19:25:42 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=FE2H1pUc6uD/EUpdzKmoIUzfFBxNPUE+RcY8/CQyi1M=; c=relaxed/simple; d=groups.io; h=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:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type:Content-Transfer-Encoding; s=20140610; t=1699039541; v=1; b=eoX30MmmrVBCY6vDiu2s3BeXfp2sho4oI/O0YFe+gc+Vw0WTVpV4bGVZaFEeP0APgQhkbkvW m3+ENEDoXiE18mPPr7/ZvxMSReMWwAovK8ruiGDOijemV7Fac9jf5dz6e0uKNkBPtCsWHi1qpjB 0lk56EOzaK/CfcZqzOlxMfsg= X-Received: by 127.0.0.2 with SMTP id QR8TYY7687511xAE69yrewJe; Fri, 03 Nov 2023 12:25:41 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by mx.groups.io with SMTP id smtpd.web10.63167.1699039540310579449 for ; Fri, 03 Nov 2023 12:25:40 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10883"; a="1959762" X-IronPort-AV: E=Sophos;i="6.03,275,1694761200"; d="scan'208";a="1959762" X-Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2023 12:25:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10883"; a="1093163139" X-IronPort-AV: E=Sophos;i="6.03,275,1694761200"; d="scan'208";a="1093163139" X-Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by fmsmga005.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 03 Nov 2023 12:25:38 -0700 X-Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Fri, 3 Nov 2023 12:25:37 -0700 X-Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34 via Frontend Transport; Fri, 3 Nov 2023 12:25:37 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.101) 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.2507.34; Fri, 3 Nov 2023 12:25:10 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=damBUdW1ft2pgXNaNK7J0wyNfNwFyI0PAK2wabzPuPW5J6wZnQMzR9Oz6kndyd413CG+Gg6dQCW8PWSTMze0Jz539A/iQJLmFICHUbZCs8j5kFvUMtkRsoabTYU+1YB9l6Y/QwVTDDqfigLkk4aU2k+Bs4xrUQLLWs1GnW2Pyt6dwNwhwoSdyF5dPmZwVr3yaQCvysTbrM0wNwhIFLea+fQ0+iE4Hzal66T/m9NWqR7rgcHvPmNkPv2OECrTWqFtI56C2kXLumkK/E+9j31lPoNpV0ta8gCB9hrX08bIgsB7Uf0TGOVQeM3F7TVHERE7zhZXi/nNDldDGCdLSVJZdQ== 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=ReTyzHvx0ED4zAtO8u/GH9NFf1EqtiDs3I8Q++uoZ8Y=; b=fb3CTU+lPBrdga7RJgmEaqAHoKOzraxlZWfj13z0y4HjAO1rEYhW48s9JO0qNjy3zq9oOK+52iwfmJhp1W3cZShMLTk3qUMYnXjUeiAObUyV6esIIAl2JucvPwQRtJqIyYB038xwxIIqPTuHyLWtAeBerBZETNqu4gSScvUG5VybgN7XbEHx+kFiOFMqPcsEhWxYyxEyC+aBsvvwJT7Whs+HpAFLyhJ6tcpOvg8ixlxkQ4D5hTaZHiThhIs34piX9BAS1KSWP43arjyD/ql0HyF0x2lKIC1alhxKZCTK/HDkXlk8Q9nrikT+KZZUh3ilHIdgB5AeW6U6R3egMaIoQA== 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 X-Received: from MW4PR11MB5821.namprd11.prod.outlook.com (2603:10b6:303:184::5) by MN2PR11MB4693.namprd11.prod.outlook.com (2603:10b6:208:261::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.21; Fri, 3 Nov 2023 19:25:07 +0000 X-Received: from MW4PR11MB5821.namprd11.prod.outlook.com ([fe80::c90f:1f62:c3fa:3ac8]) by MW4PR11MB5821.namprd11.prod.outlook.com ([fe80::c90f:1f62:c3fa:3ac8%6]) with mapi id 15.20.6954.019; Fri, 3 Nov 2023 19:25:07 +0000 From: "Nate DeSimone" To: "devel@edk2.groups.io" , "Ni, Ray" CC: "Chiu, Chasel" Subject: Re: [edk2-devel] [PATCH] IntelFsp2Pkg/SwitchStack: Reserve 32B when calling C function in 64bit Thread-Topic: [edk2-devel] [PATCH] IntelFsp2Pkg/SwitchStack: Reserve 32B when calling C function in 64bit Thread-Index: AQHaC9N9JS5I69sZUUa9vYCNf6sxnbBo/yNg Date: Fri, 3 Nov 2023 19:25:07 +0000 Message-ID: References: <20231031082216.2038-1-ray.ni@intel.com> In-Reply-To: <20231031082216.2038-1-ray.ni@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MW4PR11MB5821:EE_|MN2PR11MB4693:EE_ x-ms-office365-filtering-correlation-id: 3a2cb26b-9ac5-4013-57fe-08dbdca296ba x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam-message-info: hVnWFtFpYWA9BoDQ2s98bEzF6MH3vD7FcNNFj22YOdExJBz02vDsVf0irw+pA4s1TlnO3yNelhxf/xJ8pEpL1ZKzmG6rmfSGB3AsEvu0Td2J35s3YZcvG2sIvBphIwSWrxlcR33yhXilQkQrSwEougKVDJXsyRIbBBE/CmIMwLfxD6e+dhiZR/sJg30VkYG8Ag1NG//EUevulo23pbHG+9H8oZbLTEUoA0qR7/NzKVQVkILqP74/Isud505ps/ldaktZZkkEA8EI+NdHgLIR8WRrJloMS3CqFsXM831JZukXA5KtXVIOzuQwnkFOxOtBF6VCBGSgqQ02Lz/DlAC3al1PTueRIb5pr46VUayY/b0nFGa30mCwnnN3vw2rbHEgwpQ89ymJX13QH2MyKq8vroNFagGVFrbb459M/Nw2DjWLY0/3kF7YDaaOS9YlhScNXbXiulElzt8tyFb2qCJm3CXLsF3N1fNCgvL6It3ABla1+ZzEtau1ZJh3OdVJVvPlJh8s832i+filWhY4yqhp6R243RnSPFhRK8YGsH+DCIiSuhrm8/FZQkLTRdk/TIEdxUeqxjODHYRYJW/XYb9QLarlPuqVuL9H+sHrp+TRtafHUjY2qg0I/JF6FoZsupK9s8JFtP6dZWAT3I+Nj8JJ0g== x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?Q6s3RUronxCd8GSFjXlOyr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ascii?Q?nqst9NdQVzwftopdtMegnUdqbJlAIqHeW5LimTC1wia1WsDaSycB/L9XlIpJ?= =?us-ascii?Q?YGcOsukgkd98qeM4PH9zTvxlT6Qg5CiFiKhnFKnjd5HN8gh2VOZFsUa7VsFk?= =?us-ascii?Q?6XeI7wZrq2zXv3ClGvC0KnQyb/Cs+41Q2tYT2EHvWQq3PUGWGGj6bcK7DVUa?= =?us-ascii?Q?njFF4FLeMf9TrCpnfESLSliFZgYx1y95cCpDBBcG4b66xWytfcXi0w5qR7AT?= =?us-ascii?Q?xM9Myujr0EYG+VY5kb8QdVvrGeTGufNNISpCW/JKkZ9+lWHKwk9mLxdRz63l?= =?us-ascii?Q?0KfBnpDk73m3V74cUIU9HuGsDLj4Agd4SivaYftsbNvbGz1aMhiHO5DpbcaC?= =?us-ascii?Q?94namL5N1OsyoKcjCcax7Gz/pqaK0NTFluzoryGdHDVRlHq5fIJWhLWKKOmi?= =?us-ascii?Q?Ay7j3ecBbZx4mYgePSXu+WrXWmzooGDM6tvF+N7zF8FvWqb53mBvG9t2RBCv?= =?us-ascii?Q?xVIX3seheQh5KgvPIgGmp8Rnl869wutrtkjieT0BJG2n3re91tny7Q7F+6Fk?= =?us-ascii?Q?IGIX7OP1Qf4vzDc5RpeCJMRvEBZVnxAAd3LS3pCbpN6+B3I51GiDgkT8tes4?= =?us-ascii?Q?4D4izhgBjnsQi8zN5f8tEzQsabVuoWLl/5HTojRFYd7Rgg33/BaRfqqTT1KU?= =?us-ascii?Q?MSeCbCqpupLjhLI1EbFHAdnXnjcHrzRXEhWRRBGJ5yttj/cAGTVp+YDMuPSD?= =?us-ascii?Q?Ag=3D=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MW4PR11MB5821.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3a2cb26b-9ac5-4013-57fe-08dbdca296ba X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Nov 2023 19:25:07.4075 (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: /y9R1eRiSrUQkZAMonv8QxKaIa42ShDxT7j4kH+EFs0zfeH1KvYNUwJKt3KcsOKzDhWGhGEbyz5yIxPEx1UJV5Y0sAzw+MyrNoSWTL8hEd0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB4693 X-OriginatorOrg: intel.com Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,nathaniel.l.desimone@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: YuWGauwwxlhtcz0zunChoKenx7686176AA= Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=eoX30Mmm; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}"); dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io Good catch! Reviewed-by: Nate DeSimone -----Original Message----- From: devel@edk2.groups.io On Behalf Of Ni, Ray Sent: Tuesday, October 31, 2023 1:22 AM To: devel@edk2.groups.io Cc: Chiu, Chasel Subject: [edk2-devel] [PATCH] IntelFsp2Pkg/SwitchStack: Reserve 32B when ca= lling C function in 64bit When FSP runs in API mode, it saves the IDTR in its own stack then switches= to bootloader's stack before it returns from FspMemoryInit. Next time when the bootloader calls TempRamExit, FSP switches to its own st= ack and restores IDTR from its stack saved earlier. However, due to a bug in BaseFspSwitchStackLib, the IDTR saved on FSP's sta= ck might be corrupted that results the following TempRamExit call fails ins= ide FSP due to PeiServices pointer cannot be retrieved from IDT.base - 8. The bug is the assembly code doesn't reserve 32 bytes before calling the C = routine in 64bit. According to the x86-64 calling convention, caller is res= ponsible for allocating 32 bytes of "shadow space" on the stack right befor= e calling the function (regardless of the actual number of parameters used)= . When FSP is built in optimization-off mode, the C routine makes use of the = 32-byte "shadow space" which is not reserved by the assembly caller. That c= auses the IDTR saved on the stack is corrupted by the C routine. The patch fixes so by reserving the 32 bytes before calling C routine. Signed-off-by: Ray Ni Cc: Chasel Chiu M: Nate DeSimone M: Duggapu Chinni B M: Ray Han Lim Ng R: Star Zeng R: Ted Kuo R: Ashraf Ali S R: Susovan Mohapatra --- IntelFsp2Pkg/Library/BaseFspSwitchStackLib/X64/Stack.nasm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/IntelFsp2Pkg/Library/BaseFspSwitchStackLib/X64/Stack.nasm b/In= telFsp2Pkg/Library/BaseFspSwitchStackLib/X64/Stack.nasm index 1ea1220608..e3a7cf002f 100644 --- a/IntelFsp2Pkg/Library/BaseFspSwitchStackLib/X64/Stack.nasm +++ b/IntelFsp2Pkg/Library/BaseFspSwitchStackLib/X64/Stack.nasm @@ -1,6 +1,6 @@ ;-------------------------------------------------------------------------= ----- ;-; Copyright (c) 2022, Intel Corporation. All rights reserved.
+;= Copyright (c) 2022 - 2023, Intel Corporation. All rights reserved.
; S= PDX-License-Identifier: BSD-2-Clause-Patent ; ; Abstract:@@ -60,7 +60,9 @@ = ASM_PFX(FspSwitchStack): ; Load new stack mov rcx, rsp+ sub rsp, 0x20 call = ASM_PFX(SwapStack)+ add rsp, 0x20 mov rsp, rax ; Res= tore previous contexts--=20 2.39.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D Groups.io Links: You receive all messages sent to this group. View/Reply Online (#110384): https://edk2.groups.io/g/devel/message/110384 Mute This Topic: https://groups.io/mt/102293342/1767664 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/3861758/1767664/118797010= 1/xyzzy [nathaniel.l.desimone@intel.com] -=3D-=3D-=3D-=3D-=3D-=3D -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#110667): https://edk2.groups.io/g/devel/message/110667 Mute This Topic: https://groups.io/mt/102293342/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-