e6db53b
From f0d41555cc5b42bd284c8ee1f3b419c612a9a8ca Mon Sep 17 00:00:00 2001
e6db53b
From: Gerd Hoffmann <kraxel@redhat.com>
e6db53b
Date: Fri, 2 Dec 2022 14:10:06 +0100
e6db53b
Subject: [PATCH 28/32] OvmfPkg/PlatformPei: remove mFeatureControlValue
e6db53b
e6db53b
Use PlatformInfoHob->FeatureControlValue instead.
e6db53b
OnMpServicesAvailable() will find PlatformInfoHob using
e6db53b
GetFirstGuidHob() and pass a pointer to the WriteFeatureControl
e6db53b
callback.
e6db53b
e6db53b
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
e6db53b
Tested-by: Tom Lendacky <thomas.lendacky@amd.com>
e6db53b
Acked-by: Ard Biesheuvel <ardb@kernel.org>
e6db53b
(cherry picked from commit f6a196c7eb34affff0cfe1864e126953096885e1)
e6db53b
---
e6db53b
 OvmfPkg/Include/Library/PlatformInitLib.h |  2 ++
e6db53b
 OvmfPkg/PlatformPei/Platform.h            |  2 +-
e6db53b
 OvmfPkg/PlatformPei/FeatureControl.c      | 44 ++++++++++++++++-------
e6db53b
 OvmfPkg/PlatformPei/Platform.c            |  2 +-
e6db53b
 4 files changed, 36 insertions(+), 14 deletions(-)
e6db53b
e6db53b
diff --git a/OvmfPkg/Include/Library/PlatformInitLib.h b/OvmfPkg/Include/Library/PlatformInitLib.h
e6db53b
index c5234bf26d45..da7ed76041d2 100644
e6db53b
--- a/OvmfPkg/Include/Library/PlatformInitLib.h
e6db53b
+++ b/OvmfPkg/Include/Library/PlatformInitLib.h
e6db53b
@@ -48,6 +48,8 @@ typedef struct {
e6db53b
 
e6db53b
   UINT32               S3AcpiReservedMemoryBase;
e6db53b
   UINT32               S3AcpiReservedMemorySize;
e6db53b
+
e6db53b
+  UINT64               FeatureControlValue;
e6db53b
 } EFI_HOB_PLATFORM_INFO;
e6db53b
 #pragma pack()
e6db53b
 
