From: Min M Xu <min.m.xu@...>
QEMU command option -pflash is not supported in Tdx guest. When Tdx guest
is booted, EmuVariableFvbRuntimeDxe driver is loaded and the NvVarStore
is initialized with empty content. This patch is to initialize the
NvVarStore with the content of Configuration FV (CFV).
Cc: Erdem Aktas <erdemaktas@...>
Cc: James Bottomley <jejb@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Signed-off-by: Min Xu <min.m.xu@...>
---
OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c | 19 +++++++++++++++++++
OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf | 2 ++
2 files changed, 21 insertions(+)
diff --git a/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c b/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c
index 4fc715dc3681..96895272d806 100644
--- a/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c
+++ b/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c
@@ -717,6 +717,8 @@ FvbInitialize (
EFI_HANDLE Handle;
EFI_PHYSICAL_ADDRESS Address;
RETURN_STATUS PcdStatus;
+ UINT8 *CfvBase;
+ UINT32 CfvSize;
DEBUG ((DEBUG_INFO, "EMU Variable FVB Started\n"));
@@ -774,6 +776,23 @@ FvbInitialize (
mEmuVarsFvb.BufferPtr = Ptr;
+ //
+ // In Tdx guest the VarNvStore content should be initialized by the Configuration FV (CFV).
+ // Integrity of the CFV has been validated by TdxValidateCfv (@PlatformInitLib)
+ //
+ if (TdIsEnabled ()) {
+ CfvBase = (UINT8 *)(UINTN)PcdGet32 (PcdCfvBase);
+ CfvSize = (UINT32)PcdGet32 (PcdCfvRawDataSize);
+
+ if (CfvSize > mEmuVarsFvb.Size) {
+ DEBUG ((DEBUG_ERROR, "Size of CFV is larger than the EMU Variable FVB.\n"));
+ ASSERT (FALSE);
+ } else {
+ CopyMem (Ptr, CfvBase, CfvSize);
+ Initialize = FALSE;
+ }
+ }
+
//
// Initialize the main FV header and variable store header
//
diff --git a/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf b/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf
index 0811545cf7b3..15e8e673e8a0 100644
--- a/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf
+++ b/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf
@@ -56,6 +56,8 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
+ gUefiOvmfPkgTokenSpaceGuid.PcdCfvBase
+ gUefiOvmfPkgTokenSpaceGuid.PcdCfvRawDataSize
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64
--
2.29.2.windows.2