Skip to content

Commit

Permalink
OvmfPkg: Use TdInfo instead of fw_cfg to get cpu count in TDVF
Browse files Browse the repository at this point in the history
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 <[email protected]>
Cc: Jiewen Yao <[email protected]>
Cc: Min Xu <[email protected]>
Cc: Gerd Hoffmann <[email protected]>
Cc: Elena Reshetova <[email protected]>
Signed-off-by: Ceping Sun <[email protected]>
  • Loading branch information
sunceping committed Sep 4, 2024
1 parent 1240a72 commit d32b2f0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
15 changes: 15 additions & 0 deletions OvmfPkg/Library/PlatformInitLib/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <Guid/SystemNvDataGuid.h>
#include <Guid/VariableFormat.h>
#include <OvmfPlatforms.h>
#include <Library/TdxLib.h>

#include <Library/PlatformInitLib.h>

Expand Down Expand Up @@ -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.
//
Expand Down
2 changes: 0 additions & 2 deletions OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@
PcdLib
PciLib
PeiHardwareInfoLib

[LibraryClasses.X64]
TdxLib

[Guids]
Expand Down
1 change: 1 addition & 0 deletions OvmfPkg/OvmfPkgIa32.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit d32b2f0

Please sign in to comment.