TianoCore EDK2 master
Loading...
Searching...
No Matches
SecTdxHelper.c File Reference

Go to the source code of this file.

Macros

#define ALIGNED_2MB_MASK   0x1fffff
 
#define MEGABYTE_SHIFT   20
 
#define ACCEPT_CHUNK_SIZE   SIZE_32MB
 
#define AP_STACK_SIZE   SIZE_16KB
 
#define APS_STACK_SIZE(CpusNum)   (ALIGN_VALUE(CpusNum*AP_STACK_SIZE, SIZE_2MB))
 

Functions

EFI_STATUS InternalBuildGuidHobForTdxMeasurement (VOID)
 
STATIC EFI_STATUS EFIAPI BspAcceptMemoryResourceRange (IN EFI_PHYSICAL_ADDRESS PhysicalAddress, IN EFI_PHYSICAL_ADDRESS PhysicalEnd)
 
STATIC EFI_STATUS EFIAPI BspApAcceptMemoryResourceRange (UINT32 CpuIndex, UINT32 CpusNum, EFI_PHYSICAL_ADDRESS PhysicalStart, EFI_PHYSICAL_ADDRESS PhysicalEnd)
 
STATIC EFI_STATUS EFIAPI ApAcceptMemoryResourceRange (UINT32 CpuIndex, EFI_PHYSICAL_ADDRESS PhysicalStart, EFI_PHYSICAL_ADDRESS PhysicalEnd)
 
STATIC EFI_STATUS EFIAPI MpAcceptMemoryResourceRange (IN EFI_PHYSICAL_ADDRESS PhysicalStart, IN EFI_PHYSICAL_ADDRESS PhysicalEnd, IN OUT EFI_PHYSICAL_ADDRESS APsStackAddress, IN UINT32 CpusNum)
 
STATIC EFI_STATUS EFIAPI AcceptMemoryForAPsStack (IN CONST VOID *VmmHobList, IN UINT32 APsStackSize, OUT EFI_PHYSICAL_ADDRESS *PhysicalAddressEnd)
 
STATIC EFI_STATUS EFIAPI AcceptMemory (IN CONST VOID *VmmHobList, IN UINT32 CpusNum, IN EFI_PHYSICAL_ADDRESS APsStackStartAddress, IN EFI_PHYSICAL_ADDRESS PhysicalAddressStart)
 
STATIC BOOLEAN EFIAPI IsInValidList (IN UINT32 Value, IN UINT32 *ValidList, IN UINT32 ValidListLength)
 
STATIC BOOLEAN EFIAPI ValidateHobList (IN CONST VOID *VmmHobList)
 
STATIC EFI_STATUS EFIAPI ProcessHobList (IN CONST VOID *VmmHobList)
 
EFI_STATUS EFIAPI TdxHelperProcessTdHob (VOID)
 
STATIC EFI_STATUS HashAndExtendToRtmr (IN UINT32 RtmrIndex, IN VOID *DataToHash, IN UINTN DataToHashLen, OUT UINT8 *Digest, IN UINTN DigestLen)
 
EFI_STATUS EFIAPI TdxHelperMeasureTdHob (VOID)
 
EFI_STATUS EFIAPI TdxHelperMeasureCfvImage (VOID)
 
EFI_STATUS EFIAPI TdxHelperBuildGuidHobForTdxMeasurement (VOID)
 

Detailed Description

TdxHelper Functions which are used in SEC phase

Copyright (c) 2022 - 2023, Intel Corporation. All rights reserved.

SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file SecTdxHelper.c.

Macro Definition Documentation

◆ ACCEPT_CHUNK_SIZE

#define ACCEPT_CHUNK_SIZE   SIZE_32MB

Definition at line 30 of file SecTdxHelper.c.

◆ ALIGNED_2MB_MASK

#define ALIGNED_2MB_MASK   0x1fffff

Definition at line 27 of file SecTdxHelper.c.

◆ AP_STACK_SIZE

#define AP_STACK_SIZE   SIZE_16KB

Definition at line 31 of file SecTdxHelper.c.

◆ APS_STACK_SIZE

#define APS_STACK_SIZE (   CpusNum)    (ALIGN_VALUE(CpusNum*AP_STACK_SIZE, SIZE_2MB))

Definition at line 32 of file SecTdxHelper.c.

◆ MEGABYTE_SHIFT

#define MEGABYTE_SHIFT   20

Definition at line 28 of file SecTdxHelper.c.

Function Documentation

◆ AcceptMemory()

