public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Kuo, Ted" <ted.kuo@intel.com>
To: "devel@edk2.groups.io" <devel@edk2.groups.io>,
	"Kuo, Ted" <ted.kuo@intel.com>
Cc: "Bi, Dandan" <dandan.bi@intel.com>,
	"Gao, Liming" <gaoliming@byosoft.com.cn>,
	"De, Debkumar" <debkumar.de@intel.com>,
	"Han, Harry" <harry.han@intel.com>,
	"West, Catharine" <catharine.west@intel.com>,
	"Wang, Jian J" <jian.j.wang@intel.com>,
	"S, Ashraf Ali" <ashraf.ali.s@intel.com>,
	"Kinney, Michael D" <michael.d.kinney@intel.com>
Subject: Re: [edk2-devel][PATCH] MdeModulePkg: Make RSP 16-byte boundary aligned for PEI 64bit
Date: Thu, 17 Mar 2022 01:04:52 +0000	[thread overview]
Message-ID: <MW5PR11MB5932765D3C6A7DC2C45F256CE5129@MW5PR11MB5932.namprd11.prod.outlook.com> (raw)
In-Reply-To: <16DAF0B16C1B1922.28111@groups.io>

Hi Liming and Mike,

Can you please review the change?

Thanks,
Ted

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Kuo, Ted
Sent: Thursday, March 10, 2022 2:21 PM
To: devel@edk2.groups.io
Cc: Bi, Dandan <dandan.bi@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>; De, Debkumar <debkumar.de@intel.com>; Han, Harry <harry.han@intel.com>; West, Catharine <catharine.west@intel.com>; Wang, Jian J <jian.j.wang@intel.com>; S, Ashraf Ali <ashraf.ali.s@intel.com>
Subject: [edk2-devel][PATCH] MdeModulePkg: Make RSP 16-byte boundary aligned for PEI 64bit

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3865
Use SwitchPeiCore instead of calling PeiCore directly when switching PeiCore from temporary memory to permanent memory. For PEI 32bit, SwitchPeiCore always calls PeiCore without any additional step. For PEI 64bit, SwitchPeiCore makes RSP 16-byte boundary aligned and then allocate 32 bytes as a shadow store on call stack before calling PeiCore.

Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Debkumar De <debkumar.de@intel.com>
Cc: Harry Han <harry.han@intel.com>
Cc: Catharine West <catharine.west@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Ashraf Ali S <ashraf.ali.s@intel.com>
Signed-off-by: Ted Kuo <ted.kuo@intel.com>
---
 MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c |  2 +-  MdeModulePkg/Core/Pei/Ia32/SwitchPeiCore.nasm | 33 +++++++++++++++++++++++
 MdeModulePkg/Core/Pei/PeiMain.h               | 25 ++++++++++++++++++
 MdeModulePkg/Core/Pei/PeiMain.inf             |  6 +++++
 MdeModulePkg/Core/Pei/X64/SwitchPeiCore.nasm  | 38 +++++++++++++++++++++++++++
 5 files changed, 103 insertions(+), 1 deletion(-)  create mode 100644 MdeModulePkg/Core/Pei/Ia32/SwitchPeiCore.nasm
 create mode 100644 MdeModulePkg/Core/Pei/X64/SwitchPeiCore.nasm

diff --git a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
index 3552feda8f..5af6e6e86f 100644
--- a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
+++ b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
@@ -871,7 +871,7 @@ PeiCheckAndSwitchStack (
       //
       // Entry PEI Phase 2
       //
-      PeiCore (SecCoreData, NULL, Private);
+      SwitchPeiCore (SecCoreData, NULL, Private);
     } else {
       //
       // Migrate memory pages allocated in pre-memory phase.
diff --git a/MdeModulePkg/Core/Pei/Ia32/SwitchPeiCore.nasm b/MdeModulePkg/Core/Pei/Ia32/SwitchPeiCore.nasm
new file mode 100644
index 0000000000..23cfb5090b
--- /dev/null
+++ b/MdeModulePkg/Core/Pei/Ia32/SwitchPeiCore.nasm
@@ -0,0 +1,33 @@
+;----------------------------------------------------------------------
+--------
+;
+; Copyright (c) 2022, Intel Corporation. All rights reserved.<BR> ; 
+SPDX-License-Identifier: BSD-2-Clause-Patent ; ; Abstract:
+;
+;   Switch PeiCore from temporary memory to permanent memory.
+;
+;----------------------------------------------------------------------
+--------
+
+    SECTION .text
+
+extern ASM_PFX(PeiCore)
+
+;----------------------------------------------------------------------
+--------
+; VOID
+; EFIAPI
+; SwitchPeiCore (
+;   EFI_SEC_PEI_HAND_OFF    *SecCoreDataPtr,
+;   EFI_PEI_PPI_DESCRIPTOR  *PpiList,
+;   VOID                    *Data
+;   );
+;----------------------------------------------------------------------
+--------
+global ASM_PFX(SwitchPeiCore)
+ASM_PFX(SwitchPeiCore):
+  push   DWORD [esp + 12]
+  push   DWORD [esp + 12]
+  push   DWORD [esp + 12]
+  call   ASM_PFX(PeiCore)
+  jmp    $                ; Should never reach here
+  ret
+
diff --git a/MdeModulePkg/Core/Pei/PeiMain.h b/MdeModulePkg/Core/Pei/PeiMain.h index 556beddad5..8e8ed3dadf 100644
--- a/MdeModulePkg/Core/Pei/PeiMain.h
+++ b/MdeModulePkg/Core/Pei/PeiMain.h
@@ -2038,4 +2038,29 @@ PeiReinitializeFv (
   IN  PEI_CORE_INSTANCE  *PrivateData
   );
 
+/**
+  This routine is invoked by main entry of PeiMain module during 
+transition
+  from temporary memory to permanent memory.
+
+  @param SecCoreDataPtr  Points to a data structure containing information about the PEI core's operating
+                         environment, such as the size and location of temporary RAM, the stack location and
+                         the BFV location.
+  @param PpiList         Points to a list of one or more PPI descriptors to be installed initially by the PEI core.
+                         An empty PPI list consists of a single descriptor with the end-tag
+                         EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST. As part of its initialization
+                         phase, the PEI Foundation will add these SEC-hosted PPIs to its PPI database such
+                         that both the PEI Foundation and any modules can leverage the associated service
+                         calls and/or code in these early PPIs
+  @param Data            Pointer to old core data that is used to initialize the
+                         core's data areas.
+                         If NULL, it is first PeiCore entering.
+
+**/
+VOID
+EFIAPI
+SwitchPeiCore (
+  IN CONST EFI_SEC_PEI_HAND_OFF    *SecCoreDataPtr,
+  IN CONST EFI_PEI_PPI_DESCRIPTOR  *PpiList,
+  IN VOID                          *Data
+  );
 #endif
diff --git a/MdeModulePkg/Core/Pei/PeiMain.inf b/MdeModulePkg/Core/Pei/PeiMain.inf
index 0cf357371a..b597aed8f6 100644
--- a/MdeModulePkg/Core/Pei/PeiMain.inf
+++ b/MdeModulePkg/Core/Pei/PeiMain.inf
@@ -47,6 +47,12 @@
   PciCfg2/PciCfg2.c
   PeiMain.h
 
+[Sources.IA32]
+  Ia32/SwitchPeiCore.nasm
+
+[Sources.X64]
+  X64/SwitchPeiCore.nasm
+
 [Packages]
   MdePkg/MdePkg.dec
   MdeModulePkg/MdeModulePkg.dec
diff --git a/MdeModulePkg/Core/Pei/X64/SwitchPeiCore.nasm b/MdeModulePkg/Core/Pei/X64/SwitchPeiCore.nasm
new file mode 100644
index 0000000000..94e09be757
--- /dev/null
+++ b/MdeModulePkg/Core/Pei/X64/SwitchPeiCore.nasm
@@ -0,0 +1,38 @@
+;----------------------------------------------------------------------
+--------
+;
+; Copyright (c) 2022, Intel Corporation. All rights reserved.<BR> ; 
+SPDX-License-Identifier: BSD-2-Clause-Patent ; ; Abstract:
+;
+;   Switch PeiCore from temporary memory to permanent memory.
+;
+;----------------------------------------------------------------------
+--------
+
+    SECTION .text
+
+extern ASM_PFX(PeiCore)
+
+;----------------------------------------------------------------------
+--------
+; VOID
+; EFIAPI
+; SwitchPeiCore (
+;   EFI_SEC_PEI_HAND_OFF    *SecCoreDataPtr,
+;   EFI_PEI_PPI_DESCRIPTOR  *PpiList,
+;   VOID                    *Data
+;   );
+;----------------------------------------------------------------------
+--------
+global ASM_PFX(SwitchPeiCore)
+ASM_PFX(SwitchPeiCore):
+  ;
+  ; Per X64 calling convention, make sure RSP is 16-byte aligned.
+  ;
+  mov    rax, rsp
+  and    rax, 0fh
+  sub    rsp, rax
+
+  sub    rsp, 20h         ; Allocate 32 bytes as a shadow store on call stack
+  call   ASM_PFX(PeiCore)
+  jmp    $                ; Should never reach here
+  ret
+
--
2.16.2.windows.1








       reply	other threads:[~2022-03-17  1:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <16DAF0B16C1B1922.28111@groups.io>
2022-03-17  1:04 ` Kuo, Ted [this message]
2022-03-17 11:08   ` [edk2-devel][PATCH] MdeModulePkg: Make RSP 16-byte boundary aligned for PEI 64bit Marvin Häuser
2022-03-18 13:46     ` Kuo, Ted
2022-03-10  6:20 Kuo, Ted

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=MW5PR11MB5932765D3C6A7DC2C45F256CE5129@MW5PR11MB5932.namprd11.prod.outlook.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox