From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (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 1EE982095D2CF for ; Sun, 9 Jul 2017 21:48:44 -0700 (PDT) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Jul 2017 21:50:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,338,1496127600"; d="scan'208";a="1149870126" Received: from ydong10-win10.ccr.corp.intel.com ([10.239.158.51]) by orsmga001.jf.intel.com with ESMTP; 09 Jul 2017 21:50:25 -0700 From: Eric Dong To: edk2-devel@lists.01.org Date: Mon, 10 Jul 2017 12:50:21 +0800 Message-Id: <1499662221-21760-3-git-send-email-eric.dong@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 In-Reply-To: <1499662221-21760-1-git-send-email-eric.dong@intel.com> References: <1499662221-21760-1-git-send-email-eric.dong@intel.com> Subject: [Patch 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: , X-List-Received-Date: Mon, 10 Jul 2017 04:48:44 -0000 Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Eric Dong Reviewed-by: Jeff Fan --- .../CpuCommonFeaturesLib/CpuCommonFeatures.h | 47 +++------- .../CpuCommonFeaturesLib/CpuCommonFeaturesLib.c | 19 +--- .../Library/CpuCommonFeaturesLib/FeatureControl.c | 100 ++++++++------------- 3 files changed, 50 insertions(+), 116 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 ( ); /** - Initializes VMX inside SMX feature to specific state. + Initializes VMX feature to specific state. @param[in] ProcessorNumber The index of the CPU executing this function. @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION @@ -355,42 +355,16 @@ VmxSupport ( by CPU_FEATURE_GET_CONFIG_DATA. NULL if CPU_FEATURE_GET_CONFIG_DATA was not provided in RegisterCpuFeature(). - @param[in] State If TRUE, then the VMX inside SMX feature must be enabled. - If FALSE, then the VMX inside SMX feature must be disabled. + @param[in] State If TRUE, then the VMX feature must be enabled. + If FALSE, then the VMX feature must be disabled. - @retval RETURN_SUCCESS VMX inside SMX feature is initialized. + @retval RETURN_SUCCESS VMX feature is initialized. @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 function. - @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION - structure for the CPU executing this function. - @param[in] ConfigData A pointer to the configuration buffer returned - by CPU_FEATURE_GET_CONFIG_DATA. NULL if - CPU_FEATURE_GET_CONFIG_DATA was not provided in - RegisterCpuFeature(). - @param[in] State If TRUE, then the SENTER feature must be enabled. - If FALSE, then the SENTER feature must be disabled. - - @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 ( ); /** - Initializes VMX outside SMX feature to specific state. + Initializes SMX feature to specific state. @param[in] ProcessorNumber The index of the CPU executing this function. @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION @@ -481,16 +455,17 @@ SmxSupport ( by CPU_FEATURE_GET_CONFIG_DATA. NULL if CPU_FEATURE_GET_CONFIG_DATA was not provided in RegisterCpuFeature(). - @param[in] State If TRUE, then the VMX outside SMX feature must 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. - @retval RETURN_SUCCESS VMX outside SMX feature is initialized. + @retval RETURN_SUCCESS SMX feature is initialized. + @retval RETURN_UNSUPPORTED VMX not initialized. @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 = RegisterCpuFeature ( - "SENTER", - FeatureControlGetConfigData, - VmxSupport, - SenterInitialize, - CPU_FEATURE_SENTER, - CPU_FEATURE_LOCK_FEATURE_CONTROL_REGISTER | CPU_FEATURE_BEFORE, - CPU_FEATURE_SMX | CPU_FEATURE_AFTER, - CPU_FEATURE_END - ); - ASSERT_EFI_ERROR (Status); - } if (IsCpuFeatureSupported (CPU_FEATURE_SMX)) { Status = RegisterCpuFeature ( "SMX", FeatureControlGetConfigData, SmxSupport, - VmxInsideSmxInitialize, + SmxInitialize, CPU_FEATURE_SMX, CPU_FEATURE_LOCK_FEATURE_CONTROL_REGISTER | CPU_FEATURE_BEFORE, CPU_FEATURE_END @@ -134,8 +121,8 @@ CpuCommonFeaturesLibConstructor ( Status = RegisterCpuFeature ( "VMX", FeatureControlGetConfigData, - SmxSupport, - VmxOutsideSmxInitialize, + VmxSupport, + VmxInitialize, CPU_FEATURE_VMX, CPU_FEATURE_LOCK_FEATURE_CONTROL_REGISTER | CPU_FEATURE_BEFORE, CPU_FEATURE_END diff --git a/UefiCpuPkg/Library/CpuCommonFeaturesLib/FeatureControl.c b/UefiCpuPkg/Library/CpuCommonFeaturesLib/FeatureControl.c index 0b5c161..d8fc76c 100644 --- a/UefiCpuPkg/Library/CpuCommonFeaturesLib/FeatureControl.c +++ b/UefiCpuPkg/Library/CpuCommonFeaturesLib/FeatureControl.c @@ -69,7 +69,7 @@ VmxSupport ( } /** - Initializes VMX inside SMX feature to specific state. + Initializes VMX feature to specific state. @param[in] ProcessorNumber The index of the CPU executing this function. @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION @@ -78,16 +78,16 @@ VmxSupport ( by CPU_FEATURE_GET_CONFIG_DATA. NULL if CPU_FEATURE_GET_CONFIG_DATA was not provided in RegisterCpuFeature(). - @param[in] State If TRUE, then the VMX inside SMX feature must be enabled. - If FALSE, then the VMX inside SMX feature must be disabled. + @param[in] State If TRUE, then the VMX feature must be enabled. + If FALSE, then the VMX feature must be disabled. - @retval RETURN_SUCCESS VMX inside SMX feature is initialized. + @retval RETURN_SUCCESS VMX feature is initialized. @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 function. - @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION - structure for the CPU executing this function. - @param[in] ConfigData A pointer to the configuration buffer returned - by CPU_FEATURE_GET_CONFIG_DATA. NULL if - CPU_FEATURE_GET_CONFIG_DATA was not provided in - RegisterCpuFeature(). - @param[in] State If TRUE, then the SENTER feature must be enabled. - If FALSE, then the SENTER feature must be disabled. - - @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 != NULL); - MsrRegister = (MSR_IA32_FEATURE_CONTROL_REGISTER *) ConfigData; - if (MsrRegister[ProcessorNumber].Bits.Lock == 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 ( } /** - Initializes VMX outside SMX feature to specific state. + Initializes SMX feature to specific state. @param[in] ProcessorNumber The index of the CPU executing this function. @param[in] CpuInfo A pointer to the REGISTER_CPU_FEATURE_INFORMATION @@ -280,16 +228,17 @@ SmxSupport ( by CPU_FEATURE_GET_CONFIG_DATA. NULL if CPU_FEATURE_GET_CONFIG_DATA was not provided in RegisterCpuFeature(). - @param[in] State If TRUE, then the VMX outside SMX feature must 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. - @retval RETURN_SUCCESS VMX outside SMX feature is initialized. + @retval RETURN_SUCCESS SMX feature is initialized. + @retval RETURN_UNSUPPORTED VMX not initialized. @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 @@ -298,6 +247,11 @@ VmxOutsideSmxInitialize ( { MSR_IA32_FEATURE_CONTROL_REGISTER *MsrRegister; + if (!IsCpuFeatureInSetting (CPU_FEATURE_VMX)) { + DEBUG ((DEBUG_WARN, "VMX feature not enabled! Can't enable SMX feature!\n")); + return RETURN_UNSUPPORTED; + } + ASSERT (ConfigData != NULL); MsrRegister = (MSR_IA32_FEATURE_CONTROL_REGISTER *) ConfigData; if (MsrRegister[ProcessorNumber].Bits.Lock == 0) { @@ -306,7 +260,25 @@ 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 ); } -- 2.7.0.windows.1