From ec18fa81d311663e24e9b9ad61b90b38862a1ea8 Mon Sep 17 00:00:00 2001 From: Ceping Sun Date: Thu, 29 Aug 2024 07:34:47 +0800 Subject: OvmfPkg: Use TdInfo instead of fw_cfg to get cpu count in TDVF Currently TDVF gets cpu count information via fw_cfg, but this information can also be retrieved by calling of TdCall.TdInfo. And TdCall is responded by tdx-module which is trust. So, from the security perspective we shall use TdCall.Tdinfo instead of fw_cfg. Cc: Erdem Aktas Cc: Jiewen Yao Cc: Min Xu Cc: Gerd Hoffmann Cc: Elena Reshetova Signed-off-by: Ceping Sun --- OvmfPkg/Library/PlatformInitLib/Platform.c | 15 +++++++++++++++ OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf | 2 -- OvmfPkg/OvmfPkgIa32.dsc | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) (limited to 'OvmfPkg') diff --git a/OvmfPkg/Library/PlatformInitLib/Platform.c b/OvmfPkg/Library/PlatformInitLib/Platform.c index c2e0430d22..10fc17355f 100644 --- a/OvmfPkg/Library/PlatformInitLib/Platform.c +++ b/OvmfPkg/Library/PlatformInitLib/Platform.c @@ -33,6 +33,7 @@ #include #include #include +#include #include @@ -563,6 +564,20 @@ PlatformMaxCpuCountInitialization ( UINT16 BootCpuCount = 0; UINT32 MaxCpuCount; + if (TdIsEnabled ()) { + BootCpuCount = (UINT16)TdVCpuNum (); + MaxCpuCount = TdMaxVCpuNum (); + + if (BootCpuCount > MaxCpuCount) { + DEBUG ((DEBUG_ERROR, "%a: Failed with BootCpuCount (%d) more than MaxCpuCount(%u) \n", __func__, BootCpuCount, MaxCpuCount)); + ASSERT (FALSE); + } + + PlatformInfoHob->PcdCpuMaxLogicalProcessorNumber = MaxCpuCount; + PlatformInfoHob->PcdCpuBootLogicalProcessorNumber = BootCpuCount; + return; + } + // // Try to fetch the boot CPU count. // diff --git a/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf b/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf index e9c07467bb..3e63ef4423 100644 --- a/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf +++ b/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf @@ -53,8 +53,6 @@ PcdLib PciLib PeiHardwareInfoLib - -[LibraryClasses.X64] TdxLib [Guids] diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 5e2086eb33..34f7b9958b 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -251,6 +251,7 @@ AmdSvsmLib|UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.inf BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf CcExitLib|UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf + TdxLib|MdePkg/Library/TdxLib/TdxLib.inf TdxMailboxLib|OvmfPkg/Library/TdxMailboxLib/TdxMailboxLibNull.inf [LibraryClasses.common.SEC] -- cgit v1.2.3