STATIC EFI_STATUS EFIAPI AcceptMemory ( IN CONST VOID *  VmmHobList,
IN UINT32  CpusNum,
IN EFI_PHYSICAL_ADDRESS  APsStackStartAddress,
IN EFI_PHYSICAL_ADDRESS  PhysicalAddressStart 
)

BSP and APs work togeter to accept memory which is under the address of 4G.

Parameters
[in]VmmHobListThe Hoblist pass the firmware
[in]CpusNumNumber of vCPUs
[in]APsStackStartAddresStart address of APs stack
[in]PhysicalAddressStartStart physical address which to be accepted
Return values
EFI_SUCCESSProcess the HobList successfully
OthersOther errors as indicated

Definition at line 404 of file SecTdxHelper.c.

◆ AcceptMemoryForAPsStack()

STATIC EFI_STATUS EFIAPI AcceptMemoryForAPsStack ( IN CONST VOID *  VmmHobList,
IN UINT32  APsStackSize,
OUT EFI_PHYSICAL_ADDRESS PhysicalAddressEnd 
)

BSP accept a small piece of memory which will be used as APs stack.

Parameters
[in]VmmHobListThe Hoblist pass the firmware
[in]APsStackSizeAPs stack size
[out]PhysicalAddressEndThe physical end address of accepted memory in phase-1
Return values
EFI_SUCCESSProcess the HobList successfully
OthersOther errors as indicated

Definition at line 326 of file SecTdxHelper.c.

◆ ApAcceptMemoryResourceRange()

STATIC EFI_STATUS EFIAPI ApAcceptMemoryResourceRange ( UINT32  CpuIndex,
EFI_PHYSICAL_ADDRESS  PhysicalStart,
EFI_PHYSICAL_ADDRESS  PhysicalEnd 
)

This function is called by APs to accept memory.

Parameters
CpuIndexvCPU index of an AP
PhysicalStartStart address of a memory region which is to be accepted
PhysicalEndEnd address of a memory region which is to be accepted
Return values
EFI_SUCCESSSuccessfully accept the memory
OthersOther errors as indicated

Definition at line 211 of file SecTdxHelper.c.

◆ BspAcceptMemoryResourceRange()

STATIC EFI_STATUS EFIAPI BspAcceptMemoryResourceRange ( IN EFI_PHYSICAL_ADDRESS  PhysicalAddress,
IN EFI_PHYSICAL_ADDRESS  PhysicalEnd 
)

This function will be called to accept pages. Only BSP accepts pages.

TDCALL(ACCEPT_PAGE) supports the accept page size of 4k and 2M. To simplify the implementation, the Memory to be accpeted is splitted into 3 parts: --------------— <– StartAddress1 (not 2M aligned) | part 1 | Length1 < 2M |------------—| <– StartAddress2 (2M aligned) | | Length2 = Integer multiples of 2M | part 2 | | | |------------—| <– StartAddress3 | part 3 | Length3 < 2M |------------—|

Parameters
[in]PhysicalAddressStart physical adress
[in]PhysicalEndEnd physical address
Return values
EFI_SUCCESSAccept memory successfully
OthersOther errors as indicated

Definition at line 71 of file SecTdxHelper.c.

◆ BspApAcceptMemoryResourceRange()

STATIC EFI_STATUS EFIAPI BspApAcceptMemoryResourceRange ( UINT32  CpuIndex,
UINT32  CpusNum,
EFI_PHYSICAL_ADDRESS  PhysicalStart,
EFI_PHYSICAL_ADDRESS  PhysicalEnd 
)

This function is called by BSP and APs to accept memory. Note: The input PhysicalStart/PhysicalEnd indicates the whole memory region to be accepted. BSP or AP only accepts one piece in the whole memory region.

Parameters
CpuIndexvCPU index
CpusNumTotal vCPU number of a Tdx guest
PhysicalStartStart address of a memory region which is to be accepted
PhysicalEndEnd address of a memory region which is to be accepted
Return values
EFI_SUCCESSSuccessfully accept the memory
OtherOther errors as indicated

Definition at line 169 of file SecTdxHelper.c.

◆ HashAndExtendToRtmr()

STATIC EFI_STATUS HashAndExtendToRtmr ( IN UINT32  RtmrIndex,
IN VOID *  DataToHash,
IN UINTN  DataToHashLen,
OUT UINT8 *  Digest,
IN UINTN  DigestLen 
)

Calculate the sha384 of input Data and extend it to RTMR register.

Parameters
RtmrIndexIndex of the RTMR register
DataToHashData to be hashed
DataToHashLenLength of the data
DigestHash value of the input data
DigestLenLength of the hash value
Return values
EFI_SUCCESSSuccessfully hash and extend to RTMR
OthersOther errors as indicated

