From nobody Sat May 18 03:46:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+87792+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+87792+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1647866655; cv=none; d=zohomail.com; s=zohoarc; b=FiSOBQjM8p4yM1Yg3mI7DWD9OCQ0JVU+Mfw5F+DevJqHdjw+Oz0fK9Lyh+bZ0dOoI8nLtZRUunvBF4Qo6U9/yQ0OeWRJ7cYDU7KQVJsh57q0P4+nsF/bYCF47HbX+AO67EahUwKxSIaFAV10hMzKIfQehPIReNHO2Jl2shXm8ZM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1647866655; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=CzYcSZgT485nS4+A/s4VzFW4oeT1X1UvCGRsjrMfUnY=; b=AdL3OVJAwvkO8X/jKOMBpbnajM4J+JPxvnqyNp1dLT3z50vuNUoSYRBaOdDyWrPN6AjOIzQDrMUGFvs2n9+OxYXWS4jGKytF2zbiShmYse+tbWSUEl1KeMAySAvR74qSYkN4IoC5vYJVwlVmRXRtwCKu2OUlo3t5RAroZ22CGaQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+87792+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1647866655331573.78328346636; Mon, 21 Mar 2022 05:44:15 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ggCtYY1788612xbqF3uChC0N; Mon, 21 Mar 2022 05:44:14 -0700 X-Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web12.29753.1647866653427366424 for ; Mon, 21 Mar 2022 05:44:14 -0700 X-IronPort-AV: E=McAfee;i="6200,9189,10292"; a="237483232" X-IronPort-AV: E=Sophos;i="5.90,198,1643702400"; d="scan'208";a="237483232" X-Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Mar 2022 05:44:12 -0700 X-IronPort-AV: E=Sophos;i="5.90,198,1643702400"; d="scan'208";a="692159690" X-Received: from tedkuo1-win10.gar.corp.intel.com ([10.5.215.13]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Mar 2022 05:44:10 -0700 From: "Kuo, Ted" To: devel@edk2.groups.io Cc: Michael D Kinney , Dandan Bi , Liming Gao , Debkumar De , Harry Han , Catharine West , Jian J Wang , =?UTF-8?q?Marvin=20H=C3=A4user?= Subject: [edk2-devel][PATCH 1/2] MdeModulePkg: StackOffset must be aligned to a 16-byte boundary in X64 Date: Mon, 21 Mar 2022 20:43:27 +0800 Message-Id: <6301e56ae7ec1852c8bf499c2df69e0a04420443.1647864782.git.ted.kuo@intel.com> In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ted.kuo@intel.com X-Gm-Message-State: vyTwBnPbB6vo4Xj3FUkAsRRXx1787277AA= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1647866654; bh=PeJEEe1U+EBU8beTOZ6tn+hffyKxCKemShyF0tyV7IE=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=O7BtNQ1EbLWjc+JVAoLJEjBiVAHi3iaQN9GEYoWXeMP43JVwg/9CnwU8C0/y6RD7yEz GU/l7pUeBOZeBHF+rIA/aKfLZLBnZFBNg4COXhT5E4XcG46mxiygmUeCAXNL/8SEeVa+0 I3B6KC8OK2GJGDLPO6CQ5h/Jakm6qeSsIPQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1647866656156100001 REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D3865 For X64, StackOffset must be aligned to a 16-byte boundary as well as old stack and new stack. Otherwise, it'll get wrong data from Private pointer after switching from old stack to new stack. Cc: Michael D Kinney Cc: Dandan Bi Cc: Liming Gao Cc: Debkumar De Cc: Harry Han Cc: Catharine West Cc: Jian J Wang Cc: Marvin H=C3=A4user Signed-off-by: Ted Kuo --- MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c b/MdeModulePkg/C= ore/Pei/Dispatcher/Dispatcher.c index 3552feda8f..8a2c1ec779 100644 --- a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c +++ b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c @@ -823,6 +823,19 @@ PeiCheckAndSwitchStack ( (VOID **)&TemporaryRamSupportPpi ); if (!EFI_ERROR (Status)) { + // + // For X64, StackOffset must be aligned to a 16-byte boundary. Other= wise, it'll get wrong data + // from Private pointer after switching to new stack. + // + if ((sizeof (UINTN) =3D=3D sizeof (UINT64)) && ((StackOffset & 0x0F)= =3D=3D 8)) { + if (StackOffsetPositive =3D=3D TRUE) { + StackOffset -=3D 8; + } else { + StackOffset +=3D 8; + } + Private->StackOffset =3D StackOffset; + } + // // Heap Offset // @@ -852,7 +865,10 @@ PeiCheckAndSwitchStack ( // Temporary Ram Support PPI is provided by platform, it will copy // temporary memory to permanent memory and do stack switching. // After invoking Temporary Ram Support PPI, the following code's - // stack is in permanent memory. + // stack is in permanent memory. For X64, the bit3:0 of the new stack + // produced by TemporaryRamMigration must be aligned with the bit3:0= of + // the old stack. Otherwise, it'll break the original stack alignment + // after switching to new stack. // TemporaryRamSupportPpi->TemporaryRamMigration ( PeiServices, --=20 2.16.2.windows.1 -=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 (#87792): https://edk2.groups.io/g/devel/message/87792 Mute This Topic: https://groups.io/mt/89926603/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sat May 18 03:46:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+87793+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+87793+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1647866661186963.6687992930296; Mon, 21 Mar 2022 05:44:21 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id aaGSYY1788612xOToeUHtSw8; Mon, 21 Mar 2022 05:44:22 -0700 X-Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web08.29837.1647866661614615744 for ; Mon, 21 Mar 2022 05:44:22 -0700 X-IronPort-AV: E=McAfee;i="6200,9189,10292"; a="318250648" X-IronPort-AV: E=Sophos;i="5.90,198,1643702400"; d="scan'208";a="318250648" X-Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Mar 2022 05:44:20 -0700 X-IronPort-AV: E=Sophos;i="5.90,198,1643702400"; d="scan'208";a="692159723" X-Received: from tedkuo1-win10.gar.corp.intel.com ([10.5.215.13]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Mar 2022 05:44:19 -0700 From: "Kuo, Ted" To: devel@edk2.groups.io Cc: Chasel Chiu , Nate DeSimone , Star Zeng , Ashraf Ali S Subject: [edk2-devel][PATCH 2/2] IntelFsp2Pkg: Ensure new stack is aligned to old stack for X64 Date: Mon, 21 Mar 2022 20:43:28 +0800 Message-Id: <8c8e4573d5998e2e957dfef66ab7a7774794a31b.1647864782.git.ted.kuo@intel.com> In-Reply-To: References: In-Reply-To: References: Precedence: Bulk List-Unsubscribe: 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,ted.kuo@intel.com X-Gm-Message-State: sfliZQX0EFWwBZrgwG6h1Rtnx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1647866662; bh=w+uAg0sTeGA33gxZo17ILk8ppIh1gGx/AxOwlAZQ7l0=; h=Cc:Date:From:Reply-To:Subject:To; b=hmzk0WnbhVWhcmMGeDSYAchf5Y/RJpSaXZgZ0qa2p8qdZZLfr+WFveSBrUnBWzfAjXx C1eBOjHTEPZkrvTRGnq2RV7Fz/nE66L8PDzMmFYVFgb2mUoU9Ay8txSDH94Mf2L9iP5UF ncWcl3kTAoSCh3AfPPoDncMmkgngvZP4mvU= X-ZohoMail-DKIM: fail (Signature date is -1 seconds in the future.) X-ZM-MESSAGEID: 1647866692349100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D3865 Ensure bit3:0 of NewStack is aligned with bit3:0 of OldStack for X64 before switching stack. Otherwise, RSP may not be aligned to a 16-byte boundary after returning from SecTemporaryRamSupport. Cc: Chasel Chiu Cc: Nate DeSimone Cc: Star Zeng Cc: Ashraf Ali S Signed-off-by: Ted Kuo --- IntelFsp2Pkg/FspSecCore/SecMain.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/IntelFsp2Pkg/FspSecCore/SecMain.c b/IntelFsp2Pkg/FspSecCore/Se= cMain.c index d376fb8361..f93e2d2ff7 100644 --- a/IntelFsp2Pkg/FspSecCore/SecMain.c +++ b/IntelFsp2Pkg/FspSecCore/SecMain.c @@ -258,6 +258,14 @@ SecTemporaryRamSupport ( NewStack =3D (VOID *)(UINTN)PermanentMemoryBase; } =20 + // + // Ensure bit3:0 of NewStack is aligned with bit3:0 of OldStack for X64 = before switching stack. + // Otherwise, RSP may not be aligned to a 16-byte boundary after returni= ng from SecTemporaryRamSupport. + // + if ((sizeof (UINTN) =3D=3D sizeof (UINT64)) && (((UINTN)NewStack & 0x0F)= !=3D ((UINTN)OldStack & 0x0F))) { + NewStack =3D (VOID *)((UINTN)NewStack - 8); + } + // // Migrate Heap // --=20 2.16.2.windows.1 -=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 (#87793): https://edk2.groups.io/g/devel/message/87793 Mute This Topic: https://groups.io/mt/89926608/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-