]> xenbits.xensource.com Git - people/aperard/ovmf.git/commitdiff
OvmfPkg: Use TdInfo instead of fw_cfg to get cpu count in TDVF
authorCeping Sun <cepingx.sun@intel.com>
Wed, 28 Aug 2024 23:34:47 +0000 (07:34 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Fri, 13 Sep 2024 18:10:08 +0000 (18:10 +0000)
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 <erdemaktas@google.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Min Xu <min.m.xu@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Elena Reshetova <elena.reshetova@intel.com>
Signed-off-by: Ceping Sun <cepingx.sun@intel.com>
OvmfPkg/Library/PlatformInitLib/Platform.c
OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf
OvmfPkg/OvmfPkgIa32.dsc

index c2e0430d22697b623e590773b99ce6b107dbc7be..10fc17355fac3e2870d50a253bd1e197e217d191 100644 (file)
@@ -33,6 +33,7 @@
 #include <Guid/SystemNvDataGuid.h>\r
 #include <Guid/VariableFormat.h>\r
 #include <OvmfPlatforms.h>\r
+#include <Library/TdxLib.h>\r
 \r
 #include <Library/PlatformInitLib.h>\r
 \r
@@ -563,6 +564,20 @@ PlatformMaxCpuCountInitialization (
   UINT16  BootCpuCount = 0;\r
   UINT32  MaxCpuCount;\r
 \r
+  if (TdIsEnabled ()) {\r
+    BootCpuCount = (UINT16)TdVCpuNum ();\r
+    MaxCpuCount  = TdMaxVCpuNum ();\r
+\r
+    if (BootCpuCount > MaxCpuCount) {\r
+      DEBUG ((DEBUG_ERROR, "%a: Failed with BootCpuCount (%d) more than MaxCpuCount(%u) \n", __func__, BootCpuCount, MaxCpuCount));\r
+      ASSERT (FALSE);\r
+    }\r
+\r
+    PlatformInfoHob->PcdCpuMaxLogicalProcessorNumber  = MaxCpuCount;\r
+    PlatformInfoHob->PcdCpuBootLogicalProcessorNumber = BootCpuCount;\r
+    return;\r
+  }\r
+\r
   //\r
   // Try to fetch the boot CPU count.\r
   //\r
index e9c07467bbf0d7bf1196b69b32d847df42ec23ab..3e63ef44239afa681de331ff6e0f871f9dd98967 100644 (file)
@@ -53,8 +53,6 @@
   PcdLib\r
   PciLib\r
   PeiHardwareInfoLib\r
-\r
-[LibraryClasses.X64]\r
   TdxLib\r
 \r
 [Guids]\r
index 5e2086eb3309e18883dfb6df49418e4426283c15..34f7b9958bda6c432007447b5dc67f8e9abc6d08 100644 (file)
   AmdSvsmLib|UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.inf\r
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf\r
   CcExitLib|UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf\r
+  TdxLib|MdePkg/Library/TdxLib/TdxLib.inf\r
   TdxMailboxLib|OvmfPkg/Library/TdxMailboxLib/TdxMailboxLibNull.inf\r
 \r
 [LibraryClasses.common.SEC]\r