[edk2-devel] [PATCH V2 00/14] Introduce Lazy-accept for Tdx guest

Min Xu posted 14 patches 1 year, 8 months ago
Failed in applying to current master (apply log)
There is a newer version of this series
MdeModulePkg/Core/Dxe/DxeMain.inf             |   1 +
MdeModulePkg/Core/Dxe/Gcd/Gcd.c               |   6 +
MdeModulePkg/Core/Dxe/Mem/Imem.h              |  16 ++
MdeModulePkg/Core/Dxe/Mem/Page.c              | 253 ++++++++++++++++--
MdeModulePkg/Core/Dxe/Mem/Pool.c              |  14 +
MdeModulePkg/Include/Pi/PrePiDxeCis.h         |  25 ++
MdeModulePkg/Include/Pi/PrePiHob.h            |  20 ++
MdePkg/Include/Pi/PiDxeCis.h                  |  10 +-
MdePkg/Include/Pi/PiHob.h                     |  11 +-
MdePkg/Include/Protocol/MemoryAccept.h        |  37 +++
MdePkg/Include/Uefi/UefiMultiPhase.h          |   5 +
MdePkg/MdePkg.dec                             |   3 +
OvmfPkg/Include/Library/PlatformInitLib.h     |   6 +
OvmfPkg/Include/WorkArea.h                    |   1 +
OvmfPkg/IntelTdx/IntelTdxX64.dsc              |   8 +
.../BaseMemEncryptTdxLib.inf                  |   3 +
.../BaseMemEncryptTdxLib/MemoryEncryption.c   |  12 +-
OvmfPkg/Library/PeilessStartupLib/Hob.c       |  26 +-
.../PeilessStartupLib/PeilessStartupLib.inf   |   1 +
OvmfPkg/Library/PlatformInitLib/IntelTdx.c    | 154 ++++++++++-
OvmfPkg/Library/PlatformInitLib/MemDetect.c   |  27 ++
.../PlatformInitLib/PlatformInitLib.inf       |   1 +
OvmfPkg/OvmfPkg.dec                           |   4 +
OvmfPkg/OvmfPkgX64.dsc                        |   9 +
OvmfPkg/PlatformPei/MemDetect.c               |   5 +
OvmfPkg/TdxDxe/TdxDxe.c                       | 103 +++++++
OvmfPkg/TdxDxe/TdxDxe.inf                     |   2 +
.../UefiShellDebug1CommandsLib/MemMap.c       |  13 +
.../UefiShellDebug1CommandsLib.uni            |   3 +-
29 files changed, 741 insertions(+), 38 deletions(-)
create mode 100644 MdeModulePkg/Include/Pi/PrePiDxeCis.h
create mode 100644 MdeModulePkg/Include/Pi/PrePiHob.h
create mode 100644 MdePkg/Include/Protocol/MemoryAccept.h
[edk2-devel] [PATCH V2 00/14] Introduce Lazy-accept for Tdx guest
Posted by Min Xu 1 year, 8 months ago
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3937

UnacceptedMemory is one of the four defined types of TD memory in Intel
TDX guest. TDVF must invoke TDCALL [TDG.MEM.PAGE.ACCEPT] the unaccepted
memory before use it. See [TDVF] Section 7.1.
TDVF: https://www.intel.com/content/dam/develop/external/us/en/
documents/tdx-virtual-firmware-design-guide-rev-1.01.pdf 

It is a time-consuming task which impacts the boot performance badly.
One of the mitigation is the lazy-accept mechanism. That the whole system
memory is divided into 2 parts, one is accepted in bios phase, the other
is tagged as EfiGcdMemoryTypeUnaccepted and OS will handle these
"unaccepted" memories.
See "UEFI Spec v2.9 Table 7-5 Memory Type Usage before ExitBootServices()"

In current implementation, we configure the lazy accept memory size with
PcdLazyAcceptPartialMemorySize in build time. If the
PcdLazyAcceptPartialMemorySize is 0, it means to accept all the memory
under 4G. This is to optimize the performance.

Patch 1-4: 
  Introduce lazy-accept related definitions.

Patch 5-6:
  Update Dxe and shell for unaccepted memory.

Patch 7 - 11:
  Update OvmfPkg for unaccepted memory.

Patch 12 - 13:
  Introduce EfiMemoryAcceptProtocol and realize it in TdxDxe.

Patch 14:
  Update Pool and Page functions to accept memory when OOM occurs.

Code: https://github.com/mxu9/edk2/tree/lazyaccept.v2

