[edk2-devel] [PATCH V11 07/47] UefiCpuPkg/CpuExceptionHandler: Add base support for the #VE exception

Min Xu min.m.xu at intel.com
Mon Mar 28 08:07:46 UTC 2022


RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429

Add base support to handle #VE exceptions. Update the common exception
handlers to invoke the VmTdExitHandleVe () function of the VmgExitLib
library when a #VE is encountered. A non-zero return code will propagate
to the targeted exception handler.

Cc: Brijesh Singh <brijesh.singh at amd.com>
Cc: Erdem Aktas <erdemaktas at google.com>
Cc: James Bottomley <jejb at linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao at intel.com>
Cc: Tom Lendacky <thomas.lendacky at amd.com>
Cc: Eric Dong <eric.dong at intel.com>
Cc: Ray Ni <ray.ni at intel.com>
Cc: Rahul Kumar <rahul1.kumar at intel.com>
Cc: Gerd Hoffmann <kraxel at redhat.com>
Acked-by: Gerd Hoffmann <kraxel at redhat.com>
Reviewed-by: Ray Ni <ray.ni at intel.com>
Signed-off-by: Min Xu <min.m.xu at intel.com>
---
 .../PeiDxeSmmCpuException.c                   | 53 ++++++++++++-----
 .../SecPeiCpuException.c                      | 57 +++++++++++++------
 2 files changed, 79 insertions(+), 31 deletions(-)

diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c
index 762ea2460f91..f47a80dcab8f 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c
@@ -24,25 +24,48 @@ CommonExceptionHandlerWorker (
   IN EXCEPTION_HANDLER_DATA  *ExceptionHandlerData
   )
 {
+  EFI_STATUS                 Status;
   EXCEPTION_HANDLER_CONTEXT  *ExceptionHandlerContext;
   RESERVED_VECTORS_DATA      *ReservedVectors;
   EFI_CPU_INTERRUPT_HANDLER  *ExternalInterruptHandler;
 
-  if (ExceptionType == VC_EXCEPTION) {
-    EFI_STATUS  Status;
-    //
-    // #VC needs to be handled immediately upon enabling exception handling
-    // and therefore can't use the RegisterCpuInterruptHandler() interface.
-    //
-    // Handle the #VC:
-    //   On EFI_SUCCESS - Exception has been handled, return
-    //   On other       - ExceptionType contains (possibly new) exception
-    //                    value
-    //
-    Status = VmgExitHandleVc (&ExceptionType, SystemContext);
-    if (!EFI_ERROR (Status)) {
-      return;
-    }
+  switch (ExceptionType) {
+    case VC_EXCEPTION:
+      //
+      // #VC needs to be handled immediately upon enabling exception handling
+      // and therefore can't use the RegisterCpuInterruptHandler() interface.
+      //
+      // Handle the #VC:
+      //   On EFI_SUCCESS - Exception has been handled, return
+      //   On other       - ExceptionType contains (possibly new) exception
+      //                    value
+      //
+      Status = VmgExitHandleVc (&ExceptionType, SystemContext);
+      if (!EFI_ERROR (Status)) {
+        return;
+      }
+
+      break;
+
+    case VE_EXCEPTION:
+      //
+      // #VE needs to be handled immediately upon enabling exception handling
+      // and therefore can't use the RegisterCpuInterruptHandler() interface.
+      //
+      // Handle the #VE:
+      //   On EFI_SUCCESS - Exception has been handled, return
+      //   On other       - ExceptionType contains (possibly new) exception
+      //                    value
+      //
+      Status = VmTdExitHandleVe (&ExceptionType, SystemContext);
+      if (!EFI_ERROR (Status)) {
+        return;
+      }
+
+      break;
+
+    default:
+      break;
   }
 
   ExceptionHandlerContext  = (EXCEPTION_HANDLER_CONTEXT *)(UINTN)(SystemContext.SystemContextIa32);
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c
index c614d5b0b6f1..6e5216380da8 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c
@@ -25,22 +25,47 @@ CommonExceptionHandler (
   IN EFI_SYSTEM_CONTEXT  SystemContext
   )
 {
-  if (ExceptionType == VC_EXCEPTION) {
-    EFI_STATUS  Status;
-    //
-    // #VC needs to be handled immediately upon enabling exception handling
-    // and therefore can't use the RegisterCpuInterruptHandler() interface
-    // (which isn't supported under Sec and Pei anyway).
-    //
-    // Handle the #VC:
-    //   On EFI_SUCCESS - Exception has been handled, return
-    //   On other       - ExceptionType contains (possibly new) exception
-    //                    value
-    //
-    Status = VmgExitHandleVc (&ExceptionType, SystemContext);
-    if (!EFI_ERROR (Status)) {
-      return;
-    }
+  EFI_STATUS  Status;
+
+  switch (ExceptionType) {
+    case VC_EXCEPTION:
+      //
+      // #VC needs to be handled immediately upon enabling exception handling
+      // and therefore can't use the RegisterCpuInterruptHandler() interface
+      // (which isn't supported under Sec and Pei anyway).
+      //
+      // Handle the #VC:
+      //   On EFI_SUCCESS - Exception has been handled, return
+      //   On other       - ExceptionType contains (possibly new) exception
+      //                    value
+      //
+      Status = VmgExitHandleVc (&ExceptionType, SystemContext);
+      if (!EFI_ERROR (Status)) {
+        return;
+      }
+
+      break;
+
+    case VE_EXCEPTION:
+      //
+      // #VE needs to be handled immediately upon enabling exception handling
+      // and therefore can't use the RegisterCpuInterruptHandler() interface
+      // (which isn't supported under Sec and Pei anyway).
+      //
+      // Handle the #VE:
+      //   On EFI_SUCCESS - Exception has been handled, return
+      //   On other       - ExceptionType contains (possibly new) exception
+      //                    value
+      //
+      Status = VmTdExitHandleVe (&ExceptionType, SystemContext);
+      if (!EFI_ERROR (Status)) {
+        return;
+      }
+
+      break;
+
+    default:
+      break;
   }
 
   //
-- 
2.29.2.windows.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#88097): https://edk2.groups.io/g/devel/message/88097
Mute This Topic: https://groups.io/mt/90079980/1813853
Mute #ve:https://edk2.groups.io/g/devel/mutehashtag/ve
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-




More information about the edk2-devel-archive mailing list