From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mx.groups.io with SMTP id smtpd.web12.1139.1648597631562797263 for ; Tue, 29 Mar 2022 16:47:19 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=i5hAlXuo; spf=pass (domain: intel.com, ip: 134.134.136.65, 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=1648597639; x=1680133639; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZRF2mBjXi+Q3h8xPxhUkl+Aqxg2MtidCri328HXQ2/M=; b=i5hAlXuoRf6P2bke+tV0I2oxp+0n0haVErtY/TsC4PIQk/myTSz2k9ns ccFXP5cdF4RNErmLDmGLc2yUYa9xUpfdUJDD2hELr9QDaXK+RUme+opMu YaU49lqYCdkzCqlMUkXBAcd0lv+Cgm1octuS8KNlrhqw5JeiBFBt2bH/1 +AM7QG3xJA7oGX92z7BWCUqjLBfcpHXaBEhJvrsrI5XuFpCfny7QHTLf/ VDJuixxoyjePcT67CNCAM0yy7OKxaV8OjdEr1fZ8EUyWqRQEcUC9cSYWN /lxa5sMZjWfW8GYqU7BZiTPWY0A1BwftZ7xJJfbDoLUgpBZk8gaxHY99i g==; X-IronPort-AV: E=McAfee;i="6200,9189,10301"; a="259375016" X-IronPort-AV: E=Sophos;i="5.90,220,1643702400"; d="scan'208";a="259375016" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 16:47:19 -0700 X-IronPort-AV: E=Sophos;i="5.90,220,1643702400"; d="scan'208";a="521658465" Received: from zhangpen-mobl.ccr.corp.intel.com (HELO mxu9-mobl1.ccr.corp.intel.com) ([10.255.29.230]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 16:47:16 -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 V12 07/47] UefiCpuPkg/CpuExceptionHandler: Add base support for the #VE exception Date: Wed, 30 Mar 2022 07:46:00 +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