v2 changes:
 - Fix a typo that change EfiUnacceptedMemory to EfiUnacceptedMemoryType.
 - Define EFI_GCD_MEMORY_TYPE_UNACCEPTED in PrePiDxeCis.h because it has
   not been defined in PI spec.
 - AllocatePages should return EFI_INVALID_PARAMETERS if input MemoryType
   is EfiUnacceptedMemoryType. 
 - Use EDKII_ prefix instead of EFI_ prefix in the protocol name of
   EDKII_MEMORY_ACCEPT_PROTOCOL_GUID. Because this protocol is not EFI
   defined.
 - Accept memory under 4G even if the PcdLazyAcceptPartialMemorySize is
   bigger than 4G. So with this setting, even if the
   PcdLazyAcceptPartialMemorySize is 0 (which means to accept all
   memories), only the memory under 4G will be accepted. This is to
   optimize the performance.

Cc: Zhichao Gao <zhichao.gao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Jiaqi Gao <jiaqi.gao@intel.com>
Signed-off-by: Min Xu <min.m.xu@intel.com>

Jiaqi Gao (2):
  MdePkg: The prototype definition of EdkiiMemoryAcceptProtocol
  MdeModulePkg: Pool and page functions accept memory when OOM occurs

Min M Xu (12):
  MdeModulePkg: Add PrePiHob.h
  MdePkg: Increase EFI_RESOURCE_MAX_MEMORY_TYPE
  OvmfPkg: Use EFI_RESOURCE_MEMORY_UNACCEPTED which defined in
    MdeModulePkg
  MdePkg: Add UEFI Unaccepted memory definition
  MdeModulePkg: Update Dxe to handle unaccepted memory type
  ShellPkg: Update shell command memmap to show unaccepted memory
  OvmfPkg: Add PCD and DEFINEs for Lazy Accept page.
  OvmfPkg: Add MaxAcceptedMemoryAddress in TDX work area
  OvmfPkg: Introduce lazy accept in PlatformInitLib and PlatformPei
  OvmfPkg: Update ConstructFwHobList for lazy accept
  OvmfPkg: Realize EdkiiMemoryAcceptProtocol in TdxDxe
  OvmfPkg: Call gEdkiiMemoryAcceptProtocolGuid to accept pages

 MdeModulePkg/Core/Dxe/DxeMain.inf             |   1 +
 MdeModulePkg/Core/Dxe/Gcd/Gcd.c               |   6 +
 MdeModulePkg/Core/Dxe/Mem/Imem.h              |  16 ++
 MdeModulePkg/Core/Dxe/Mem/Page.c              | 253 ++++++++++++++++--
 MdeModulePkg/Core/Dxe/Mem/Pool.c              |  14 +
 MdeModulePkg/Include/Pi/PrePiDxeCis.h         |  25 ++
 MdeModulePkg/Include/Pi/PrePiHob.h            |  20 ++
 MdePkg/Include/Pi/PiDxeCis.h                  |  10 +-
 MdePkg/Include/Pi/PiHob.h                     |  11 +-
 MdePkg/Include/Protocol/MemoryAccept.h        |  37 +++
 MdePkg/Include/Uefi/UefiMultiPhase.h          |   5 +
 MdePkg/MdePkg.dec                             |   3 +
 OvmfPkg/Include/Library/PlatformInitLib.h     |   6 +
 OvmfPkg/Include/WorkArea.h                    |   1 +
 OvmfPkg/IntelTdx/IntelTdxX64.dsc              |   8 +
 .../BaseMemEncryptTdxLib.inf                  |   3 +
 .../BaseMemEncryptTdxLib/MemoryEncryption.c   |  12 +-
 OvmfPkg/Library/PeilessStartupLib/Hob.c       |  26 +-
 .../PeilessStartupLib/PeilessStartupLib.inf   |   1 +
 OvmfPkg/Library/PlatformInitLib/IntelTdx.c    | 154 ++++++++++-
 OvmfPkg/Library/PlatformInitLib/MemDetect.c   |  27 ++
 .../PlatformInitLib/PlatformInitLib.inf       |   1 +
 OvmfPkg/OvmfPkg.dec                           |   4 +
 OvmfPkg/OvmfPkgX64.dsc                        |   9 +
 OvmfPkg/PlatformPei/MemDetect.c               |   5 +
 OvmfPkg/TdxDxe/TdxDxe.c                       | 103 +++++++
 OvmfPkg/TdxDxe/TdxDxe.inf                     |   2 +
 .../UefiShellDebug1CommandsLib/MemMap.c       |  13 +
 .../UefiShellDebug1CommandsLib.uni            |   3 +-
 29 files changed, 741 insertions(+), 38 deletions(-)
 create mode 100644 MdeModulePkg/Include/Pi/PrePiDxeCis.h
 create mode 100644 MdeModulePkg/Include/Pi/PrePiHob.h
 create mode 100644 MdePkg/Include/Protocol/MemoryAccept.h

-- 
2.29.2.windows.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#92879): https://edk2.groups.io/g/devel/message/92879
Mute This Topic: https://groups.io/mt/93285597/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-