[edk2-devel] [PATCH V3 8/8] OvmfPkg: Introduce IntelTdxX64 for TDVF Config-B

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 Intel's Trust Domain Extensions (Intel TDX) refers to an Intel technology that extends Virtual Machines Extensions (VMX) and Multi-Key Total Memory Encryption (MKTME) with a new kind of virutal machines guest called a Trust Domain (TD). A TD

[edk2-devel] [PATCH V3 7/8] OvmfPkg: Update DxeAcpiTimerLib to read HostBridgeDevId in PlatformInfoHob

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 The entrypoint of DxeAcpiTimerLib checks HostBridgeDevId by reading PcdOvmfHostBridgePciDevId. If the DevId is not set, ASSERT is triggered. Normally this DevId is set in PlatformPei which is executed in PEI phase. This patch-set is introdu

[edk2-devel] [PATCH V3 6/8] OvmfPkg: Update TdxDxe to set TDX PCDs

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 TDX_PEI_LESS_BOOT indicates the boot without PEI phase. In this case settings in EFI_HOB_PLATFORM_INFO should be set to its according PCDs. TdxDxe driver is workable for both Legacy guest and Tdx guest. It is because for Legacy guest (in PEI

[edk2-devel] [PATCH V3 5/8] OvmfPkg/IntelTdx: Add Sec to bring up both Legacy and Tdx guest

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 OvmfPkg/IntelTdx/Sec is a simplied version of OvmfPkg/Sec. There are below differences between these 2 Sec - IntelTdx/Sec only supports Legacy guest and Tdx guest in X64. - IntelTdx/Sec calls TdxStartup () to jump from SEC to DXE directly.

[edk2-devel] [PATCH V3 4/8] OvmfPkg: Add TdxStartupLib

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 TdxStarupLib provides a function (TdxStartup ()) which brings up both Legacy and Tdx guest from SEC phase to DXE phase. PEI phase is skipped so that the attack surfaces are reduced as much as possible. TdxStartup() does below tasks: 1. Cont

[edk2-devel] [PATCH V3 3/8] OvmfPkg: Update EFI_HOB_PLATFORM_INFO with more platform settings

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 This patch-sets is to bring up Legacy guest and Tdx guest without PEI phase. So platform initialization has to be done in SEC phase. It is similar to the work of OvmfPkg/PlatformPei. In OvmfPkg/PlatformPei some PCDs are set during platform i

[edk2-devel] [PATCH V3 2/8] OvmfPkg: Add PrePiHobListPointerLibTdx

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 This library sets / gets the Hob list pointer in TDX_WORK_AREA. This is because it is designed to be used in SEC where the value of global variable cannot be saved, so the Hob list pointer is saved in TDX_WORK_AREA. TDX_WORK_AREA shares the

[edk2-devel] [PATCH V3 1/8] OvmfPkg: Add TdxWorkArea definition

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 Add the TDX work area definition. Cc: Michael D Kinney Cc: Brijesh Singh Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Cc: Gerd Hoffmann Acked-by: Gerd Hoffmann Signed-off-by: Min Xu --- OvmfPkg/Include/WorkA

[edk2-devel] [PATCH V3 0/8] Introduce TDVF Config-B (basic) in OvmfPkg

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 Intel's Trust Domain Extensions (Intel TDX) refers to an Intel technology that extends Virtual Machines Extensions (VMX) and Multi-Key Total Memory Encryption (MKTME) with a new kind of virutal machines guest called a Trust Domain (TD). A TD

[edk2-devel] [PATCH V6 40/42] OvmfPkg: Rename XenTimerDxe to LocalApicTimerDxe

2022-02-19 Thread Min Xu
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3711 XenTimerDxe is a local Apic timer driver and it has nothing to do with Xen. So rename it to LocalApicTimerDxe. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Brijesh Singh Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky

[edk2-devel] [PATCH V6 39/42] OvmfPkg: Update IoMmuDxe to support TDX

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 The IOMMU protocol driver provides capabilities to set a DMA access attribute and methods to allocate, free, map and unmap the DMA memory for the PCI Bus devices. The current IoMmuDxe driver supports DMA operations inside SEV guest. To supp

[edk2-devel] [PATCH V6 38/42] OvmfPkg/QemuFwCfgLib: Support Tdx in QemuFwCfgDxe

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 In the previous QemuFwCfgDxe only SEV is supported. This commit introduce TDX support in QemuFwCfgDxe. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Brijesh Singh Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Cc: Ger

[edk2-devel] [PATCH V6 37/42] OvmfPkg: Add TdxDxe driver

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 TdxDxe driver is dispatched early in DXE, due to being list in APRIORI. This module is responsible for below features: - Sets max logical cpus based on TDINFO - Sets PCI PCDs based on resource hobs - Set shared bit in MMIO region - Reloc

[edk2-devel] [PATCH V6 34/42] OvmfPkg: Update PlatformPei to support Tdx guest

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 OvmfPkg/PlatformPei is updated to support Tdx guest. There are below major changes. - Set Tdx related PCDs - Build Tdx PlatformInfoHob - Publish Tdx RamRegions Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Brijesh Singh Cc: Erdem Aktas Cc

[edk2-devel] [PATCH V6 33/42] OvmfPkg: Update PlatformInitLib for Tdx guest to publish ram regions

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 In Tdx guest, the system memory is passed in TdHob by host VMM. So the major task of PlatformTdxPublishRamRegions is to walk thru the TdHob list and transfer the ResourceDescriptorHob and MemoryAllocationHob to the hobs in DXE phase. Memory

[edk2-devel] [PATCH V6 35/42] OvmfPkg: Update AcpiPlatformDxe to alter MADT table

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 In TDX the guest firmware is designed to publish a multiprocessor-wakeup structure to let the guest-bootstrap processor wake up guest-application processors with a mailbox. The mailbox is memory that the guest firmware can reserve so each gu

[edk2-devel] [PATCH V6 36/42] OvmfPkg/BaseMemEncryptTdxLib: Add TDX helper library

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 Add Intel Tdx helper library. The library provides the routines to: - set or clear Shared bit for a given memory region. - query whether TDX is enabled. Please be noted, there a lot of duplicated codes for Page Table operations. These cod

[edk2-devel] [PATCH V6 27/42] OvmfPkg/Sec: Declare local variable as volatile in SecCoreStartupWithStack

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 Declare the local variables in SecCoreStartupWithStack that actually move the data elements as volatile to prevent the optimizer from replacing this function with the intrinsic memcpy(). Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Brijesh Si

[edk2-devel] [PATCH V6 28/42] OvmfPkg: Update Sec to support Tdx

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 There are below major changes in this commit. 1. SecEntry.nasm In TDX BSP and APs goes to the same entry point in SecEntry.nasm. BSP initialize the temporary stack and then jumps to SecMain, just as legacy Ovmf does. APs spin in a modifie

[edk2-devel] [PATCH V6 31/42] MdeModulePkg: Add PcdTdxSharedBitMask

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 Guest Physical Address (GPA) space in Td guest is divided into private and shared sub-spaces, determined by the SHARED bit of GPA. This PCD holds the shared bit mask. Its default value is 0 and it will be set in PlatformPei driver if it is o

[edk2-devel] [PATCH V6 30/42] MdeModulePkg: EFER should not be changed in TDX

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 In TDX IA32_ERER is RO to host VMM. It could not be changed. PcdIa32EferChangeAllowed is added in MdeModulePkg.dec and it is to be set to FALSE in Tdx guest. Cc: Jian J Wang Cc: Hao A Wu Cc: Brijesh Singh Cc: Erdem Aktas Cc: James Botto

[edk2-devel] [PATCH V6 29/42] OvmfPkg: Check Tdx in QemuFwCfgPei to avoid DMA operation

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 If TDX is enabled then we do not support DMA operation in PEI phase. This is mainly because DMA in TDX guest requires using bounce buffer (which need to allocate dynamic memory and allocating a PAGE size'd buffer can be challenge in PEI phas

[edk2-devel] [PATCH V6 32/42] UefiCpuPkg: Update AddressEncMask in CpuPageTable

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 MMIO region in Tdx guest is set with PcdTdxSharedBitMask in TdxDxe's entry point. In SEV guest the page table entries is set with PcdPteMemoryEncryptionAddressOrMask when creating 1:1 identity table. So the AddressEncMask in GetPageTableEnt

[edk2-devel] [PATCH V6 26/42] OvmfPkg: Add null instance of PlatformInitLib

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 Add null instance of PlatformInitLib. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Brijesh Singh Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Cc: Gerd Hoffmann Signed-off-by: Min Xu --- .../PlatformInitLib/Platf

[edk2-devel] [PATCH V6 25/42] OvmfPkg: Update PlatformInitLib to process Tdx hoblist

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 When host VMM create the Td guest, the system memory informations are stored in TdHob, which is a memory region described in Tdx metadata. The system memory region in TdHob should be accepted before it can be accessed. So the newly added fun

[edk2-devel] [PATCH V6 23/42] OvmfPkg/PlatformInitLib: Add platform functions

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 Below platform functions are introducted in PlatformInitLib: - PlatformMaxCpuCountInitialization - PlatformMemMapInitialization - PlatformNoexecDxeInitialization - PlatformMiscInitialization They correspond to the below functions in Ovm

[edk2-devel] [PATCH V6 22/42] OvmfPkg/PlatformPei: Update memory functions with PlatformInitLib

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 Memory functions in OvmfPkg/PlatformPei are updated with the ones in PlatformInitLib. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Brijesh Singh Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Cc: Gerd Hoffmann Signe

[edk2-devel] [PATCH V6 21/42] OvmfPkg/PlatformInitLib: Add memory functions

2022-02-19 Thread Min Xu
Below functions are introduced in PlatformInitLib: - PlatformGetFirstNonAddress - PlatformAddressWidthInitialization - PlatformGetSystemMemorySizeBelow4gb - PlatformQemuUc32BaseInitialization - PlatformInitializeRamRegions They correspond to the below functions in OvmfPkg/PlatformPei: - GetF

[edk2-devel] [PATCH V6 20/42] OvmfPkg/PlatformPei: Update hob functions PlatformInitLib

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 Hob functions in OvmfPkg/PlatformPei are updated with the ones in PlatformInitLib. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Brijesh Singh Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Cc: Gerd Hoffmann Signed-o

[edk2-devel] [PATCH V6 19/42] OvmfPkg/PlatformInitLib: Add hob functions

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 In this patch of PlatformInitLib, below hob functions are introduced: - PlatformAddIoMemoryBaseSizeHob - PlatformAddIoMemoryRangeHob - PlatformAddMemoryBaseSizeHob - PlatformAddMemoryRangeHob - PlatformAddReservedMemoryBaseSizeHob They

[edk2-devel] [PATCH V6 18/42] OvmfPkg/PlatformPei: Update Cmos functions with PlatformInitLib

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 Update the Cmos functions in OvmfPkg/PlatformPei with PlatformInitLib. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Brijesh Singh Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Cc: Gerd Hoffmann Signed-off-by: Min X

[edk2-devel] [PATCH V6 17/42] OvmfPkg: Create initial version of PlatformInitLib

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 There are 3 variants of PlatformPei in OvmfPkg: - OvmfPkg/PlatformPei - OvmfPkg/XenPlatformPei - OvmfPkg/Bhyve/PlatformPei/PlatformPei.inf These PlatformPeis can share many common codes, such as Cmos / Hob / Memory / Platform related func

[edk2-devel] [PATCH V6 16/42] MdePkg: Add EFI_RESOURCE_ATTRIBUTE_ENCRYPTED in PiHob.h

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 EFI_RESOURCE_ATTRIBUTE_ENCRYPTED is Physical memory encrypted attribute. It indicates the memory uses platform encrpytion capabilities for protection. If this bit is clear, the memory does not use platform encryption protection. Cc: Ard Bie

[edk2-devel] [PATCH V6 15/42] OvmfPkg: Add TdxMailboxLib

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 In Tdx BSP may issues commands to APs for some task, for example, to accept pages paralelly. BSP also need to wait until all the APs have done the task. TdxMailboxLib wraps these common funtions for BSP. Cc: Ard Biesheuvel Cc: Jordan Juste

[edk2-devel] [PATCH V6 14/42] OvmfPkg: Add IntelTdx.h in OvmfPkg/Include/IndustryStandard

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 IntelTdx.h defines the defition used by TDX in OvmfPkg: - Mailbox related defitions,such as the data structure, command code, AP relocation defitions. See Table 5.44 Multiprocessor Wakeup Mailbox Structure in below link. https://uefi.or

[edk2-devel] [PATCH V6 13/42] UefiCpuPkg: Enable Tdx support in MpInitLib

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 In TDVF BSP and APs are simplified. BSP is the vCPU-0, while the others are treated as APs. So MP intialization is rather simple. The processor info is retrieved by TDCALL, ApWorker is not supported, BSP is always the working processor, whi

[edk2-devel] [PATCH V6 12/42] MdePkg: Add macro to check SEV / TDX guest

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 Add macros CC_GUEST_IS_SEV / CC_GUEST_IS_TDX to check SEV / TDX guest. Cc: Michael Roth Cc: Ray Ni Cc: Rahul Kumar Cc: Eric Dong Cc: James Bottomley Cc: Min Xu Cc: Jiewen Yao Cc: Tom Lendacky Cc: Jordan Justen Cc: Ard Biesheuvel C

[edk2-devel] [PATCH V6 11/42] UefiCpuPkg: Support TDX in BaseXApicX2ApicLib

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 MSR is accessed in BaseXApicX2ApicLib. In TDX some MSRs are accessed directly from/to CPU. Some should be accessed via explicit requests from the host VMM using TDCALL(TDG.VP.VMCALL). This is done by the help of TdxLib. Please refer to [TDX

[edk2-devel] [PATCH V6 10/42] MdePkg: Support IoRead/IoWrite for Tdx guest in BaseIoLibIntrinsic

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 This commit supports IoRead/IoWrite for SEV/TDX/Legacy guest in one binary. It checks the guest type in runtime and then call corresponding functions. Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Cc: Brijesh Singh Cc: Erdem Akta

[edk2-devel] [PATCH V6 09/42] MdePkg: Support IoFifo for Tdx guest in BaseIoLibIntrinsic

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 Previously IoFifo functions are in X64/IoFifoSev.nasm which supports both SEV guest and Legacy guest. IoLibFifo.c is introduced to support SEV/TDX/Legacy guest in one binary. It checks the guest type in runtime and call corresponding functio

[edk2-devel] [PATCH V6 08/42] MdePkg: Support mmio for Tdx guest in BaseIoLibIntrinsic

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 TDVF access MMIO with TDG.VP.VMCALL to invoke VMM provided emulation functions. If the access to MMIO fails, it fall backs to the direct access. BaseIoLibIntrinsic.inf is the IoLib used by other packages. It will not support I/O in Td guest

[edk2-devel] [PATCH V6 07/42] MdePkg: Add helper functions for Tdx guest in BaseIoLibIntrinsic

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 Intel TDX architecture does not prescribe a specific software convention to perform I/O from the guest TD. Guest TD providers have many choices to provide I/O to the guest. The common I/O models are emulated devices, para-virtualized devices

[edk2-devel] [PATCH V6 06/42] UefiCpuPkg/CpuExceptionHandler: Add base support for the #VE exception

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 Add base support to handle #VE exceptions. Update the common exception handlers to invoke the VmTdExitHandleVe () function of the VmgExitLib library when a #VE is encountered. A non-zero return code will propagate to the targeted exception h

[edk2-devel] [PATCH V6 05/42] OvmfPkg: Extend VmgExitLib to handle #VE exception

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 The base VmgExitLib library provides a default limited interface to handle #VE exception. To provide full support, the OVMF version of VmgExitLib is extended to provide full support of #VE handler. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jo

[edk2-devel] [PATCH V6 04/42] UefiCpuPkg: Extend VmgExitLibNull to handle #VE exception

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 VmgExitLib performs the necessary processing to handle a #VC exception. VmgExitLibNull is a NULL instance of VmgExitLib which provides a default limited interface. In this commit VmgExitLibNull is extended to handle a #VE exception with a de

[edk2-devel] [PATCH V6 03/42] MdePkg: Add TdxLib to wrap Tdx operations

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 TdxLib is created with functions to perform the related Tdx operation. This includes functions for: - TdAcceptPages : Accept pending private pages and initialize the pages to all-0 using the TD ephemeral private key.

[edk2-devel] [PATCH V6 02/42] MdePkg: Introduce basic Tdx functions in BaseLib

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 Introduce basic Tdx functions in BaseLib: - TdCall () - TdVmCall () - TdIsEnabled () Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Cc: Brijesh Singh Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Cc: G

[edk2-devel] [PATCH V6 01/42] MdePkg: Add Tdx.h

2022-02-19 Thread Min Xu
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 Tdx.h includes the Intel Trust Domain Extension definitions. Detailed information can be found in below document: https://software.intel.com/content/dam/develop/external/us/en/ documents/tdx-module-1eas-v0.85.039.pdf Cc: Michael D Kinney

[edk2-devel] [PATCH V6 00/42] Enable Intel TDX in OvmfPkg (Config-A)

2022-02-19 Thread Min Xu
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3249 Intel's Trust Domain Extensions (Intel TDX) refers to an Intel technology that extends Virtual Machines Extensions (VMX) and Multi-Key Total Memory Encryption (MKTME) with a new kind of virutal machines guest called a Trust Domain (TD). A T