From 02e5acdcfa10eebc86f1600b40f3cf999fd64521 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Thu, 15 Dec 2022 13:31:46 +0100 Subject: [PATCH] backport https://github.com/tianocore/edk2/pull/3770 --- ...Pei-AmdSev-stop-using-mPlatformInfoH.patch | 116 +++++++++++ ...Pei-PeiFv-stop-using-mPlatformInfoHo.patch | 78 ++++++++ ...Pei-Q35-SMM-helpers-stop-using-mPlat.patch | 134 +++++++++++++ ...Pei-PeiMemory-stop-using-mPlatformIn.patch | 160 +++++++++++++++ ...Pei-MemTypeInfo-stop-using-mPlatform.patch | 67 +++++++ ...Pei-NoExec-stop-using-mPlatformInfoH.patch | 54 ++++++ ...Pei-Verification-stop-using-mPlatfor.patch | 85 ++++++++ ...-PlatformPei-remove-mPlatformInfoHob.patch | 177 +++++++++++++++++ ...tformPei-remove-mFeatureControlValue.patch | 176 +++++++++++++++++ ...bugLibIoPort-use-Rom-version-for-PEI.patch | 169 ++++++++++++++++ ...kg-QemuFwCfgLib-rewrite-fw_cfg-probe.patch | 183 ++++++++++++++++++ ...gLib-remove-mQemuFwCfgSupported-mQem.patch | 144 ++++++++++++++ edk2.spec | 17 +- 13 files changed, 1559 insertions(+), 1 deletion(-) create mode 100644 0020-OvmfPkg-PlatformPei-AmdSev-stop-using-mPlatformInfoH.patch create mode 100644 0021-OvmfPkg-PlatformPei-PeiFv-stop-using-mPlatformInfoHo.patch create mode 100644 0022-OvmfPkg-PlatformPei-Q35-SMM-helpers-stop-using-mPlat.patch create mode 100644 0023-OvmfPkg-PlatformPei-PeiMemory-stop-using-mPlatformIn.patch create mode 100644 0024-OvmfPkg-PlatformPei-MemTypeInfo-stop-using-mPlatform.patch create mode 100644 0025-OvmfPkg-PlatformPei-NoExec-stop-using-mPlatformInfoH.patch create mode 100644 0026-OvmfPkg-PlatformPei-Verification-stop-using-mPlatfor.patch create mode 100644 0027-OvmfPkg-PlatformPei-remove-mPlatformInfoHob.patch create mode 100644 0028-OvmfPkg-PlatformPei-remove-mFeatureControlValue.patch create mode 100644 0029-OvmfPkg-DebugLibIoPort-use-Rom-version-for-PEI.patch create mode 100644 0030-OvmfPkg-QemuFwCfgLib-rewrite-fw_cfg-probe.patch create mode 100644 0031-OvmfPkg-QemuFwCfgLib-remove-mQemuFwCfgSupported-mQem.patch diff --git a/0020-OvmfPkg-PlatformPei-AmdSev-stop-using-mPlatformInfoH.patch b/0020-OvmfPkg-PlatformPei-AmdSev-stop-using-mPlatformInfoH.patch new file mode 100644 index 0000000..cd27dcb --- /dev/null +++ b/0020-OvmfPkg-PlatformPei-AmdSev-stop-using-mPlatformInfoH.patch @@ -0,0 +1,116 @@ +From 4e22a4d1c1d7b492d1e1eee4fa81c697e0d59314 Mon Sep 17 00:00:00 2001 +From: Gerd Hoffmann +Date: Fri, 2 Dec 2022 14:09:58 +0100 +Subject: [PATCH 20/32] OvmfPkg/PlatformPei: AmdSev: stop using + mPlatformInfoHob + +Stop using the mPlatformInfoHob global variable in AmdSevInitialize() +and AmdSevEsInitialize() functions. Pass a pointer to the +PlatformInfoHob instead. + +Signed-off-by: Gerd Hoffmann +Tested-by: Tom Lendacky +Acked-by: Ard Biesheuvel +(cherry picked from commit 78c373f2a5273af00b23b55d3e8c41583310cfb6) +--- + 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 e5132d95a8f8..14a75d40c005 100644 +--- a/OvmfPkg/PlatformPei/Platform.c ++++ b/OvmfPkg/PlatformPei/Platform.c +@@ -392,7 +392,7 @@ InitializePlatform ( + } + + InstallClearCacheCallback (); +- AmdSevInitialize (); ++ AmdSevInitialize (&mPlatformInfoHob); + if (mPlatformInfoHob.HostBridgeDevId == 0xffff) { + MiscInitializationForMicrovm (&mPlatformInfoHob); + } else { +-- +2.38.1 + diff --git a/0021-OvmfPkg-PlatformPei-PeiFv-stop-using-mPlatformInfoHo.patch b/0021-OvmfPkg-PlatformPei-PeiFv-stop-using-mPlatformInfoHo.patch new file mode 100644 index 0000000..96900a5 --- /dev/null +++ b/0021-OvmfPkg-PlatformPei-PeiFv-stop-using-mPlatformInfoHo.patch @@ -0,0 +1,78 @@ +From 8d45eeb9bbec1085b31b8b5ede6145bf9458566c Mon Sep 17 00:00:00 2001 +From: Gerd Hoffmann +Date: Fri, 2 Dec 2022 14:09:59 +0100 +Subject: [PATCH 21/32] OvmfPkg/PlatformPei: PeiFv: stop using mPlatformInfoHob + +Stop using the mPlatformInfoHob global variable in PeiFvInitialization() +function. Pass a pointer to the PlatformInfoHob instead. + +Signed-off-by: Gerd Hoffmann +Tested-by: Tom Lendacky +Acked-by: Ard Biesheuvel +(cherry picked from commit 9d9d15b42a5e13bb18729da0f608c629aa274e80) +--- + 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 14a75d40c005..5ecd5d8b1ab6 100644 +--- a/OvmfPkg/PlatformPei/Platform.c ++++ b/OvmfPkg/PlatformPei/Platform.c +@@ -384,7 +384,7 @@ InitializePlatform ( + ReserveEmuVariableNvStore (); + } + +- PeiFvInitialization (); ++ PeiFvInitialization (&mPlatformInfoHob); + MemTypeInfoInitialization (); + MemMapInitialization (&mPlatformInfoHob); + NoexecDxeInitialization (); +-- +2.38.1 + diff --git a/0022-OvmfPkg-PlatformPei-Q35-SMM-helpers-stop-using-mPlat.patch b/0022-OvmfPkg-PlatformPei-Q35-SMM-helpers-stop-using-mPlat.patch new file mode 100644 index 0000000..1d063a4 --- /dev/null +++ b/0022-OvmfPkg-PlatformPei-Q35-SMM-helpers-stop-using-mPlat.patch @@ -0,0 +1,134 @@ +From 1f0cc9c8bbc387a3e39daea604931fc819ba1650 Mon Sep 17 00:00:00 2001 +From: Gerd Hoffmann +Date: Fri, 2 Dec 2022 14:10:00 +0100 +Subject: [PATCH 22/32] OvmfPkg/PlatformPei Q35 SMM helpers: stop using + mPlatformInfoHob + +Stop using the mPlatformInfoHob global variable in +Q35TsegMbytesInitialization() and +Q35SmramAtDefaultSmbaseInitialization() ) functions. +Pass a pointer to the PlatformInfoHob instead. + +Signed-off-by: Gerd Hoffmann +Tested-by: Tom Lendacky +Acked-by: Ard Biesheuvel +(cherry picked from commit 00743d144bc5b643e9323ad66f16cb48cf338705) +--- + 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 5ecd5d8b1ab6..402b2e88461e 100644 +--- a/OvmfPkg/PlatformPei/Platform.c ++++ b/OvmfPkg/PlatformPei/Platform.c +@@ -369,8 +369,8 @@ InitializePlatform ( + + if (mPlatformInfoHob.SmmSmramRequire) { + Q35BoardVerification (); +- Q35TsegMbytesInitialization (); +- Q35SmramAtDefaultSmbaseInitialization (); ++ Q35TsegMbytesInitialization (&mPlatformInfoHob); ++ Q35SmramAtDefaultSmbaseInitialization (&mPlatformInfoHob); + } + + PublishPeiMemory (); +-- +2.38.1 + diff --git a/0023-OvmfPkg-PlatformPei-PeiMemory-stop-using-mPlatformIn.patch b/0023-OvmfPkg-PlatformPei-PeiMemory-stop-using-mPlatformIn.patch new file mode 100644 index 0000000..6f048b4 --- /dev/null +++ b/0023-OvmfPkg-PlatformPei-PeiMemory-stop-using-mPlatformIn.patch @@ -0,0 +1,160 @@ +From 44d2137d1bc1c3768b7c75843d6c40ef7491e630 Mon Sep 17 00:00:00 2001 +From: Gerd Hoffmann +Date: Fri, 2 Dec 2022 14:10:01 +0100 +Subject: [PATCH 23/32] OvmfPkg/PlatformPei: PeiMemory: stop using + mPlatformInfoHob + +Stop using the mPlatformInfoHob global variable in PublishPeiMemory() +and GetPeiMemoryCap() functions. Pass a pointer to the PlatformInfoHob +instead. + +Signed-off-by: Gerd Hoffmann +Tested-by: Tom Lendacky +Acked-by: Ard Biesheuvel +(cherry picked from commit 27874a382c38a95d3ab613eebd35c152ca9b3897) +--- + 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 402b2e88461e..0d5ead724d3f 100644 +--- a/OvmfPkg/PlatformPei/Platform.c ++++ b/OvmfPkg/PlatformPei/Platform.c +@@ -373,7 +373,7 @@ InitializePlatform ( + Q35SmramAtDefaultSmbaseInitialization (&mPlatformInfoHob); + } + +- PublishPeiMemory (); ++ PublishPeiMemory (&mPlatformInfoHob); + + PlatformQemuUc32BaseInitialization (&mPlatformInfoHob); + +-- +2.38.1 + diff --git a/0024-OvmfPkg-PlatformPei-MemTypeInfo-stop-using-mPlatform.patch b/0024-OvmfPkg-PlatformPei-MemTypeInfo-stop-using-mPlatform.patch new file mode 100644 index 0000000..cfeddda --- /dev/null +++ b/0024-OvmfPkg-PlatformPei-MemTypeInfo-stop-using-mPlatform.patch @@ -0,0 +1,67 @@ +From 63ce5d51b90f213ec2281b6da8c1def59f9acaf8 Mon Sep 17 00:00:00 2001 +From: Gerd Hoffmann +Date: Fri, 2 Dec 2022 14:10:02 +0100 +Subject: [PATCH 24/32] OvmfPkg/PlatformPei: MemTypeInfo: stop using + mPlatformInfoHob + +Stop using the mPlatformInfoHob global variable in MemTypeInfoInitialization() +function. Pass a pointer to the PlatformInfoHob instead. + +Signed-off-by: Gerd Hoffmann +Tested-by: Tom Lendacky +Acked-by: Ard Biesheuvel +(cherry picked from commit cc6efda7770b8cabea3ae8c6054d47c4a8e229c3) +--- + 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 0d5ead724d3f..c0273091326c 100644 +--- a/OvmfPkg/PlatformPei/Platform.c ++++ b/OvmfPkg/PlatformPei/Platform.c +@@ -385,7 +385,7 @@ InitializePlatform ( + } + + PeiFvInitialization (&mPlatformInfoHob); +- MemTypeInfoInitialization (); ++ MemTypeInfoInitialization (&mPlatformInfoHob); + MemMapInitialization (&mPlatformInfoHob); + NoexecDxeInitialization (); + UPDATE_BOOLEAN_PCD_FROM_FW_CFG (PcdResizeXterm); +-- +2.38.1 + diff --git a/0025-OvmfPkg-PlatformPei-NoExec-stop-using-mPlatformInfoH.patch b/0025-OvmfPkg-PlatformPei-NoExec-stop-using-mPlatformInfoH.patch new file mode 100644 index 0000000..06c2833 --- /dev/null +++ b/0025-OvmfPkg-PlatformPei-NoExec-stop-using-mPlatformInfoH.patch @@ -0,0 +1,54 @@ +From 6c10dc63b0753d9e241274d1cac62c0af406256e Mon Sep 17 00:00:00 2001 +From: Gerd Hoffmann +Date: Fri, 2 Dec 2022 14:10:03 +0100 +Subject: [PATCH 25/32] OvmfPkg/PlatformPei: NoExec: stop using + mPlatformInfoHob + +Stop using the mPlatformInfoHob global variable in NoexecDxeInitialization() +function. Pass a pointer to the PlatformInfoHob instead. + +Signed-off-by: Gerd Hoffmann +Tested-by: Tom Lendacky +Acked-by: Ard Biesheuvel +(cherry picked from commit 7dbb8a24d1a3403f85d959bc1234b9f4a92bfbf0) +--- + 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 c0273091326c..8307a80617fc 100644 +--- a/OvmfPkg/PlatformPei/Platform.c ++++ b/OvmfPkg/PlatformPei/Platform.c +@@ -87,16 +87,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); + } + } +@@ -387,7 +388,7 @@ InitializePlatform ( + PeiFvInitialization (&mPlatformInfoHob); + MemTypeInfoInitialization (&mPlatformInfoHob); + MemMapInitialization (&mPlatformInfoHob); +- NoexecDxeInitialization (); ++ NoexecDxeInitialization (&mPlatformInfoHob); + UPDATE_BOOLEAN_PCD_FROM_FW_CFG (PcdResizeXterm); + } + +-- +2.38.1 + diff --git a/0026-OvmfPkg-PlatformPei-Verification-stop-using-mPlatfor.patch b/0026-OvmfPkg-PlatformPei-Verification-stop-using-mPlatfor.patch new file mode 100644 index 0000000..dcb5dea --- /dev/null +++ b/0026-OvmfPkg-PlatformPei-Verification-stop-using-mPlatfor.patch @@ -0,0 +1,85 @@ +From d9fb9c50028ab90b0a1b044c9d13f3143f6093aa Mon Sep 17 00:00:00 2001 +From: Gerd Hoffmann +Date: Fri, 2 Dec 2022 14:10:04 +0100 +Subject: [PATCH 26/32] OvmfPkg/PlatformPei: Verification: stop using + mPlatformInfoHob + +Stop using the mPlatformInfoHob global variable in S3Verification() and +Q35BoardVerification() functions. Pass a pointer to the PlatformInfoHob +instead. + +Signed-off-by: Gerd Hoffmann +Tested-by: Tom Lendacky +Acked-by: Ard Biesheuvel +(cherry picked from commit 4bc2c748516e5c4a8bb86093cd5e1b80a9f35c0f) +--- + 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 8307a80617fc..6e31c5fc1f41 100644 +--- a/OvmfPkg/PlatformPei/Platform.c ++++ b/OvmfPkg/PlatformPei/Platform.c +@@ -243,13 +243,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", +@@ -272,12 +273,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; + } + +@@ -286,7 +288,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); +@@ -357,7 +359,7 @@ InitializePlatform ( + ASSERT_EFI_ERROR (Status); + } + +- S3Verification (); ++ S3Verification (&mPlatformInfoHob); + BootModeInitialization (&mPlatformInfoHob); + + // +@@ -369,7 +371,7 @@ InitializePlatform ( + MaxCpuCountInitialization (&mPlatformInfoHob); + + if (mPlatformInfoHob.SmmSmramRequire) { +- Q35BoardVerification (); ++ Q35BoardVerification (&mPlatformInfoHob); + Q35TsegMbytesInitialization (&mPlatformInfoHob); + Q35SmramAtDefaultSmbaseInitialization (&mPlatformInfoHob); + } +-- +2.38.1 + diff --git a/0027-OvmfPkg-PlatformPei-remove-mPlatformInfoHob.patch b/0027-OvmfPkg-PlatformPei-remove-mPlatformInfoHob.patch new file mode 100644 index 0000000..5fa1df9 --- /dev/null +++ b/0027-OvmfPkg-PlatformPei-remove-mPlatformInfoHob.patch @@ -0,0 +1,177 @@ +From 0aa971e9b02ff1b380c5363a5a543bc4e2b9532f Mon Sep 17 00:00:00 2001 +From: Gerd Hoffmann +Date: Fri, 2 Dec 2022 14:10:05 +0100 +Subject: [PATCH 27/32] OvmfPkg/PlatformPei: remove mPlatformInfoHob + +Stop using the mPlatformInfoHob global variable. Let +BuildPlatformInfoHob() allocate and return PlatformInfoHob instead. + +Signed-off-by: Gerd Hoffmann +Tested-by: Tom Lendacky +Acked-by: Ard Biesheuvel +(cherry picked from commit 862614e2544997c848fab7388733774ae0ea92d8) +--- + 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 + #include + +-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 6e31c5fc1f41..ee72b4ef24aa 100644 +--- a/OvmfPkg/PlatformPei/Platform.c ++++ b/OvmfPkg/PlatformPei/Platform.c +@@ -53,8 +53,6 @@ + } \ + } while (0) + +-EFI_HOB_PLATFORM_INFO mPlatformInfoHob = { 0 }; +- + EFI_PEI_PPI_DESCRIPTOR mPpiBootMode[] = { + { + EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST, +@@ -317,12 +315,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); + } + + /** +@@ -341,70 +345,71 @@ 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); + UPDATE_BOOLEAN_PCD_FROM_FW_CFG (PcdResizeXterm); + } + + 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 + diff --git a/0028-OvmfPkg-PlatformPei-remove-mFeatureControlValue.patch b/0028-OvmfPkg-PlatformPei-remove-mFeatureControlValue.patch new file mode 100644 index 0000000..a9dae02 --- /dev/null +++ b/0028-OvmfPkg-PlatformPei-remove-mFeatureControlValue.patch @@ -0,0 +1,176 @@ +From f0d41555cc5b42bd284c8ee1f3b419c612a9a8ca Mon Sep 17 00:00:00 2001 +From: Gerd Hoffmann +Date: Fri, 2 Dec 2022 14:10:06 +0100 +Subject: [PATCH 28/32] OvmfPkg/PlatformPei: remove mFeatureControlValue + +Use PlatformInfoHob->FeatureControlValue instead. +OnMpServicesAvailable() will find PlatformInfoHob using +GetFirstGuidHob() and pass a pointer to the WriteFeatureControl +callback. + +Signed-off-by: Gerd Hoffmann +Tested-by: Tom Lendacky +Acked-by: Ard Biesheuvel +(cherry picked from commit f6a196c7eb34affff0cfe1864e126953096885e1) +--- + 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 ++#include + #include + #include + #include +@@ -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 ee72b4ef24aa..d324ae95f8f5 100644 +--- a/OvmfPkg/PlatformPei/Platform.c ++++ b/OvmfPkg/PlatformPei/Platform.c +@@ -409,7 +409,7 @@ InitializePlatform ( + } + + IntelTdxInitialize (); +- InstallFeatureControlCallback (); ++ InstallFeatureControlCallback (PlatformInfoHob); + + return EFI_SUCCESS; + } +-- +2.38.1 + diff --git a/0029-OvmfPkg-DebugLibIoPort-use-Rom-version-for-PEI.patch b/0029-OvmfPkg-DebugLibIoPort-use-Rom-version-for-PEI.patch new file mode 100644 index 0000000..3361245 --- /dev/null +++ b/0029-OvmfPkg-DebugLibIoPort-use-Rom-version-for-PEI.patch @@ -0,0 +1,169 @@ +From b0f503de63b9f177d5457956025567806066bfb3 Mon Sep 17 00:00:00 2001 +From: Gerd Hoffmann +Date: Fri, 2 Dec 2022 14:10:07 +0100 +Subject: [PATCH 29/32] OvmfPkg/DebugLibIoPort: use Rom version for PEI + +This variant does not use global variables. + +Signed-off-by: Gerd Hoffmann +Tested-by: Tom Lendacky +Acked-by: Ard Biesheuvel +(cherry picked from commit e59747bd8246135faeecc18879d62db66a6acfc2) +--- + 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 05908a72270f..ea755afbab82 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 3444304d0e46..97339d48a5ef 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 9c0fb7d545b8..72e623a65a38 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 8b93437044e7..55ceb5c3420b 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 8c9162db1743..6cef37c10822 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 + diff --git a/0030-OvmfPkg-QemuFwCfgLib-rewrite-fw_cfg-probe.patch b/0030-OvmfPkg-QemuFwCfgLib-rewrite-fw_cfg-probe.patch new file mode 100644 index 0000000..af711fe --- /dev/null +++ b/0030-OvmfPkg-QemuFwCfgLib-rewrite-fw_cfg-probe.patch @@ -0,0 +1,183 @@ +From 64d555122ee65151008255a30173a3608006ae25 Mon Sep 17 00:00:00 2001 +From: Gerd Hoffmann +Date: Fri, 2 Dec 2022 14:10:08 +0100 +Subject: [PATCH 30/32] OvmfPkg/QemuFwCfgLib: rewrite fw_cfg probe + +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 +Tested-by: Tom Lendacky +Acked-by: Ard Biesheuvel +(cherry picked from commit 81bbc1452c972218f071cd4a8f5899df974b1dae) +--- + .../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 + #include + #include +-#include + #include + + #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 + diff --git a/0031-OvmfPkg-QemuFwCfgLib-remove-mQemuFwCfgSupported-mQem.patch b/0031-OvmfPkg-QemuFwCfgLib-remove-mQemuFwCfgSupported-mQem.patch new file mode 100644 index 0000000..14e6450 --- /dev/null +++ b/0031-OvmfPkg-QemuFwCfgLib-remove-mQemuFwCfgSupported-mQem.patch @@ -0,0 +1,144 @@ +From ed22693f4fc4d780c19280a7a26438b7c9d84ecd Mon Sep 17 00:00:00 2001 +From: Gerd Hoffmann +Date: Fri, 2 Dec 2022 14:10:09 +0100 +Subject: [PATCH 31/32] OvmfPkg/QemuFwCfgLib: remove mQemuFwCfgSupported + + mQemuFwCfgDmaSupported + +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 +Tested-by: Tom Lendacky +Acked-by: Ard Biesheuvel +(cherry picked from commit cda98df16228970dcf9a4ce2af5368219711b4b0) +--- + .../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 + #include +-#include + #include ++#include ++#include ++#include + #include + #include + + #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 + diff --git a/edk2.spec b/edk2.spec index 04c7f41..70d841d 100644 --- a/edk2.spec +++ b/edk2.spec @@ -35,7 +35,7 @@ ExclusiveArch: x86_64 aarch64 Name: edk2 Version: %{GITDATE}git%{GITCOMMIT} -Release: 6%{?dist} +Release: 7%{?dist} Summary: UEFI firmware for 64-bit virtual machines License: BSD-2-Clause-Patent and OpenSSL and MIT URL: http://www.tianocore.org @@ -92,6 +92,18 @@ Patch0016: 0016-tools_def-add-fno-omit-frame-pointer-to-GCC48_-IA32-.patch Patch0017: 0017-Revert-ArmVirtPkg-make-EFI_LOADER_DATA-non-executabl.patch Patch0018: 0018-Revert-OvmfPkg-PlatformDxe-Handle-all-requests-in-Ex.patch Patch0019: 0019-OvmfPkg-SmbiosPlatformDxe-use-PcdFirmware.patch +Patch0020: 0020-OvmfPkg-PlatformPei-AmdSev-stop-using-mPlatformInfoH.patch +Patch0021: 0021-OvmfPkg-PlatformPei-PeiFv-stop-using-mPlatformInfoHo.patch +Patch0022: 0022-OvmfPkg-PlatformPei-Q35-SMM-helpers-stop-using-mPlat.patch +Patch0023: 0023-OvmfPkg-PlatformPei-PeiMemory-stop-using-mPlatformIn.patch +Patch0024: 0024-OvmfPkg-PlatformPei-MemTypeInfo-stop-using-mPlatform.patch +Patch0025: 0025-OvmfPkg-PlatformPei-NoExec-stop-using-mPlatformInfoH.patch +Patch0026: 0026-OvmfPkg-PlatformPei-Verification-stop-using-mPlatfor.patch +Patch0027: 0027-OvmfPkg-PlatformPei-remove-mPlatformInfoHob.patch +Patch0028: 0028-OvmfPkg-PlatformPei-remove-mFeatureControlValue.patch +Patch0029: 0029-OvmfPkg-DebugLibIoPort-use-Rom-version-for-PEI.patch +Patch0030: 0030-OvmfPkg-QemuFwCfgLib-rewrite-fw_cfg-probe.patch +Patch0031: 0031-OvmfPkg-QemuFwCfgLib-remove-mQemuFwCfgSupported-mQem.patch # python3-devel and libuuid-devel are required for building tools. @@ -598,6 +610,9 @@ done %changelog +* Thu Dec 15 2022 Gerd Hoffmann - 20221117gitfff6d81270b5-7 +- backport https://github.com/tianocore/edk2/pull/3770 + * Mon Dec 12 2022 Gerd Hoffmann - 20221117gitfff6d81270b5-6 - fix ovmf platform config (revert broken commit). - show version information in smbios (backport).