From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web10.27786.1654484421189395311 for ; Sun, 05 Jun 2022 20:00:22 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=jbL3bjRG; spf=pass (domain: intel.com, ip: 134.134.136.24, mailfrom: min.m.xu@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1654484421; x=1686020421; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=uOw+yR60Ef6CMv8S40gNHEbQbmB3vr0k5ppWJBpAaYY=; b=jbL3bjRGpR+WE6Ju8C8iI9LBbZKzhgki6oKMeLLtFWDu07ryZGz2apHb dm/yRn/OKC03NTJUUpL/zvaGqhC3D4aLfHsYICyz/q89K7UtMfSRWKHvY A1su2qDVaDalCVV5xA45wgh8q9/xRZoj5ab+bHycvEc60Pyt3/ekd15c5 ptu/M8HUQp3qRa/0jXoWjFmT6Z4ScuovLfyp0i9c9xFk9Cd1CLLKjRFLD w5C5udL5eOj5hvNX0NdLH4FncfimzINAAyW1Jv7HRUl6OV4LYv1eSvtig LdfO7220A9ygI80hSPqY8L/EfUC90dOy706Xuc1wqE24twBoVqMf/HBil g==; X-IronPort-AV: E=McAfee;i="6400,9594,10369"; a="276458001" X-IronPort-AV: E=Sophos;i="5.91,280,1647327600"; d="scan'208";a="276458001" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jun 2022 20:00:19 -0700 X-IronPort-AV: E=Sophos;i="5.91,280,1647327600"; d="scan'208";a="647285691" Received: from mxu9-mobl1.ccr.corp.intel.com ([10.255.29.66]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jun 2022 20:00:15 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min Xu , Zhichao Gao , Michael D Kinney , Zhiguang Liu , Jian J Wang , Liming Gao , Ray Ni , Erdem Aktas , Gerd Hoffmann , James Bottomley , Jiewen Yao , Tom Lendacky , Jiaqi Gao Subject: [PATCH 00/14] Introduce Lazy-accept for Tdx guest Date: Mon, 6 Jun 2022 10:59:48 +0800 Message-Id: X-Mailer: git-send-email 2.29.2.windows.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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()" 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.v1 Cc: Zhichao Gao Cc: Michael D Kinney Cc: Zhiguang Liu Cc: Jian J Wang Cc: Liming Gao Cc: Ray Ni Cc: Erdem Aktas Cc: Gerd Hoffmann Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Signed-off-by: Jiaqi Gao Signed-off-by: Min Xu Jiaqi Gao (2): MdePkg: The prototype definition of EfiMemoryAcceptProtocol 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: Use PcdOvmfWorkAreaBase instead of PcdSevEsWorkAreaBase OvmfPkg: Add MaxAcceptedMemoryAddress in TDX work area OvmfPkg: Introduce lazy accept in PlatformInitLib and PlatformPei OvmfPkg: Update ConstructFwHobList for lazy accept OvmfPkg: Realize EfiMemoryAcceptProtocol in TdxDxe MdeModulePkg/Core/Dxe/DxeMain.inf | 1 + MdeModulePkg/Core/Dxe/Gcd/Gcd.c | 5 + MdeModulePkg/Core/Dxe/Mem/Imem.h | 16 ++ MdeModulePkg/Core/Dxe/Mem/Page.c | 218 ++++++++++++++++++ MdeModulePkg/Core/Dxe/Mem/Pool.c | 14 ++ MdeModulePkg/Include/Pi/PrePiHob.h | 20 ++ MdePkg/Include/Pi/PiDxeCis.h | 5 + 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 + .../PrePiHobListPointer.c | 4 +- .../PrePiHobListPointerLibTdx.inf | 2 +- OvmfPkg/Library/PeilessStartupLib/Hob.c | 26 ++- .../PeilessStartupLib/PeilessStartupLib.inf | 1 + OvmfPkg/Library/PlatformInitLib/IntelTdx.c | 145 +++++++++++- 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 | 6 + 27 files changed, 666 insertions(+), 19 deletions(-) create mode 100644 MdeModulePkg/Include/Pi/PrePiHob.h create mode 100644 MdePkg/Include/Protocol/MemoryAccept.h -- 2.29.2.windows.2