From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web08.5676.1655519541534598350 for ; Fri, 17 Jun 2022 19:32:27 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=Okpy6uPQ; spf=pass (domain: intel.com, ip: 134.134.136.24, mailfrom: min.m.xu@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1655519546; x=1687055546; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Cy87WcGzCSMXXNHfXnYjBa/s3r1TvIbiG2HelrGa8a8=; b=Okpy6uPQbFlpuQu73E9FErkTH8U5/z3dAowhl08haIzvWn1RNaN1OYkR eSLcFirb9k11vOWVQvIczGw3VyNYsI2KQ4rTfWSfuIFplM8XKJ7AjmZoH owQZGXEsyR9AJp+/0/7ZmzVVbNP8J2IaVM8mqNr7i3NV4cVmSx2aLI89V yCtRTGTlhp+NpAtMnw9ZDH/mqLvhxJNzI0leBm3El88RJKrYyOqrbw0+m 2pIw7VfdDOUXagZrndkGyu2fhZc6rMWOTutNPFEnFvPetlcMEcH0fmbhx 6pDNiX5/zPWklAah/33ha/ruAvQZkNDBVVS0Ml5nJ5cjM595/Gc70irD7 g==; X-IronPort-AV: E=McAfee;i="6400,9594,10380"; a="280355770" X-IronPort-AV: E=Sophos;i="5.92,306,1650956400"; d="scan'208";a="280355770" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jun 2022 19:32:26 -0700 X-IronPort-AV: E=Sophos;i="5.92,306,1650956400"; d="scan'208";a="642270321" Received: from mxu9-mobl1.ccr.corp.intel.com ([10.249.173.231]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jun 2022 19:32:24 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Erdem Aktas , James Bottomley , Jiewen Yao , Gerd Hoffmann , Tom Lendacky Subject: [PATCH 3/3] OvmfPkg: Initialize NvVarStore with Configuration FV in Td guest Date: Sat, 18 Jun 2022 10:32:03 +0800 Message-Id: X-Mailer: git-send-email 2.29.2.windows.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: 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 Cc: James Bottomley Cc: Jiewen Yao Cc: Gerd Hoffmann Cc: Tom Lendacky Signed-off-by: Min 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