Definition at line 823 of file SecTdxHelper.c.

◆ InternalBuildGuidHobForTdxMeasurement()

EFI_STATUS InternalBuildGuidHobForTdxMeasurement ( VOID  )

Build the GuidHob for tdx measurements which were done in SEC phase. The measurement values are stored in WorkArea.

Return values
EFI_SUCCESSThe GuidHob is built successfully
OthersOther errors as indicated

Definition at line 173 of file TdxMeasurementHob.c.

◆ IsInValidList()

STATIC BOOLEAN EFIAPI IsInValidList ( IN UINT32  Value,
IN UINT32 *  ValidList,
IN UINT32  ValidListLength 
)

Check the value whether in the valid list.

Parameters
[in]ValueA value
[in]ValidListA pointer to valid list
[in]ValidListLengthLength of valid list
Return values
TRUEThe value is in valid list.
FALSEThe value is not in valid list.

Definition at line 505 of file SecTdxHelper.c.

◆ MpAcceptMemoryResourceRange()

STATIC EFI_STATUS EFIAPI MpAcceptMemoryResourceRange ( IN EFI_PHYSICAL_ADDRESS  PhysicalStart,
IN EFI_PHYSICAL_ADDRESS  PhysicalEnd,
IN OUT EFI_PHYSICAL_ADDRESS  APsStackAddress,
IN UINT32  CpusNum 
)

This function is called by BSP. It coordinates BSP/APs to accept memory together.

Parameters
PhysicalStartStart address of a memory region which is to be accepted
PhysicalEndEnd address of a memory region which is to be accepted
APsStackAddressAPs stack address
CpusNumTotal vCPU number of the Tdx guest
Return values
EFI_SUCCESSSuccessfully accept the memory
OthersOther errors as indicated

Definition at line 248 of file SecTdxHelper.c.

◆ ProcessHobList()

STATIC EFI_STATUS EFIAPI ProcessHobList ( IN CONST VOID *  VmmHobList)

Processing the incoming HobList for the TDX

Firmware must parse list, and accept the pages of memory before their can be use by the guest.

Parameters
[in]VmmHobListThe Hoblist pass the firmware
Return values
EFI_SUCCESSProcess the HobList successfully
OthersOther errors as indicated

Definition at line 726 of file SecTdxHelper.c.

◆ TdxHelperBuildGuidHobForTdxMeasurement()

EFI_STATUS EFIAPI TdxHelperBuildGuidHobForTdxMeasurement ( VOID  )

Build the GuidHob for tdx measurements which were done in SEC phase. The measurement values are stored in WorkArea.

Return values
EFI_SUCCESSThe GuidHob is built successfully
OthersOther errors as indicated

Definition at line 972 of file SecTdxHelper.c.

◆ TdxHelperMeasureCfvImage()

EFI_STATUS EFIAPI TdxHelperMeasureCfvImage ( VOID  )

In Tdx guest, Configuration FV (CFV) is treated as external input because it may contain the data provided by VMM. From the sucurity perspective Cfv image should be measured before it is consumed.

Return values
EFI_SUCCESSSuccessfully measure the CFV image
OthersOther error as indicated

Definition at line 928 of file SecTdxHelper.c.

◆ TdxHelperMeasureTdHob()

EFI_STATUS EFIAPI TdxHelperMeasureTdHob ( VOID  )

In Tdx guest, TdHob is passed from host VMM to guest firmware and it contains the information of the memory resource. From the security perspective before it is consumed, it should be measured and extended.

Return values
EFI_SUCCESSSuccessfully measure the TdHob
OthersOther error as indicated

Definition at line 871 of file SecTdxHelper.c.

◆ TdxHelperProcessTdHob()

EFI_STATUS EFIAPI TdxHelperProcessTdHob ( VOID  )

In Tdx guest, some information need to be passed from host VMM to guest firmware. For example, the memory resource, etc. These information are prepared by host VMM and put in TdHob which is described in TdxMetadata. TDVF processes the TdHob to accept memories.

Return values
EFI_SUCCESSSuccessfully process the TdHob
OthersOther error as indicated

Definition at line 773 of file SecTdxHelper.c.

◆ ValidateHobList()

STATIC BOOLEAN EFIAPI ValidateHobList ( IN CONST VOID *  VmmHobList)

Check the integrity of VMM Hob List.

Parameters
[in]VmmHobListA pointer to Hob List
Return values
TRUEThe Hob List is valid.
FALSEThe Hob List is invalid.

Definition at line 538 of file SecTdxHelper.c.