public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Kuo, Ted" <ted.kuo@intel.com>
To: devel@edk2.groups.io
Cc: Chasel Chiu <chasel.chiu@intel.com>,
	Nate DeSimone <nathaniel.l.desimone@intel.com>,
	Star Zeng <star.zeng@intel.com>,
	Ashraf Ali S <ashraf.ali.s@intel.com>
Subject: [edk2-devel][PATCH 2/2] IntelFsp2Pkg: Ensure new stack is aligned to old stack for X64
Date: Mon, 21 Mar 2022 20:43:28 +0800	[thread overview]
Message-ID: <8c8e4573d5998e2e957dfef66ab7a7774794a31b.1647864782.git.ted.kuo@intel.com> (raw)
In-Reply-To: <cover.1647864782.git.ted.kuo@intel.com>
In-Reply-To: <cover.1647864782.git.ted.kuo@intel.com>

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3865
Ensure bit3:0 of NewStack is aligned with bit3:0 of OldStack for X64
before switching stack. Otherwise, RSP may not be aligned to a 16-byte
boundary after returning from SecTemporaryRamSupport.

Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Ashraf Ali S <ashraf.ali.s@intel.com>
Signed-off-by: Ted Kuo <ted.kuo@intel.com>
---
 IntelFsp2Pkg/FspSecCore/SecMain.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/IntelFsp2Pkg/FspSecCore/SecMain.c b/IntelFsp2Pkg/FspSecCore/SecMain.c
index d376fb8361..f93e2d2ff7 100644
--- a/IntelFsp2Pkg/FspSecCore/SecMain.c
+++ b/IntelFsp2Pkg/FspSecCore/SecMain.c
@@ -258,6 +258,14 @@ SecTemporaryRamSupport (
     NewStack = (VOID *)(UINTN)PermanentMemoryBase;
   }
 
+  //
+  // Ensure bit3:0 of NewStack is aligned with bit3:0 of OldStack for X64 before switching stack.
+  // Otherwise, RSP may not be aligned to a 16-byte boundary after returning from SecTemporaryRamSupport.
+  //
+  if ((sizeof (UINTN) == sizeof (UINT64)) && (((UINTN)NewStack & 0x0F) != ((UINTN)OldStack & 0x0F))) {
+    NewStack = (VOID *)((UINTN)NewStack - 8);
+  }
+
   //
   // Migrate Heap
   //
-- 
2.16.2.windows.1


      parent reply	other threads:[~2022-03-21 12:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-21 12:43 [edk2-devel][PATCH 0/2] Ensure RSP is aligned to a 16-byte boundary for PEI 64bit Kuo, Ted
2022-03-21 12:43 ` [edk2-devel][PATCH 1/2] MdeModulePkg: StackOffset must be aligned to a 16-byte boundary in X64 Kuo, Ted
2022-03-21 19:46   ` Marvin Häuser
2022-03-22  7:23     ` Kuo, Ted
2022-03-22  9:27       ` Marvin Häuser
2022-03-22 14:22         ` Kuo, Ted
2022-03-21 12:43 ` Kuo, Ted [this message]

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=8c8e4573d5998e2e957dfef66ab7a7774794a31b.1647864782.git.ted.kuo@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