From nobody Sat Apr 27 21:26:05 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1499739564813532.6622436583091; Mon, 10 Jul 2017 19:19:24 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id F371C21CF25DF; Mon, 10 Jul 2017 19:17:35 -0700 (PDT) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D075321CF25DC for ; Mon, 10 Jul 2017 19:17:34 -0700 (PDT) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Jul 2017 19:19:20 -0700 Received: from ydong10-win10.ccr.corp.intel.com ([10.239.158.51]) by orsmga004.jf.intel.com with ESMTP; 10 Jul 2017 19:19:19 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,343,1496127600"; d="scan'208";a="106818900" From: Eric Dong To: edk2-devel@lists.01.org Date: Tue, 11 Jul 2017 10:19:15 +0800 Message-Id: <1499739556-14440-2-git-send-email-eric.dong@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 In-Reply-To: <1499739556-14440-1-git-send-email-eric.dong@intel.com> References: <1499739556-14440-1-git-send-email-eric.dong@intel.com> Subject: [edk2] [Patch V2 1/2] UefiCpuPkg RegisterCpuFeaturesLib: Add error handling code. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jeff Fan MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add error handling code when initialize the CPU feature failed. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Eric Dong Cc: Jeff Fan Reviewed-by: Jeff Fan --- .../RegisterCpuFeaturesLib/CpuFeaturesInitialize.c | 47 ++++++++++++++++++= +++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitializ= e.c b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c index 5e11b2b..e91a438 100644 --- a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c +++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c @@ -235,6 +235,31 @@ SupportedMaskAnd ( } =20 /** + Worker function to clean bit operation on CPU feature supported bits mas= k buffer. + + @param[in] SupportedFeatureMask The pointer to CPU feature bits mask b= uffer + @param[in] AndFeatureBitMask The feature bit mask to do XOR operati= on +**/ +VOID +SupportedMaskCleanBit ( + IN UINT8 *SupportedFeatureMask, + IN UINT8 *AndFeatureBitMask + ) +{ + UINTN Index; + UINTN BitMaskSize; + UINT8 *Data1; + UINT8 *Data2; + + BitMaskSize =3D PcdGetSize (PcdCpuFeaturesSupport); + Data1 =3D SupportedFeatureMask; + Data2 =3D AndFeatureBitMask; + for (Index =3D 0; Index < BitMaskSize; Index++) { + *(Data1++) &=3D ~(*(Data2++)); + } +} + +/** Worker function to check if the compared CPU feature set in the CPU feat= ure supported bits mask buffer. =20 @@ -497,12 +522,32 @@ AnalysisProcessorFeatures ( CpuFeatureInOrder =3D CPU_FEATURE_ENTRY_FROM_LINK (Entry); if (IsBitMaskMatch (CpuFeatureInOrder->FeatureMask, CpuFeaturesData-= >SettingPcds)) { Status =3D CpuFeatureInOrder->InitializeFunc (ProcessorNumber, Cpu= Info, CpuFeatureInOrder->ConfigData, TRUE); + if (EFI_ERROR (Status)) { + // + // Clean the CpuFeatureInOrder->FeatureMask in setting PCD. + // + SupportedMaskCleanBit (CpuFeaturesData->SettingPcds, CpuFeatureI= nOrder->FeatureMask); + if (CpuFeatureInOrder->FeatureName !=3D NULL) { + DEBUG ((DEBUG_WARN, "Warning :: Failed to enable Feature Name = =3D %a.\n", CpuFeatureInOrder->FeatureName)); + } else { + DEBUG ((DEBUG_WARN, "Warning :: Failed to enable Feature Mask = =3D ")); + DumpCpuFeatureMask (CpuFeatureInOrder->FeatureMask); + } + } } else { Status =3D CpuFeatureInOrder->InitializeFunc (ProcessorNumber, Cpu= Info, CpuFeatureInOrder->ConfigData, FALSE); + ASSERT_EFI_ERROR (Status); } - ASSERT_EFI_ERROR (Status); Entry =3D Entry->ForwardLink; } + + // + // Dump PcdCpuFeaturesSetting again because this value maybe updated + // again during initialize the features. + // + DEBUG ((DEBUG_INFO, "Dump final value for PcdCpuFeaturesSetting:\n")); + DumpCpuFeatureMask (CpuFeaturesData->SettingPcds); + // // Dump the RegisterTable // --=20 2.7.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat Apr 27 21:26:05 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1499739567050759.3659574415909; Mon, 10 Jul 2017 19:19:27 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 376BE21D147A5; Mon, 10 Jul 2017 19:17:37 -0700 (PDT) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 0180B21CF3B67 for ; Mon, 10 Jul 2017 19:17:35 -0700 (PDT) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Jul 2017 19:19:21 -0700 Received: from ydong10-win10.ccr.corp.intel.com ([10.239.158.51]) by orsmga004.jf.intel.com with ESMTP; 10 Jul 2017 19:19:20 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,343,1496127600"; d="scan'208";a="106818906" From: Eric Dong To: edk2-devel@lists.01.org Date: Tue, 11 Jul 2017 10:19:16 +0800 Message-Id: <1499739556-14440-3-git-send-email-eric.dong@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 In-Reply-To: <1499739556-14440-1-git-send-email-eric.dong@intel.com> References: <1499739556-14440-1-git-send-email-eric.dong@intel.com> Subject: [edk2] [Patch V2 2/2] UefiCpuPkg CpuCommonFeaturesLib: Fix smx/vmx enable logic error. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jeff Fan MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Eric Dong Cc: Jeff Fan Reviewed-by: Jeff Fan --- .../CpuCommonFeaturesLib/CpuCommonFeatures.h | 47 +++------ .../CpuCommonFeaturesLib/CpuCommonFeaturesLib.c | 19 +--- .../Library/CpuCommonFeaturesLib/FeatureControl.c | 106 ++++++++---------= ---- 3 files changed, 55 insertions(+), 117 deletions(-) diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatures.h b/= UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatures.h index 9a7afed..9c6e0b4 100644 --- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatures.h +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeatures.h @@ -346,7 +346,7 @@ VmxSupport ( ); =20 /** - Initializes VMX inside SMX feature to specific state. + Initializes VMX feature to specific state. =20 @param[in] ProcessorNumber The index of the CPU executing this functio= n. @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION @@ -355,42 +355,16 @@ VmxSupport ( by CPU_FEATURE_GET_CONFIG_DATA. NULL if CPU_FEATURE_GET_CONFIG_DATA was not provide= d in RegisterCpuFeature(). - @param[in] State If TRUE, then the VMX inside SMX feature mu= st be enabled. - If FALSE, then the VMX inside SMX feature m= ust be disabled. + @param[in] State If TRUE, then the VMX feature must be enabl= ed. + If FALSE, then the VMX feature must be disa= bled. =20 - @retval RETURN_SUCCESS VMX inside SMX feature is initialized. + @retval RETURN_SUCCESS VMX feature is initialized. =20 @note This service could be called by BSP only. **/ RETURN_STATUS EFIAPI -VmxInsideSmxInitialize ( - IN UINTN ProcessorNumber, - IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, - IN VOID *ConfigData, OPTIONAL - IN BOOLEAN State - ); - -/** - Initializes SENTER feature to specific state. - - @param[in] ProcessorNumber The index of the CPU executing this functio= n. - @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION - structure for the CPU executing this functi= on. - @param[in] ConfigData A pointer to the configuration buffer retur= ned - by CPU_FEATURE_GET_CONFIG_DATA. NULL if - CPU_FEATURE_GET_CONFIG_DATA was not provide= d in - RegisterCpuFeature(). - @param[in] State If TRUE, then the SENTER feature must be en= abled. - If FALSE, then the SENTER feature must be d= isabled. - - @retval RETURN_SUCCESS SENTER feature is initialized. - - @note This service could be called by BSP only. -**/ -RETURN_STATUS -EFIAPI -SenterInitialize ( +VmxInitialize ( IN UINTN ProcessorNumber, IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, IN VOID *ConfigData, OPTIONAL @@ -472,7 +446,7 @@ SmxSupport ( ); =20 /** - Initializes VMX outside SMX feature to specific state. + Initializes SMX feature to specific state. =20 @param[in] ProcessorNumber The index of the CPU executing this functio= n. @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION @@ -481,16 +455,17 @@ SmxSupport ( by CPU_FEATURE_GET_CONFIG_DATA. NULL if CPU_FEATURE_GET_CONFIG_DATA was not provide= d in RegisterCpuFeature(). - @param[in] State If TRUE, then the VMX outside SMX feature m= ust be enabled. - If FALSE, then the VMX outside SMX feature = must be disabled. + @param[in] State If TRUE, then SMX feature must be enabled. + If FALSE, then SMX feature must be disabled. =20 - @retval RETURN_SUCCESS VMX outside SMX feature is initialized. + @retval RETURN_SUCCESS SMX feature is initialized. + @retval RETURN_UNSUPPORTED VMX not initialized. =20 @note This service could be called by BSP only. **/ RETURN_STATUS EFIAPI -VmxOutsideSmxInitialize ( +SmxInitialize ( IN UINTN ProcessorNumber, IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, IN VOID *ConfigData, OPTIONAL diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.c= b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.c index 793a095..2bd32ab 100644 --- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.c +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/CpuCommonFeaturesLib.c @@ -105,25 +105,12 @@ CpuCommonFeaturesLibConstructor ( ); ASSERT_EFI_ERROR (Status); } - if (IsCpuFeatureSupported (CPU_FEATURE_SENTER)) { - Status =3D RegisterCpuFeature ( - "SENTER", - FeatureControlGetConfigData, - VmxSupport, - SenterInitialize, - CPU_FEATURE_SENTER, - CPU_FEATURE_LOCK_FEATURE_CONTROL_REGISTER | CPU_FEATURE_BEF= ORE, - CPU_FEATURE_SMX | CPU_FEATURE_AFTER, - CPU_FEATURE_END - ); - ASSERT_EFI_ERROR (Status); - } if (IsCpuFeatureSupported (CPU_FEATURE_SMX)) { Status =3D RegisterCpuFeature ( "SMX", FeatureControlGetConfigData, SmxSupport, - VmxInsideSmxInitialize, + SmxInitialize, CPU_FEATURE_SMX, CPU_FEATURE_LOCK_FEATURE_CONTROL_REGISTER | CPU_FEATURE_BEF= ORE, CPU_FEATURE_END @@ -134,8 +121,8 @@ CpuCommonFeaturesLibConstructor ( Status =3D RegisterCpuFeature ( "VMX", FeatureControlGetConfigData, - SmxSupport, - VmxOutsideSmxInitialize, + VmxSupport, + VmxInitialize, CPU_FEATURE_VMX, CPU_FEATURE_LOCK_FEATURE_CONTROL_REGISTER | CPU_FEATURE_BEF= ORE, CPU_FEATURE_END diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/FeatureControl.c b/Uef= iCpuPkg/Library/CpuCommonFeaturesLib/FeatureControl.c index 0b5c161..d28c4ec 100644 --- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/FeatureControl.c +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/FeatureControl.c @@ -69,7 +69,7 @@ VmxSupport ( } =20 /** - Initializes VMX inside SMX feature to specific state. + Initializes VMX feature to specific state. =20 @param[in] ProcessorNumber The index of the CPU executing this functio= n. @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION @@ -78,16 +78,16 @@ VmxSupport ( by CPU_FEATURE_GET_CONFIG_DATA. NULL if CPU_FEATURE_GET_CONFIG_DATA was not provide= d in RegisterCpuFeature(). - @param[in] State If TRUE, then the VMX inside SMX feature mu= st be enabled. - If FALSE, then the VMX inside SMX feature m= ust be disabled. + @param[in] State If TRUE, then the VMX feature must be enabl= ed. + If FALSE, then the VMX feature must be disa= bled. =20 - @retval RETURN_SUCCESS VMX inside SMX feature is initialized. + @retval RETURN_SUCCESS VMX feature is initialized. =20 @note This service could be called by BSP only. **/ RETURN_STATUS EFIAPI -VmxInsideSmxInitialize ( +VmxInitialize ( IN UINTN ProcessorNumber, IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, IN VOID *ConfigData, OPTIONAL @@ -104,59 +104,7 @@ VmxInsideSmxInitialize ( Msr, MSR_IA32_FEATURE_CONTROL, MSR_IA32_FEATURE_CONTROL_REGISTER, - Bits.EnableVmxInsideSmx, - (State) ? 1 : 0 - ); - } - return RETURN_SUCCESS; -} - -/** - Initializes SENTER feature to specific state. - - @param[in] ProcessorNumber The index of the CPU executing this functio= n. - @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION - structure for the CPU executing this functi= on. - @param[in] ConfigData A pointer to the configuration buffer retur= ned - by CPU_FEATURE_GET_CONFIG_DATA. NULL if - CPU_FEATURE_GET_CONFIG_DATA was not provide= d in - RegisterCpuFeature(). - @param[in] State If TRUE, then the SENTER feature must be en= abled. - If FALSE, then the SENTER feature must be d= isabled. - - @retval RETURN_SUCCESS SENTER feature is initialized. - - @note This service could be called by BSP only. -**/ -RETURN_STATUS -EFIAPI -SenterInitialize ( - IN UINTN ProcessorNumber, - IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, - IN VOID *ConfigData, OPTIONAL - IN BOOLEAN State - ) -{ - MSR_IA32_FEATURE_CONTROL_REGISTER *MsrRegister; - - ASSERT (ConfigData !=3D NULL); - MsrRegister =3D (MSR_IA32_FEATURE_CONTROL_REGISTER *) ConfigData; - if (MsrRegister[ProcessorNumber].Bits.Lock =3D=3D 0) { - CPU_REGISTER_TABLE_WRITE_FIELD ( - ProcessorNumber, - Msr, - MSR_IA32_FEATURE_CONTROL, - MSR_IA32_FEATURE_CONTROL_REGISTER, - Bits.SenterLocalFunctionEnables, - (State) ? 0x7F : 0 - ); - - CPU_REGISTER_TABLE_WRITE_FIELD ( - ProcessorNumber, - Msr, - MSR_IA32_FEATURE_CONTROL, - MSR_IA32_FEATURE_CONTROL_REGISTER, - Bits.SenterGlobalEnable, + Bits.EnableVmxOutsideSmx, (State) ? 1 : 0 ); } @@ -271,7 +219,7 @@ SmxSupport ( } =20 /** - Initializes VMX outside SMX feature to specific state. + Initializes SMX feature to specific state. =20 @param[in] ProcessorNumber The index of the CPU executing this functio= n. @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFOR= MATION @@ -280,16 +228,17 @@ SmxSupport ( by CPU_FEATURE_GET_CONFIG_DATA. NULL if CPU_FEATURE_GET_CONFIG_DATA was not provide= d in RegisterCpuFeature(). - @param[in] State If TRUE, then the VMX outside SMX feature m= ust be enabled. - If FALSE, then the VMX outside SMX feature = must be disabled. + @param[in] State If TRUE, then SMX feature must be enabled. + If FALSE, then SMX feature must be disabled. =20 - @retval RETURN_SUCCESS VMX outside SMX feature is initialized. + @retval RETURN_SUCCESS SMX feature is initialized. + @retval RETURN_UNSUPPORTED VMX not initialized. =20 @note This service could be called by BSP only. **/ RETURN_STATUS EFIAPI -VmxOutsideSmxInitialize ( +SmxInitialize ( IN UINTN ProcessorNumber, IN REGISTER_CPU_FEATURE_INFORMATION *CpuInfo, IN VOID *ConfigData, OPTIONAL @@ -297,6 +246,15 @@ VmxOutsideSmxInitialize ( ) { MSR_IA32_FEATURE_CONTROL_REGISTER *MsrRegister; + RETURN_STATUS Status; + + Status =3D RETURN_SUCCESS; + + if (State && (!IsCpuFeatureInSetting (CPU_FEATURE_VMX))) { + DEBUG ((DEBUG_WARN, "Warning :: Can't enable SMX feature when VMX feat= ure not enabled, disable it.\n")); + State =3D FALSE; + Status =3D RETURN_UNSUPPORTED; + } =20 ASSERT (ConfigData !=3D NULL); MsrRegister =3D (MSR_IA32_FEATURE_CONTROL_REGISTER *) ConfigData; @@ -306,9 +264,27 @@ VmxOutsideSmxInitialize ( Msr, MSR_IA32_FEATURE_CONTROL, MSR_IA32_FEATURE_CONTROL_REGISTER, - Bits.EnableVmxOutsideSmx, + Bits.SenterLocalFunctionEnables, + (State) ? 0x7F : 0 + ); + + CPU_REGISTER_TABLE_WRITE_FIELD ( + ProcessorNumber, + Msr, + MSR_IA32_FEATURE_CONTROL, + MSR_IA32_FEATURE_CONTROL_REGISTER, + Bits.SenterGlobalEnable, + (State) ? 1 : 0 + ); + + CPU_REGISTER_TABLE_WRITE_FIELD ( + ProcessorNumber, + Msr, + MSR_IA32_FEATURE_CONTROL, + MSR_IA32_FEATURE_CONTROL_REGISTER, + Bits.EnableVmxInsideSmx, (State) ? 1 : 0 ); } - return RETURN_SUCCESS; + return Status; } --=20 2.7.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel