From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=fail (domain: intel.com, ip: , mailfrom: jordan.l.justen@intel.com) Received: from mga11.intel.com (mga11.intel.com []) by groups.io with SMTP; Wed, 10 Apr 2019 01:41:11 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Apr 2019 01:41:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,332,1549958400"; d="scan'208";a="130116360" Received: from askirtik-mobl1.amr.corp.intel.com (HELO jljusten-skl.amr.corp.intel.com) ([10.254.188.249]) by orsmga007.jf.intel.com with ESMTP; 10 Apr 2019 01:41:09 -0700 From: "Jordan Justen" To: devel@edk2.groups.io Cc: Jordan Justen , Jian J Wang , Hao Wu , Ray Ni , Star Zeng Subject: [PATCH v2 1/6] MdeModulePkg/Core/Pei: Add interface for assembly based TemporaryRamSupport Date: Wed, 10 Apr 2019 01:39:55 -0700 Message-Id: <20190410084000.19660-2-jordan.l.justen@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190410084000.19660-1-jordan.l.justen@intel.com> References: <20190410084000.19660-1-jordan.l.justen@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Cc: Jian J Wang Cc: Hao Wu Cc: Ray Ni Cc: Star Zeng --- 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