diff options
Diffstat (limited to 'UefiCpuPkg')
18 files changed, 404 insertions, 86 deletions
diff --git a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExceptionHandlerLib.inf b/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExceptionHandlerLib.inf deleted file mode 100644 index d804629..0000000 --- a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExceptionHandlerLib.inf +++ /dev/null @@ -1,42 +0,0 @@ -## @file
-# RISC-V CPU Exception Handler Library
-#
-# Copyright (c) 2022-2023, Ventana Micro Systems Inc. All rights reserved.<BR>
-#
-# SPDX-License-Identifier: BSD-2-Clause-Patent
-#
-##
-
-[Defines]
- INF_VERSION = 0x0001001B
- BASE_NAME = BaseRiscV64CpuExceptionHandlerLib
- MODULE_UNI_FILE = BaseRiscV64CpuExceptionHandlerLib.uni
- FILE_GUID = 6AB0D5FD-E615-45A3-9374-E284FB061FC9
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = CpuExceptionHandlerLib
-
-#
-# The following information is for reference only and not required by the build tools.
-#
-# VALID_ARCHITECTURES = RISCV64
-#
-
-[Sources]
- SupervisorTrapHandler.S
- CpuExceptionHandlerLib.c
- CpuExceptionHandlerLib.h
-
-[Packages]
- MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
- UefiCpuPkg/UefiCpuPkg.dec
-
-[LibraryClasses]
- BaseLib
- SerialPortLib
- PrintLib
- SynchronizationLib
- PeCoffGetEntryPointLib
- MemoryAllocationLib
- DebugLib
diff --git a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExceptionHandlerLib.uni b/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExceptionHandlerLib.uni deleted file mode 100644 index 00cca22..0000000 --- a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExceptionHandlerLib.uni +++ /dev/null @@ -1,13 +0,0 @@ -// /** @file
-//
-// Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
-//
-// SPDX-License-Identifier: BSD-2-Clause-Patent
-//
-// **/
-
-
-#string STR_MODULE_ABSTRACT #language en-US "RISC-V CPU Exception Handler Librarys."
-
-#string STR_MODULE_DESCRIPTION #language en-US "RISC-V CPU Exception Handler Librarys."
-
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf index 9fcba00..9e0b54e 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf @@ -19,7 +19,7 @@ #
# The following information is for reference only and not required by the build tools.
#
-# VALID_ARCHITECTURES = IA32 X64 LOONGARCH64
+# VALID_ARCHITECTURES = IA32 X64 LOONGARCH64 RISCV64
#
[Sources.Ia32]
@@ -46,6 +46,14 @@ LoongArch/LoongArch64/ArchExceptionHandler.c
LoongArch/LoongArch64/ExceptionHandlerAsm.S | GCC
+[Sources.RISCV64]
+ RiscV/Backtrace.h
+ RiscV/Backtrace.c
+ RiscV/BacktraceHelper.c
+ RiscV/ExceptionLib.c
+ RiscV/ExceptionHandler.h
+ RiscV/ExceptionHandlerAsm.S | GCC
+
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard
gUefiCpuPkgTokenSpaceGuid.PcdCpuStackSwitchExceptionList
@@ -75,5 +83,8 @@ [LibraryClasses.LoongArch64]
CpuLib
+[Guids.RISCV64]
+ gEfiDebugImageInfoTableGuid
+
[BuildOptions]
XCODE:*_*_X64_NASM_FLAGS = -D NO_ABSOLUTE_RELOCS_IN_TEXT
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/Backtrace.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/Backtrace.c new file mode 100644 index 0000000..9765d72 --- /dev/null +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/Backtrace.c @@ -0,0 +1,175 @@ +/** @file
+ RISC-V backtrace implementation.
+
+ Copyright (c) 2016 - 2022, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+ Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>
+ Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2025, Ventana Micro Systems Inc. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "Backtrace.h"
+
+#define MAX_STACK_FRAME_SIZE SIZE_16KB
+
+STATIC
+INTN
+CheckFpValid (
+ IN UINTN Fp,
+ IN UINTN Sp
+ )
+{
+ UINTN Low, High;
+
+ Low = Sp + 2 * sizeof (UINTN);
+ High = ALIGN_VALUE (Sp, MAX_STACK_FRAME_SIZE);
+
+ return !(Fp < Low || Fp > High || Fp & 0x07);
+}
+
+STATIC
+CONST CHAR8 *
+BaseName (
+ IN CONST CHAR8 *FullName
+ )
+{
+ CONST CHAR8 *Str;
+
+ Str = FullName + AsciiStrLen (FullName);
+
+ while (--Str > FullName) {
+ if ((*Str == '/') || (*Str == '\\')) {
+ return Str + 1;
+ }
+ }
+
+ return Str;
+}
+
+/**
+ Helper for displaying a backtrace.
+
+ @param Regs Pointer to SMODE_TRAP_REGISTERS.
+ @param FirstPdb Pointer to the first symbol file used.
+ @param ListImage If true, only show the full path to symbol file, else
+ show the PC value and its decoded components.
+**/
+STATIC
+VOID
+DumpCpuBacktraceHelper (
+ IN SMODE_TRAP_REGISTERS *Regs,
+ IN CHAR8 *FirstPdb,
+ IN BOOLEAN ListImage
+ )
+{
+ UINTN ImageBase;
+ UINTN PeCoffSizeOfHeader;
+ BOOLEAN IsLeaf;
+ UINTN RootFp;
+ UINTN RootRa;
+ UINTN Sp;
+ UINTN Fp;
+ UINTN Ra;
+ UINTN Idx;
+ CHAR8 *Pdb;
+ CHAR8 *PrevPdb;
+
+ RootRa = Regs->ra;
+ RootFp = Regs->s0;
+
+ Idx = 0;
+ IsLeaf = TRUE;
+ Fp = RootFp;
+ Ra = RootRa;
+ PrevPdb = FirstPdb;
+ while (Fp != 0) {
+ Pdb = GetImageName (Ra, &ImageBase, &PeCoffSizeOfHeader);
+ if (Pdb != NULL) {
+ if (Pdb != PrevPdb) {
+ Idx++;
+ if (ListImage) {
+ DEBUG ((DEBUG_ERROR, "[% 2d] %a\n", Idx, Pdb));
+ }
+
+ PrevPdb = Pdb;
+ }
+
+ if (!ListImage) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "PC 0x%012lx (0x%012lx+0x%08x) [% 2d] %a\n",
+ Ra,
+ ImageBase,
+ Ra - ImageBase,
+ Idx,
+ BaseName (Pdb)
+ ));
+ }
+ } else if (!ListImage) {
+ DEBUG ((DEBUG_ERROR, "PC 0x%012lx\n", Ra));
+ }
+
+ /*
+ * After the prologue, the frame pointer register s0 will point
+ * to the Canonical Frame Address or CFA, which is the stack
+ * pointer value on entry to the current procedure. The previous
+ * frame pointer and return address pair will reside just prior
+ * to the current stack address held in s0. This puts the return
+ * address at s0 - XLEN/8, and the previous frame pointer at
+ * s0 - 2 * XLEN/8.
+ */
+ Sp = Fp;
+ Fp -= sizeof (UINTN) * 2;
+ Ra = *(UINTN *)(Fp + sizeof (UINTN));
+ Fp = *(UINTN *)(Fp);
+ if (IsLeaf && CheckFpValid (Ra, Sp)) {
+ /* We hit function where ra is not saved on the stack */
+ Fp = Ra;
+ Ra = RootRa;
+ }
+
+ IsLeaf = FALSE;
+ }
+}
+
+/**
+ Display a backtrace.
+
+ @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.
+**/
+VOID
+EFIAPI
+DumpCpuBacktrace (
+ IN EFI_SYSTEM_CONTEXT SystemContext
+ )
+{
+ SMODE_TRAP_REGISTERS *Regs;
+ CHAR8 *Pdb;
+ UINTN ImageBase;
+ UINTN PeCoffSizeOfHeader;
+
+ Regs = (SMODE_TRAP_REGISTERS *)SystemContext.SystemContextRiscV64;
+ Pdb = GetImageName (Regs->sepc, &ImageBase, &PeCoffSizeOfHeader);
+ if (Pdb != NULL) {
+ DEBUG ((
+ DEBUG_ERROR,
+ "PC 0x%012lx (0x%012lx+0x%08x) [ 0] %a\n",
+ Regs->sepc,
+ ImageBase,
+ Regs->sepc - ImageBase,
+ BaseName (Pdb)
+ ));
+ } else {
+ DEBUG ((DEBUG_ERROR, "PC 0x%012lx\n", Regs->sepc));
+ }
+
+ DumpCpuBacktraceHelper (Regs, Pdb, FALSE);
+
+ if (Pdb != NULL) {
+ DEBUG ((DEBUG_ERROR, "\n[ 0] %a\n", Pdb));
+ }
+
+ DumpCpuBacktraceHelper (Regs, Pdb, TRUE);
+}
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/Backtrace.h b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/Backtrace.h new file mode 100644 index 0000000..6e29b90 --- /dev/null +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/Backtrace.h @@ -0,0 +1,57 @@ +/** @file
+
+ RISC-V backtrace definition file.
+
+ Copyright (c) 2025, Ventana Micro Systems Inc. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef BACKTRACE_H_
+#define BACKTRACE_H_
+
+#include <PiPei.h>
+#include <Uefi.h>
+#include <Library/DebugLib.h>
+#include <Library/BaseLib.h>
+#include <Library/PeCoffExtraActionLib.h>
+#include <Library/PeCoffGetEntryPointLib.h>
+#include <Library/UefiLib.h>
+#include <Guid/DebugImageInfoTable.h>
+#include "ExceptionHandler.h"
+
+/**
+ Use the EFI Debug Image Table to lookup the FaultAddress and find which PE/COFF image
+ it came from. As long as the PE/COFF image contains a debug directory entry a
+ string can be returned. For ELF and Mach-O images the string points to the Mach-O or ELF
+ image. Microsoft tools contain a pointer to the PDB file that contains the debug information.
+
+ @param FaultAddress Address to find PE/COFF image for.
+ @param ImageBase Return load address of found image
+ @param PeCoffSizeOfHeaders Return the size of the PE/COFF header for the image that was found
+
+ @retval NULL FaultAddress not in a loaded PE/COFF image.
+ @retval Path and file name of PE/COFF image.
+
+**/
+CHAR8 *
+EFIAPI
+GetImageName (
+ IN UINTN FaultAddress,
+ OUT UINTN *ImageBase,
+ OUT UINTN *PeCoffSizeOfHeaders
+ );
+
+/**
+ Display a backtrace.
+
+ @param SystemContext Pointer to EFI_SYSTEM_CONTEXT.
+**/
+VOID
+EFIAPI
+DumpCpuBacktrace (
+ IN EFI_SYSTEM_CONTEXT SystemContext
+ );
+
+#endif // BACKTRACE_H_
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/BacktraceHelper.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/BacktraceHelper.c new file mode 100644 index 0000000..fdc5666 --- /dev/null +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/BacktraceHelper.c @@ -0,0 +1,71 @@ +/** @file
+ RISC-V backtrace helper functions.
+
+ Copyright (c) 2016 - 2022, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+ Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>
+ Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2025, Ventana Micro Systems Inc. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "Backtrace.h"
+
+/**
+ Use the EFI Debug Image Table to lookup the FaultAddress and find which PE/COFF image
+ it came from. As long as the PE/COFF image contains a debug directory entry a
+ string can be returned. For ELF and Mach-O images the string points to the Mach-O or ELF
+ image. Microsoft tools contain a pointer to the PDB file that contains the debug information.
+
+ @param FaultAddress Address to find PE/COFF image for.
+ @param ImageBase Return load address of found image
+ @param PeCoffSizeOfHeaders Return the size of the PE/COFF header for the image that was found
+
+ @retval NULL FaultAddress not in a loaded PE/COFF image.
+ @retval Path and file name of PE/COFF image.
+
+**/
+CHAR8 *
+EFIAPI
+GetImageName (
+ IN UINTN FaultAddress,
+ OUT UINTN *ImageBase,
+ OUT UINTN *PeCoffSizeOfHeaders
+ )
+{
+ EFI_STATUS Status;
+ EFI_DEBUG_IMAGE_INFO_TABLE_HEADER *DebugTableHeader;
+ EFI_DEBUG_IMAGE_INFO *DebugTable;
+ UINTN Entry;
+ CHAR8 *Address;
+
+ Status = EfiGetSystemConfigurationTable (&gEfiDebugImageInfoTableGuid, (VOID **)&DebugTableHeader);
+ if (EFI_ERROR (Status)) {
+ return NULL;
+ }
+
+ DebugTable = DebugTableHeader->EfiDebugImageInfoTable;
+ if (DebugTable == NULL) {
+ return NULL;
+ }
+
+ Address = (CHAR8 *)(UINTN)FaultAddress;
+ for (Entry = 0; Entry < DebugTableHeader->TableSize; Entry++, DebugTable++) {
+ if (DebugTable->NormalImage != NULL) {
+ if ((DebugTable->NormalImage->ImageInfoType == EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL) &&
+ (DebugTable->NormalImage->LoadedImageProtocolInstance != NULL))
+ {
+ if ((Address >= (CHAR8 *)DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase) &&
+ (Address <= ((CHAR8 *)DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase + DebugTable->NormalImage->LoadedImageProtocolInstance->ImageSize)))
+ {
+ *ImageBase = (UINTN)DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase;
+ *PeCoffSizeOfHeaders = PeCoffGetSizeOfHeaders ((VOID *)(UINTN)*ImageBase);
+ return PeCoffLoaderGetPdbPointer (DebugTable->NormalImage->LoadedImageProtocolInstance->ImageBase);
+ }
+ }
+ }
+ }
+
+ return NULL;
+}
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/BacktraceHelperSec.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/BacktraceHelperSec.c new file mode 100644 index 0000000..10e3497 --- /dev/null +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/BacktraceHelperSec.c @@ -0,0 +1,42 @@ +/** @file
+ RISC-V backtrace helper functions for SEC.
+
+ Copyright (c) 2025, Ventana Micro Systems Inc. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "Backtrace.h"
+
+/**
+ Use the EFI Debug Image Table to lookup the FaultAddress and find which PE/COFF image
+ it came from. As long as the PE/COFF image contains a debug directory entry a
+ string can be returned. For ELF and Mach-O images the string points to the Mach-O or ELF
+ image. Microsoft tools contain a pointer to the PDB file that contains the debug information.
+
+ @param FaultAddress Address to find PE/COFF image for.
+ @param ImageBase Return load address of found image
+ @param PeCoffSizeOfHeaders Return the size of the PE/COFF header for the image that was found
+
+ @retval NULL FaultAddress not in a loaded PE/COFF image.
+ @retval Path and file name of PE/COFF image.
+
+**/
+CHAR8 *
+EFIAPI
+GetImageName (
+ IN UINTN FaultAddress,
+ OUT UINTN *ImageBase,
+ OUT UINTN *PeCoffSizeOfHeaders
+ )
+{
+ //
+ // This function is not implemented in SEC phase.
+ // It should be implemented in DXE phase.
+ //
+ *ImageBase = 0;
+ *PeCoffSizeOfHeaders = 0;
+
+ return NULL;
+}
diff --git a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHandlerLib.h b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/ExceptionHandler.h index 9b7e130..0cf8221 100644 --- a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHandlerLib.h +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/ExceptionHandler.h @@ -8,16 +8,16 @@ **/
-#ifndef RISCV_CPU_EXECPTION_HANDLER_LIB_H_
-#define RISCV_CPU_EXECPTION_HANDLER_LIB_H_
+#ifndef EXCEPTION_HANDLER_H_
+#define EXCEPTION_HANDLER_H_
#include <Register/RiscV64/RiscVImpl.h>
/**
Trap Handler for S-mode
-
**/
VOID
+EFIAPI
SupervisorModeTrap (
VOID
);
@@ -108,4 +108,4 @@ typedef struct { } SMODE_TRAP_REGISTERS;
#pragma pack()
-#endif
+#endif /* EXCEPTION_HANDLER_H_ */
diff --git a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/SupervisorTrapHandler.S b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/ExceptionHandlerAsm.S index 45070b5..815e28b 100644 --- a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/SupervisorTrapHandler.S +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/ExceptionHandlerAsm.S @@ -8,7 +8,7 @@ **/
#include <Base.h>
-#include "CpuExceptionHandlerLib.h"
+#include "ExceptionHandler.h"
.align 3
.section .entry, "ax", %progbits
diff --git a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHandlerLib.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/ExceptionLib.c index 73a9dd5..d19c992 100644 --- a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHandlerLib.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV/ExceptionLib.c @@ -2,6 +2,9 @@ RISC-V Exception Handler library implementation.
Copyright (c) 2016 - 2022, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
+ Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>
+ Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2025, Ventana Micro Systems Inc. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -14,7 +17,8 @@ #include <Library/SerialPortLib.h>
#include <Library/PrintLib.h>
#include <Register/RiscV64/RiscVEncoding.h>
-#include "CpuExceptionHandlerLib.h"
+#include "Backtrace.h"
+#include "ExceptionHandler.h"
//
// Define the maximum message length
@@ -136,11 +140,21 @@ DumpCpuContext ( )
{
UINTN Printed;
+ UINTN RecursiveException;
SMODE_TRAP_REGISTERS *Regs;
Printed = 0;
Regs = (SMODE_TRAP_REGISTERS *)SystemContext.SystemContextRiscV64;
+ RecursiveException = RiscVGetSupervisorScratch ();
+ if (RecursiveException == 0xdeaddead) {
+ InternalPrintMessage ("\nRecursive exception occurred while dumping the CPU state\n");
+
+ CpuDeadLoop ();
+ }
+
+ RiscVSetSupervisorScratch ((UINTN)0xdeaddead);
+
InternalPrintMessage (
"!!!! RISCV64 Exception Type - %016x(%a) !!!!\n",
ExceptionType,
@@ -171,6 +185,8 @@ DumpCpuContext ( #undef REG
#undef REGS
+ DumpCpuBacktrace (SystemContext);
+
DEBUG_CODE_END ();
}
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf index 64de252..00a5b49 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf @@ -20,7 +20,7 @@ # The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64
-# VALID_ARCHITECTURES = IA32 X64 LOONGARCH64
+# VALID_ARCHITECTURES = IA32 X64 LOONGARCH64 RISCV64
#
[Sources.Ia32]
@@ -46,6 +46,13 @@ LoongArch/LoongArch64/ArchExceptionHandler.c
LoongArch/LoongArch64/ExceptionHandlerAsm.S | GCC
+[Sources.RISCV64]
+ RiscV/Backtrace.h
+ RiscV/Backtrace.c
+ RiscV/BacktraceHelperSec.c
+ RiscV/ExceptionLib.c
+ RiscV/ExceptionHandler.h
+ RiscV/ExceptionHandlerAsm.S | GCC
[Packages]
MdePkg/MdePkg.dec
diff --git a/UefiCpuPkg/Library/MpInitLib/AmdSev.c b/UefiCpuPkg/Library/MpInitLib/AmdSev.c index 5108873..8ffb1b5 100644 --- a/UefiCpuPkg/Library/MpInitLib/AmdSev.c +++ b/UefiCpuPkg/Library/MpInitLib/AmdSev.c @@ -273,7 +273,7 @@ SevEsPlaceApHlt ( @param[in] ExchangeInfo The pointer to CPU Exchange Data structure
**/
VOID
-FillExchangeInfoDataSevEs (
+FillExchangeInfoDataSevSnp (
IN volatile MP_CPU_EXCHANGE_INFO *ExchangeInfo
)
{
@@ -293,8 +293,6 @@ FillExchangeInfoDataSevEs ( );
ExchangeInfo->ExtTopoAvail = !!ExtTopoEbx.Bits.LogicalProcessors;
}
-
- ExchangeInfo->SevSnpKnownInitApicId = FALSE;
}
/**
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c index 96c0980..63b8464 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -1018,15 +1018,17 @@ FillExchangeInfoData ( ExchangeInfo->Enable5LevelPaging = (BOOLEAN)(Cr4.Bits.LA57 == 1);
DEBUG ((DEBUG_INFO, "%a: 5-Level Paging = %d\n", gEfiCallerBaseName, ExchangeInfo->Enable5LevelPaging));
- ExchangeInfo->SevEsIsEnabled = CpuMpData->SevEsIsEnabled;
- ExchangeInfo->SevSnpIsEnabled = CpuMpData->SevSnpIsEnabled;
- ExchangeInfo->GhcbBase = (UINTN)CpuMpData->GhcbBase;
+ ExchangeInfo->SevEsIsEnabled = CpuMpData->SevEsIsEnabled;
+ ExchangeInfo->SevSnpIsEnabled = CpuMpData->SevSnpIsEnabled;
+ ExchangeInfo->GhcbBase = (UINTN)CpuMpData->GhcbBase;
+ ExchangeInfo->ExtTopoAvail = FALSE;
+ ExchangeInfo->SevSnpKnownInitApicId = FALSE;
//
- // Populate SEV-ES specific exchange data.
+ // Populate SEV-SNP specific exchange data.
//
if (ExchangeInfo->SevSnpIsEnabled) {
- FillExchangeInfoDataSevEs (ExchangeInfo);
+ FillExchangeInfoDataSevSnp (ExchangeInfo);
}
//
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpInitLib/MpLib.h index 60cae3b..5d10516 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -901,7 +901,7 @@ ConfidentialComputingGuestHas ( @param[in] ExchangeInfo The pointer to CPU Exchange Data structure
**/
VOID
-FillExchangeInfoDataSevEs (
+FillExchangeInfoDataSevSnp (
IN volatile MP_CPU_EXCHANGE_INFO *ExchangeInfo
);
diff --git a/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm b/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm index 66d63a2..64358e5 100644 --- a/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm +++ b/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm @@ -24,13 +24,6 @@ ;
SevSnpGetInitCpuNumber:
;
- ; If not an SNP guest, leave EBX (CpuNumber) as is
- ;
- lea edi, [esi + MP_CPU_EXCHANGE_INFO_FIELD (SevSnpIsEnabled)]
- cmp byte [edi], 1 ; SevSnpIsEnabled
- jne SevSnpGetCpuNumberDone
-
- ;
; If not starting the AP with a specific ApicId, leave EBX (CpuNumber) as is
;
lea edi, [esi + MP_CPU_EXCHANGE_INFO_FIELD (SevSnpKnownInitApicId)]
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c index 7402a28..1d53b78 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c @@ -236,12 +236,14 @@ SmmWaitForApArrival ( UINTN Index;
UINT32 DelayedCount;
UINT32 BlockedCount;
+ UINT32 DisabledCount;
BOOLEAN SyncNeeded;
PERF_FUNCTION_BEGIN ();
- DelayedCount = 0;
- BlockedCount = 0;
+ DelayedCount = 0;
+ BlockedCount = 0;
+ DisabledCount = 0;
ASSERT (SmmCpuSyncGetArrivedCpuCount (mSmmMpSyncData->SyncContext) <= mNumberOfCpus);
@@ -318,12 +320,13 @@ SmmWaitForApArrival ( }
}
+ mSmmMpSyncData->AllApArrivedWithException = AllCpusInSmmExceptBlockedDisabled ();
if (!mSmmMpSyncData->AllApArrivedWithException) {
//
- // Check for the Blocked & Delayed Case.
+ // Check for the Disabled & Blocked & Delayed Case.
//
- GetSmmDelayedBlockedDisabledCount (&DelayedCount, &BlockedCount, NULL);
- DEBUG ((DEBUG_INFO, "SmmWaitForApArrival: Delayed AP Count = %d, Blocked AP Count = %d\n", DelayedCount, BlockedCount));
+ GetSmmDelayedBlockedDisabledCount (&DelayedCount, &BlockedCount, &DisabledCount);
+ DEBUG ((DEBUG_ERROR, "SmmWaitForApArrival: Failed to wait all APs enter SMI. Delayed AP Count = %d, Blocked AP Count = %d, Disabled AP Count = %d\n", DelayedCount, BlockedCount, DisabledCount));
}
PERF_FUNCTION_END ();
diff --git a/UefiCpuPkg/UefiCpuPkg.ci.yaml b/UefiCpuPkg/UefiCpuPkg.ci.yaml index a6fd147..57867dd 100644 --- a/UefiCpuPkg/UefiCpuPkg.ci.yaml +++ b/UefiCpuPkg/UefiCpuPkg.ci.yaml @@ -30,7 +30,6 @@ ],
## Both file path and directory path are accepted.
"IgnoreFiles": [
- "Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHandlerLib.h"
]
},
"CompilerPlugin": {
diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index aac4668..e011b18 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -218,7 +218,6 @@ UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerLibUnitTest.inf
[Components.RISCV64]
- UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExceptionHandlerLib.inf
UefiCpuPkg/Library/BaseRiscV64CpuTimerLib/BaseRiscV64CpuTimerLib.inf
UefiCpuPkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.inf
UefiCpuPkg/CpuTimerDxeRiscV64/CpuTimerDxeRiscV64.inf
|