public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [Patch V2 0/2] Fix enable Smx/Vmx error.
@ 2017-07-11  2:19 Eric Dong
  2017-07-11  2:19 ` [Patch V2 1/2] UefiCpuPkg RegisterCpuFeaturesLib: Add error handling code Eric Dong
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Eric Dong @ 2017-07-11  2:19 UTC (permalink / raw)
  To: edk2-devel

Patch also add error handling code when enable feature failed.

V2 changes:
  If can't enable the feature, then disable it. V1 patch missed it.

Eric Dong (2):
  UefiCpuPkg RegisterCpuFeaturesLib: Add error handling code.
  UefiCpuPkg CpuCommonFeaturesLib: Fix smx/vmx enable logic error.

 .../CpuCommonFeaturesLib/CpuCommonFeatures.h       |  47 +++------
 .../CpuCommonFeaturesLib/CpuCommonFeaturesLib.c    |  19 +---
 .../Library/CpuCommonFeaturesLib/FeatureControl.c  | 106 ++++++++-------------
 .../RegisterCpuFeaturesLib/CpuFeaturesInitialize.c |  47 ++++++++-
 4 files changed, 101 insertions(+), 118 deletions(-)

-- 
2.7.0.windows.1



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Patch V2 1/2] UefiCpuPkg RegisterCpuFeaturesLib: Add error handling code.
  2017-07-11  2:19 [Patch V2 0/2] Fix enable Smx/Vmx error Eric Dong
@ 2017-07-11  2:19 ` Eric Dong
  2017-07-11  2:19 ` [Patch V2 2/2] UefiCpuPkg CpuCommonFeaturesLib: Fix smx/vmx enable logic error Eric Dong
  2017-07-11  6:25 ` [Patch V2 0/2] Fix enable Smx/Vmx error Fan, Jeff
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Dong @ 2017-07-11  2:19 UTC (permalink / raw)
  To: edk2-devel; +Cc: Jeff Fan

Add error handling code when initialize the CPU feature failed.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Eric Dong <eric.dong@intel.com>
Cc: Jeff Fan <jeff.fan@intel.com>
---
 .../RegisterCpuFeaturesLib/CpuFeaturesInitialize.c | 47 +++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)

