From nobody Wed May 15 10:16:09 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+112940+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+112940+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1703732207; cv=none; d=zohomail.com; s=zohoarc; b=DWSQ1flt6twRO1yiIAJSQqeMAuiahkrTDcllXAtsDQ1+TqDbYSUea5Ojt8jgt2l8ZRPxFk9vZVveptpKT8Mt7BmQRcVQYaprPnXu+U0d9gl65D0Qk2uwOL+ZDP1DMoEBJyFGJi/2qTL6fZcZrTn4ez1ZQXHl8+lyMWAesuvBT/Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703732207; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=dPU057G/5VZPhdeyZ5/KiEQ5nSwMm2+t/gqLMT8fmnA=; b=DpcGw9HUWVAgiJ5CVoDggKpHixiALSFfthN4qc8ecuSuE/xpkA+FI9fhyzmyPCo+ctLqM22afCnB8IfpPrP/BNGc1gIozpnY2AyZRZcWGRhFN2yQ4nFR1OM30Sj77hWcqPAbdkv2nqYFPiTvIQLJjcdiEyPk6WqNIl91oR+x0Fo= 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+112940+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 170373220699085.39855406324625; Wed, 27 Dec 2023 18:56:46 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=c7/75mcCztO7SNOE73i6rnKAsvZLkkNiYw4mnGwY8nI=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1703732206; v=1; b=PKXZy3ga+TBWYcKAvB8osLhrxOjfCuvypofgs2/V3F5/Mlkj2qDW3WXo2vbC9ugId8ky9C5w 6nUzmpGQH83z22VLAwcTwm6hlcBtlObmZ5r/dVTGTDFw8bZ2cmKMXKq5TXInaHVpY/Pm8uaMZ7d vU/jfcIeftCq/rO7EDsUXLpA= X-Received: by 127.0.0.2 with SMTP id jsenYY1788612xV50WlmrjHQ; Wed, 27 Dec 2023 18:56:46 -0800 X-Received: from azure-sdnproxy.icoremail.net (azure-sdnproxy.icoremail.net [52.175.55.52]) by mx.groups.io with SMTP id smtpd.web11.116206.1703732204945633237 for ; Wed, 27 Dec 2023 18:56:45 -0800 X-Received: from localhost.localdomain (unknown [123.114.53.210]) by mail (Coremail) with SMTP id AQAAfwBH4Nrm44xlJDVfAA--.13078S2; Thu, 28 Dec 2023 10:56:39 +0800 (CST) From: =?UTF-8?B?546L5rSL?= To: andrei.warkentin@intel.com, devel@edk2.groups.io Cc: Yang Wang , Ran Wang , Bamvor Jian ZHANG , Liming Gao , Michael D Kinney , Sunil V L , Zhiguang Liu Subject: [edk2-devel] [PATCH v2] MdePkg/BaseLib:Fix boot DxeCore hang on riscv platform Date: Thu, 28 Dec 2023 10:56:32 +0800 Message-Id: <63fe1c56bfa5d917d34c6ca9c5d85494385687bb.1703678382.git.wangyang@bosc.ac.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAfwBH4Nrm44xlJDVfAA--.13078S2 X-Coremail-Antispam: 1UD129KBjvJXoWxuryrWr4UAFy3Aw13CF1DAwb_yoW7Jw1rpr y3Aa13ArnrJr4av3sxXa1UtryFyFZ5tr1UG395Zr1FvrnIyas7Wr47tw1FqFyF9348Zw1F vrWjgFsY9as3C37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkS14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26r1j6r1xM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4j 6F4UM28EF7xvwVC2z280aVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r4j6r 4UJwAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY02Avz4vE14v_Gr1l 42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJV WUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAK I48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F 4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY 6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUomiiDUUUU X-CM-SenderInfo: 5zdqw5hdqjquxrvfhtffof0/ 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,wangyang@bosc.ac.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: E6aRLrAEQFygFzO3G3QLkGYJx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1703732208451100003 Content-Type: text/plain; charset="utf-8" For scene of HandOffToDxeCore()->SwitchStack(DxeCoreEntryPoint)-> InternalSwitchStack()->LongJump(),Variable HobList.Raw will be passed (from *Context1 to register a0) to DxeMain() in parameter *HobStart. 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. 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) 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 Reviewed-by: Andrei Warkentin --- Change in v2: - Remove JumpBuffer variable parameter - Take these in the order of Context1, Context2, EntryPoint, NewSta= ck=20 - Fix BaseLib.inf, add Compilation SwitchStack.S - Drop REG_S/REG_L 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 diff --git a/MdePkg/Library/BaseLib/BaseLib.inf b/MdePkg/Library/BaseLib/Ba= seLib.inf index 5338938944..6b46949be3 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -397,6 +397,7 @@ RiscV64/CpuPause.c RiscV64/MemoryFence.S | GCC RiscV64/RiscVSetJumpLongJump.S | GCC + RiscV64/SwitchStack.S | GCC RiscV64/RiscVCpuBreakpoint.S | GCC RiscV64/RiscVCpuPause.S | GCC RiscV64/RiscVInterrupt.S | GCC 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 #include "BaseLibInternals.h" =20 +/** + Transfers control to a function starting with a new stack. + + This internal worker function transfers control to the function + specified by EntryPoint using the new stack specified by NewStack, + and passes in the parameters specified by Context1 and Context2. + Context1 and Context2 are optional and may be NULL. + The function EntryPoint must never return. + + @param Context1 The first parameter to pass in. + @param Context2 The second Parameter to pass in + @param EntryPoint The pointer to the function to enter. + @param NewStack The new Location of the stack + +**/ +VOID +EFIAPI +InternalSwitchStackAsm ( + IN VOID *Context1 OPTIONAL, + IN VOID *Context2 OPTIONAL, + IN SWITCH_STACK_ENTRY_POINT EntryPoint, + IN VOID *NewStack + ); /** Transfers control to a function starting with a new stack. =20 @@ -42,12 +65,6 @@ InternalSwitchStack ( IN VA_LIST Marker ) { - BASE_LIBRARY_JUMP_BUFFER JumpBuffer; - - JumpBuffer.RA =3D (UINTN)EntryPoint; - JumpBuffer.SP =3D (UINTN)NewStack - sizeof (VOID *); - JumpBuffer.S0 =3D (UINT64)(UINTN)Context1; - JumpBuffer.S1 =3D (UINT64)(UINTN)Context2; - LongJump (&JumpBuffer, (UINTN)-1); + InternalSwitchStackAsm (Context1, Context2, EntryPoint, (VOID *)((UINTN)= NewStack - sizeof (VOID *))); ASSERT (FALSE); } 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 @@ +//------------------------------------------------------------------------= ------ +// +// InternalSwitchStackAsm for RISC-V +// +// Copyright (c) 2023, Bosc Corporation. All rights reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +//------------------------------------------------------------------------= ------ +.align 3 + +#/** +# +# This allows the caller to switch the stack and goes to the new entry poi= nt +# +# @param Context Parameter to pass in +# @param Context2 Parameter2 to pass in +# @param EntryPoint The pointer to the location to enter +# @param NewStack New Location of the stack +# +# @return Nothing. Goes to the Entry Point passing in the new paramete= rs +# +#**/ +#VOID +#EFIAPI +#InternalSwitchStackAsm ( +# VOID *Context, +# VOID *Context2, +# SWITCH_STACK_ENTRY_POINT EntryPoint, +# VOID *NewStack +# ); +# + .globl InternalSwitchStackAsm +InternalSwitchStackAsm: + mv ra, a2 + mv sp, a3 + 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 (#112940): https://edk2.groups.io/g/devel/message/112940 Mute This Topic: https://groups.io/mt/103395756/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-