The stack doesn't grow downwards but upwards for RISC-V.
Hence, fix the UEFI memory range calculation by including the correct
stack memory range. Without this fix, SCT hangs in MemoryAllocation
test cases which call AllocateAddress().

Cc: Ard Biesheuvel <[email protected]>
Cc: Jiewen Yao <[email protected]>
Cc: Jordan Justen <[email protected]>
Cc: Gerd Hoffmann <[email protected]>
Cc: Andrei Warkentin <[email protected]>
Reported-by: Heinrich Schuchardt <[email protected]>
Signed-off-by: Sunil V L <[email protected]>
---
 OvmfPkg/RiscVVirt/Sec/SecMain.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/OvmfPkg/RiscVVirt/Sec/SecMain.c b/OvmfPkg/RiscVVirt/Sec/SecMain.c
index 054e49ef0c1e..0e1f9b891af9 100644
--- a/OvmfPkg/RiscVVirt/Sec/SecMain.c
+++ b/OvmfPkg/RiscVVirt/Sec/SecMain.c
@@ -54,7 +54,7 @@ SecStartup (
   EFI_RISCV_FIRMWARE_CONTEXT  FirmwareContext;
   EFI_STATUS                  Status;
   UINT64                      UefiMemoryBase;
-  UINT64                      StackBase;
+  UINT64                      StackEnd;
 
   //
   // Report Status Code to indicate entering SEC core
@@ -71,15 +71,16 @@ SecStartup (
   FirmwareContext.FlattenedDeviceTree = (UINT64)DeviceTreeAddress;
   SetFirmwareContextPointer (&FirmwareContext);
 
-  StackBase      = (UINT64)FixedPcdGet32 (PcdOvmfSecPeiTempRamBase);
-  UefiMemoryBase = StackBase +  FixedPcdGet32 (PcdOvmfSecPeiTempRamSize) - 
SIZE_32MB;
+  StackEnd = (UINT64)FixedPcdGet32 (PcdOvmfSecPeiTempRamBase) +
+             FixedPcdGet32 (PcdOvmfSecPeiTempRamSize);
+  UefiMemoryBase = StackEnd - SIZE_32MB;
 
   // Declare the PI/UEFI memory region
   HobList = HobConstructor (
               (VOID *)UefiMemoryBase,
               SIZE_32MB,
               (VOID *)UefiMemoryBase,
-              (VOID *)StackBase // The top of the UEFI Memory is reserved for 
the stacks
+              (VOID *)StackEnd // The top of the UEFI Memory is reserved for 
the stacks
               );
   PrePeiSetHobList (HobList);
 
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#100381): https://edk2.groups.io/g/devel/message/100381
Mute This Topic: https://groups.io/mt/97094512/21656
Group Owner: [email protected]
Unsubscribe: https://edk2.groups.io/g/devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to