From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mx.groups.io with SMTP id smtpd.web12.4829.1648080697438249429 for ; Wed, 23 Mar 2022 17:11:37 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=WdoyUS+y; spf=pass (domain: intel.com, ip: 192.55.52.120, mailfrom: min.m.xu@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1648080697; x=1679616697; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZRF2mBjXi+Q3h8xPxhUkl+Aqxg2MtidCri328HXQ2/M=; b=WdoyUS+yiOFITyHEvlx1cMMs4S0HPNO9tnGoT2SepHO4Z04D3kwyqzH5 mWe/H2oAMhw+PtGwCjttlJnr8K5kNXIRQ3bkPGGEoDdbVOgXrVIOXFWzR FEgruf/zIGISzIMF3U34BQYEmfkmJ4rmtV9oeajvxQikgHYj9QfVvmsNe 7Bt3e+c0dMczYxCD/qiqjjMs8T6er9J4sxqfQ0R9het0WJqHNtom8xW/C JkxUHO3qyceCTCP//CjApj5rfJcpgxOZPtRH6h0bYmf3zSh89j9Dc1w2a Pbb5a/RdoMcP+y+8Jzd7Q+LWvVt37VtKEXYYeH610vfW5Yfsnddlchw/y w==; X-IronPort-AV: E=McAfee;i="6200,9189,10295"; a="257080292" X-IronPort-AV: E=Sophos;i="5.90,205,1643702400"; d="scan'208";a="257080292" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2022 17:11:07 -0700 X-IronPort-AV: E=Sophos;i="5.90,205,1643702400"; d="scan'208";a="649650941" Received: from mxu9-mobl1.ccr.corp.intel.com ([10.255.31.90]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2022 17:11:04 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min Xu , Brijesh Singh , Erdem Aktas , James Bottomley , Jiewen Yao , Tom Lendacky , Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [PATCH V10 07/47] UefiCpuPkg/CpuExceptionHandler: Add base support for the #VE exception Date: Thu, 24 Mar 2022 08:09:53 +0800 Message-Id: <20220324001033.1169-8-min.m.xu@intel.com> X-Mailer: git-send-email 2.29.2.windows.2 In-Reply-To: <20220324001033.1169-1-min.m.xu@intel.com> References: <20220324001033.1169-1-min.m.xu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann Acked-by: Gerd Hoffmann Reviewed-by: Ray Ni Signed-off-by: Min Xu --- .../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