e6db53b
diff --git a/OvmfPkg/PlatformPei/Platform.h b/OvmfPkg/PlatformPei/Platform.h
e6db53b
index 86f603ff649c..1cf44844a781 100644
e6db53b
--- a/OvmfPkg/PlatformPei/Platform.h
e6db53b
+++ b/OvmfPkg/PlatformPei/Platform.h
e6db53b
@@ -70,7 +70,7 @@ MemTypeInfoInitialization (
e6db53b
 
e6db53b
 VOID
e6db53b
 InstallFeatureControlCallback (
e6db53b
-  VOID
e6db53b
+  IN OUT EFI_HOB_PLATFORM_INFO  *PlatformInfoHob
e6db53b
   );
e6db53b
 
e6db53b
 VOID
e6db53b
diff --git a/OvmfPkg/PlatformPei/FeatureControl.c b/OvmfPkg/PlatformPei/FeatureControl.c
e6db53b
index 5864ee0c214d..d8a398cd5565 100644
e6db53b
--- a/OvmfPkg/PlatformPei/FeatureControl.c
e6db53b
+++ b/OvmfPkg/PlatformPei/FeatureControl.c
e6db53b
@@ -8,6 +8,7 @@
e6db53b
 **/
e6db53b
 
e6db53b
 #include <Library/DebugLib.h>
e6db53b
+#include <Library/HobLib.h>
e6db53b
 #include <Library/PeiServicesLib.h>
e6db53b
 #include <Library/QemuFwCfgLib.h>
e6db53b
 #include <Ppi/MpServices.h>
e6db53b
@@ -16,11 +17,6 @@
e6db53b
 
e6db53b
 #include "Platform.h"
e6db53b
 
e6db53b
-//
e6db53b
-// The value to be written to the Feature Control MSR, retrieved from fw_cfg.
e6db53b
-//
e6db53b
-STATIC UINT64  mFeatureControlValue;
e6db53b
-
e6db53b
 /**
e6db53b
   Write the Feature Control MSR on an Application Processor or the Boot
e6db53b
   Processor.
e6db53b
@@ -38,10 +34,22 @@ WriteFeatureControl (
e6db53b
   IN OUT VOID  *WorkSpace
e6db53b
   )
e6db53b
 {
e6db53b
+  EFI_HOB_PLATFORM_INFO  *PlatformInfoHob = WorkSpace;
e6db53b
+
e6db53b
   if (TdIsEnabled ()) {
e6db53b
-    TdVmCall (TDVMCALL_WRMSR, (UINT64)MSR_IA32_FEATURE_CONTROL, mFeatureControlValue, 0, 0, 0);
e6db53b
+    TdVmCall (
e6db53b
+      TDVMCALL_WRMSR,
e6db53b
+      (UINT64)MSR_IA32_FEATURE_CONTROL,
e6db53b
+      PlatformInfoHob->FeatureControlValue,
e6db53b
+      0,
e6db53b
+      0,
e6db53b
+      0
e6db53b
+      );
e6db53b
   } else {
e6db53b
-    AsmWriteMsr64 (MSR_IA32_FEATURE_CONTROL, mFeatureControlValue);
e6db53b
+    AsmWriteMsr64 (
e6db53b
+      MSR_IA32_FEATURE_CONTROL,
e6db53b
+      PlatformInfoHob->FeatureControlValue
e6db53b
+      );
e6db53b
   }
e6db53b
 }
e6db53b
 
e6db53b
@@ -67,6 +75,15 @@ OnMpServicesAvailable (
e6db53b
 {
e6db53b
   EFI_PEI_MP_SERVICES_PPI  *MpServices;
e6db53b
   EFI_STATUS               Status;
e6db53b
+  EFI_HOB_PLATFORM_INFO    *PlatformInfoHob;
e6db53b
+  EFI_HOB_GUID_TYPE        *GuidHob;
e6db53b
+
e6db53b
+  GuidHob = GetFirstGuidHob (&gUefiOvmfPkgPlatformInfoGuid);
e6db53b
+  if (GuidHob == NULL) {
e6db53b
+    return EFI_UNSUPPORTED;
e6db53b
+  }
e6db53b
+
e6db53b
+  PlatformInfoHob = (EFI_HOB_PLATFORM_INFO *)GET_GUID_HOB_DATA (GuidHob);
e6db53b
 
e6db53b
   DEBUG ((DEBUG_VERBOSE, "%a: %a\n", gEfiCallerBaseName, __FUNCTION__));
e6db53b
 
e6db53b
@@ -80,7 +97,7 @@ OnMpServicesAvailable (
e6db53b
                              WriteFeatureControl, // Procedure
e6db53b
                              FALSE,               // SingleThread
e6db53b
                              0,                   // TimeoutInMicroSeconds: inf.
e6db53b
-                             NULL                 // ProcedureArgument
e6db53b
+                             PlatformInfoHob      // ProcedureArgument
e6db53b
                              );
e6db53b
   if (EFI_ERROR (Status) && (Status != EFI_NOT_STARTED)) {
e6db53b
     DEBUG ((DEBUG_ERROR, "%a: StartupAllAps(): %r\n", __FUNCTION__, Status));
e6db53b
@@ -90,7 +107,7 @@ OnMpServicesAvailable (
e6db53b
   //
e6db53b
   // Now write the MSR on the BSP too.
e6db53b
   //
e6db53b
-  WriteFeatureControl (NULL);
e6db53b
+  WriteFeatureControl (PlatformInfoHob);
e6db53b
   return EFI_SUCCESS;
e6db53b
 }
e6db53b
 
e6db53b
@@ -107,7 +124,7 @@ STATIC CONST EFI_PEI_NOTIFY_DESCRIPTOR  mMpServicesNotify = {
e6db53b
 
e6db53b
 VOID
e6db53b
 InstallFeatureControlCallback (
e6db53b
-  VOID
e6db53b
+  IN OUT EFI_HOB_PLATFORM_INFO  *PlatformInfoHob
e6db53b
   )
e6db53b
 {
e6db53b
   EFI_STATUS            Status;
e6db53b
@@ -119,7 +136,7 @@ InstallFeatureControlCallback (
e6db53b
              &FwCfgItem,
e6db53b
              &FwCfgSize
e6db53b
              );
e6db53b
-  if (EFI_ERROR (Status) || (FwCfgSize != sizeof mFeatureControlValue)) {
e6db53b
+  if (EFI_ERROR (Status) || (FwCfgSize != sizeof (PlatformInfoHob->FeatureControlValue))) {
e6db53b
     //
e6db53b
     // Nothing to do.
e6db53b
     //
e6db53b
@@ -127,7 +144,10 @@ InstallFeatureControlCallback (
e6db53b
   }
e6db53b
 
e6db53b
   QemuFwCfgSelectItem (FwCfgItem);
e6db53b
-  QemuFwCfgReadBytes (sizeof mFeatureControlValue, &mFeatureControlValue);
e6db53b
+  QemuFwCfgReadBytes (
e6db53b
+    sizeof (PlatformInfoHob->FeatureControlValue),
e6db53b
+    &(PlatformInfoHob->FeatureControlValue)
e6db53b
+    );
e6db53b
 
e6db53b
   Status = PeiServicesNotifyPpi (&mMpServicesNotify);
e6db53b
   if (EFI_ERROR (Status)) {
e6db53b
diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c
e6db53b
index ee72b4ef24aa..d324ae95f8f5 100644
e6db53b
--- a/OvmfPkg/PlatformPei/Platform.c
e6db53b
+++ b/OvmfPkg/PlatformPei/Platform.c
e6db53b
@@ -409,7 +409,7 @@ InitializePlatform (
e6db53b
   }
e6db53b
 
e6db53b
   IntelTdxInitialize ();
e6db53b
-  InstallFeatureControlCallback ();
e6db53b
+  InstallFeatureControlCallback (PlatformInfoHob);
e6db53b
 
e6db53b
   return EFI_SUCCESS;
e6db53b
 }
e6db53b
-- 
e6db53b
2.38.1
e6db53b