From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web09.22417.1662366920227192887 for ; Mon, 05 Sep 2022 01:35:20 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=khTYt+Sh; spf=permerror, err=too many SPF records (domain: intel.com, ip: 134.134.136.126, 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=1662366920; x=1693902920; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=F0GSTm5b/SWzhwXL9Bg8YN51WE99ns5JK+sPlIGgIeA=; b=khTYt+Sh5++xA0woNk8/ENJN8TlaR5RTnNT+Nb3Y/YsgJKlmPXU+JOQK ZdrgdC6zBR3b0yAtRHhNci53OkQAxUg0gXMr8JVsRz3upX9+71HyRRxqo SzH6AR4l/MdfF9zcYrKO3+jbdRNBwAW4ZKpzJCSZt+GcibqHb4AQ6MrYx 8Wx1h8ol74hbdnvz50z0b7w4yxJQbhR8+HZb8cXHbGlgMwXBKeuSHv/Av 8AshB+TzcgCcyoT+2TCToECtGUJFzNnUtgl9IpkU/JRSEvLI8+23NC9gp bu5V4qpxlsJKe0QYrlJ43iFKfWUXslxsXB48TPexv6rOQzG+gJpImm+gc Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10460"; a="279355776" X-IronPort-AV: E=Sophos;i="5.93,290,1654585200"; d="scan'208";a="279355776" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Sep 2022 01:35:19 -0700 X-IronPort-AV: E=Sophos;i="5.93,290,1654585200"; d="scan'208";a="675194184" Received: from mxu9-mobl1.ccr.corp.intel.com ([10.255.30.119]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Sep 2022 01:35:16 -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 V3 00/12] Introduce Lazy-accept for Tdx guest Date: Mon, 5 Sep 2022 16:34:54 +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()" As the first stage we accept all the memory under 4G. Please see the discussion in https://edk2.groups.io/g/devel/message/93086 Patch 1-4: Introduce lazy-accept related definitions. Patch 5-6: Update Dxe and shell for unaccepted memory. Patch 7 - 9: Update OvmfPkg for unaccepted memory. Patch 10 - 12: Introduce EfiMemoryAcceptProtocol and realize it in TdxDxe. Code: https://github.com/mxu9/edk2/tree/lazyaccept.v3 v3 changes: - As the first stage we accept all the memory under 4G. See the discussion in https://edk2.groups.io/g/devel/message/93086 - "Pool and page functions accept memory when OOM occurs" is dropped. See the discussion in https://edk2.groups.io/g/devel/message/93086 - PlatformAdjustSystemMemorySizeBelow4gbForLazyAccep is deleted because in current stage we accept all the memory under 4G. 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 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 (1): MdePkg: The prototype definition of EdkiiMemoryAcceptProtocol Min M Xu (11): 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 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/Gcd/Gcd.c | 6 + MdeModulePkg/Core/Dxe/Mem/Page.c | 63 ++++++--- 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/WorkArea.h | 1 + .../BaseMemEncryptTdxLib.inf | 3 + .../BaseMemEncryptTdxLib/MemoryEncryption.c | 12 +- OvmfPkg/Library/PeilessStartupLib/Hob.c | 26 +++- .../PeilessStartupLib/PeilessStartupLib.inf | 1 + OvmfPkg/Library/PlatformInitLib/IntelTdx.c | 131 ++++++++++++++++-- OvmfPkg/Library/PlatformInitLib/MemDetect.c | 2 + OvmfPkg/TdxDxe/TdxDxe.c | 103 ++++++++++++++ OvmfPkg/TdxDxe/TdxDxe.inf | 2 + .../UefiShellDebug1CommandsLib/MemMap.c | 13 ++ .../UefiShellDebug1CommandsLib.uni | 3 +- 20 files changed, 440 insertions(+), 37 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