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 08B1B7803DE for ; Tue, 31 Oct 2023 08:48:07 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=6frmuhifXjCAffWFQPe/iHLvM8LVxtIC8vJbG55RBjc=; 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:msip_labels: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; s=20140610; t=1698742086; v=1; b=bIHibrgRQcNi/m9FADZJXtb2QIVv6mdy2eiSFgQ90AmQktw9VT5U3aiD5vzoP2G3/yl+tsVr FpTzy9v95ILPYE86t/LZ+Rk4UltH/m6alcpgufSnWQqIXZulG3Wom42cBkhIj+hOZh2j7RXLDXV kf6ZKa4RSxQxOpuNVRYFYqvU= X-Received: by 127.0.0.2 with SMTP id 4E5NYY7687511xJRE4LwpmgQ; Tue, 31 Oct 2023 01:48:06 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web11.182042.1698742085520739938 for ; Tue, 31 Oct 2023 01:48:06 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10879"; a="454709616" X-IronPort-AV: E=Sophos;i="6.03,265,1694761200"; d="scan'208,217";a="454709616" X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Oct 2023 01:48:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10879"; a="826336543" X-IronPort-AV: E=Sophos;i="6.03,265,1694761200"; d="scan'208,217";a="826336543" X-Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by fmsmga008.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 31 Oct 2023 01:48:03 -0700 X-Received: from fmsmsx603.amr.corp.intel.com (10.18.126.83) 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; Tue, 31 Oct 2023 01:48:03 -0700 X-Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) 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 via Frontend Transport; Tue, 31 Oct 2023 01:48:03 -0700 X-Received: from NAM02-SN1-obe.outbound.protection.outlook.com (104.47.57.41) 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; Tue, 31 Oct 2023 01:48:03 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fnLLwAJCba3Wp2vLp0xhrChXmBVEWi7giglzec66IvSbbLSunzQQIpSCR263geJHGuT6HhBrHMrgA1vkSyhRiEEF+V6rdYIyryKYot++AAiTk7Z4mrKi6K+382+O6H5qlsNoUYzk2quKmE+THrk3NKHv1d1zpLpx3DzI8MfXKTlCocJJJxFIPWCpPxo1E0REfWlKt9JRhaqQ811bDLXsMDbDMQ/T2hIan52IzsePnJ+OLprESTFAS2vtoEz2ruLEMQ/YFUQMuAeyEj14JpIoIM5ZarwkczFILZ/IbQUDv2qUhasHiPhdWjW+fMeN0XB3oK8Z3nvzcXnLB8Ns1vNuag== 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=cO9pNpOrRoulFXMqlUObq7aB+mjer56I0cTvGPs34XI=; b=ElpfCAIvHAhCnPbH9KGC4+1Tn0X+x+Ky0i+mhOoXscah1S5Mkme7XfMaIfXmqSFMdR/mnRcQVIBuJs57gWinCKw3S8Lui3rZaHjKRHHz9erccsfH28prk2KuVjb/10lWvY/a81/So2lVwgxhPED2SFZerT67PpfnmFMrzT6usDa2m6NNLnfJj+i7nwep5JhMHahQJ+LmoEnsAqtK87eVivkS02z1Wvhftcob5UZx6zPLc2R32oYnf11HPpCAwvOn7/lYvaWZLzHzfUNXAL9BsmaL4+qKfpEK0epxz2tHtBjySBSTevLZACMPhTIV2ByhWuCAXrqmJZbFLFYDbRCPEA== 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 DM4PR11MB5280.namprd11.prod.outlook.com (2603:10b6:5:38b::18) by LV8PR11MB8558.namprd11.prod.outlook.com (2603:10b6:408:1ed::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.27; Tue, 31 Oct 2023 08:47:56 +0000 X-Received: from DM4PR11MB5280.namprd11.prod.outlook.com ([fe80::efad:9d8e:4793:108a]) by DM4PR11MB5280.namprd11.prod.outlook.com ([fe80::efad:9d8e:4793:108a%4]) with mapi id 15.20.6933.029; Tue, 31 Oct 2023 08:47:56 +0000 From: "Ashraf Ali S" To: "Kuo, Ted" , "Ni, Ray" , "devel@edk2.groups.io" CC: "Chiu, Chasel" , "Desimone, Nathaniel L" , "Duggapu, Chinni B" , "Ng, Ray Han Lim" , "Zeng, Star" , "Mohapatra, Susovan" 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: AQHaC9N7djijmg8kPEKHV7LmiKoD4bBjj583gAAC7BCAAAOdsA== Date: Tue, 31 Oct 2023 08:47:56 +0000 Message-ID: References: <1793238D7061082B.20486@groups.io> In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: DM4PR11MB5280:EE_|LV8PR11MB8558:EE_ x-ms-office365-filtering-correlation-id: defa4bd9-0ed6-4509-5306-08dbd9ee13d7 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam-message-info: kU2TQ3cJRDNPQ3hB6pUHG93TA4KE1+VV7lkSBIZKAOWGhNibVk32gvGY3aF21Xll+CgS8O9RvbsnyjQsKOL5w/mX4wP5JO4lWHwkjHgGhfM8iJqsSNMiCB0m8qUKDxo3e9KjWS9XO6QdocV3gMi9f1ncdGWLp9XCqWTVjHoUuMO4OaurKKitQi64tD1nMe56ld0hbbOwZLsFto2oyqj0SgwJVq8//y9dtym4NhFcgtnchlPnINMygOjFjQpIpqiWBlYswM1cOZvxmiEwW7yUTb5nPLiGSL6GVxycBjbza4Dw1LoR7ClqNDokdqzgWWu6VyuLlUC4WCnMIr1bc43jftv2FzdXFP+z+tFoL3TkhpWiK+9RH13XR1d/qd2mt9m+e6Kv2kLBLuIYsrcd6Job6A27nIkJy/1H8exOPkU8pNKjHLUNy7Ir5kRnAJLz3OCHUcPNODIybexZeH/PL+kermhwIAUO+GueGGN7uemm/fBxHyX2Ub4KWM4wjQJBXFneyXvL5mGdSCyZV16Uv6Z7EuvqM2Y6m/l3zFau8UsASsG8vxZOqaI75I7iuk4VAcV80ZOuhxykZmppDVcRD+G5MMDharK5gkIvpYMO3+BTCjTvHwir8T7AyQisCTTbkemqh1ifUPYxQ6gxODEayAYcaA== x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?8/fiMy8PdIQmu5YgzPi6dk1rpm2sTUoCWqf7VPRC6Q0OycnPHr3VtzgoaDC7?= =?us-ascii?Q?EecRrWMDou6sg90CJBxSCCU74tXMAIvDe+u53XV7Ok2VWyOAMkOwvQO+Fjsz?= =?us-ascii?Q?G9Cd7XsxDHRzhsU21BuiDTLcz6DICFGQnBBD6prLs0sBhQ6rt58f7CQvt51c?= =?us-ascii?Q?sUWqUTuPrgrE5idehJaCskD/2+TNHbF0hwdd9pPnOE37/nb9Z+ZQGvmOGoD2?= =?us-ascii?Q?wB5r8JOCxbDZ8VDfpeh5kzYdeakAH5Yc/IbUFzC3plH52HHOQB2tY+JKFLl2?= =?us-ascii?Q?3ZwJ8gFByOnS0fZyUm6GsEtwS9UhShYmsEUAQU+vMysrz+fXN7/X6qAwBjTp?= =?us-ascii?Q?w0Kbw9XvTLvRe7sh6BBiLgqP77nhBxWmNRI98eIDIVbZ6w+OK8Uzm8vWAbHD?= =?us-ascii?Q?AiYemiN4jxWHfU31upnhmiurqXNPVuPy91gGcLNPFsnQ21PwTp5sdgMRmRlW?= =?us-ascii?Q?K1Ym8ciC4I602jnOT5X2SeU4yt++h3xzoqe2e9bUUFTDU7K/3C2Dx6Yd/8+G?= =?us-ascii?Q?vmvie0EAXp7uexZ5klOISl5kzzizW48yQ3codnSWTiR1q0gOrBY+u5kJiFLK?= =?us-ascii?Q?8VUeN+IhF7krinTCtZQFzf1DrgqwuWoir2g5XN8zH41Ou+o009kGmttLcRWm?= =?us-ascii?Q?K7+qTJIppXud9HrSd4elWATHnHUSifFndBkc1P8uOjZbJiHC0gJ6DWNEs0Eu?= =?us-ascii?Q?9U9Gn1JU3qfX/K91LjFBA19fmVKegVWSFvL9BMkapMjdalfwVvSkKRKM0Z0R?= =?us-ascii?Q?melb2QNe32Tb3U3CK+t5bQ0+/h7AC+EzJuVj0k4OMe6ECyREyDK2coLpOkko?= =?us-ascii?Q?RewbVAphGGaKqv2BYD3fPCH10BAvZ9ur3YSc6n4v0/NSiMEkphR44wiFpOJk?= =?us-ascii?Q?txEHT+M8F2bY+vFxDkmEOazHU+2T7NDMw5/v+b/hGx4eDlhFCYSVoeL/GRMG?= =?us-ascii?Q?JV/+KZSl2Ne8fmsm7hb9qhwR7VV1v3SSYDzEEckIpN5Dz7HLQWO0kex26BMm?= =?us-ascii?Q?G72jz/ggFoVx5FBFKAR9yToa+fJkftLNKo3zqNr9QloG14u6bZhngUQdNXW4?= =?us-ascii?Q?mre18bLMEocOaqOfPknoheJk+zvyezfJpiwY7GOYGGoUrKOcunpGl0dgl8K0?= =?us-ascii?Q?5HHV6kSoDX0uFDQO/mbeF/Gn0Kec2BZ2Kfsjz4zqgQ1OISSnFeE5hPRd4f0P?= =?us-ascii?Q?z4A/fQEYyAPxt8xJ5Otg7VTrnsGzFxuz4gF3WWru8dHzR/5V1Vn8L86hq+u3?= =?us-ascii?Q?zLxppJAhPh4Dv9lccow9fac/+ypfcchWCVdFgzaFwN5S5qsKgUk95+RzFlii?= =?us-ascii?Q?4Z+iNut1vEpuM/WsMOyv1mgOL6BSnZDqYL7uIIuAlcDzyznop9ts5uKYoMSv?= =?us-ascii?Q?aEtLRpHmKKZZ0iJm39MntE3FK31PUY1L5BGMCIbBbvJxQ3ZpJ/LCzM7Wbhqs?= =?us-ascii?Q?AgjeEsrNkGhWWgRNPwON3360bqyfGDzB9BdF4dUkWq2axsgQBNufk6vvzHCM?= =?us-ascii?Q?K+U7KZGIsQ0TJ9z0c5BPCRjgMAC6BFQ2soRjQoz0zO/0FkL+6uw9Q/ymmQha?= =?us-ascii?Q?BsYIDPTImDIvNZxMQSvHhJqq7WXym/26rrC+O1+G?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5280.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: defa4bd9-0ed6-4509-5306-08dbd9ee13d7 X-MS-Exchange-CrossTenant-originalarrivaltime: 31 Oct 2023 08:47:56.0939 (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: ZtlB0Npjzvx7Pp1Ku7dqofVgHGsVCM4ZJAiAB4RWyFT5PKU2gYzG/GmuXV/rgFktwqyUysSmkzYTFzcneDdCxg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR11MB8558 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,ashraf.ali.s@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: F8FRb3GlGRpUP5QUmzVxLEdpx7686176AA= Content-Language: en-US Content-Type: multipart/alternative; boundary="_000_DM4PR11MB5280BA2B91E2ECEE6CE23F8AD7A0ADM4PR11MB5280namp_" X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=bIHibrgR; 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 --_000_DM4PR11MB5280BA2B91E2ECEE6CE23F8AD7A0ADM4PR11MB5280namp_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: >; Thanks., S, Ashraf Ali From: Kuo, Ted Sent: Tuesday, October 31, 2023 2:06 PM To: Ni, Ray ; devel@edk2.groups.io Cc: Chiu, Chasel ; Desimone, Nathaniel L ; Duggapu, Chinni B ; Ng, = Ray Han Lim ; Zeng, Star ; S= , Ashraf Ali ; Mohapatra, Susovan Subject: RE: [edk2-devel] [PATCH] IntelFsp2Pkg/SwitchStack: Reserve 32B whe= n calling C function in 64bit Reviewed-by: Ted Kuo > From: Ni, Ray > Sent: Tuesday, October 31, 2023 4:26 PM To: devel@edk2.groups.io; Ni, Ray > Cc: Chiu, Chasel >; Des= imone, Nathaniel L >; Duggapu, Chinni B >; Ng, Ray Han Lim >; Zeng, Star >; Kuo, Ted >; S, As= hraf Ali >; Mohapatra= , Susovan > Subject: Re: [edk2-devel] [PATCH] IntelFsp2Pkg/SwitchStack: Reserve 32B whe= n calling C function in 64bit Sorry, I copied the maintainers from Maintainers.txt but forgot to change a= ll M/R to "Cc". That caused not all the maintainers/reviewers are CCed. I will fix the commit message before merging. Thanks, Ray ________________________________ From: devel@edk2.groups.io > on behalf of Ni, Ray > Sent: Tuesday, October 31, 2023 4:22 PM 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 stack and restores IDTR from its stack saved earlier. However, due to a bug in BaseFspSwitchStackLib, the IDTR saved on FSP's stack might be corrupted that results the following TempRamExit call fails inside 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 responsible for allocating 32 bytes of "shadow space" on the stack right before 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 causes 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.
; SPDX-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 ; Restore previous contexts -- 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/1712937 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/3759105/1712937/893644498= /xyzzy [ray.ni@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 (#110389): https://edk2.groups.io/g/devel/message/110389 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- --_000_DM4PR11MB5280BA2B91E2ECEE6CE23F8AD7A0ADM4PR11MB5280namp_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Reviewed-by: <ashraf.ali.s@intel.com>;

 

Thanks.,=

S, Ashraf Ali<= /o:p>

 

From: Kuo, Ted <ted.kuo@intel.com>
Sent: Tuesday, October 31, 2023 2:06 PM
To: Ni, Ray <ray.ni@intel.com>; devel@edk2.groups.io
Cc: Chiu, Chasel <chasel.chiu@intel.com>; Desimone, Nathaniel = L <nathaniel.l.desimone@intel.com>; Duggapu, Chinni B <chinni.b.du= ggapu@intel.com>; Ng, Ray Han Lim <ray.han.lim.ng@intel.com>; Zeng= , Star <star.zeng@intel.com>; S, Ashraf Ali <ashraf.ali.s@intel.co= m>; Mohapatra, Susovan <susovan.mohapatra@intel.com>
Subject: RE: [edk2-devel] [PATCH] IntelFsp2Pkg/SwitchStack: Reserve = 32B when calling C function in 64bit

 

Reviewed-by: Ted Kuo <ted.kuo@intel.com>

 

From: Ni, Ray <ray.ni@intel.com>
Sent: Tuesday, October 31, 2023 4:26 PM
To: devel@edk2.groups.io= ; Ni, Ray <ray.ni@intel.com><= br> Cc: Chiu, Chasel <chasel= .chiu@intel.com>; Desimone, Nathaniel L <nathaniel.l.desimone@intel.com>; Duggapu, = Chinni B <chinni.b.duggapu= @intel.com>; Ng, Ray Han Lim <ray.han.li= m.ng@intel.com>; Zeng, Star <star.zeng@intel.com>; Kuo, Ted <ted.kuo@intel.com>; S, Ashraf Ali <ashraf.ali.s@intel.com>; Mohapatra, Susovan <suso= van.mohapatra@intel.com>
Subject: Re: [edk2-devel] [PATCH] IntelFsp2Pkg/SwitchStack: Reserve = 32B when calling C function in 64bit

 

Sorry, I copied the maintainers from Maintainers.txt but f= orgot to change all M/R to "Cc". That caused not all the maintain= ers/reviewers are CCed.

I will fix the commit message before merging.

 

Thanks,

Ray


From: devel@edk2.groups.io <devel@edk2.groups.io> on behalf of= Ni, Ray <ray.ni@intel.com> Sent: Tuesday, October 31, 2023 4:22 PM
To: devel@edk2.groups.io= <devel@edk2.groups.io> Cc: Chiu, Chasel <chasel= .chiu@intel.com>
Subject: [edk2-devel] [PATCH] IntelFsp2Pkg/SwitchStack: Reserve 32B = when calling 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 stack and restores IDTR from its stack saved earlier.

However, due to a bug in BaseFspSwitchStackLib, the IDTR saved on
FSP's stack might be corrupted that results the following TempRamExit
call fails inside 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 responsible for allocating 32 bytes of "shadow space" o= n the
stack right before 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 assemb= ly
caller. That causes 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 <ray.ni@intel.= com>
Cc: Chasel Chiu <chasel.chiu@in= tel.com>
M: Nate DeSimone <nath= aniel.l.desimone@intel.com>
M: Duggapu Chinni B <chinn= i.b.duggapu@intel.com>
M: Ray Han Lim Ng <ray.han.l= im.ng@intel.com>
R: Star Zeng <star.zeng@intel.com= >
R: Ted Kuo <ted.kuo@intel.com&g= t;
R: Ashraf Ali S <ashraf.ali.s@= intel.com>
R: Susovan Mohapatra <sus= ovan.mohapatra@intel.com>
---
 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.<BR>
+; Copyright (c) 2022 - 2023, Intel Corporation. All rights reserved.<BR= >

 ; SPDX-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

 

     ; Restore previous contexts

--
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/1712937
Group Owner: devel+owner@edk2= .groups.io
Unsubscribe: https://edk2.groups.io/g/devel/leave/3759105/1712937/893644498/xyzzy [r= ay.ni@intel.com]
-=3D-=3D-=3D-=3D-=3D-=3D

_._,_._,_

Groups.io Links:

=20 You receive all messages sent to this group. =20 =20

View/Reply Online (#110389) | =20 | Mute= This Topic | New Topic
Your Subscriptio= n | Contact Group Owner | Unsubscribe [rebecca@openfw.io]

_._,_._,_
--_000_DM4PR11MB5280BA2B91E2ECEE6CE23F8AD7A0ADM4PR11MB5280namp_--