public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Sami Mujawar" <sami.mujawar@arm.com>
To: <devel@edk2.groups.io>
Cc: Sami Mujawar <sami.mujawar@arm.com>, <ardb+tianocore@kernel.org>,
	<quic_llindhol@quicinc.com>, <kraxel@redhat.com>,
	<Pierre.Gondois@arm.com>, <jean-philippe@linaro.org>,
	<Matteo.Carlini@arm.com>, <Akanksha.Jain2@arm.com>,
	<Ben.Adderson@arm.com>, <Sibel.Allinson@arm.com>, <nd@arm.com>
Subject: [PATCH v2 5/5] ArmVirtPkg/PrePi: Allocate separate stack for Dxe phase
Date: Fri, 19 May 2023 15:55:40 +0100	[thread overview]
Message-ID: <20230519145540.46700-6-sami.mujawar@arm.com> (raw)
In-Reply-To: <20230519145540.46700-1-sami.mujawar@arm.com>

The patch "f07a9df9af60 ArmVirtPkg: Enable stack guard"
enabled stack overflow detection for ArmVirtPkg. Following
this patch, running UEFI shell command 'dmpstore' resulted
in a crash indicating a stack overflow. Invoking 'dmpstore'
results in recursive calls to CascadeProcessVariables ()
which apparently consumes the available stack space and
overflows.

Normally, SEC and PEI run off the initial stack, and the
DxeIpl PEIM is in charge of launching the DxeCore with a
full-sized stack and remapping it non-executable as well.

PrePi platforms take some shortcuts and the DXE and BDS
run off the initial stack which is relatively small. It
is therefore desirable to allocate 128 KiB worth of boot
services data memory as the stack for the Dxe phase.

The PrePiMain () in ArmVirtPkg/PrePi/PrePi.c invokes the
LoadDxeCoreFromFv () to load the Dxe core and transfers
control. The second parameter to LoadDxeCoreFromFv () is
the stack size, which is currently set to 0.
LoadDxeCoreFromFv () is implemented in PrePiLib and if the
stack size is 0, it continues to use the initial stack.
However, if a stack size is specified in the call to
LoadDxeCoreFromFv (), memory is allocated for a new stack
and the stack is switched to use the newly allocated stack
for the Dxe phase.

Therefore, specify 128 KiB as the stack size in the call to
LoadDxeCoreFromFv () so that a separate stack is allocated
and used for the Dxe phase.

Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
---
 ArmVirtPkg/PrePi/PrePi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ArmVirtPkg/PrePi/PrePi.c b/ArmVirtPkg/PrePi/PrePi.c
index 3d943b2138d3fe8a03322262111d5f7df3e39d39..ff51a757a21a19347c78b0936987c9f8cc283c0f 100755
--- a/ArmVirtPkg/PrePi/PrePi.c
+++ b/ArmVirtPkg/PrePi/PrePi.c
@@ -1,6 +1,6 @@
 /** @file
 *
-*  Copyright (c) 2011-2014, ARM Limited. All rights reserved.
+*  Copyright (c) 2011-2023, Arm Limited. All rights reserved.
 *
 *  SPDX-License-Identifier: BSD-2-Clause-Patent
 *
@@ -101,7 +101,7 @@ PrePiMain (
   ASSERT_EFI_ERROR (Status);
 
   // Load the DXE Core and transfer control to it
-  Status = LoadDxeCoreFromFv (NULL, 0);
+  Status = LoadDxeCoreFromFv (NULL, SIZE_128KB);
   ASSERT_EFI_ERROR (Status);
 }
 
-- 
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'


  parent reply	other threads:[~2023-05-19 14:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-19 14:55 [PATCH v2 0/5] ArmVirtPkg: Add dynamic CFI flash detection for Kvmtool guests Sami Mujawar
2023-05-19 14:55 ` [PATCH v2 1/5] ArmPkg: Configure PcdEmuVariableNvModeEnable as a dynamic PCD Sami Mujawar
2023-05-19 14:55 ` [PATCH v2 2/5] ArmVirtPkg: Define variables for emulating runtime variables Sami Mujawar
2023-05-19 14:55 ` [PATCH v2 3/5] ArmVirtPkg: Fallback to variable emulation if no CFI is found Sami Mujawar
2023-05-19 14:55 ` [PATCH v2 4/5] ArmVirtPkg: Dispatch variable service if variable emulation is enabled Sami Mujawar
2023-05-19 14:55 ` Sami Mujawar [this message]
2023-05-25 15:51 ` [PATCH v2 0/5] ArmVirtPkg: Add dynamic CFI flash detection for Kvmtool guests Ard Biesheuvel

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=20230519145540.46700-6-sami.mujawar@arm.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