public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Jordan Justen" <jordan.l.justen@intel.com>
To: devel@edk2.groups.io
Cc: Jordan Justen <jordan.l.justen@intel.com>,
	Jian J Wang <jian.j.wang@intel.com>, Hao Wu <hao.a.wu@intel.com>,
	Ray Ni <ray.ni@intel.com>, Star Zeng <star.zeng@intel.com>
Subject: [PATCH v2 1/6] MdeModulePkg/Core/Pei: Add interface for assembly based TemporaryRamSupport
Date: Wed, 10 Apr 2019 01:39:55 -0700	[thread overview]
Message-ID: <20190410084000.19660-2-jordan.l.justen@intel.com> (raw)
In-Reply-To: <20190410084000.19660-1-jordan.l.justen@intel.com>

There is potential problem with PEI Core's usage of the
TemporaryRamSupport PPI. When the TemporaryRamMigration function is
called, it returns to C based code after changing the stack to the new
permanent memory copy of the stack. But, the C compiler may have
stored pointers to addresses on the old temporary RAM stack. Even
though the stack is copied to a new permanent memory location, it is
not possible to adjust all pointers that the C compiler may have added
within the stack data.

For this reason, it is only safe to return to assembly code after
calling TemporaryRamMigration. The assembly code can make sure the old
temporary RAM stack is not used before calling a new C function. When
the new function is called, it will use the new permanent memory
stack, so it is safe to use C code again.

This patch add the interface that the assembly function will need. The
PEI_CORE_TEMPORARY_RAM_TRANSITION contains all the data that the
assembly code will need to call the
TemporaryRamSupport->TemporaryRamMigration function, and then the
context that PEI will need after this call when the new C based
PeiTemporaryRamMigrated function is called.

After all assembly code based implementations have been added, PEI
Core will be updated to use the new assembly based code path.

Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
---
 MdeModulePkg/Core/Pei/PeiMain.h | 52 +++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/MdeModulePkg/Core/Pei/PeiMain.h b/MdeModulePkg/Core/Pei/PeiMain.h
index 0aed4f4685..6522798059 100644
--- a/MdeModulePkg/Core/Pei/PeiMain.h
+++ b/MdeModulePkg/Core/Pei/PeiMain.h
@@ -1865,4 +1865,56 @@ PeiReinitializeFv (
   IN  PEI_CORE_INSTANCE           *PrivateData
   );
 
+#pragma pack(1)
+typedef struct {
+  /**
+    These fields are used by PeiTemporaryRamMigration to call the
+    TemporaryRamMigration PPI.
+  **/
+  TEMPORARY_RAM_MIGRATION       TemporaryRamMigration;
+  CONST EFI_PEI_SERVICES        **PeiServices;
+  EFI_PHYSICAL_ADDRESS          TemporaryMemoryBase;
+  EFI_PHYSICAL_ADDRESS          PermanentMemoryBase;
+  UINTN                         CopySize;
+
+  /**
+    These fields are used by PeiTemporaryRamMigrated.
+  **/
+  PEI_CORE_INSTANCE             *Private;
+  CONST EFI_SEC_PEI_HAND_OFF    *SecCoreData;
+} PEI_CORE_TEMPORARY_RAM_TRANSITION;
+#pragma pack()
+
+/**
+  To call the TemporaryRamMigration PPI, we might not be able to rely
+  on C code's handling of the stack. In these cases we use an assembly
+  function to make sure the old stack is not used after the
+  TemporaryRamMigration PPI is used.
+
+  After calling the TemporaryRamMigration PPI, this function calls
+  PeiTemporaryRamMigrated.
+
+  @param TempRamTransitionData
+**/
+VOID
+EFIAPI
+PeiTemporaryRamMigration (
+  IN  PEI_CORE_TEMPORARY_RAM_TRANSITION  *TempRamTransitionData
+  );
+
+/**
+  After PeiTemporaryRamMigration has called the TemporaryRamMigration
+  PPI, it will call this C based function to allow PEI to continue
+  after the migration using the new stack in the migrated RAM.
+
+  @param CallbackContext   Pointer to PEI_CORE_TEMPORARY_RAM_TRANSITION
+                           data.
+**/
+VOID
+EFIAPI
+PeiTemporaryRamMigrated (
+  IN  VOID  *CallbackContext
+  );
+
+
 #endif
-- 
2.20.1


  reply	other threads:[~2019-04-10  8:41 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-10  8:39 [PATCH v2 0/6] Fix PEI Core issue during TemporaryRamMigration Jordan Justen
2019-04-10  8:39 ` Jordan Justen [this message]
2019-04-10  8:39 ` [PATCH v2 2/6] MdeModulePkg/Core/Pei: Add AARCH64 assembly for TemporaryRamMigration Jordan Justen
2019-04-10  8:39 ` [PATCH v2 3/6] MdeModulePkg/Core/Pei: Add ARM " Jordan Justen
2019-04-10  8:39 ` [PATCH v2 4/6] MdeModulePkg/Core/Pei: Add IA32 " Jordan Justen
2019-04-10  8:39 ` [PATCH v2 5/6] MdeModulePkg/Core/Pei: Add X64 " Jordan Justen
2019-04-10  8:40 ` [PATCH v2 6/6] MdeModulePkg/Core/Pei: Use code path for assembly based TemporaryRamSupport Jordan Justen
2019-04-10 16:41 ` [edk2-devel] [PATCH v2 0/6] Fix PEI Core issue during TemporaryRamMigration Ard Biesheuvel
2019-04-10 18:28   ` Laszlo Ersek
2019-04-10 18:31     ` Ard Biesheuvel
2019-04-10 18:54   ` Jordan Justen
2019-04-10 17:26 ` Laszlo Ersek

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=20190410084000.19660-2-jordan.l.justen@intel.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