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.8480.1648454962517853012 for ; Mon, 28 Mar 2022 01:09:24 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=k9JoNwEV; 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=1648454964; x=1679990964; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZRF2mBjXi+Q3h8xPxhUkl+Aqxg2MtidCri328HXQ2/M=; b=k9JoNwEV1e37jec8Wov8aDkmTrz903S9EglkDUNMl9BvSTkeBqJrK6jm DzPdJdEIwVYm0ln2H9BRQFZ8QDjEEtOHoOLBUWH83g5CyR+0kTXypuR2z ksnDrN4ZRpzbiSjCMbuGdTnJk+4XOZ2dp1DM+OtDhBwfYtZt7LGigg+81 i4fJRcDHOQM+nZwf/gsvCrtBZA5rpkTIsD9SH2tvv6RtaQKIaxxBv+BWK CJYykjw8F/F0X8dC1gZwifVsMJLAuEzztZ6yxqMn+aXbA+w3GCyFomVwl b8bllCxxAC3vBZTbPlbEGhGxkFOC92n2WsjbT28Ky8STOStpkEFlPzb9k w==; X-IronPort-AV: E=McAfee;i="6200,9189,10299"; a="257770689" X-IronPort-AV: E=Sophos;i="5.90,216,1643702400"; d="scan'208";a="257770689" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Mar 2022 01:09:01 -0700 X-IronPort-AV: E=Sophos;i="5.90,216,1643702400"; d="scan'208";a="563426793" Received: from mxu9-mobl1.ccr.corp.intel.com ([10.249.175.167]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Mar 2022 01:08:59 -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 V11 07/47] UefiCpuPkg/CpuExceptionHandler: Add base support for the #VE exception Date: Mon, 28 Mar 2022 16:07:46 +0800 Message-Id: X-Mailer: git-send-email 2.29.2.windows.2 In-Reply-To: References: 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