public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 00/14] OvmfPkg: avoid global variables in PEI
@ 2022-12-02 13:09 Gerd Hoffmann
  2022-12-02 13:09 ` [PATCH 01/14] tools_def: remove GCC_IA32_CC_FLAGS/GCC_X64_CC_FLAGS Gerd Hoffmann
                   ` (14 more replies)
  0 siblings, 15 replies; 17+ messages in thread
From: Gerd Hoffmann @ 2022-12-02 13:09 UTC (permalink / raw)
  To: devel
  Cc: Bob Feng, Yuwei Chen, Erdem Aktas, Jordan Justen, Peter Grehan,
	Rebecca Cran, Liming Gao, Ard Biesheuvel, Gerd Hoffmann,
	Jiewen Yao, Min Xu, Brijesh Singh, Oliver Steffen, Pawel Polawski,
	Tom Lendacky, James Bottomley

Writing to global variables changes the PEI firmware volume which in
turn screws up firmware volume measurements.  Fix OvmfPkg to avoid that,
for the most part by using the PlatformInfoHob instead.

Gerd Hoffmann (14):
  tools_def: remove GCC_IA32_CC_FLAGS/GCC_X64_CC_FLAGS
  tools_def: add -fno-omit-frame-pointer to GCC48_{IA32,X64}_CC_FLAGS
  OvmfPkg/PlatformPei: AmdSev: stop using mPlatformInfoHob
  OvmfPkg/PlatformPei: PeiFv: stop using mPlatformInfoHob
  OvmfPkg/PlatformPei Q35 SMM helpers: stop using mPlatformInfoHob
  OvmfPkg/PlatformPei: PeiMemory: stop using mPlatformInfoHob
  OvmfPkg/PlatformPei: MemTypeInfo: stop using mPlatformInfoHob
  OvmfPkg/PlatformPei: NoExec: stop using mPlatformInfoHob
  OvmfPkg/PlatformPei: Verification: stop using mPlatformInfoHob
  OvmfPkg/PlatformPei: remove mPlatformInfoHob
  OvmfPkg/PlatformPei: remove mFeatureControlValue
  OvmfPkg/DebugLibIoPort: use Rom version for PEI
  OvmfPkg/QemuFwCfgLib: rewrite fw_cfg probe
  OvmfPkg/QemuFwCfgLib: remove mQemuFwCfgSupported +
    mQemuFwCfgDmaSupported

 OvmfPkg/AmdSev/AmdSevX64.dsc                  |   4 +-
 OvmfPkg/Bhyve/BhyveX64.dsc                    |   4 +-
 OvmfPkg/Microvm/MicrovmX64.dsc                |   4 +-
 OvmfPkg/OvmfPkgIa32.dsc                       |   4 +-
 OvmfPkg/OvmfPkgIa32X64.dsc                    |   4 +-
 OvmfPkg/OvmfPkgX64.dsc                        |   4 +-
 .../PlatformRomDebugLibIoPort.inf             |   2 +-
 .../Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf  |   5 +-
 OvmfPkg/Include/Library/PlatformInitLib.h     |   6 +
 OvmfPkg/PlatformPei/Platform.h                |  18 +--
 OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPei.c   | 143 ++++++++++--------
 OvmfPkg/PlatformPei/AmdSev.c                  |  14 +-
 OvmfPkg/PlatformPei/FeatureControl.c          |  44 ++++--
 OvmfPkg/PlatformPei/Fv.c                      |   6 +-
 OvmfPkg/PlatformPei/MemDetect.c               |  56 +++----
 OvmfPkg/PlatformPei/MemTypeInfo.c             |   4 +-
 OvmfPkg/PlatformPei/Platform.c                |  92 ++++++-----
 BaseTools/Conf/tools_def.template             |   6 +-
 18 files changed, 232 insertions(+), 188 deletions(-)

-- 
2.38.1


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

* [PATCH 01/14] tools_def: remove GCC_IA32_CC_FLAGS/GCC_X64_CC_FLAGS
  2022-12-02 13:09 [PATCH 00/14] OvmfPkg: avoid global variables in PEI Gerd Hoffmann
@ 2022-12-02 13:09 ` Gerd Hoffmann
  2022-12-02 13:09 ` [PATCH 02/14] tools_def: add -fno-omit-frame-pointer to GCC48_{IA32,X64}_CC_FLAGS Gerd Hoffmann
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Gerd Hoffmann @ 2022-12-02 13:09 UTC (permalink / raw)
  To: devel
  Cc: Bob Feng, Yuwei Chen, Erdem Aktas, Jordan Justen, Peter Grehan,
	Rebecca Cran, Liming Gao, Ard Biesheuvel, Gerd Hoffmann,
	Jiewen Yao, Min Xu, Brijesh Singh, Oliver Steffen, Pawel Polawski,
	Tom Lendacky, James Bottomley

They are not used anywhere.  Remove them.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 BaseTools/Conf/tools_def.template | 2 --
 1 file changed, 2 deletions(-)

diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template
index c4e4c7ded0af..73f95b2a3a9f 100755
--- a/BaseTools/Conf/tools_def.template
+++ b/BaseTools/Conf/tools_def.template
@@ -1850,8 +1850,6 @@ NOOPT_*_*_OBJCOPY_ADDDEBUGFLAG     = --add-gnu-debuglink=$(DEBUG_DIR)/$(MODULE_N
 *_*_*_DTC_PATH                     = DEF(DTC_BIN)
 
 DEFINE GCC_ALL_CC_FLAGS            = -g -Os -fshort-wchar -fno-builtin -fno-strict-aliasing -Wall -Werror -Wno-array-bounds -include AutoGen.h -fno-common
-DEFINE GCC_IA32_CC_FLAGS           = DEF(GCC_ALL_CC_FLAGS) -m32 -malign-double -freorder-blocks -freorder-blocks-and-partition -O2 -mno-stack-arg-probe
-DEFINE GCC_X64_CC_FLAGS            = DEF(GCC_ALL_CC_FLAGS) -mno-red-zone -Wno-address -mno-stack-arg-probe
 DEFINE GCC_ARM_CC_FLAGS            = DEF(GCC_ALL_CC_FLAGS) -mlittle-endian -mabi=aapcs -fno-short-enums -funsigned-char -ffunction-sections -fdata-sections -fomit-frame-pointer -Wno-address -mthumb -mfloat-abi=soft -fno-pic -fno-pie
 DEFINE GCC_LOONGARCH64_CC_FLAGS    = DEF(GCC_ALL_CC_FLAGS) -mabi=lp64d -fno-asynchronous-unwind-tables -fno-plt -Wno-address -fno-short-enums -fsigned-char -ffunction-sections -fdata-sections
 DEFINE GCC_ARM_CC_XIPFLAGS         = -mno-unaligned-access
-- 
2.38.1


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

* [PATCH 02/14] tools_def: add -fno-omit-frame-pointer to GCC48_{IA32,X64}_CC_FLAGS
  2022-12-02 13:09 [PATCH 00/14] OvmfPkg: avoid global variables in PEI Gerd Hoffmann
  2022-12-02 13:09 ` [PATCH 01/14] tools_def: remove GCC_IA32_CC_FLAGS/GCC_X64_CC_FLAGS Gerd Hoffmann
@ 2022-12-02 13:09 ` Gerd Hoffmann
  2022-12-02 13:09 ` [PATCH 03/14] OvmfPkg/PlatformPei: AmdSev: stop using mPlatformInfoHob Gerd Hoffmann
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Gerd Hoffmann @ 2022-12-02 13:09 UTC (permalink / raw)
  To: devel
  Cc: Bob Feng, Yuwei Chen, Erdem Aktas, Jordan Justen, Peter Grehan,
	Rebecca Cran, Liming Gao, Ard Biesheuvel, Gerd Hoffmann,
	Jiewen Yao, Min Xu, Brijesh Singh, Oliver Steffen, Pawel Polawski,
	Tom Lendacky, James Bottomley

Fixes problems due to code assuming it runs with frame pointers and thus
updates rbp / ebp registers when switching stacks.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 BaseTools/Conf/tools_def.template | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template
index 73f95b2a3a9f..f1fd6a003062 100755
--- a/BaseTools/Conf/tools_def.template
+++ b/BaseTools/Conf/tools_def.template
@@ -1888,8 +1888,8 @@ DEFINE GCC_DEPS_FLAGS              = -MMD -MF $@.deps
 
 DEFINE GCC48_ALL_CC_FLAGS            = DEF(GCC_ALL_CC_FLAGS) -ffunction-sections -fdata-sections -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings
 DEFINE GCC48_IA32_X64_DLINK_COMMON   = -nostdlib -Wl,-n,-q,--gc-sections -z common-page-size=0x20
-DEFINE GCC48_IA32_CC_FLAGS           = DEF(GCC48_ALL_CC_FLAGS) -m32 -march=i586 -malign-double -fno-stack-protector -D EFI32 -fno-asynchronous-unwind-tables -Wno-address
-DEFINE GCC48_X64_CC_FLAGS            = DEF(GCC48_ALL_CC_FLAGS) -m64 -fno-stack-protector "-DEFIAPI=__attribute__((ms_abi))" -maccumulate-outgoing-args -mno-red-zone -Wno-address -mcmodel=small -fpie -fno-asynchronous-unwind-tables -Wno-address
+DEFINE GCC48_IA32_CC_FLAGS           = DEF(GCC48_ALL_CC_FLAGS) -m32 -march=i586 -malign-double -fno-stack-protector -D EFI32 -fno-asynchronous-unwind-tables -Wno-address -fno-omit-frame-pointer
+DEFINE GCC48_X64_CC_FLAGS            = DEF(GCC48_ALL_CC_FLAGS) -m64 -fno-stack-protector "-DEFIAPI=__attribute__((ms_abi))" -maccumulate-outgoing-args -mno-red-zone -Wno-address -mcmodel=small -fpie -fno-asynchronous-unwind-tables -Wno-address  -fno-omit-frame-pointer
 DEFINE GCC48_IA32_X64_ASLDLINK_FLAGS = DEF(GCC48_IA32_X64_DLINK_COMMON) -Wl,--entry,ReferenceAcpiTable -u ReferenceAcpiTable
 DEFINE GCC48_IA32_X64_DLINK_FLAGS    = DEF(GCC48_IA32_X64_DLINK_COMMON) -Wl,--entry,$(IMAGE_ENTRY_POINT) -u $(IMAGE_ENTRY_POINT) -Wl,-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map,--whole-archive
 DEFINE GCC48_IA32_DLINK2_FLAGS       = -Wl,--defsym=PECOFF_HEADER_SIZE=0x220 DEF(GCC_DLINK2_FLAGS_COMMON)
-- 
2.38.1


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

* [PATCH 03/14] OvmfPkg/PlatformPei: AmdSev: stop using mPlatformInfoHob
  2022-12-02 13:09 [PATCH 00/14] OvmfPkg: avoid global variables in PEI Gerd Hoffmann
  2022-12-02 13:09 ` [PATCH 01/14] tools_def: remove GCC_IA32_CC_FLAGS/GCC_X64_CC_FLAGS Gerd Hoffmann
  2022-12-02 13:09 ` [PATCH 02/14] tools_def: add -fno-omit-frame-pointer to GCC48_{IA32,X64}_CC_FLAGS Gerd Hoffmann
@ 2022-12-02 13:09 ` Gerd Hoffmann
  2022-12-02 13:09 ` [PATCH 04/14] OvmfPkg/PlatformPei: PeiFv: " Gerd Hoffmann
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Gerd Hoffmann @ 2022-12-02 13:09 UTC (permalink / raw)
  To: devel
  Cc: Bob Feng, Yuwei Chen, Erdem Aktas, Jordan Justen, Peter Grehan,
	Rebecca Cran, Liming Gao, Ard Biesheuvel, Gerd Hoffmann,
	Jiewen Yao, Min Xu, Brijesh Singh, Oliver Steffen, Pawel Polawski,
	Tom Lendacky, James Bottomley

Stop using the mPlatformInfoHob global variable in AmdSevInitialize()
and AmdSevEsInitialize() functions.  Pass a pointer to the
PlatformInfoHob instead.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 OvmfPkg/PlatformPei/Platform.h |  2 +-
 OvmfPkg/PlatformPei/AmdSev.c   | 14 +++++++-------
 OvmfPkg/PlatformPei/Platform.c |  2 +-
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/OvmfPkg/PlatformPei/Platform.h b/OvmfPkg/PlatformPei/Platform.h
index 29b51b2debd8..f245025fb46f 100644
--- a/OvmfPkg/PlatformPei/Platform.h
+++ b/OvmfPkg/PlatformPei/Platform.h
@@ -82,7 +82,7 @@ InstallClearCacheCallback (
 
 VOID
 AmdSevInitialize (
-  VOID
+  IN EFI_HOB_PLATFORM_INFO  *PlatformInfoHob
   );
 
 /**
diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c
index e1b9fd9b7f68..c23fae7fcae0 100644
--- a/OvmfPkg/PlatformPei/AmdSev.c
+++ b/OvmfPkg/PlatformPei/AmdSev.c
@@ -201,7 +201,7 @@ GhcbRegister (
 STATIC
 VOID
 AmdSevEsInitialize (
-  VOID
+  IN EFI_HOB_PLATFORM_INFO  *PlatformInfoHob
   )
 {
   UINT8                *GhcbBase;
@@ -228,7 +228,7 @@ AmdSevEsInitialize (
   //   Since the pages must survive across the UEFI to OS transition
   //   make them reserved.
   //
-  GhcbPageCount = mPlatformInfoHob.PcdCpuMaxLogicalProcessorNumber * 2;
+  GhcbPageCount = PlatformInfoHob->PcdCpuMaxLogicalProcessorNumber * 2;
   GhcbBase      = AllocateReservedPages (GhcbPageCount);
   ASSERT (GhcbBase != NULL);
 
@@ -266,7 +266,7 @@ AmdSevEsInitialize (
   // Allocate #VC recursion backup pages. The number of backup pages needed is
   // one less than the maximum VC count.
   //
-  GhcbBackupPageCount = mPlatformInfoHob.PcdCpuMaxLogicalProcessorNumber * (VMGEXIT_MAXIMUM_VC_COUNT - 1);
+  GhcbBackupPageCount = PlatformInfoHob->PcdCpuMaxLogicalProcessorNumber * (VMGEXIT_MAXIMUM_VC_COUNT - 1);
   GhcbBackupBase      = AllocatePages (GhcbBackupPageCount);
   ASSERT (GhcbBackupBase != NULL);
 
@@ -320,7 +320,7 @@ AmdSevEsInitialize (
   **/
 VOID
 AmdSevInitialize (
-  VOID
+  IN OUT EFI_HOB_PLATFORM_INFO  *PlatformInfoHob
   )
 {
   UINT64         EncryptionMask;
@@ -367,7 +367,7 @@ AmdSevInitialize (
   // until after re-encryption, in order to prevent an information leak to the
   // hypervisor.
   //
-  if (mPlatformInfoHob.SmmSmramRequire && (mPlatformInfoHob.BootMode != BOOT_ON_S3_RESUME)) {
+  if (PlatformInfoHob->SmmSmramRequire && (PlatformInfoHob->BootMode != BOOT_ON_S3_RESUME)) {
     RETURN_STATUS  LocateMapStatus;
     UINTN          MapPagesBase;
     UINTN          MapPagesCount;
@@ -378,7 +378,7 @@ AmdSevInitialize (
                         );
     ASSERT_RETURN_ERROR (LocateMapStatus);
 
-    if (mPlatformInfoHob.Q35SmramAtDefaultSmbase) {
+    if (PlatformInfoHob->Q35SmramAtDefaultSmbase) {
       //
       // The initial SMRAM Save State Map has been covered as part of a larger
       // reserved memory allocation in InitializeRamRegions().
@@ -400,7 +400,7 @@ AmdSevInitialize (
   //
   // Check and perform SEV-ES initialization if required.
   //
-  AmdSevEsInitialize ();
+  AmdSevEsInitialize (PlatformInfoHob);
 
   //
   // Set the Confidential computing attr PCD to communicate which SEV
diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c
index b1f8140d6041..f2c1e2b213cb 100644
--- a/OvmfPkg/PlatformPei/Platform.c
+++ b/OvmfPkg/PlatformPei/Platform.c
@@ -379,7 +379,7 @@ InitializePlatform (
   }
 
   InstallClearCacheCallback ();
-  AmdSevInitialize ();
+  AmdSevInitialize (&mPlatformInfoHob);
   if (mPlatformInfoHob.HostBridgeDevId == 0xffff) {
     MiscInitializationForMicrovm (&mPlatformInfoHob);
   } else {
-- 
2.38.1


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

* [PATCH 04/14] OvmfPkg/PlatformPei: PeiFv: stop using mPlatformInfoHob
  2022-12-02 13:09 [PATCH 00/14] OvmfPkg: avoid global variables in PEI Gerd Hoffmann
                   ` (2 preceding siblings ...)
  2022-12-02 13:09 ` [PATCH 03/14] OvmfPkg/PlatformPei: AmdSev: stop using mPlatformInfoHob Gerd Hoffmann
@ 2022-12-02 13:09 ` Gerd Hoffmann
  2022-12-02 13:10 ` [PATCH 05/14] OvmfPkg/PlatformPei Q35 SMM helpers: " Gerd Hoffmann
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Gerd Hoffmann @ 2022-12-02 13:09 UTC (permalink / raw)
  To: devel
  Cc: Bob Feng, Yuwei Chen, Erdem Aktas, Jordan Justen, Peter Grehan,
	Rebecca Cran, Liming Gao, Ard Biesheuvel, Gerd Hoffmann,
	Jiewen Yao, Min Xu, Brijesh Singh, Oliver Steffen, Pawel Polawski,
	Tom Lendacky, James Bottomley

Stop using the mPlatformInfoHob global variable in PeiFvInitialization()
function.  Pass a pointer to the PlatformInfoHob instead.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 OvmfPkg/PlatformPei/Platform.h | 2 +-
 OvmfPkg/PlatformPei/Fv.c       | 6 +++---
 OvmfPkg/PlatformPei/Platform.c | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/OvmfPkg/PlatformPei/Platform.h b/OvmfPkg/PlatformPei/Platform.h
index f245025fb46f..b13f45ecdb69 100644
--- a/OvmfPkg/PlatformPei/Platform.h
+++ b/OvmfPkg/PlatformPei/Platform.h
@@ -62,7 +62,7 @@ MaxCpuCountInitialization (
 
 EFI_STATUS
 PeiFvInitialization (
-  VOID
+  IN EFI_HOB_PLATFORM_INFO  *PlatformInfoHob
   );
 
 VOID
diff --git a/OvmfPkg/PlatformPei/Fv.c b/OvmfPkg/PlatformPei/Fv.c
index e40c5922206b..fcf14c88faa7 100644
--- a/OvmfPkg/PlatformPei/Fv.c
+++ b/OvmfPkg/PlatformPei/Fv.c
@@ -22,7 +22,7 @@
 **/
 EFI_STATUS
 PeiFvInitialization (
-  VOID
+  IN EFI_HOB_PLATFORM_INFO  *PlatformInfoHob
   )
 {
   BOOLEAN  SecureS3Needed;
@@ -37,7 +37,7 @@ PeiFvInitialization (
   BuildMemoryAllocationHob (
     PcdGet32 (PcdOvmfPeiMemFvBase),
     PcdGet32 (PcdOvmfPeiMemFvSize),
-    mPlatformInfoHob.S3Supported ? EfiACPIMemoryNVS : EfiBootServicesData
+    PlatformInfoHob->S3Supported ? EfiACPIMemoryNVS : EfiBootServicesData
     );
 
   //
@@ -45,7 +45,7 @@ PeiFvInitialization (
   //
   BuildFvHob (PcdGet32 (PcdOvmfDxeMemFvBase), PcdGet32 (PcdOvmfDxeMemFvSize));
 
-  SecureS3Needed = mPlatformInfoHob.S3Supported && mPlatformInfoHob.SmmSmramRequire;
+  SecureS3Needed = PlatformInfoHob->S3Supported && PlatformInfoHob->SmmSmramRequire;
 
   //
   // Create a memory allocation HOB for the DXE FV.
diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c
index f2c1e2b213cb..9646a1fa63b0 100644
--- a/OvmfPkg/PlatformPei/Platform.c
+++ b/OvmfPkg/PlatformPei/Platform.c
@@ -372,7 +372,7 @@ InitializePlatform (
       ReserveEmuVariableNvStore ();
     }
 
-    PeiFvInitialization ();
+    PeiFvInitialization (&mPlatformInfoHob);
     MemTypeInfoInitialization ();
     MemMapInitialization (&mPlatformInfoHob);
     NoexecDxeInitialization ();
-- 
2.38.1


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

* [PATCH 05/14] OvmfPkg/PlatformPei Q35 SMM helpers: stop using mPlatformInfoHob
  2022-12-02 13:09 [PATCH 00/14] OvmfPkg: avoid global variables in PEI Gerd Hoffmann
                   ` (3 preceding siblings ...)
  2022-12-02 13:09 ` [PATCH 04/14] OvmfPkg/PlatformPei: PeiFv: " Gerd Hoffmann
@ 2022-12-02 13:10 ` Gerd Hoffmann
  2022-12-02 13:10 ` [PATCH 06/14] OvmfPkg/PlatformPei: PeiMemory: " Gerd Hoffmann
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Gerd Hoffmann @ 2022-12-02 13:10 UTC (permalink / raw)
  To: devel
  Cc: Bob Feng, Yuwei Chen, Erdem Aktas, Jordan Justen, Peter Grehan,
	Rebecca Cran, Liming Gao, Ard Biesheuvel, Gerd Hoffmann,
	Jiewen Yao, Min Xu, Brijesh Singh, Oliver Steffen, Pawel Polawski,
	Tom Lendacky, James Bottomley

Stop using the mPlatformInfoHob global variable in
Q35TsegMbytesInitialization() and
Q35SmramAtDefaultSmbaseInitialization() ) functions.
Pass a pointer to the PlatformInfoHob instead.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 OvmfPkg/PlatformPei/Platform.h  |  4 ++--
 OvmfPkg/PlatformPei/MemDetect.c | 20 ++++++++++----------
 OvmfPkg/PlatformPei/Platform.c  |  4 ++--
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/OvmfPkg/PlatformPei/Platform.h b/OvmfPkg/PlatformPei/Platform.h
index b13f45ecdb69..7baa5e1d289f 100644
--- a/OvmfPkg/PlatformPei/Platform.h
+++ b/OvmfPkg/PlatformPei/Platform.h
@@ -22,12 +22,12 @@ AddressWidthInitialization (
 
 VOID
 Q35TsegMbytesInitialization (
-  VOID
+  IN OUT EFI_HOB_PLATFORM_INFO  *PlatformInfoHob
   );
 
 VOID
 Q35SmramAtDefaultSmbaseInitialization (
-  VOID
+  IN OUT EFI_HOB_PLATFORM_INFO  *PlatformInfoHob
   );
 
 EFI_STATUS
diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetect.c
index 2e47b1322990..b9207107b4d9 100644
--- a/OvmfPkg/PlatformPei/MemDetect.c
+++ b/OvmfPkg/PlatformPei/MemDetect.c
@@ -41,13 +41,13 @@ Module Name:
 
 VOID
 Q35TsegMbytesInitialization (
-  VOID
+  IN OUT EFI_HOB_PLATFORM_INFO  *PlatformInfoHob
   )
 {
   UINT16         ExtendedTsegMbytes;
   RETURN_STATUS  PcdStatus;
 
-  ASSERT (mPlatformInfoHob.HostBridgeDevId == INTEL_Q35_MCH_DEVICE_ID);
+  ASSERT (PlatformInfoHob->HostBridgeDevId == INTEL_Q35_MCH_DEVICE_ID);
 
   //
   // Check if QEMU offers an extended TSEG.
@@ -68,7 +68,7 @@ Q35TsegMbytesInitialization (
   PciWrite16 (DRAMC_REGISTER_Q35 (MCH_EXT_TSEG_MB), MCH_EXT_TSEG_MB_QUERY);
   ExtendedTsegMbytes = PciRead16 (DRAMC_REGISTER_Q35 (MCH_EXT_TSEG_MB));
   if (ExtendedTsegMbytes == MCH_EXT_TSEG_MB_QUERY) {
-    mPlatformInfoHob.Q35TsegMbytes = PcdGet16 (PcdQ35TsegMbytes);
+    PlatformInfoHob->Q35TsegMbytes = PcdGet16 (PcdQ35TsegMbytes);
     return;
   }
 
@@ -80,19 +80,19 @@ Q35TsegMbytesInitialization (
     ));
   PcdStatus = PcdSet16S (PcdQ35TsegMbytes, ExtendedTsegMbytes);
   ASSERT_RETURN_ERROR (PcdStatus);
-  mPlatformInfoHob.Q35TsegMbytes = ExtendedTsegMbytes;
+  PlatformInfoHob->Q35TsegMbytes = ExtendedTsegMbytes;
 }
 
 VOID
 Q35SmramAtDefaultSmbaseInitialization (
-  VOID
+  IN OUT EFI_HOB_PLATFORM_INFO  *PlatformInfoHob
   )
 {
   RETURN_STATUS  PcdStatus;
 
-  ASSERT (mPlatformInfoHob.HostBridgeDevId == INTEL_Q35_MCH_DEVICE_ID);
+  ASSERT (PlatformInfoHob->HostBridgeDevId == INTEL_Q35_MCH_DEVICE_ID);
 
-  mPlatformInfoHob.Q35SmramAtDefaultSmbase = FALSE;
+  PlatformInfoHob->Q35SmramAtDefaultSmbase = FALSE;
   if (FeaturePcdGet (PcdCsmEnable)) {
     DEBUG ((
       DEBUG_INFO,
@@ -106,19 +106,19 @@ Q35SmramAtDefaultSmbaseInitialization (
     CtlReg = DRAMC_REGISTER_Q35 (MCH_DEFAULT_SMBASE_CTL);
     PciWrite8 (CtlReg, MCH_DEFAULT_SMBASE_QUERY);
     CtlRegVal                                = PciRead8 (CtlReg);
-    mPlatformInfoHob.Q35SmramAtDefaultSmbase = (BOOLEAN)(CtlRegVal ==
+    PlatformInfoHob->Q35SmramAtDefaultSmbase = (BOOLEAN)(CtlRegVal ==
                                                          MCH_DEFAULT_SMBASE_IN_RAM);
     DEBUG ((
       DEBUG_INFO,
       "%a: SMRAM at default SMBASE %a\n",
       __FUNCTION__,
-      mPlatformInfoHob.Q35SmramAtDefaultSmbase ? "found" : "not found"
+      PlatformInfoHob->Q35SmramAtDefaultSmbase ? "found" : "not found"
       ));
   }
 
   PcdStatus = PcdSetBoolS (
                 PcdQ35SmramAtDefaultSmbase,
-                mPlatformInfoHob.Q35SmramAtDefaultSmbase
+                PlatformInfoHob->Q35SmramAtDefaultSmbase
                 );
   ASSERT_RETURN_ERROR (PcdStatus);
 }
diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c
index 9646a1fa63b0..8b055fb451d7 100644
--- a/OvmfPkg/PlatformPei/Platform.c
+++ b/OvmfPkg/PlatformPei/Platform.c
@@ -357,8 +357,8 @@ InitializePlatform (
 
   if (mPlatformInfoHob.SmmSmramRequire) {
     Q35BoardVerification ();
-    Q35TsegMbytesInitialization ();
-    Q35SmramAtDefaultSmbaseInitialization ();
+    Q35TsegMbytesInitialization (&mPlatformInfoHob);
+    Q35SmramAtDefaultSmbaseInitialization (&mPlatformInfoHob);
   }
 
   PublishPeiMemory ();
-- 
2.38.1


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

* [PATCH 06/14] OvmfPkg/PlatformPei: PeiMemory: stop using mPlatformInfoHob
  2022-12-02 13:09 [PATCH 00/14] OvmfPkg: avoid global variables in PEI Gerd Hoffmann
                   ` (4 preceding siblings ...)
  2022-12-02 13:10 ` [PATCH 05/14] OvmfPkg/PlatformPei Q35 SMM helpers: " Gerd Hoffmann
@ 2022-12-02 13:10 ` Gerd Hoffmann
  2022-12-02 13:10 ` [PATCH 07/14] OvmfPkg/PlatformPei: MemTypeInfo: " Gerd Hoffmann
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Gerd Hoffmann @ 2022-12-02 13:10 UTC (permalink / raw)
  To: devel
  Cc: Bob Feng, Yuwei Chen, Erdem Aktas, Jordan Justen, Peter Grehan,
	Rebecca Cran, Liming Gao, Ard Biesheuvel, Gerd Hoffmann,
	Jiewen Yao, Min Xu, Brijesh Singh, Oliver Steffen, Pawel Polawski,
	Tom Lendacky, James Bottomley

Stop using the mPlatformInfoHob global variable in PublishPeiMemory()
and GetPeiMemoryCap() functions.  Pass a pointer to the PlatformInfoHob
instead.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 OvmfPkg/PlatformPei/Platform.h  |  2 +-
 OvmfPkg/PlatformPei/MemDetect.c | 36 ++++++++++++++++-----------------
 OvmfPkg/PlatformPei/Platform.c  |  2 +-
 3 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/OvmfPkg/PlatformPei/Platform.h b/OvmfPkg/PlatformPei/Platform.h
index 7baa5e1d289f..d0c673c5a346 100644
--- a/OvmfPkg/PlatformPei/Platform.h
+++ b/OvmfPkg/PlatformPei/Platform.h
@@ -32,7 +32,7 @@ Q35SmramAtDefaultSmbaseInitialization (
 
 EFI_STATUS
 PublishPeiMemory (
-  VOID
+  IN OUT EFI_HOB_PLATFORM_INFO  *PlatformInfoHob
   );
 
 VOID
diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetect.c
index b9207107b4d9..3d8375320dcb 100644
--- a/OvmfPkg/PlatformPei/MemDetect.c
+++ b/OvmfPkg/PlatformPei/MemDetect.c
@@ -188,7 +188,7 @@ AddressWidthInitialization (
 STATIC
 UINT32
 GetPeiMemoryCap (
-  VOID
+  IN EFI_HOB_PLATFORM_INFO  *PlatformInfoHob
   )
 {
   BOOLEAN  Page1GSupport;
@@ -225,15 +225,15 @@ GetPeiMemoryCap (
     }
   }
 
-  if (mPlatformInfoHob.PhysMemAddressWidth <= 39) {
+  if (PlatformInfoHob->PhysMemAddressWidth <= 39) {
     Pml4Entries = 1;
-    PdpEntries  = 1 << (mPlatformInfoHob.PhysMemAddressWidth - 30);
+    PdpEntries  = 1 << (PlatformInfoHob->PhysMemAddressWidth - 30);
     ASSERT (PdpEntries <= 0x200);
   } else {
-    if (mPlatformInfoHob.PhysMemAddressWidth > 48) {
+    if (PlatformInfoHob->PhysMemAddressWidth > 48) {
       Pml4Entries = 0x200;
     } else {
-      Pml4Entries = 1 << (mPlatformInfoHob.PhysMemAddressWidth - 39);
+      Pml4Entries = 1 << (PlatformInfoHob->PhysMemAddressWidth - 39);
     }
 
     ASSERT (Pml4Entries <= 0x200);
@@ -260,7 +260,7 @@ GetPeiMemoryCap (
 **/
 EFI_STATUS
 PublishPeiMemory (
-  VOID
+  IN OUT EFI_HOB_PLATFORM_INFO  *PlatformInfoHob
   )
 {
   EFI_STATUS            Status;
@@ -271,12 +271,12 @@ PublishPeiMemory (
   UINT32                S3AcpiReservedMemoryBase;
   UINT32                S3AcpiReservedMemorySize;
 
-  LowerMemorySize = PlatformGetSystemMemorySizeBelow4gb (&mPlatformInfoHob);
-  if (mPlatformInfoHob.SmmSmramRequire) {
+  LowerMemorySize = PlatformGetSystemMemorySizeBelow4gb (PlatformInfoHob);
+  if (PlatformInfoHob->SmmSmramRequire) {
     //
     // TSEG is chipped from the end of low RAM
     //
-    LowerMemorySize -= mPlatformInfoHob.Q35TsegMbytes * SIZE_1MB;
+    LowerMemorySize -= PlatformInfoHob->Q35TsegMbytes * SIZE_1MB;
   }
 
   S3AcpiReservedMemoryBase = 0;
@@ -287,27 +287,27 @@ PublishPeiMemory (
   // downwards. Its size is primarily dictated by CpuMpPei. The formula below
   // is an approximation.
   //
-  if (mPlatformInfoHob.S3Supported) {
+  if (PlatformInfoHob->S3Supported) {
     S3AcpiReservedMemorySize = SIZE_512KB +
-                               mPlatformInfoHob.PcdCpuMaxLogicalProcessorNumber *
+                               PlatformInfoHob->PcdCpuMaxLogicalProcessorNumber *
                                PcdGet32 (PcdCpuApStackSize);
     S3AcpiReservedMemoryBase = LowerMemorySize - S3AcpiReservedMemorySize;
     LowerMemorySize          = S3AcpiReservedMemoryBase;
   }
 
-  mPlatformInfoHob.S3AcpiReservedMemoryBase = S3AcpiReservedMemoryBase;
-  mPlatformInfoHob.S3AcpiReservedMemorySize = S3AcpiReservedMemorySize;
+  PlatformInfoHob->S3AcpiReservedMemoryBase = S3AcpiReservedMemoryBase;
+  PlatformInfoHob->S3AcpiReservedMemorySize = S3AcpiReservedMemorySize;
 
-  if (mPlatformInfoHob.BootMode == BOOT_ON_S3_RESUME) {
+  if (PlatformInfoHob->BootMode == BOOT_ON_S3_RESUME) {
     MemoryBase = S3AcpiReservedMemoryBase;
     MemorySize = S3AcpiReservedMemorySize;
   } else {
-    PeiMemoryCap = GetPeiMemoryCap ();
+    PeiMemoryCap = GetPeiMemoryCap (PlatformInfoHob);
     DEBUG ((
       DEBUG_INFO,
       "%a: PhysMemAddressWidth=%d PeiMemoryCap=%u KB\n",
       __FUNCTION__,
-      mPlatformInfoHob.PhysMemAddressWidth,
+      PlatformInfoHob->PhysMemAddressWidth,
       PeiMemoryCap >> 10
       ));
 
@@ -321,7 +321,7 @@ PublishPeiMemory (
     // allocation HOB, and other allocations served from the permanent PEI RAM
     // shouldn't overlap with that HOB.
     //
-    MemoryBase = mPlatformInfoHob.S3Supported && mPlatformInfoHob.SmmSmramRequire ?
+    MemoryBase = PlatformInfoHob->S3Supported && PlatformInfoHob->SmmSmramRequire ?
                  PcdGet32 (PcdOvmfDecompressionScratchEnd) :
                  PcdGet32 (PcdOvmfDxeMemFvBase) + PcdGet32 (PcdOvmfDxeMemFvSize);
     MemorySize = LowerMemorySize - MemoryBase;
@@ -336,7 +336,7 @@ PublishPeiMemory (
   // normal boot permanent PEI RAM. Regarding the S3 boot path, the S3
   // permanent PEI RAM is located even higher.
   //
-  if (mPlatformInfoHob.SmmSmramRequire && mPlatformInfoHob.Q35SmramAtDefaultSmbase) {
+  if (PlatformInfoHob->SmmSmramRequire && PlatformInfoHob->Q35SmramAtDefaultSmbase) {
     ASSERT (SMM_DEFAULT_SMBASE + MCH_DEFAULT_SMBASE_SIZE <= MemoryBase);
   }
 
diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c
index 8b055fb451d7..4cd77fd5f84f 100644
--- a/OvmfPkg/PlatformPei/Platform.c
+++ b/OvmfPkg/PlatformPei/Platform.c
@@ -361,7 +361,7 @@ InitializePlatform (
     Q35SmramAtDefaultSmbaseInitialization (&mPlatformInfoHob);
   }
 
-  PublishPeiMemory ();
+  PublishPeiMemory (&mPlatformInfoHob);
 
   PlatformQemuUc32BaseInitialization (&mPlatformInfoHob);
 
-- 
2.38.1


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

* [PATCH 07/14] OvmfPkg/PlatformPei: MemTypeInfo: stop using mPlatformInfoHob
  2022-12-02 13:09 [PATCH 00/14] OvmfPkg: avoid global variables in PEI Gerd Hoffmann
                   ` (5 preceding siblings ...)
  2022-12-02 13:10 ` [PATCH 06/14] OvmfPkg/PlatformPei: PeiMemory: " Gerd Hoffmann
@ 2022-12-02 13:10 ` Gerd Hoffmann
  2022-12-02 13:10 ` [PATCH 08/14] OvmfPkg/PlatformPei: NoExec: " Gerd Hoffmann
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Gerd Hoffmann @ 2022-12-02 13:10 UTC (permalink / raw)
  To: devel
  Cc: Bob Feng, Yuwei Chen, Erdem Aktas, Jordan Justen, Peter Grehan,
	Rebecca Cran, Liming Gao, Ard Biesheuvel, Gerd Hoffmann,
	Jiewen Yao, Min Xu, Brijesh Singh, Oliver Steffen, Pawel Polawski,
	Tom Lendacky, James Bottomley

Stop using the mPlatformInfoHob global variable in MemTypeInfoInitialization()
function.  Pass a pointer to the PlatformInfoHob instead.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 OvmfPkg/PlatformPei/Platform.h    | 2 +-
 OvmfPkg/PlatformPei/MemTypeInfo.c | 4 ++--
 OvmfPkg/PlatformPei/Platform.c    | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/OvmfPkg/PlatformPei/Platform.h b/OvmfPkg/PlatformPei/Platform.h
index d0c673c5a346..0c0558f0626c 100644
--- a/OvmfPkg/PlatformPei/Platform.h
+++ b/OvmfPkg/PlatformPei/Platform.h
@@ -67,7 +67,7 @@ PeiFvInitialization (
 
 VOID
 MemTypeInfoInitialization (
-  VOID
+  IN OUT EFI_HOB_PLATFORM_INFO  *PlatformInfoHob
   );
 
 VOID
diff --git a/OvmfPkg/PlatformPei/MemTypeInfo.c b/OvmfPkg/PlatformPei/MemTypeInfo.c
index c8fcf1732687..eb37febb31ae 100644
--- a/OvmfPkg/PlatformPei/MemTypeInfo.c
+++ b/OvmfPkg/PlatformPei/MemTypeInfo.c
@@ -203,12 +203,12 @@ STATIC CONST EFI_PEI_NOTIFY_DESCRIPTOR  mReadOnlyVariable2Notify = {
 
 VOID
 MemTypeInfoInitialization (
-  VOID
+  IN OUT EFI_HOB_PLATFORM_INFO  *PlatformInfoHob
   )
 {
   EFI_STATUS  Status;
 
-  if (!mPlatformInfoHob.SmmSmramRequire) {
+  if (!PlatformInfoHob->SmmSmramRequire) {
     //
     // EFI_PEI_READ_ONLY_VARIABLE2_PPI will never be available; install
     // the default memory type information HOB right away.
diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c
index 4cd77fd5f84f..85b47e7ed8df 100644
--- a/OvmfPkg/PlatformPei/Platform.c
+++ b/OvmfPkg/PlatformPei/Platform.c
@@ -373,7 +373,7 @@ InitializePlatform (
     }
 
     PeiFvInitialization (&mPlatformInfoHob);
-    MemTypeInfoInitialization ();
+    MemTypeInfoInitialization (&mPlatformInfoHob);
     MemMapInitialization (&mPlatformInfoHob);
     NoexecDxeInitialization ();
   }
-- 
2.38.1


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

* [PATCH 08/14] OvmfPkg/PlatformPei: NoExec: stop using mPlatformInfoHob
  2022-12-02 13:09 [PATCH 00/14] OvmfPkg: avoid global variables in PEI Gerd Hoffmann
                   ` (6 preceding siblings ...)
  2022-12-02 13:10 ` [PATCH 07/14] OvmfPkg/PlatformPei: MemTypeInfo: " Gerd Hoffmann
@ 2022-12-02 13:10 ` Gerd Hoffmann
  2022-12-02 13:10 ` [PATCH 09/14] OvmfPkg/PlatformPei: Verification: " Gerd Hoffmann
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Gerd Hoffmann @ 2022-12-02 13:10 UTC (permalink / raw)
  To: devel
  Cc: Bob Feng, Yuwei Chen, Erdem Aktas, Jordan Justen, Peter Grehan,
	Rebecca Cran, Liming Gao, Ard Biesheuvel, Gerd Hoffmann,
	Jiewen Yao, Min Xu, Brijesh Singh, Oliver Steffen, Pawel Polawski,
	Tom Lendacky, James Bottomley

Stop using the mPlatformInfoHob global variable in NoexecDxeInitialization()
function.  Pass a pointer to the PlatformInfoHob instead.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 OvmfPkg/PlatformPei/Platform.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c
index 85b47e7ed8df..7f3a26092626 100644
--- a/OvmfPkg/PlatformPei/Platform.c
+++ b/OvmfPkg/PlatformPei/Platform.c
@@ -75,16 +75,17 @@ MemMapInitialization (
   ASSERT_RETURN_ERROR (PcdStatus);
 }
 
+STATIC
 VOID
 NoexecDxeInitialization (
-  VOID
+  IN OUT EFI_HOB_PLATFORM_INFO  *PlatformInfoHob
   )
 {
   RETURN_STATUS  Status;
 
-  Status = PlatformNoexecDxeInitialization (&mPlatformInfoHob);
+  Status = PlatformNoexecDxeInitialization (PlatformInfoHob);
   if (!RETURN_ERROR (Status)) {
-    Status = PcdSetBoolS (PcdSetNxForStack, mPlatformInfoHob.PcdSetNxForStack);
+    Status = PcdSetBoolS (PcdSetNxForStack, PlatformInfoHob->PcdSetNxForStack);
     ASSERT_RETURN_ERROR (Status);
   }
 }
@@ -375,7 +376,7 @@ InitializePlatform (
     PeiFvInitialization (&mPlatformInfoHob);
     MemTypeInfoInitialization (&mPlatformInfoHob);
     MemMapInitialization (&mPlatformInfoHob);
-    NoexecDxeInitialization ();
+    NoexecDxeInitialization (&mPlatformInfoHob);
   }
 
   InstallClearCacheCallback ();
-- 
2.38.1


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

* [PATCH 09/14] OvmfPkg/PlatformPei: Verification: stop using mPlatformInfoHob
  2022-12-02 13:09 [PATCH 00/14] OvmfPkg: avoid global variables in PEI Gerd Hoffmann
                   ` (7 preceding siblings ...)
  2022-12-02 13:10 ` [PATCH 08/14] OvmfPkg/PlatformPei: NoExec: " Gerd Hoffmann
@ 2022-12-02 13:10 ` Gerd Hoffmann
  2022-12-02 13:10 ` [PATCH 10/14] OvmfPkg/PlatformPei: remove mPlatformInfoHob Gerd Hoffmann
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Gerd Hoffmann @ 2022-12-02 13:10 UTC (permalink / raw)
  To: devel
  Cc: Bob Feng, Yuwei Chen, Erdem Aktas, Jordan Justen, Peter Grehan,
	Rebecca Cran, Liming Gao, Ard Biesheuvel, Gerd Hoffmann,
	Jiewen Yao, Min Xu, Brijesh Singh, Oliver Steffen, Pawel Polawski,
	Tom Lendacky, James Bottomley

Stop using the mPlatformInfoHob global variable in S3Verification() and
Q35BoardVerification() functions.  Pass a pointer to the PlatformInfoHob
instead.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 OvmfPkg/PlatformPei/Platform.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c
index 7f3a26092626..d8c4499804fb 100644
--- a/OvmfPkg/PlatformPei/Platform.c
+++ b/OvmfPkg/PlatformPei/Platform.c
@@ -231,13 +231,14 @@ ReserveEmuVariableNvStore (
   ASSERT_RETURN_ERROR (PcdStatus);
 }
 
+STATIC
 VOID
 S3Verification (
-  VOID
+  IN EFI_HOB_PLATFORM_INFO  *PlatformInfoHob
   )
 {
  #if defined (MDE_CPU_X64)
-  if (mPlatformInfoHob.SmmSmramRequire && mPlatformInfoHob.S3Supported) {
+  if (PlatformInfoHob->SmmSmramRequire && PlatformInfoHob->S3Supported) {
     DEBUG ((
       DEBUG_ERROR,
       "%a: S3Resume2Pei doesn't support X64 PEI + SMM yet.\n",
@@ -260,12 +261,13 @@ S3Verification (
  #endif
 }
 
+STATIC
 VOID
 Q35BoardVerification (
-  VOID
+  IN EFI_HOB_PLATFORM_INFO  *PlatformInfoHob
   )
 {
-  if (mPlatformInfoHob.HostBridgeDevId == INTEL_Q35_MCH_DEVICE_ID) {
+  if (PlatformInfoHob->HostBridgeDevId == INTEL_Q35_MCH_DEVICE_ID) {
     return;
   }
 
@@ -274,7 +276,7 @@ Q35BoardVerification (
     "%a: no TSEG (SMRAM) on host bridge DID=0x%04x; "
     "only DID=0x%04x (Q35) is supported\n",
     __FUNCTION__,
-    mPlatformInfoHob.HostBridgeDevId,
+    PlatformInfoHob->HostBridgeDevId,
     INTEL_Q35_MCH_DEVICE_ID
     ));
   ASSERT (FALSE);
@@ -345,7 +347,7 @@ InitializePlatform (
     ASSERT_EFI_ERROR (Status);
   }
 
-  S3Verification ();
+  S3Verification (&mPlatformInfoHob);
   BootModeInitialization (&mPlatformInfoHob);
 
   //
@@ -357,7 +359,7 @@ InitializePlatform (
   MaxCpuCountInitialization (&mPlatformInfoHob);
 
   if (mPlatformInfoHob.SmmSmramRequire) {
-    Q35BoardVerification ();
+    Q35BoardVerification (&mPlatformInfoHob);
     Q35TsegMbytesInitialization (&mPlatformInfoHob);
     Q35SmramAtDefaultSmbaseInitialization (&mPlatformInfoHob);
   }
-- 
2.38.1


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

* [PATCH 10/14] OvmfPkg/PlatformPei: remove mPlatformInfoHob
  2022-12-02 13:09 [PATCH 00/14] OvmfPkg: avoid global variables in PEI Gerd Hoffmann
                   ` (8 preceding siblings ...)
  2022-12-02 13:10 ` [PATCH 09/14] OvmfPkg/PlatformPei: Verification: " Gerd Hoffmann
@ 2022-12-02 13:10 ` Gerd Hoffmann
  2022-12-02 13:10 ` [PATCH 11/14] OvmfPkg/PlatformPei: remove mFeatureControlValue Gerd Hoffmann
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Gerd Hoffmann @ 2022-12-02 13:10 UTC (permalink / raw)
  To: devel
  Cc: Bob Feng, Yuwei Chen, Erdem Aktas, Jordan Justen, Peter Grehan,
	Rebecca Cran, Liming Gao, Ard Biesheuvel, Gerd Hoffmann,
	Jiewen Yao, Min Xu, Brijesh Singh, Oliver Steffen, Pawel Polawski,
	Tom Lendacky, James Bottomley

Stop using the mPlatformInfoHob global variable.  Let
BuildPlatformInfoHob() allocate and return PlatformInfoHob instead.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 OvmfPkg/PlatformPei/Platform.h |  4 +-
 OvmfPkg/PlatformPei/Platform.c | 71 ++++++++++++++++++----------------
 2 files changed, 39 insertions(+), 36 deletions(-)

diff --git a/OvmfPkg/PlatformPei/Platform.h b/OvmfPkg/PlatformPei/Platform.h
index 0c0558f0626c..86f603ff649c 100644
--- a/OvmfPkg/PlatformPei/Platform.h
+++ b/OvmfPkg/PlatformPei/Platform.h
@@ -13,8 +13,6 @@
 #include <Library/PlatformInitLib.h>
 #include <IndustryStandard/IntelTdx.h>
 
-extern EFI_HOB_PLATFORM_INFO  mPlatformInfoHob;
-
 VOID
 AddressWidthInitialization (
   IN OUT EFI_HOB_PLATFORM_INFO  *PlatformInfoHob
@@ -98,7 +96,7 @@ IntelTdxInitialize (
 /**
  * @brief Builds PlatformInfo Hob
  */
-VOID
+EFI_HOB_PLATFORM_INFO *
 BuildPlatformInfoHob (
   VOID
   );
diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c
index d8c4499804fb..ebce2ba1290e 100644
--- a/OvmfPkg/PlatformPei/Platform.c
+++ b/OvmfPkg/PlatformPei/Platform.c
@@ -41,8 +41,6 @@
 
 #include "Platform.h"
 
-EFI_HOB_PLATFORM_INFO  mPlatformInfoHob = { 0 };
-
 EFI_PEI_PPI_DESCRIPTOR  mPpiBootMode[] = {
   {
     EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
@@ -305,12 +303,18 @@ MaxCpuCountInitialization (
 /**
  * @brief Builds PlatformInfo Hob
  */
-VOID
+EFI_HOB_PLATFORM_INFO *
 BuildPlatformInfoHob (
   VOID
   )
 {
-  BuildGuidDataHob (&gUefiOvmfPkgPlatformInfoGuid, &mPlatformInfoHob, sizeof (EFI_HOB_PLATFORM_INFO));
+  EFI_HOB_PLATFORM_INFO  PlatformInfoHob;
+  EFI_HOB_GUID_TYPE      *GuidHob;
+
+  ZeroMem (&PlatformInfoHob, sizeof PlatformInfoHob);
+  BuildGuidDataHob (&gUefiOvmfPkgPlatformInfoGuid, &PlatformInfoHob, sizeof (EFI_HOB_PLATFORM_INFO));
+  GuidHob = GetFirstGuidHob (&gUefiOvmfPkgPlatformInfoGuid);
+  return (EFI_HOB_PLATFORM_INFO *)GET_GUID_HOB_DATA (GuidHob);
 }
 
 /**
@@ -329,69 +333,70 @@ InitializePlatform (
   IN CONST EFI_PEI_SERVICES     **PeiServices
   )
 {
-  EFI_STATUS  Status;
+  EFI_HOB_PLATFORM_INFO  *PlatformInfoHob;
+  EFI_STATUS             Status;
 
   DEBUG ((DEBUG_INFO, "Platform PEIM Loaded\n"));
+  PlatformInfoHob = BuildPlatformInfoHob ();
 
-  mPlatformInfoHob.SmmSmramRequire     = FeaturePcdGet (PcdSmmSmramRequire);
-  mPlatformInfoHob.SevEsIsEnabled      = MemEncryptSevEsIsEnabled ();
-  mPlatformInfoHob.PcdPciMmio64Size    = PcdGet64 (PcdPciMmio64Size);
-  mPlatformInfoHob.DefaultMaxCpuNumber = PcdGet32 (PcdCpuMaxLogicalProcessorNumber);
+  PlatformInfoHob->SmmSmramRequire     = FeaturePcdGet (PcdSmmSmramRequire);
+  PlatformInfoHob->SevEsIsEnabled      = MemEncryptSevEsIsEnabled ();
+  PlatformInfoHob->PcdPciMmio64Size    = PcdGet64 (PcdPciMmio64Size);
+  PlatformInfoHob->DefaultMaxCpuNumber = PcdGet32 (PcdCpuMaxLogicalProcessorNumber);
 
   PlatformDebugDumpCmos ();
 
   if (QemuFwCfgS3Enabled ()) {
     DEBUG ((DEBUG_INFO, "S3 support was detected on QEMU\n"));
-    mPlatformInfoHob.S3Supported = TRUE;
+    PlatformInfoHob->S3Supported = TRUE;
     Status                       = PcdSetBoolS (PcdAcpiS3Enable, TRUE);
     ASSERT_EFI_ERROR (Status);
   }
 
-  S3Verification (&mPlatformInfoHob);
-  BootModeInitialization (&mPlatformInfoHob);
+  S3Verification (PlatformInfoHob);
+  BootModeInitialization (PlatformInfoHob);
 
   //
   // Query Host Bridge DID
   //
-  mPlatformInfoHob.HostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID);
-  AddressWidthInitialization (&mPlatformInfoHob);
+  PlatformInfoHob->HostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID);
+  AddressWidthInitialization (PlatformInfoHob);
 
-  MaxCpuCountInitialization (&mPlatformInfoHob);
+  MaxCpuCountInitialization (PlatformInfoHob);
 
-  if (mPlatformInfoHob.SmmSmramRequire) {
-    Q35BoardVerification (&mPlatformInfoHob);
-    Q35TsegMbytesInitialization (&mPlatformInfoHob);
-    Q35SmramAtDefaultSmbaseInitialization (&mPlatformInfoHob);
+  if (PlatformInfoHob->SmmSmramRequire) {
+    Q35BoardVerification (PlatformInfoHob);
+    Q35TsegMbytesInitialization (PlatformInfoHob);
+    Q35SmramAtDefaultSmbaseInitialization (PlatformInfoHob);
   }
 
-  PublishPeiMemory (&mPlatformInfoHob);
+  PublishPeiMemory (PlatformInfoHob);
 
-  PlatformQemuUc32BaseInitialization (&mPlatformInfoHob);
+  PlatformQemuUc32BaseInitialization (PlatformInfoHob);
 
-  InitializeRamRegions (&mPlatformInfoHob);
+  InitializeRamRegions (PlatformInfoHob);
 
-  if (mPlatformInfoHob.BootMode != BOOT_ON_S3_RESUME) {
-    if (!mPlatformInfoHob.SmmSmramRequire) {
+  if (PlatformInfoHob->BootMode != BOOT_ON_S3_RESUME) {
+    if (!PlatformInfoHob->SmmSmramRequire) {
       ReserveEmuVariableNvStore ();
     }
 
-    PeiFvInitialization (&mPlatformInfoHob);
-    MemTypeInfoInitialization (&mPlatformInfoHob);
-    MemMapInitialization (&mPlatformInfoHob);
-    NoexecDxeInitialization (&mPlatformInfoHob);
+    PeiFvInitialization (PlatformInfoHob);
+    MemTypeInfoInitialization (PlatformInfoHob);
+    MemMapInitialization (PlatformInfoHob);
+    NoexecDxeInitialization (PlatformInfoHob);
   }
 
   InstallClearCacheCallback ();
-  AmdSevInitialize (&mPlatformInfoHob);
-  if (mPlatformInfoHob.HostBridgeDevId == 0xffff) {
-    MiscInitializationForMicrovm (&mPlatformInfoHob);
+  AmdSevInitialize (PlatformInfoHob);
+  if (PlatformInfoHob->HostBridgeDevId == 0xffff) {
+    MiscInitializationForMicrovm (PlatformInfoHob);
   } else {
-    MiscInitialization (&mPlatformInfoHob);
+    MiscInitialization (PlatformInfoHob);
   }
 
   IntelTdxInitialize ();
   InstallFeatureControlCallback ();
-  BuildPlatformInfoHob ();
 
   return EFI_SUCCESS;
 }
-- 
2.38.1


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

* [PATCH 11/14] OvmfPkg/PlatformPei: remove mFeatureControlValue
  2022-12-02 13:09 [PATCH 00/14] OvmfPkg: avoid global variables in PEI Gerd Hoffmann
                   ` (9 preceding siblings ...)
  2022-12-02 13:10 ` [PATCH 10/14] OvmfPkg/PlatformPei: remove mPlatformInfoHob Gerd Hoffmann
@ 2022-12-02 13:10 ` Gerd Hoffmann
  2022-12-02 13:10 ` [PATCH 12/14] OvmfPkg/DebugLibIoPort: use Rom version for PEI Gerd Hoffmann
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Gerd Hoffmann @ 2022-12-02 13:10 UTC (permalink / raw)
  To: devel
  Cc: Bob Feng, Yuwei Chen, Erdem Aktas, Jordan Justen, Peter Grehan,
	Rebecca Cran, Liming Gao, Ard Biesheuvel, Gerd Hoffmann,
	Jiewen Yao, Min Xu, Brijesh Singh, Oliver Steffen, Pawel Polawski,
	Tom Lendacky, James Bottomley

Use PlatformInfoHob->FeatureControlValue instead.
OnMpServicesAvailable() will find PlatformInfoHob using
GetFirstGuidHob() and pass a pointer to the WriteFeatureControl
callback.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 OvmfPkg/Include/Library/PlatformInitLib.h |  2 ++
 OvmfPkg/PlatformPei/Platform.h            |  2 +-
 OvmfPkg/PlatformPei/FeatureControl.c      | 44 ++++++++++++++++-------
 OvmfPkg/PlatformPei/Platform.c            |  2 +-
 4 files changed, 36 insertions(+), 14 deletions(-)

diff --git a/OvmfPkg/Include/Library/PlatformInitLib.h b/OvmfPkg/Include/Library/PlatformInitLib.h
index c5234bf26d45..da7ed76041d2 100644
--- a/OvmfPkg/Include/Library/PlatformInitLib.h
+++ b/OvmfPkg/Include/Library/PlatformInitLib.h
@@ -48,6 +48,8 @@ typedef struct {
 
   UINT32               S3AcpiReservedMemoryBase;
   UINT32               S3AcpiReservedMemorySize;
+
+  UINT64               FeatureControlValue;
 } EFI_HOB_PLATFORM_INFO;
 #pragma pack()
 
diff --git a/OvmfPkg/PlatformPei/Platform.h b/OvmfPkg/PlatformPei/Platform.h
index 86f603ff649c..1cf44844a781 100644
--- a/OvmfPkg/PlatformPei/Platform.h
+++ b/OvmfPkg/PlatformPei/Platform.h
@@ -70,7 +70,7 @@ MemTypeInfoInitialization (
 
 VOID
 InstallFeatureControlCallback (
-  VOID
+  IN OUT EFI_HOB_PLATFORM_INFO  *PlatformInfoHob
   );
 
 VOID
diff --git a/OvmfPkg/PlatformPei/FeatureControl.c b/OvmfPkg/PlatformPei/FeatureControl.c
index 5864ee0c214d..d8a398cd5565 100644
--- a/OvmfPkg/PlatformPei/FeatureControl.c
+++ b/OvmfPkg/PlatformPei/FeatureControl.c
@@ -8,6 +8,7 @@
 **/
 
 #include <Library/DebugLib.h>
+#include <Library/HobLib.h>
 #include <Library/PeiServicesLib.h>
 #include <Library/QemuFwCfgLib.h>
 #include <Ppi/MpServices.h>
@@ -16,11 +17,6 @@
 
 #include "Platform.h"
 
-//
-// The value to be written to the Feature Control MSR, retrieved from fw_cfg.
-//
-STATIC UINT64  mFeatureControlValue;
-
 /**
   Write the Feature Control MSR on an Application Processor or the Boot
   Processor.
@@ -38,10 +34,22 @@ WriteFeatureControl (
   IN OUT VOID  *WorkSpace
   )
 {
+  EFI_HOB_PLATFORM_INFO  *PlatformInfoHob = WorkSpace;
+
   if (TdIsEnabled ()) {
-    TdVmCall (TDVMCALL_WRMSR, (UINT64)MSR_IA32_FEATURE_CONTROL, mFeatureControlValue, 0, 0, 0);
+    TdVmCall (
+      TDVMCALL_WRMSR,
+      (UINT64)MSR_IA32_FEATURE_CONTROL,
+      PlatformInfoHob->FeatureControlValue,
+      0,
+      0,
+      0
+      );
   } else {
-    AsmWriteMsr64 (MSR_IA32_FEATURE_CONTROL, mFeatureControlValue);
+    AsmWriteMsr64 (
+      MSR_IA32_FEATURE_CONTROL,
+      PlatformInfoHob->FeatureControlValue
+      );
   }
 }
 
@@ -67,6 +75,15 @@ OnMpServicesAvailable (
 {
   EFI_PEI_MP_SERVICES_PPI  *MpServices;
   EFI_STATUS               Status;
+  EFI_HOB_PLATFORM_INFO    *PlatformInfoHob;
+  EFI_HOB_GUID_TYPE        *GuidHob;
+
+  GuidHob = GetFirstGuidHob (&gUefiOvmfPkgPlatformInfoGuid);
+  if (GuidHob == NULL) {
+    return EFI_UNSUPPORTED;
+  }
+
+  PlatformInfoHob = (EFI_HOB_PLATFORM_INFO *)GET_GUID_HOB_DATA (GuidHob);
 
   DEBUG ((DEBUG_VERBOSE, "%a: %a\n", gEfiCallerBaseName, __FUNCTION__));
 
@@ -80,7 +97,7 @@ OnMpServicesAvailable (
                              WriteFeatureControl, // Procedure
                              FALSE,               // SingleThread
                              0,                   // TimeoutInMicroSeconds: inf.
-                             NULL                 // ProcedureArgument
+                             PlatformInfoHob      // ProcedureArgument
                              );
   if (EFI_ERROR (Status) && (Status != EFI_NOT_STARTED)) {
     DEBUG ((DEBUG_ERROR, "%a: StartupAllAps(): %r\n", __FUNCTION__, Status));
@@ -90,7 +107,7 @@ OnMpServicesAvailable (
   //
   // Now write the MSR on the BSP too.
   //
-  WriteFeatureControl (NULL);
+  WriteFeatureControl (PlatformInfoHob);
   return EFI_SUCCESS;
 }
 
@@ -107,7 +124,7 @@ STATIC CONST EFI_PEI_NOTIFY_DESCRIPTOR  mMpServicesNotify = {
 
 VOID
 InstallFeatureControlCallback (
-  VOID
+  IN OUT EFI_HOB_PLATFORM_INFO  *PlatformInfoHob
   )
 {
   EFI_STATUS            Status;
@@ -119,7 +136,7 @@ InstallFeatureControlCallback (
              &FwCfgItem,
              &FwCfgSize
              );
-  if (EFI_ERROR (Status) || (FwCfgSize != sizeof mFeatureControlValue)) {
+  if (EFI_ERROR (Status) || (FwCfgSize != sizeof (PlatformInfoHob->FeatureControlValue))) {
     //
     // Nothing to do.
     //
@@ -127,7 +144,10 @@ InstallFeatureControlCallback (
   }
 
   QemuFwCfgSelectItem (FwCfgItem);
-  QemuFwCfgReadBytes (sizeof mFeatureControlValue, &mFeatureControlValue);
+  QemuFwCfgReadBytes (
+    sizeof (PlatformInfoHob->FeatureControlValue),
+    &(PlatformInfoHob->FeatureControlValue)
+    );
 
   Status = PeiServicesNotifyPpi (&mMpServicesNotify);
   if (EFI_ERROR (Status)) {
diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c
index ebce2ba1290e..148240342b4b 100644
--- a/OvmfPkg/PlatformPei/Platform.c
+++ b/OvmfPkg/PlatformPei/Platform.c
@@ -396,7 +396,7 @@ InitializePlatform (
   }
 
   IntelTdxInitialize ();
-  InstallFeatureControlCallback ();
+  InstallFeatureControlCallback (PlatformInfoHob);
 
   return EFI_SUCCESS;
 }
-- 
2.38.1


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

* [PATCH 12/14] OvmfPkg/DebugLibIoPort: use Rom version for PEI
  2022-12-02 13:09 [PATCH 00/14] OvmfPkg: avoid global variables in PEI Gerd Hoffmann
                   ` (10 preceding siblings ...)
  2022-12-02 13:10 ` [PATCH 11/14] OvmfPkg/PlatformPei: remove mFeatureControlValue Gerd Hoffmann
@ 2022-12-02 13:10 ` Gerd Hoffmann
  2022-12-02 13:10 ` [PATCH 13/14] OvmfPkg/QemuFwCfgLib: rewrite fw_cfg probe Gerd Hoffmann
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Gerd Hoffmann @ 2022-12-02 13:10 UTC (permalink / raw)
  To: devel
  Cc: Bob Feng, Yuwei Chen, Erdem Aktas, Jordan Justen, Peter Grehan,
	Rebecca Cran, Liming Gao, Ard Biesheuvel, Gerd Hoffmann,
	Jiewen Yao, Min Xu, Brijesh Singh, Oliver Steffen, Pawel Polawski,
	Tom Lendacky, James Bottomley

This variant does not use global variables.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 OvmfPkg/AmdSev/AmdSevX64.dsc                                  | 4 ++--
 OvmfPkg/Bhyve/BhyveX64.dsc                                    | 4 ++--
 OvmfPkg/Microvm/MicrovmX64.dsc                                | 4 ++--
 OvmfPkg/OvmfPkgIa32.dsc                                       | 4 ++--
 OvmfPkg/OvmfPkgIa32X64.dsc                                    | 4 ++--
 OvmfPkg/OvmfPkgX64.dsc                                        | 4 ++--
 .../PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf      | 2 +-
 7 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc
index 8f7cae787e97..cf051c83165e 100644
--- a/OvmfPkg/AmdSev/AmdSevX64.dsc
+++ b/OvmfPkg/AmdSev/AmdSevX64.dsc
@@ -244,7 +244,7 @@ [LibraryClasses.common.PEI_CORE]
 !ifdef $(DEBUG_ON_SERIAL_PORT)
   DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
 !else
-  DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
+  DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf
 !endif
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
 
@@ -260,7 +260,7 @@ [LibraryClasses.common.PEIM]
 !ifdef $(DEBUG_ON_SERIAL_PORT)
   DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
 !else
-  DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
+  DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf
 !endif
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
   ResourcePublicationLib|MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.inf
diff --git a/OvmfPkg/Bhyve/BhyveX64.dsc b/OvmfPkg/Bhyve/BhyveX64.dsc
index e3bb367b6bf6..befec670d4f3 100644
--- a/OvmfPkg/Bhyve/BhyveX64.dsc
+++ b/OvmfPkg/Bhyve/BhyveX64.dsc
@@ -265,7 +265,7 @@ [LibraryClasses.common.PEI_CORE]
 !ifdef $(DEBUG_ON_SERIAL_PORT)
   DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
 !else
-  DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
+  DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf
 !endif
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
 
@@ -281,7 +281,7 @@ [LibraryClasses.common.PEIM]
 !ifdef $(DEBUG_ON_SERIAL_PORT)
   DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
 !else
-  DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
+  DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf
 !endif
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
   ResourcePublicationLib|MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.inf
diff --git a/OvmfPkg/Microvm/MicrovmX64.dsc b/OvmfPkg/Microvm/MicrovmX64.dsc
index 994a02d30107..583e0cd12dc0 100644
--- a/OvmfPkg/Microvm/MicrovmX64.dsc
+++ b/OvmfPkg/Microvm/MicrovmX64.dsc
@@ -292,7 +292,7 @@ [LibraryClasses.common.PEI_CORE]
 !ifdef $(DEBUG_ON_SERIAL_PORT)
   DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
 !else
-  DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
+  DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf
 !endif
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
 
@@ -308,7 +308,7 @@ [LibraryClasses.common.PEIM]
 !ifdef $(DEBUG_ON_SERIAL_PORT)
   DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
 !else
-  DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
+  DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf
 !endif
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
   ResourcePublicationLib|MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.inf
diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
index 6f774baf90f5..23ed6fb2b659 100644
--- a/OvmfPkg/OvmfPkgIa32.dsc
+++ b/OvmfPkg/OvmfPkgIa32.dsc
@@ -294,7 +294,7 @@ [LibraryClasses.common.PEI_CORE]
 !ifdef $(DEBUG_ON_SERIAL_PORT)
   DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
 !else
-  DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
+  DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf
 !endif
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
 
@@ -310,7 +310,7 @@ [LibraryClasses.common.PEIM]
 !ifdef $(DEBUG_ON_SERIAL_PORT)
   DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
 !else
-  DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
+  DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf
 !endif
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
   ResourcePublicationLib|MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.inf
diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc
index c851764dec05..6ed5eadd163d 100644
--- a/OvmfPkg/OvmfPkgIa32X64.dsc
+++ b/OvmfPkg/OvmfPkgIa32X64.dsc
@@ -300,7 +300,7 @@ [LibraryClasses.common.PEI_CORE]
 !ifdef $(DEBUG_ON_SERIAL_PORT)
   DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
 !else
-  DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
+  DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf
 !endif
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
 
@@ -316,7 +316,7 @@ [LibraryClasses.common.PEIM]
 !ifdef $(DEBUG_ON_SERIAL_PORT)
   DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
 !else
-  DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
+  DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf
 !endif
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
   ResourcePublicationLib|MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.inf
diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index 63c3a47aea30..39bba265e877 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -318,7 +318,7 @@ [LibraryClasses.common.PEI_CORE]
 !ifdef $(DEBUG_ON_SERIAL_PORT)
   DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
 !else
-  DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
+  DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf
 !endif
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
   CcProbeLib|OvmfPkg/Library/CcProbeLib/SecPeiCcProbeLib.inf
@@ -335,7 +335,7 @@ [LibraryClasses.common.PEIM]
 !ifdef $(DEBUG_ON_SERIAL_PORT)
   DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
 !else
-  DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
+  DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf
 !endif
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
   ResourcePublicationLib|MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.inf
diff --git a/OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf b/OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf
index 8f721d249dd5..c89b1571bad8 100644
--- a/OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf
+++ b/OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf
@@ -16,7 +16,7 @@ [Defines]
   FILE_GUID                      = CEB0D9D3-328F-4C24-8C02-28FA1986AE1B
   MODULE_TYPE                    = BASE
   VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = DebugLib|SEC
+  LIBRARY_CLASS                  = DebugLib|SEC PEI_CORE PEIM
   CONSTRUCTOR                    = PlatformRomDebugLibIoPortConstructor
 
 #
-- 
2.38.1


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

* [PATCH 13/14] OvmfPkg/QemuFwCfgLib: rewrite fw_cfg probe
  2022-12-02 13:09 [PATCH 00/14] OvmfPkg: avoid global variables in PEI Gerd Hoffmann
                   ` (11 preceding siblings ...)
  2022-12-02 13:10 ` [PATCH 12/14] OvmfPkg/DebugLibIoPort: use Rom version for PEI Gerd Hoffmann
@ 2022-12-02 13:10 ` Gerd Hoffmann
  2022-12-02 13:10 ` [PATCH 14/14] OvmfPkg/QemuFwCfgLib: remove mQemuFwCfgSupported + mQemuFwCfgDmaSupported Gerd Hoffmann
  2022-12-12 16:58 ` [PATCH 00/14] OvmfPkg: avoid global variables in PEI Lendacky, Thomas
  14 siblings, 0 replies; 17+ messages in thread
From: Gerd Hoffmann @ 2022-12-02 13:10 UTC (permalink / raw)
  To: devel
  Cc: Bob Feng, Yuwei Chen, Erdem Aktas, Jordan Justen, Peter Grehan,
	Rebecca Cran, Liming Gao, Ard Biesheuvel, Gerd Hoffmann,
	Jiewen Yao, Min Xu, Brijesh Singh, Oliver Steffen, Pawel Polawski,
	Tom Lendacky, James Bottomley

Move the code to a new QemuFwCfgProbe() function.  Use direct Io*() calls
instead of indirect QemuFwCfg*() calls to make sure we don't get
recursive calls.  Also simplify CC guest detection.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 .../Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf  |   1 -
 OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPei.c   | 101 +++++++-----------
 2 files changed, 41 insertions(+), 61 deletions(-)

diff --git a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf
index 3910511880c9..1d7543a7d40f 100644
--- a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf
+++ b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf
@@ -41,7 +41,6 @@ [LibraryClasses]
   DebugLib
   IoLib
   MemoryAllocationLib
-  MemEncryptSevLib
 
 [Pcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase
diff --git a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPei.c b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPei.c
index 7ab7027af168..a936fd103955 100644
--- a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPei.c
+++ b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPei.c
@@ -13,7 +13,6 @@
 #include <Library/IoLib.h>
 #include <Library/DebugLib.h>
 #include <Library/QemuFwCfgLib.h>
-#include <Library/MemEncryptSevLib.h>
 #include <WorkArea.h>
 
 #include "QemuFwCfgLibInternal.h"
@@ -27,15 +26,16 @@ STATIC BOOLEAN  mQemuFwCfgDmaSupported;
   @retval    TRUE   It is Tdx guest
   @retval    FALSE  It is not Tdx guest
 **/
+STATIC
 BOOLEAN
-QemuFwCfgIsTdxGuest (
+QemuFwCfgIsCcGuest (
   VOID
   )
 {
   CONFIDENTIAL_COMPUTING_WORK_AREA_HEADER  *CcWorkAreaHeader;
 
   CcWorkAreaHeader = (CONFIDENTIAL_COMPUTING_WORK_AREA_HEADER *)FixedPcdGet32 (PcdOvmfWorkAreaBase);
-  return (CcWorkAreaHeader != NULL && CcWorkAreaHeader->GuestType == CcGuestTypeIntelTdx);
+  return (CcWorkAreaHeader != NULL && CcWorkAreaHeader->GuestType != CcGuestTypeNonEncrypted);
 }
 
 /**
@@ -57,62 +57,49 @@ QemuFwCfgIsAvailable (
   return InternalQemuFwCfgIsAvailable ();
 }
 
+STATIC
+VOID
+QemuFwCfgProbe (
+  BOOLEAN  *Supported,
+  BOOLEAN  *DmaSupported
+  )
+{
+  UINT32   Signature;
+  UINT32   Revision;
+  BOOLEAN  CcGuest;
+
+  // Use direct Io* calls for probing to avoid recursion.
+  IoWrite16 (FW_CFG_IO_SELECTOR, (UINT16)QemuFwCfgItemSignature);
+  IoReadFifo8 (FW_CFG_IO_DATA, sizeof Signature, &Signature);
+  IoWrite16 (FW_CFG_IO_SELECTOR, (UINT16)QemuFwCfgItemInterfaceVersion);
+  IoReadFifo8 (FW_CFG_IO_DATA, sizeof Revision, &Revision);
+  CcGuest = QemuFwCfgIsCcGuest ();
+
+  *Supported    = FALSE;
+  *DmaSupported = FALSE;
+  if ((Signature == SIGNATURE_32 ('Q', 'E', 'M', 'U')) && (Revision >= 1)) {
+    *Supported = TRUE;
+    if ((Revision & FW_CFG_F_DMA) && !CcGuest) {
+      *DmaSupported = TRUE;
+    }
+  }
+
+  DEBUG ((
+    DEBUG_INFO,
+    "%a: Supported %d, DMA %d\n",
+    __func__,
+    *Supported,
+    *DmaSupported
+    ));
+}
+
 RETURN_STATUS
 EFIAPI
 QemuFwCfgInitialize (
   VOID
   )
 {
-  UINT32  Signature;
-  UINT32  Revision;
-
-  //
-  // Enable the access routines while probing to see if it is supported.
-  // For probing we always use the IO Port (IoReadFifo8()) access method.
-  //
-  mQemuFwCfgSupported    = TRUE;
-  mQemuFwCfgDmaSupported = FALSE;
-
-  QemuFwCfgSelectItem (QemuFwCfgItemSignature);
-  Signature = QemuFwCfgRead32 ();
-  DEBUG ((DEBUG_INFO, "FW CFG Signature: 0x%x\n", Signature));
-  QemuFwCfgSelectItem (QemuFwCfgItemInterfaceVersion);
-  Revision = QemuFwCfgRead32 ();
-  DEBUG ((DEBUG_INFO, "FW CFG Revision: 0x%x\n", Revision));
-  if ((Signature != SIGNATURE_32 ('Q', 'E', 'M', 'U')) ||
-      (Revision < 1)
-      )
-  {
-    DEBUG ((DEBUG_INFO, "QemuFwCfg interface not supported.\n"));
-    mQemuFwCfgSupported = FALSE;
-    return RETURN_SUCCESS;
-  }
-
-  if ((Revision & FW_CFG_F_DMA) == 0) {
-    DEBUG ((DEBUG_INFO, "QemuFwCfg interface (IO Port) is supported.\n"));
-  } else {
-    //
-    // If SEV is enabled then we do not support DMA operations in PEI phase.
-    // This is mainly because DMA in SEV guest requires using bounce buffer
-    // (which need to allocate dynamic memory and allocating a PAGE size'd
-    // buffer can be challenge in PEI phase)
-    //
-    if (MemEncryptSevIsEnabled ()) {
-      DEBUG ((DEBUG_INFO, "SEV: QemuFwCfg fallback to IO Port interface.\n"));
-    } else if (QemuFwCfgIsTdxGuest ()) {
-      //
-      // If TDX is enabled then we do not support DMA operations in PEI phase.
-      // This is mainly because DMA in TDX guest requires using bounce buffer
-      // (which need to allocate dynamic memory and allocating a PAGE size'd
-      // buffer can be challenge in PEI phase)
-      //
-      DEBUG ((DEBUG_INFO, "TDX: QemuFwCfg fallback to IO Port interface.\n"));
-    } else {
-      mQemuFwCfgDmaSupported = TRUE;
-      DEBUG ((DEBUG_INFO, "QemuFwCfg interface (DMA) is supported.\n"));
-    }
-  }
-
+  QemuFwCfgProbe (&mQemuFwCfgSupported, &mQemuFwCfgDmaSupported);
   return RETURN_SUCCESS;
 }
 
@@ -183,17 +170,11 @@ InternalQemuFwCfgDmaBytes (
     return;
   }
 
-  //
-  // SEV does not support DMA operations in PEI stage, we should
-  // not have reached here.
-  //
-  ASSERT (!MemEncryptSevIsEnabled ());
-
   //
   // TDX does not support DMA operations in PEI stage, we should
   // not have reached here.
   //
-  ASSERT (!QemuFwCfgIsTdxGuest ());
+  ASSERT (!QemuFwCfgIsCcGuest ());
 
   Access.Control = SwapBytes32 (Control);
   Access.Length  = SwapBytes32 (Size);
-- 
2.38.1


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

* [PATCH 14/14] OvmfPkg/QemuFwCfgLib: remove mQemuFwCfgSupported + mQemuFwCfgDmaSupported
  2022-12-02 13:09 [PATCH 00/14] OvmfPkg: avoid global variables in PEI Gerd Hoffmann
                   ` (12 preceding siblings ...)
  2022-12-02 13:10 ` [PATCH 13/14] OvmfPkg/QemuFwCfgLib: rewrite fw_cfg probe Gerd Hoffmann
@ 2022-12-02 13:10 ` Gerd Hoffmann
  2022-12-12 16:58 ` [PATCH 00/14] OvmfPkg: avoid global variables in PEI Lendacky, Thomas
  14 siblings, 0 replies; 17+ messages in thread
From: Gerd Hoffmann @ 2022-12-02 13:10 UTC (permalink / raw)
  To: devel
  Cc: Bob Feng, Yuwei Chen, Erdem Aktas, Jordan Justen, Peter Grehan,
	Rebecca Cran, Liming Gao, Ard Biesheuvel, Gerd Hoffmann,
	Jiewen Yao, Min Xu, Brijesh Singh, Oliver Steffen, Pawel Polawski,
	Tom Lendacky, James Bottomley

Remove global variables, store the state in PlatformInfoHob instead.
Probing for fw_cfg happens on first use, at library initialization
time the Hob might not be present yet.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 .../Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf  |  4 ++
 OvmfPkg/Include/Library/PlatformInitLib.h     |  4 ++
 OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPei.c   | 44 ++++++++++++++++---
 3 files changed, 45 insertions(+), 7 deletions(-)

diff --git a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf
index 1d7543a7d40f..b1f548febcf7 100644
--- a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf
+++ b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf
@@ -39,8 +39,12 @@ [LibraryClasses]
   BaseLib
   BaseMemoryLib
   DebugLib
+  HobLib
   IoLib
   MemoryAllocationLib
 
+[Guids]
+  gUefiOvmfPkgPlatformInfoGuid
+
 [Pcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase
diff --git a/OvmfPkg/Include/Library/PlatformInitLib.h b/OvmfPkg/Include/Library/PlatformInitLib.h
index da7ed76041d2..bf6f90a5761c 100644
--- a/OvmfPkg/Include/Library/PlatformInitLib.h
+++ b/OvmfPkg/Include/Library/PlatformInitLib.h
@@ -50,6 +50,10 @@ typedef struct {
   UINT32               S3AcpiReservedMemorySize;
 
   UINT64               FeatureControlValue;
+
+  BOOLEAN              QemuFwCfgChecked;
+  BOOLEAN              QemuFwCfgSupported;
+  BOOLEAN              QemuFwCfgDmaSupported;
 } EFI_HOB_PLATFORM_INFO;
 #pragma pack()
 
diff --git a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPei.c b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPei.c
index a936fd103955..da86a3c84c02 100644
--- a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPei.c
+++ b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPei.c
@@ -9,17 +9,17 @@
   SPDX-License-Identifier: BSD-2-Clause-Patent
 **/
 
+#include <PiPei.h>
 #include <Library/BaseLib.h>
-#include <Library/IoLib.h>
 #include <Library/DebugLib.h>
+#include <Library/HobLib.h>
+#include <Library/IoLib.h>
+#include <Library/PlatformInitLib.h>
 #include <Library/QemuFwCfgLib.h>
 #include <WorkArea.h>
 
 #include "QemuFwCfgLibInternal.h"
 
-STATIC BOOLEAN  mQemuFwCfgSupported = FALSE;
-STATIC BOOLEAN  mQemuFwCfgDmaSupported;
-
 /**
   Check if it is Tdx guest
 
@@ -93,13 +93,39 @@ QemuFwCfgProbe (
     ));
 }
 
+STATIC
+EFI_HOB_PLATFORM_INFO *
+QemuFwCfgGetPlatformInfo (
+  VOID
+  )
+{
+  EFI_HOB_PLATFORM_INFO  *PlatformInfoHob;
+  EFI_HOB_GUID_TYPE      *GuidHob;
+
+  GuidHob = GetFirstGuidHob (&gUefiOvmfPkgPlatformInfoGuid);
+  if (GuidHob == NULL) {
+    return NULL;
+  }
+
+  PlatformInfoHob = (EFI_HOB_PLATFORM_INFO *)GET_GUID_HOB_DATA (GuidHob);
+
+  if (!PlatformInfoHob->QemuFwCfgChecked) {
+    QemuFwCfgProbe (
+      &PlatformInfoHob->QemuFwCfgSupported,
+      &PlatformInfoHob->QemuFwCfgDmaSupported
+      );
+    PlatformInfoHob->QemuFwCfgChecked = TRUE;
+  }
+
+  return PlatformInfoHob;
+}
+
 RETURN_STATUS
 EFIAPI
 QemuFwCfgInitialize (
   VOID
   )
 {
-  QemuFwCfgProbe (&mQemuFwCfgSupported, &mQemuFwCfgDmaSupported);
   return RETURN_SUCCESS;
 }
 
@@ -117,7 +143,9 @@ InternalQemuFwCfgIsAvailable (
   VOID
   )
 {
-  return mQemuFwCfgSupported;
+  EFI_HOB_PLATFORM_INFO  *PlatformInfoHob = QemuFwCfgGetPlatformInfo ();
+
+  return PlatformInfoHob->QemuFwCfgSupported;
 }
 
 /**
@@ -132,7 +160,9 @@ InternalQemuFwCfgDmaIsAvailable (
   VOID
   )
 {
-  return mQemuFwCfgDmaSupported;
+  EFI_HOB_PLATFORM_INFO  *PlatformInfoHob = QemuFwCfgGetPlatformInfo ();
+
+  return PlatformInfoHob->QemuFwCfgDmaSupported;
 }
 
 /**
-- 
2.38.1


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

* Re: [PATCH 00/14] OvmfPkg: avoid global variables in PEI
  2022-12-02 13:09 [PATCH 00/14] OvmfPkg: avoid global variables in PEI Gerd Hoffmann
                   ` (13 preceding siblings ...)
  2022-12-02 13:10 ` [PATCH 14/14] OvmfPkg/QemuFwCfgLib: remove mQemuFwCfgSupported + mQemuFwCfgDmaSupported Gerd Hoffmann
@ 2022-12-12 16:58 ` Lendacky, Thomas
  2022-12-14 17:26   ` Ard Biesheuvel
  14 siblings, 1 reply; 17+ messages in thread
From: Lendacky, Thomas @ 2022-12-12 16:58 UTC (permalink / raw)
  To: Gerd Hoffmann, devel
  Cc: Bob Feng, Yuwei Chen, Erdem Aktas, Jordan Justen, Peter Grehan,
	Rebecca Cran, Liming Gao, Ard Biesheuvel, Jiewen Yao, Min Xu,
	Brijesh Singh, Oliver Steffen, Pawel Polawski, James Bottomley

On 12/2/22 07:09, Gerd Hoffmann wrote:
> Writing to global variables changes the PEI firmware volume which in
> turn screws up firmware volume measurements.  Fix OvmfPkg to avoid that,
> for the most part by using the PlatformInfoHob instead.

Boot tested SEV, SEV-ES and SEV-SNP guests without issues. For the series:

Tested-by: Tom Lendacky <thomas.lendacky@amd.com>

> 
> Gerd Hoffmann (14):
>    tools_def: remove GCC_IA32_CC_FLAGS/GCC_X64_CC_FLAGS
>    tools_def: add -fno-omit-frame-pointer to GCC48_{IA32,X64}_CC_FLAGS
>    OvmfPkg/PlatformPei: AmdSev: stop using mPlatformInfoHob
>    OvmfPkg/PlatformPei: PeiFv: stop using mPlatformInfoHob
>    OvmfPkg/PlatformPei Q35 SMM helpers: stop using mPlatformInfoHob
>    OvmfPkg/PlatformPei: PeiMemory: stop using mPlatformInfoHob
>    OvmfPkg/PlatformPei: MemTypeInfo: stop using mPlatformInfoHob
>    OvmfPkg/PlatformPei: NoExec: stop using mPlatformInfoHob
>    OvmfPkg/PlatformPei: Verification: stop using mPlatformInfoHob
>    OvmfPkg/PlatformPei: remove mPlatformInfoHob
>    OvmfPkg/PlatformPei: remove mFeatureControlValue
>    OvmfPkg/DebugLibIoPort: use Rom version for PEI
>    OvmfPkg/QemuFwCfgLib: rewrite fw_cfg probe
>    OvmfPkg/QemuFwCfgLib: remove mQemuFwCfgSupported +
>      mQemuFwCfgDmaSupported
> 
>   OvmfPkg/AmdSev/AmdSevX64.dsc                  |   4 +-
>   OvmfPkg/Bhyve/BhyveX64.dsc                    |   4 +-
>   OvmfPkg/Microvm/MicrovmX64.dsc                |   4 +-
>   OvmfPkg/OvmfPkgIa32.dsc                       |   4 +-
>   OvmfPkg/OvmfPkgIa32X64.dsc                    |   4 +-
>   OvmfPkg/OvmfPkgX64.dsc                        |   4 +-
>   .../PlatformRomDebugLibIoPort.inf             |   2 +-
>   .../Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf  |   5 +-
>   OvmfPkg/Include/Library/PlatformInitLib.h     |   6 +
>   OvmfPkg/PlatformPei/Platform.h                |  18 +--
>   OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPei.c   | 143 ++++++++++--------
>   OvmfPkg/PlatformPei/AmdSev.c                  |  14 +-
>   OvmfPkg/PlatformPei/FeatureControl.c          |  44 ++++--
>   OvmfPkg/PlatformPei/Fv.c                      |   6 +-
>   OvmfPkg/PlatformPei/MemDetect.c               |  56 +++----
>   OvmfPkg/PlatformPei/MemTypeInfo.c             |   4 +-
>   OvmfPkg/PlatformPei/Platform.c                |  92 ++++++-----
>   BaseTools/Conf/tools_def.template             |   6 +-
>   18 files changed, 232 insertions(+), 188 deletions(-)
> 

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

* Re: [PATCH 00/14] OvmfPkg: avoid global variables in PEI
  2022-12-12 16:58 ` [PATCH 00/14] OvmfPkg: avoid global variables in PEI Lendacky, Thomas
@ 2022-12-14 17:26   ` Ard Biesheuvel
  0 siblings, 0 replies; 17+ messages in thread
From: Ard Biesheuvel @ 2022-12-14 17:26 UTC (permalink / raw)
  To: Tom Lendacky, Liming Gao, Bob Feng
  Cc: Gerd Hoffmann, devel, Yuwei Chen, Erdem Aktas, Jordan Justen,
	Peter Grehan, Rebecca Cran, Ard Biesheuvel, Jiewen Yao, Min Xu,
	Brijesh Singh, Oliver Steffen, Pawel Polawski, James Bottomley

On Mon, 12 Dec 2022 at 17:58, Tom Lendacky <thomas.lendacky@amd.com> wrote:
>
> On 12/2/22 07:09, Gerd Hoffmann wrote:
> > Writing to global variables changes the PEI firmware volume which in
> > turn screws up firmware volume measurements.  Fix OvmfPkg to avoid that,
> > for the most part by using the PlatformInfoHob instead.
>
> Boot tested SEV, SEV-ES and SEV-SNP guests without issues. For the series:
>
> Tested-by: Tom Lendacky <thomas.lendacky@amd.com>
>

Thanks, this look good to me so i'll pick up the OvmfPkg patches right away.

Liming, Bob, any objections against the BaseTools/ patches? (#1 and #2)

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

end of thread, other threads:[~2022-12-14 17:27 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-02 13:09 [PATCH 00/14] OvmfPkg: avoid global variables in PEI Gerd Hoffmann
2022-12-02 13:09 ` [PATCH 01/14] tools_def: remove GCC_IA32_CC_FLAGS/GCC_X64_CC_FLAGS Gerd Hoffmann
2022-12-02 13:09 ` [PATCH 02/14] tools_def: add -fno-omit-frame-pointer to GCC48_{IA32,X64}_CC_FLAGS Gerd Hoffmann
2022-12-02 13:09 ` [PATCH 03/14] OvmfPkg/PlatformPei: AmdSev: stop using mPlatformInfoHob Gerd Hoffmann
2022-12-02 13:09 ` [PATCH 04/14] OvmfPkg/PlatformPei: PeiFv: " Gerd Hoffmann
2022-12-02 13:10 ` [PATCH 05/14] OvmfPkg/PlatformPei Q35 SMM helpers: " Gerd Hoffmann
2022-12-02 13:10 ` [PATCH 06/14] OvmfPkg/PlatformPei: PeiMemory: " Gerd Hoffmann
2022-12-02 13:10 ` [PATCH 07/14] OvmfPkg/PlatformPei: MemTypeInfo: " Gerd Hoffmann
2022-12-02 13:10 ` [PATCH 08/14] OvmfPkg/PlatformPei: NoExec: " Gerd Hoffmann
2022-12-02 13:10 ` [PATCH 09/14] OvmfPkg/PlatformPei: Verification: " Gerd Hoffmann
2022-12-02 13:10 ` [PATCH 10/14] OvmfPkg/PlatformPei: remove mPlatformInfoHob Gerd Hoffmann
2022-12-02 13:10 ` [PATCH 11/14] OvmfPkg/PlatformPei: remove mFeatureControlValue Gerd Hoffmann
2022-12-02 13:10 ` [PATCH 12/14] OvmfPkg/DebugLibIoPort: use Rom version for PEI Gerd Hoffmann
2022-12-02 13:10 ` [PATCH 13/14] OvmfPkg/QemuFwCfgLib: rewrite fw_cfg probe Gerd Hoffmann
2022-12-02 13:10 ` [PATCH 14/14] OvmfPkg/QemuFwCfgLib: remove mQemuFwCfgSupported + mQemuFwCfgDmaSupported Gerd Hoffmann
2022-12-12 16:58 ` [PATCH 00/14] OvmfPkg: avoid global variables in PEI Lendacky, Thomas
2022-12-14 17:26   ` Ard Biesheuvel

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