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 DF41E740034 for ; Fri, 5 Jan 2024 15:47:19 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=JEZx7qgfvoCAaDTN9omnthyvivgRZLxQkOZthE9iors=; 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=1704469638; v=1; b=RxSZhQlp28TPJTJMZOLbN01e+afIVuBSFGr6wNocfQ5YqVFD1QHJWLsImMxUrxY+sBLynKIC SoSZ6EkpV9S77/l9hUvpZbvz01jDrgggJrTSsnGe0LF9gT9Kc8tbd8DpQvJID3Z4GK0PJPmrQ/A C00cr1pTxaDKSYYT0fZq3UTI= X-Received: by 127.0.0.2 with SMTP id h4ZlYY7687511xvuf8jyz4Tl; Fri, 05 Jan 2024 07:47:18 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by mx.groups.io with SMTP id smtpd.web11.26439.1704469637834869051 for ; Fri, 05 Jan 2024 07:47:18 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10944"; a="483699922" X-IronPort-AV: E=Sophos;i="6.04,334,1695711600"; d="scan'208";a="483699922" X-Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2024 07:47:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10944"; a="756969693" X-IronPort-AV: E=Sophos;i="6.04,334,1695711600"; d="scan'208";a="756969693" X-Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by orsmga006.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 05 Jan 2024 07:47:17 -0800 X-Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Fri, 5 Jan 2024 07:47:16 -0800 X-Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35 via Frontend Transport; Fri, 5 Jan 2024 07:47:16 -0800 X-Received: from NAM02-SN1-obe.outbound.protection.outlook.com (104.47.57.41) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Fri, 5 Jan 2024 07:47:16 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oJUXzQ6BfrxuuNvMofpOEH2AsA0sZ6zFo1MSzDkElknwSrjhYMgKoGlDMXGElXkeJ5WzVyymWQNqYn3ZAdEjZez5qp+cfreFnJdzSiSVZffMVSi5SDF6GGBMqsGrZdYlnnqncxyPbL2AWpUKBjF+9r2eiFw2siPCc12Kq3YebQ3xl2EswzVHiebvx6ayIgJlPu1NSEoyAPiqL0p9swbTc3XhuxudJweCA5ENl9J3h/jcxBT4+454fJxh+qgC0zBF7pKdwdkkAOuh4TQvKFWC0LxqaD0wZMf4gANh4WkaV4IUhWZpoK7DdZ/TgoZ2FgtpyR3lUchvQ6dLet184ww4zg== 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=aNTPfSwRBHyLXe9Mht1f5Fua6+UhkmApZQEbZK7aGmM=; b=lOoUf33PP6JOMjTDH85gTJHJ/hz2Uk2gYfZuCzEtbKYega3v4bDb+m1zXNDwpWxW/RXRlzDCKTOWN2HgfzafF/D17GGb7aK0LBh5+Yv+EWA+pcgMSXlkooC8OprpXRPNjNhcs1A/WeHCJ7tjcjGRpsOLZX1K7irbgphPjzpGMkmoM8KlEePJVMQVd/2NQtQV2K+dVQLEUUaP/tlmmDLfauyUSMVquf8bjR6oBNQvvfAE+piWKAmvBrwTeEFeEyHwr7lhjld4y7SFRbL0bLZec2LHK+qbPtyK0hYeHMrY4ehBedrT5ssFvElsXJ5qgQZu4Lu7H/uFoeH20Khddk5qiA== 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 PH8PR11MB6856.namprd11.prod.outlook.com (2603:10b6:510:22b::7) by PH0PR11MB4919.namprd11.prod.outlook.com (2603:10b6:510:34::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.17; Fri, 5 Jan 2024 15:47:08 +0000 X-Received: from PH8PR11MB6856.namprd11.prod.outlook.com ([fe80::1ecf:18bf:776a:986a]) by PH8PR11MB6856.namprd11.prod.outlook.com ([fe80::1ecf:18bf:776a:986a%7]) with mapi id 15.20.7159.015; Fri, 5 Jan 2024 15:47:07 +0000 From: "Andrei Warkentin" To: Yang Wang , "devel@edk2.groups.io" CC: Ran Wang , Bamvor Jian ZHANG , "Gao, Liming" , "Kinney, Michael D" , Sunil V L , "Liu, Zhiguang" Subject: Re: [edk2-devel] [PATCH v2] MdePkg/BaseLib:Fix boot DxeCore hang on riscv platform Thread-Topic: [PATCH v2] MdePkg/BaseLib:Fix boot DxeCore hang on riscv platform Thread-Index: AQHaOTm0bZupzCQ12EWpvAImWPEGRrDLafkQ Date: Fri, 5 Jan 2024 15:47:07 +0000 Message-ID: References: <63fe1c56bfa5d917d34c6ca9c5d85494385687bb.1703678382.git.wangyang@bosc.ac.cn> In-Reply-To: <63fe1c56bfa5d917d34c6ca9c5d85494385687bb.1703678382.git.wangyang@bosc.ac.cn> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: PH8PR11MB6856:EE_|PH0PR11MB4919:EE_ x-ms-office365-filtering-correlation-id: 71189754-7464-45db-d198-08dc0e0592a2 x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam-message-info: xzqdDTGuCoitXanWS8dNhk96Z1amjPRe15Z27NbzEN2oJSql8aDbMz8PmTLIIaL8bgmBnmyeuey5UMtdfJpyRMugixzEbToinh4PEhIJ83whd/dK9fdyDNe7jprzhu/LgaFNdnc0DgCaWD9ckBTTalE6lFKiZQMjZ6mwH4mRAIIwLEARDftK9rUixXt1QZVZ06WwNscpxaOuDxGAOACqvKQP25Vv/2EaFAObWkCzLYq+j522LFYoGSWujSyBdD8i5uhMvCoYzZoxZn3wuvr0Cj0eRLJOdKpAlFNy+c+aRdKGv8XLZXT4t3M0OHveyc7vEMJ23KGTZ/mF5ReY61JdkTDmr2szkJgHi/O8f02xz5xIoICc7WUNB+Y++1m/QBs50t97+sWnaGvLqB+pzeIVLOwR8nSpCT3NJXkz46li+ygbcJpsgBjuSkDf5i7xBNd1J7rTP4yHA4nQO4K62/YwOoptsJnlPgWZ8EiwcTu0uRwJUfoh+mxZp0Dty0FlYxFR+QgnBO582siBNgdlHgNjN6et4KuiGbi8D9DfyvCVqQnT/hNzcH8x3oo6W7joWq0nPYTqhcmdWjYmtnQAsd41Q3rxP3yMijMfgCRUx76ePrVpGGoaiEdcW0pqodhvCoPA x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?ndEr40e1qFJdEUGTXMywuR18ipZj3q1tExsY7cuLpR8G1bPQugF0XUNxi7xb?= =?us-ascii?Q?t4ZWqFbqWSFcHeuxEl5xflHBoUvjtnmdup/0YM5cAybxSiBJqhbCeuwbrJ2+?= =?us-ascii?Q?Zu9fPjeaSCBPn+Nz0ls1pEVERYfBTv4Y0b8J3T4ys5RSf0R/z0CN3AYtb7Kr?= =?us-ascii?Q?oTPMQxbCZ7rqBBdcGpV7jMUMY+I2HC9dJBVTvsOXAVjcoMHKmisTLjdhGJHk?= =?us-ascii?Q?xfkMSR7O+ib1mgSXxoSi6gmTaN/eEB77hlvcoqdBVLuGcwfBBx5MMe3ftqqY?= =?us-ascii?Q?k0BQpNOjDQRetxbP9C9FoRPg+21Ev3JhgoWdUuOecjGkyYojTbqoorfGL6+g?= =?us-ascii?Q?ES/NYRKrhrGpV8lI1InDYpt5mLi8tK7hPu8tSK3ucI9ME+bPaRsTv3J07Zxn?= =?us-ascii?Q?ZODszXJTqENotnsAj0zpopYbBpLS/oSfulFeR6+jvy6pu6n1xU1wY/Wi63AO?= =?us-ascii?Q?AlMPtyK46YBt/4xlId9GWO3r8vFB9k9BPJaPQbzrUEvn8yPpnnxPfQzL2u6o?= =?us-ascii?Q?JXKfhvzoUSHRN+sVibYUESKMFtENG9Scm/1G5wONW+D0FGS2e8sZq05QAHV3?= =?us-ascii?Q?C8KF3wjqlxwB+1GMH3StslgkT0Hdvv1MwTcKAvfw/ygvBCL6E5i7uTnDpNG0?= =?us-ascii?Q?Ea+XDT0C4Na+HzVBVTk4Tm92cEyEP+uJ6xjjc+AXkBk78fUeSNaPdvCMI2HE?= =?us-ascii?Q?H/rjD5suQnVPfwvNWpJzlCOJucV8YOnKG1tns/NVZeh+yQ+r11iSiDJB8goY?= =?us-ascii?Q?xZNu/fuTkdELKOkraP6lO4IeUxM6/gCmqQOI6edtVx78SN3rvRJ/gI4Ega7f?= =?us-ascii?Q?4NzgLA3AUbD0a6HW2l6CfxILFvwZaIFHta4avdK6A63ypkctsfXi3V22zDlL?= =?us-ascii?Q?NcmIh7l6mtUIS0IXDpFMCC6B/RdPkjrRlU1/m3OdgZzwivfM5Q3FgWEF5IMi?= =?us-ascii?Q?eec2TFClbE6lToCqXBJS9Wc3zo9MDZo5Oyjf2hHyz1ywp6GRtOq9pFiRaJ6D?= =?us-ascii?Q?c9IyCff26AqC/y7V0P1P0FPIIN1F5kwi1ZMrOgIv0mFSxB5cfEYPxlEue6dv?= =?us-ascii?Q?A3dUdzrebg/76zlaG9ML2VSnhvxmDdxc2v0RevtoSbG3/UzHA9axSdrp7BjM?= =?us-ascii?Q?yiQmGpkS762dRuDwftIr/NBJjnzjdKybiCVhxGA9bnRdA+obBwxSuCOEBrMX?= =?us-ascii?Q?N9EBOFAeSOroO+MoDWp+5sw+wUKtmjXvOag5GzVmXC29Ih7qOt1EASOjB9Np?= =?us-ascii?Q?jo8nAUxGW7grKpVQoxr9GQTBLqBaVjqZhML93clDONgY4pKfjyFElZ3BlYEQ?= =?us-ascii?Q?UFN3g4R+y/oqehRrfjOq4yEB1iXG0tzulwbZutoS3710G/9zZjSGejERIF2B?= =?us-ascii?Q?T2rbagWIqWrBXtnwF3v0HuZKLmXSvHXiIYYFiVGyx6UwMfIYWhq1QoDei8lr?= =?us-ascii?Q?yi0D4STzG6Xa+3wfPnSPDRxPTrDwyhpqpkaCngYarMQd0QNrEeo3f+87ABhc?= =?us-ascii?Q?CuLe3Nv3onk4XgZWKh/0EWPLpzz18nqXRHSTNLJzPuGa07z8qfyUpuXHkyLi?= =?us-ascii?Q?CVnpeDjNgxRuQ6Tl5hGUQjiSmr8RNw7tgVgccIGM6caauXDMf3yDG131pe3s?= =?us-ascii?Q?Sw=3D=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PH8PR11MB6856.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 71189754-7464-45db-d198-08dc0e0592a2 X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Jan 2024 15:47:07.7180 (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: TfpzgBeONSXcrw1yvQXnGzv/p+/wtDJmjyIFqMVxVIzWA/3AacRFuUKBUtorSwrpLZswcLkZJay1+lmAun6MCLGF0h1Z0baf/t/kkxd/rXU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB4919 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,andrei.warkentin@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: qs09kXJU1WAjz4ec4XjlycGxx7686176AA= 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=RxSZhQlp; 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; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}") Looks reasonable to me. Reviewed-by: Andrei Warkentin > -----Original Message----- > From: Yang Wang > Sent: Wednesday, December 27, 2023 8:57 PM > To: Warkentin, Andrei ; devel@edk2.groups.io > Cc: Yang Wang ; Ran Wang ; > Bamvor Jian ZHANG ; Gao, Liming > ; Kinney, Michael D > ; Sunil V L ; Liu, > Zhiguang > Subject: [PATCH v2] MdePkg/BaseLib:Fix boot DxeCore hang on riscv platfor= m >=20 > For scene of > HandOffToDxeCore()->SwitchStack(DxeCoreEntryPoint)-> > InternalSwitchStack()->LongJump(),Variable HobList.Raw > will be passed (from *Context1 to register a0) to > DxeMain() in parameter *HobStart. >=20 > However, meanwhile the function LongJump() overrides > register a0 with a1 (-1) due to commit (ea628f28e5 "RISCV: Fix > InternalLongJump to return correct value"), then cause hang. >=20 > Replacing calling LongJump() with new InternalSwitchStackAsm() to pass > addres data in register s0 to register a0 could fix this issue (just > like the solution in MdePkg/Library/BaseLib/AArch64/SwitchStack.S) >=20 > Signed-off-by: Yang Wang > Reviewed-by: Ran Wang > Cc: Bamvor Jian ZHANG > Cc: Andrei Warkentin > Cc: Liming Gao > Cc: Michael D Kinney > Cc: Sunil V L > Cc: Zhiguang Liu > --- > Change in v2: > - Remove JumpBuffer variable parameter > - Take these in the order of Context1, Context2, EntryPoint, NewS= tack > - Fix BaseLib.inf, add Compilation SwitchStack.S > - Drop REG_S/REG_L >=20 > MdePkg/Library/BaseLib/BaseLib.inf | 1 + > .../BaseLib/RiscV64/InternalSwitchStack.c | 31 ++++++++++++---- > MdePkg/Library/BaseLib/RiscV64/SwitchStack.S | 37 > +++++++++++++++++++ > 3 files changed, 62 insertions(+), 7 deletions(-) > create mode 100644 MdePkg/Library/BaseLib/RiscV64/SwitchStack.S >=20 > diff --git a/MdePkg/Library/BaseLib/BaseLib.inf > b/MdePkg/Library/BaseLib/BaseLib.inf > index 5338938944..6b46949be3 100644 > --- a/MdePkg/Library/BaseLib/BaseLib.inf > +++ b/MdePkg/Library/BaseLib/BaseLib.inf > @@ -397,6 +397,7 @@ > RiscV64/CpuPause.c >=20 > RiscV64/MemoryFence.S | GCC >=20 > RiscV64/RiscVSetJumpLongJump.S | GCC >=20 > + RiscV64/SwitchStack.S | GCC >=20 > RiscV64/RiscVCpuBreakpoint.S | GCC >=20 > RiscV64/RiscVCpuPause.S | GCC >=20 > RiscV64/RiscVInterrupt.S | GCC >=20 > diff --git a/MdePkg/Library/BaseLib/RiscV64/InternalSwitchStack.c > b/MdePkg/Library/BaseLib/RiscV64/InternalSwitchStack.c > index b78424c163..3216d241ad 100644 > --- a/MdePkg/Library/BaseLib/RiscV64/InternalSwitchStack.c > +++ b/MdePkg/Library/BaseLib/RiscV64/InternalSwitchStack.c > @@ -8,6 +8,29 @@ >=20 >=20 > #include "BaseLibInternals.h" >=20 >=20 >=20 > +/** >=20 > + Transfers control to a function starting with a new stack. >=20 > + >=20 > + This internal worker function transfers control to the function >=20 > + specified by EntryPoint using the new stack specified by NewStack, >=20 > + and passes in the parameters specified by Context1 and Context2. >=20 > + Context1 and Context2 are optional and may be NULL. >=20 > + The function EntryPoint must never return. >=20 > + >=20 > + @param Context1 The first parameter to pass in. >=20 > + @param Context2 The second Parameter to pass in >=20 > + @param EntryPoint The pointer to the function to enter. >=20 > + @param NewStack The new Location of the stack >=20 > + >=20 > +**/ >=20 > +VOID >=20 > +EFIAPI >=20 > +InternalSwitchStackAsm ( >=20 > + IN VOID *Context1 OPTIONAL, >=20 > + IN VOID *Context2 OPTIONAL, >=20 > + IN SWITCH_STACK_ENTRY_POINT EntryPoint, >=20 > + IN VOID *NewStack >=20 > + ); >=20 > /** >=20 > Transfers control to a function starting with a new stack. >=20 >=20 >=20 > @@ -42,12 +65,6 @@ InternalSwitchStack ( > IN VA_LIST Marker >=20 > ) >=20 > { >=20 > - BASE_LIBRARY_JUMP_BUFFER JumpBuffer; >=20 > - >=20 > - JumpBuffer.RA =3D (UINTN)EntryPoint; >=20 > - JumpBuffer.SP =3D (UINTN)NewStack - sizeof (VOID *); >=20 > - JumpBuffer.S0 =3D (UINT64)(UINTN)Context1; >=20 > - JumpBuffer.S1 =3D (UINT64)(UINTN)Context2; >=20 > - LongJump (&JumpBuffer, (UINTN)-1); >=20 > + InternalSwitchStackAsm (Context1, Context2, EntryPoint, (VOID > *)((UINTN)NewStack - sizeof (VOID *))); >=20 > ASSERT (FALSE); >=20 > } >=20 > diff --git a/MdePkg/Library/BaseLib/RiscV64/SwitchStack.S > b/MdePkg/Library/BaseLib/RiscV64/SwitchStack.S > new file mode 100644 > index 0000000000..db535c1aab > --- /dev/null > +++ b/MdePkg/Library/BaseLib/RiscV64/SwitchStack.S > @@ -0,0 +1,37 @@ > +//----------------------------------------------------------------------= -------- >=20 > +// >=20 > +// InternalSwitchStackAsm for RISC-V >=20 > +// >=20 > +// Copyright (c) 2023, Bosc Corporation. All rights reserved.
>=20 > +// >=20 > +// SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > +// >=20 > +//----------------------------------------------------------------------= -------- >=20 > +.align 3 >=20 > + >=20 > +#/** >=20 > +# >=20 > +# This allows the caller to switch the stack and goes to the new entry p= oint >=20 > +# >=20 > +# @param Context Parameter to pass in >=20 > +# @param Context2 Parameter2 to pass in >=20 > +# @param EntryPoint The pointer to the location to enter >=20 > +# @param NewStack New Location of the stack >=20 > +# >=20 > +# @return Nothing. Goes to the Entry Point passing in the new parame= ters >=20 > +# >=20 > +#**/ >=20 > +#VOID >=20 > +#EFIAPI >=20 > +#InternalSwitchStackAsm ( >=20 > +# VOID *Context, >=20 > +# VOID *Context2, >=20 > +# SWITCH_STACK_ENTRY_POINT EntryPoint, >=20 > +# VOID *NewStack >=20 > +# ); >=20 > +# >=20 > + .globl InternalSwitchStackAsm >=20 > +InternalSwitchStackAsm: >=20 > + mv ra, a2 >=20 > + mv sp, a3 >=20 > + ret >=20 > -- > 2.25.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 (#113297): https://edk2.groups.io/g/devel/message/113297 Mute This Topic: https://groups.io/mt/103395756/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-