diff --git a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.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 (
 }
 
 /**
+  Worker function to clean bit operation on CPU feature supported bits mask buffer.
+
+  @param[in]  SupportedFeatureMask  The pointer to CPU feature bits mask buffer
+  @param[in]  AndFeatureBitMask     The feature bit mask to do XOR operation
+**/
+VOID
+SupportedMaskCleanBit (
+  IN UINT8               *SupportedFeatureMask,
+  IN UINT8               *AndFeatureBitMask
+  )
+{
+  UINTN                  Index;
+  UINTN                  BitMaskSize;
+  UINT8                  *Data1;
+  UINT8                  *Data2;
+
+  BitMaskSize = PcdGetSize (PcdCpuFeaturesSupport);
+  Data1 = SupportedFeatureMask;
+  Data2 = AndFeatureBitMask;
+  for (Index = 0; Index < BitMaskSize; Index++) {
+    *(Data1++) &=  ~(*(Data2++));
+  }
+}
+
+/**
   Worker function to check if the compared CPU feature set in the CPU feature
   supported bits mask buffer.
 
@@ -497,12 +522,32 @@ AnalysisProcessorFeatures (
       CpuFeatureInOrder = CPU_FEATURE_ENTRY_FROM_LINK (Entry);
       if (IsBitMaskMatch (CpuFeatureInOrder->FeatureMask, CpuFeaturesData->SettingPcds)) {
         Status = CpuFeatureInOrder->InitializeFunc (ProcessorNumber, CpuInfo, CpuFeatureInOrder->ConfigData, TRUE);
+        if (EFI_ERROR (Status)) {
+          //
+          // Clean the CpuFeatureInOrder->FeatureMask in setting PCD.
+          //
+          SupportedMaskCleanBit (CpuFeaturesData->SettingPcds, CpuFeatureInOrder->FeatureMask);
+          if (CpuFeatureInOrder->FeatureName != NULL) {
+            DEBUG ((DEBUG_WARN, "Warning :: Failed to enable Feature Name = %a.\n", CpuFeatureInOrder->FeatureName));
+          } else {
+            DEBUG ((DEBUG_WARN, "Warning :: Failed to enable Feature Mask = "));
+            DumpCpuFeatureMask (CpuFeatureInOrder->FeatureMask);
+          }
+        }
       } else {
         Status = CpuFeatureInOrder->InitializeFunc (ProcessorNumber, CpuInfo, CpuFeatureInOrder->ConfigData, FALSE);
+        ASSERT_EFI_ERROR (Status);
       }
-      ASSERT_EFI_ERROR (Status);
       Entry = 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
     //
-- 
2.7.0.windows.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Patch V2 2/2] UefiCpuPkg CpuCommonFeaturesLib: Fix smx/vmx enable logic error.
  2017-07-11  2:19 [Patch V2 0/2] Fix enable Smx/Vmx error Eric Dong
  2017-07-11  2:19 ` [Patch V2 1/2] UefiCpuPkg RegisterCpuFeaturesLib: Add error handling code Eric Dong
@ 2017-07-11  2:19 ` Eric Dong
  2017-07-11  6:25 ` [Patch V2 0/2] Fix enable Smx/Vmx error Fan, Jeff
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Dong @ 2017-07-11  2:19 UTC (permalink / raw)
  To: edk2-devel; +Cc: Jeff Fan

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Eric Dong <eric.dong@intel.com>
Cc: Jeff Fan <jeff.fan@intel.com>
---
 .../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 (
   );
 
 /**
-  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..d28c4ec 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
@@ -297,6 +246,15 @@ VmxOutsideSmxInitialize (
   )
 {
   MSR_IA32_FEATURE_CONTROL_REGISTER    *MsrRegister;
+  RETURN_STATUS                        Status;
+
+  Status = RETURN_SUCCESS;
+
+  if (State && (!IsCpuFeatureInSetting (CPU_FEATURE_VMX))) {
+    DEBUG ((DEBUG_WARN, "Warning :: Can't enable SMX feature when VMX feature not enabled, disable it.\n"));
+    State = FALSE;
+    Status = RETURN_UNSUPPORTED;
+  }
 
   ASSERT (ConfigData != NULL);
   MsrRegister = (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;
 }
-- 
2.7.0.windows.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Patch V2 0/2] Fix enable Smx/Vmx error.
  2017-07-11  2:19 [Patch V2 0/2] Fix enable Smx/Vmx error Eric Dong
  2017-07-11  2:19 ` [Patch V2 1/2] UefiCpuPkg RegisterCpuFeaturesLib: Add error handling code Eric Dong
  2017-07-11  2:19 ` [Patch V2 2/2] UefiCpuPkg CpuCommonFeaturesLib: Fix smx/vmx enable logic error Eric Dong
@ 2017-07-11  6:25 ` Fan, Jeff
  2 siblings, 0 replies; 4+ messages in thread
From: Fan, Jeff @ 2017-07-11  6:25 UTC (permalink / raw)
  To: Dong, Eric, edk2-devel@lists.01.org

Reviewed-by: Jeff Fan <jeff.fan@intel.com>

-----Original Message-----
From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Eric Dong
Sent: Tuesday, July 11, 2017 10:19 AM
To: edk2-devel@lists.01.org
Subject: [edk2] [Patch V2 0/2] Fix enable Smx/Vmx error.

Patch also add error handling code when enable feature failed.

V2 changes:
  If can't enable the feature, then disable it. V1 patch missed it.

Eric Dong (2):
  UefiCpuPkg RegisterCpuFeaturesLib: Add error handling code.
  UefiCpuPkg CpuCommonFeaturesLib: Fix smx/vmx enable logic error.

 .../CpuCommonFeaturesLib/CpuCommonFeatures.h       |  47 +++------
 .../CpuCommonFeaturesLib/CpuCommonFeaturesLib.c    |  19 +---
 .../Library/CpuCommonFeaturesLib/FeatureControl.c  | 106 ++++++++-------------  .../RegisterCpuFeaturesLib/CpuFeaturesInitialize.c |  47 ++++++++-
 4 files changed, 101 insertions(+), 118 deletions(-)

--
2.7.0.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-07-11  6:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-11  2:19 [Patch V2 0/2] Fix enable Smx/Vmx error Eric Dong
2017-07-11  2:19 ` [Patch V2 1/2] UefiCpuPkg RegisterCpuFeaturesLib: Add error handling code Eric Dong
2017-07-11  2:19 ` [Patch V2 2/2] UefiCpuPkg CpuCommonFeaturesLib: Fix smx/vmx enable logic error Eric Dong
2017-07-11  6:25 ` [Patch V2 0/2] Fix enable Smx/Vmx error Fan, Jeff

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox