* [PATCH V5 00/10] Introduce Lazy-accept for Tdx guest
@ 2022-11-01 5:13 Min Xu
2022-11-01 5:13 ` [PATCH V5 01/10] MdeModulePkg: Add PrePiHob.h Min Xu
` (11 more replies)
0 siblings, 12 replies; 13+ messages in thread
From: Min Xu @ 2022-11-01 5:13 UTC (permalink / raw)
To: devel
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
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
This patch-set is related to code first, so there is a edk2-staging branch.
Please see https://github.com/tianocore/edk2-staging/tree/TDVF
Patch 1-4:
Introduce lazy-accept related definitions.
Patch 5-6:
Update Dxe and shell for unaccepted memory.
Patch 7:
Update OvmfPkg for unaccepted memory.
Patch 8 - 10:
Introduce EfiMemoryAcceptProtocol and realize it in TdxDxe.
Code: https://github.com/mxu9/edk2/tree/lazyaccept.v5
v5 changes:
- Rebase the patch-set to commit df7ce74e6c75.
- Add reviewed-by in MdeModulePkg/MdePkg related patches(#1/2/4/5/8).
- Add acked-by in patch#7.
v4 changes:
- To follow the name convention of EDKII code first, the name of
EFI_RESOURCE_MEMORY_UNACCEPTED is updated to
BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED.
- Remove the definition of MaxAcceptedMemoryAddress because in current
stage we will accept all the memory under 4G. So
MaxAcceptedMemoryAddress is not useable in this assumption.
- Because this is related to code first, there is edk2-staging branch.
The branch link is attached.
https://github.com/tianocore/edk2-staging/tree/TDVF
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 <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 (1):
MdePkg: The prototype definition of EdkiiMemoryAcceptProtocol
Min M Xu (9):
MdeModulePkg: Add PrePiHob.h
MdePkg: Increase EFI_RESOURCE_MAX_MEMORY_TYPE
OvmfPkg: Use BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED 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: Introduce lazy accept in PlatformInitLib and PlatformPei
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 +
.../BaseMemEncryptTdxLib.inf | 3 +
.../BaseMemEncryptTdxLib/MemoryEncryption.c | 12 +-
OvmfPkg/Library/PeilessStartupLib/Hob.c | 5 +-
OvmfPkg/Library/PlatformInitLib/IntelTdx.c | 98 ++++++++++++++---
OvmfPkg/Library/PlatformInitLib/MemDetect.c | 2 +
OvmfPkg/TdxDxe/TdxDxe.c | 103 ++++++++++++++++++
OvmfPkg/TdxDxe/TdxDxe.inf | 2 +
.../UefiShellDebug1CommandsLib/MemMap.c | 13 +++
.../UefiShellDebug1CommandsLib.uni | 3 +-
18 files changed, 381 insertions(+), 40 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
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH V5 01/10] MdeModulePkg: Add PrePiHob.h
2022-11-01 5:13 [PATCH V5 00/10] Introduce Lazy-accept for Tdx guest Min Xu
@ 2022-11-01 5:13 ` Min Xu
2022-11-01 5:13 ` [PATCH V5 02/10] MdePkg: Increase EFI_RESOURCE_MAX_MEMORY_TYPE Min Xu
` (10 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Min Xu @ 2022-11-01 5:13 UTC (permalink / raw)
To: devel
Cc: Min M Xu, Jian J Wang, Liming Gao, Ray Ni, Erdem Aktas,
Gerd Hoffmann, James Bottomley, Jiewen Yao, Tom Lendacky
From: Min M Xu <min.m.xu@intel.com>
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3937
BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED is defined for unaccepted memory.
But this defitinion has not been officially in the PI spec. Base
on the code-first we define BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED at
MdeModulePkg/Include/Pi/PrePiHob.h.
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>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Min Xu <min.m.xu@intel.com>
---
MdeModulePkg/Include/Pi/PrePiHob.h | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
create mode 100644 MdeModulePkg/Include/Pi/PrePiHob.h
diff --git a/MdeModulePkg/Include/Pi/PrePiHob.h b/MdeModulePkg/Include/Pi/PrePiHob.h
new file mode 100644
index 000000000000..ac575e59721b
--- /dev/null
+++ b/MdeModulePkg/Include/Pi/PrePiHob.h
@@ -0,0 +1,20 @@
+/** @file
+ HOB related definitions which has not been officially published in PI.
+
+Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef MDE_MODULEPKG_PRE_PI_HOB_H_
+#define MDE_MODULEPKG_PRE_PI_HOB_H_
+
+//
+// BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED is defined for unaccepted memory.
+// But this defitinion has not been officially in the PI spec. Base
+// on the code-first we define BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED at
+// MdeModulePkg/Include/Pi/PrePiHob.h.
+//
+#define BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED 0x00000007
+
+#endif
--
2.29.2.windows.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH V5 02/10] MdePkg: Increase EFI_RESOURCE_MAX_MEMORY_TYPE
2022-11-01 5:13 [PATCH V5 00/10] Introduce Lazy-accept for Tdx guest Min Xu
2022-11-01 5:13 ` [PATCH V5 01/10] MdeModulePkg: Add PrePiHob.h Min Xu
@ 2022-11-01 5:13 ` Min Xu
2022-11-01 5:13 ` [PATCH V5 03/10] OvmfPkg: Use BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED defined in MdeModulePkg Min Xu
` (9 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Min Xu @ 2022-11-01 5:13 UTC (permalink / raw)
To: devel
Cc: Min M Xu, Michael D Kinney, Liming Gao, Zhiguang Liu, Erdem Aktas,
Gerd Hoffmann, James Bottomley, Jiewen Yao, Tom Lendacky
From: Min M Xu <min.m.xu@intel.com>
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3937
BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED is defined for unaccepted memory.
But this defitinion has not been officially in the PI spec. Base
on the code-first we define EFI_RESOURCE_MEMORY_UNACCEPTED at
MdeModulePkg/Include/Pi/PrePiHob.h and update EFI_RESOURCE_MAX_MEMORY_TYPE
to 8. After BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED is officially published
in PI spec, we will re-visit here.
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@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>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Min Xu <min.m.xu@intel.com>
---
MdePkg/Include/Pi/PiHob.h | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/MdePkg/Include/Pi/PiHob.h b/MdePkg/Include/Pi/PiHob.h
index e9f0ab4309d1..4605da56e247 100644
--- a/MdePkg/Include/Pi/PiHob.h
+++ b/MdePkg/Include/Pi/PiHob.h
@@ -232,7 +232,16 @@ typedef UINT32 EFI_RESOURCE_TYPE;
#define EFI_RESOURCE_MEMORY_MAPPED_IO_PORT 0x00000004
#define EFI_RESOURCE_MEMORY_RESERVED 0x00000005
#define EFI_RESOURCE_IO_RESERVED 0x00000006
-#define EFI_RESOURCE_MAX_MEMORY_TYPE 0x00000007
+//
+// BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED is defined for unaccepted memory.
+// But this defitinion has not been officially in the PI spec. Base
+// on the code-first we define BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED at
+// MdeModulePkg/Include/Pi/PrePiHob.h and update EFI_RESOURCE_MAX_MEMORY_TYPE
+// to 8. After BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED is officially published
+// in PI spec, we will re-visit here.
+//
+// #define BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED 0x00000007
+#define EFI_RESOURCE_MAX_MEMORY_TYPE 0x00000008
///
/// A type of recount attribute type.
--
2.29.2.windows.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH V5 03/10] OvmfPkg: Use BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED defined in MdeModulePkg
2022-11-01 5:13 [PATCH V5 00/10] Introduce Lazy-accept for Tdx guest Min Xu
2022-11-01 5:13 ` [PATCH V5 01/10] MdeModulePkg: Add PrePiHob.h Min Xu
2022-11-01 5:13 ` [PATCH V5 02/10] MdePkg: Increase EFI_RESOURCE_MAX_MEMORY_TYPE Min Xu
@ 2022-11-01 5:13 ` Min Xu
2022-11-01 5:13 ` [PATCH V5 04/10] MdePkg: Add UEFI Unaccepted memory definition Min Xu
` (8 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Min Xu @ 2022-11-01 5:13 UTC (permalink / raw)
To: devel
Cc: Min M Xu, Erdem Aktas, Gerd Hoffmann, James Bottomley, Jiewen Yao,
Tom Lendacky
From: Min M Xu <min.m.xu@intel.com>
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3937
BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED is defined in MdeModulePkg. The
files which use the definition are updated as well.
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>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Min Xu <min.m.xu@intel.com>
---
OvmfPkg/Library/PeilessStartupLib/Hob.c | 5 ++---
OvmfPkg/Library/PlatformInitLib/IntelTdx.c | 10 +++++-----
2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/OvmfPkg/Library/PeilessStartupLib/Hob.c b/OvmfPkg/Library/PeilessStartupLib/Hob.c
index 5fc84a809025..630ce445ebec 100644
--- a/OvmfPkg/Library/PeilessStartupLib/Hob.c
+++ b/OvmfPkg/Library/PeilessStartupLib/Hob.c
@@ -20,10 +20,9 @@
#include <IndustryStandard/UefiTcgPlatform.h>
#include <Library/PlatformInitLib.h>
#include <OvmfPlatforms.h>
+#include <Pi/PrePiHob.h>
#include "PeilessStartupInternal.h"
-#define EFI_RESOURCE_MEMORY_UNACCEPTED 7
-
/**
* Construct the HobList in SEC phase.
*
@@ -92,7 +91,7 @@ ConstructFwHobList (
//
while (!END_OF_HOB_LIST (Hob)) {
if (Hob.Header->HobType == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {
- if (Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_MEMORY_UNACCEPTED) {
+ if (Hob.ResourceDescriptor->ResourceType == BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED) {
PhysicalEnd = Hob.ResourceDescriptor->PhysicalStart + Hob.ResourceDescriptor->ResourceLength;
ResourceLength = Hob.ResourceDescriptor->ResourceLength;
diff --git a/OvmfPkg/Library/PlatformInitLib/IntelTdx.c b/OvmfPkg/Library/PlatformInitLib/IntelTdx.c
index c6d7c8bb6e0e..797f880df035 100644
--- a/OvmfPkg/Library/PlatformInitLib/IntelTdx.c
+++ b/OvmfPkg/Library/PlatformInitLib/IntelTdx.c
@@ -20,11 +20,11 @@
#include <Library/PeiServicesLib.h>
#include <Library/TdxLib.h>
#include <Library/SynchronizationLib.h>
+#include <Pi/PrePiHob.h>
#include <WorkArea.h>
#include <ConfidentialComputingGuestAttr.h>
-#define ALIGNED_2MB_MASK 0x1fffff
-#define EFI_RESOURCE_MEMORY_UNACCEPTED 7
+#define ALIGNED_2MB_MASK 0x1fffff
/**
This function will be called to accept pages. Only BSP accepts pages.
@@ -211,7 +211,7 @@ ValidateHobList (
EFI_RESOURCE_MEMORY_MAPPED_IO_PORT,
EFI_RESOURCE_MEMORY_RESERVED,
EFI_RESOURCE_IO_RESERVED,
- EFI_RESOURCE_MEMORY_UNACCEPTED
+ BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED
};
if (VmmHobList == NULL) {
@@ -387,7 +387,7 @@ ProcessHobList (
if (Hob.Header->HobType == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {
DEBUG ((DEBUG_INFO, "\nResourceType: 0x%x\n", Hob.ResourceDescriptor->ResourceType));
- if (Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_MEMORY_UNACCEPTED) {
+ if (Hob.ResourceDescriptor->ResourceType == BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED) {
DEBUG ((DEBUG_INFO, "ResourceAttribute: 0x%x\n", Hob.ResourceDescriptor->ResourceAttribute));
DEBUG ((DEBUG_INFO, "PhysicalStart: 0x%llx\n", Hob.ResourceDescriptor->PhysicalStart));
DEBUG ((DEBUG_INFO, "ResourceLength: 0x%llx\n", Hob.ResourceDescriptor->ResourceLength));
@@ -488,7 +488,7 @@ TransferTdxHobList (
ResourceType = Hob.ResourceDescriptor->ResourceType;
ResourceAttribute = Hob.ResourceDescriptor->ResourceAttribute;
- if (ResourceType == EFI_RESOURCE_MEMORY_UNACCEPTED) {
+ if (ResourceType == BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED) {
ResourceType = EFI_RESOURCE_SYSTEM_MEMORY;
ResourceAttribute |= (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_TESTED);
}
--
2.29.2.windows.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH V5 04/10] MdePkg: Add UEFI Unaccepted memory definition
2022-11-01 5:13 [PATCH V5 00/10] Introduce Lazy-accept for Tdx guest Min Xu
` (2 preceding siblings ...)
2022-11-01 5:13 ` [PATCH V5 03/10] OvmfPkg: Use BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED defined in MdeModulePkg Min Xu
@ 2022-11-01 5:13 ` Min Xu
2022-11-01 5:13 ` [PATCH V5 05/10] MdeModulePkg: Update Dxe to handle unaccepted memory type Min Xu
` (7 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Min Xu @ 2022-11-01 5:13 UTC (permalink / raw)
To: devel
Cc: Min M Xu, Michael D Kinney, Liming Gao, Zhiguang Liu, Erdem Aktas,
Gerd Hoffmann, James Bottomley, Jiewen Yao, Tom Lendacky
From: Min M Xu <min.m.xu@intel.com>
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3937
Plase refer to:
UEFI Spec v2.9 Table 7-5 Memory Type Usage before ExitBootServices()
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@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>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Min Xu <min.m.xu@intel.com>
---
MdeModulePkg/Include/Pi/PrePiDxeCis.h | 25 +++++++++++++++++++++++++
MdePkg/Include/Pi/PiDxeCis.h | 10 +++++++++-
MdePkg/Include/Uefi/UefiMultiPhase.h | 5 +++++
3 files changed, 39 insertions(+), 1 deletion(-)
create mode 100644 MdeModulePkg/Include/Pi/PrePiDxeCis.h
diff --git a/MdeModulePkg/Include/Pi/PrePiDxeCis.h b/MdeModulePkg/Include/Pi/PrePiDxeCis.h
new file mode 100644
index 000000000000..113ac37924cc
--- /dev/null
+++ b/MdeModulePkg/Include/Pi/PrePiDxeCis.h
@@ -0,0 +1,25 @@
+/** @file
+ Include file matches things in PI.
+
+Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef MDE_MODULEPKG_PRE_PI_DXE_CIS_H_
+#define MDE_MODULEPKG_PRE_PI_DXE_CIS_H_
+
+///
+/// A memory region that describes system memory that has not been accepted
+/// by a corresponding call to the underlying isolation architecture.
+///
+/// This memory region has not been defined in PI spec, so it is defined in
+/// PrePiDxeCis.h. And it is defined in the format of captial letters
+/// because only capital letters are allowed to be used for #define declarations.
+///
+/// After this memory region is defined in PI spec, it should be a value in
+/// EFI_GCD_MEMORY_TYPE in PiDxeCis.h.
+///
+#define EFI_GCD_MEMORY_TYPE_UNACCEPTED 7
+
+#endif
diff --git a/MdePkg/Include/Pi/PiDxeCis.h b/MdePkg/Include/Pi/PiDxeCis.h
index d0f2ed0e58df..27b219aa3ffa 100644
--- a/MdePkg/Include/Pi/PiDxeCis.h
+++ b/MdePkg/Include/Pi/PiDxeCis.h
@@ -56,7 +56,15 @@ typedef enum {
/// system. If all memory has the same reliability, then this bit is not used.
///
EfiGcdMemoryTypeMoreReliable,
- EfiGcdMemoryTypeMaximum
+ // ///
+ // /// A memory region that describes system memory that has not been accepted
+ // /// by a corresponding call to the underlying isolation architecture.
+ // ///
+ // /// Please be noted:
+ // /// EfiGcdMemoryTypeUnaccepted is defined in PrePiDxeCis.h because it has not been
+ // /// defined in PI spec.
+ // EfiGcdMemoryTypeUnaccepted,
+ EfiGcdMemoryTypeMaximum = 8
} EFI_GCD_MEMORY_TYPE;
///
diff --git a/MdePkg/Include/Uefi/UefiMultiPhase.h b/MdePkg/Include/Uefi/UefiMultiPhase.h
index 22bae43e36e8..7884913371a9 100644
--- a/MdePkg/Include/Uefi/UefiMultiPhase.h
+++ b/MdePkg/Include/Uefi/UefiMultiPhase.h
@@ -103,6 +103,11 @@ typedef enum {
/// however it happens to also support byte-addressable non-volatility.
///
EfiPersistentMemory,
+ ///
+ /// A memory region that describes system memory that has not been accepted
+ /// by a corresponding call to the underlying isolation architecture.
+ ///
+ EfiUnacceptedMemoryType,
EfiMaxMemoryType
} EFI_MEMORY_TYPE;
--
2.29.2.windows.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH V5 05/10] MdeModulePkg: Update Dxe to handle unaccepted memory type
2022-11-01 5:13 [PATCH V5 00/10] Introduce Lazy-accept for Tdx guest Min Xu
` (3 preceding siblings ...)
2022-11-01 5:13 ` [PATCH V5 04/10] MdePkg: Add UEFI Unaccepted memory definition Min Xu
@ 2022-11-01 5:13 ` Min Xu
2022-11-01 5:13 ` [PATCH V5 06/10] ShellPkg: Update shell command memmap to show unaccepted memory Min Xu
` (6 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Min Xu @ 2022-11-01 5:13 UTC (permalink / raw)
To: devel
Cc: Min M Xu, Jian J Wang, Liming Gao, Ray Ni, Erdem Aktas,
Gerd Hoffmann, James Bottomley, Jiewen Yao, Tom Lendacky
From: Min M Xu <min.m.xu@intel.com>
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3937
Unaccepted memory is a kind of new memory type,
CoreInitializeGcdServices() and CoreGetMemoryMap() are updated to handle
the unaccepted memory type.
Ref: microsoft/mu_basecore@97e9c31
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>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Min Xu <min.m.xu@intel.com>
---
MdeModulePkg/Core/Dxe/Gcd/Gcd.c | 6 +++
MdeModulePkg/Core/Dxe/Mem/Page.c | 63 +++++++++++++++++++++++---------
2 files changed, 52 insertions(+), 17 deletions(-)
diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c
index 3763467bdbc0..792cd2e0af23 100644
--- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c
+++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c
@@ -8,6 +8,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
+#include <Pi/PrePiDxeCis.h>
+#include <Pi/PrePiHob.h>
#include "DxeMain.h"
#include "Gcd.h"
#include "Mem/HeapGuard.h"
@@ -103,6 +105,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mGcdMemoryTypeNames[] = {
"MMIO ", // EfiGcdMemoryTypeMemoryMappedIo
"PersisMem", // EfiGcdMemoryTypePersistent
"MoreRelia", // EfiGcdMemoryTypeMoreReliable
+ "Unaccepte", // EFI_GCD_MEMORY_TYPE_UNACCEPTED
"Unknown " // EfiGcdMemoryTypeMaximum
};
@@ -2600,6 +2603,9 @@ CoreInitializeGcdServices (
case EFI_RESOURCE_MEMORY_RESERVED:
GcdMemoryType = EfiGcdMemoryTypeReserved;
break;
+ case BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED:
+ GcdMemoryType = EFI_GCD_MEMORY_TYPE_UNACCEPTED;
+ break;
case EFI_RESOURCE_IO:
GcdIoType = EfiGcdIoTypeIo;
break;
diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c
index cc0b90ac0df5..160289c1f9ec 100644
--- a/MdeModulePkg/Core/Dxe/Mem/Page.c
+++ b/MdeModulePkg/Core/Dxe/Mem/Page.c
@@ -9,6 +9,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "DxeMain.h"
#include "Imem.h"
#include "HeapGuard.h"
+#include <Pi/PrePiDxeCis.h>
//
// Entry for tracking the memory regions for each memory type to coalesce similar memory types
@@ -61,6 +62,7 @@ EFI_MEMORY_TYPE_STATISTICS mMemoryTypeStatistics[EfiMaxMemoryType + 1] = {
{ 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiMemoryMappedIOPortSpace
{ 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, TRUE }, // EfiPalCode
{ 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE }, // EfiPersistentMemory
+ { 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, TRUE, FALSE }, // EfiUnacceptedMemoryType
{ 0, MAX_ALLOC_ADDRESS, 0, 0, EfiMaxMemoryType, FALSE, FALSE } // EfiMaxMemoryType
};
@@ -68,22 +70,23 @@ EFI_PHYSICAL_ADDRESS mDefaultMaximumAddress = MAX_ALLOC_ADDRESS;
EFI_PHYSICAL_ADDRESS mDefaultBaseAddress = MAX_ALLOC_ADDRESS;
EFI_MEMORY_TYPE_INFORMATION gMemoryTypeInformation[EfiMaxMemoryType + 1] = {
- { EfiReservedMemoryType, 0 },
- { EfiLoaderCode, 0 },
- { EfiLoaderData, 0 },
- { EfiBootServicesCode, 0 },
- { EfiBootServicesData, 0 },
- { EfiRuntimeServicesCode, 0 },
- { EfiRuntimeServicesData, 0 },
- { EfiConventionalMemory, 0 },
- { EfiUnusableMemory, 0 },
- { EfiACPIReclaimMemory, 0 },
- { EfiACPIMemoryNVS, 0 },
- { EfiMemoryMappedIO, 0 },
- { EfiMemoryMappedIOPortSpace, 0 },
- { EfiPalCode, 0 },
- { EfiPersistentMemory, 0 },
- { EfiMaxMemoryType, 0 }
+ { EfiReservedMemoryType, 0 },
+ { EfiLoaderCode, 0 },
+ { EfiLoaderData, 0 },
+ { EfiBootServicesCode, 0 },
+ { EfiBootServicesData, 0 },
+ { EfiRuntimeServicesCode, 0 },
+ { EfiRuntimeServicesData, 0 },
+ { EfiConventionalMemory, 0 },
+ { EfiUnusableMemory, 0 },
+ { EfiACPIReclaimMemory, 0 },
+ { EfiACPIMemoryNVS, 0 },
+ { EfiMemoryMappedIO, 0 },
+ { EfiMemoryMappedIOPortSpace, 0 },
+ { EfiPalCode, 0 },
+ { EfiPersistentMemory, 0 },
+ { EFI_GCD_MEMORY_TYPE_UNACCEPTED, 0 },
+ { EfiMaxMemoryType, 0 }
};
//
// Only used when load module at fixed address feature is enabled. True means the memory is alreay successfully allocated
@@ -1286,7 +1289,7 @@ CoreInternalAllocatePages (
}
if (((MemoryType >= EfiMaxMemoryType) && (MemoryType < MEMORY_TYPE_OEM_RESERVED_MIN)) ||
- (MemoryType == EfiConventionalMemory) || (MemoryType == EfiPersistentMemory))
+ (MemoryType == EfiConventionalMemory) || (MemoryType == EfiPersistentMemory) || (MemoryType == EfiUnacceptedMemoryType))
{
return EFI_INVALID_PARAMETER;
}
@@ -1961,6 +1964,32 @@ CoreGetMemoryMap (
MemoryMap = MergeMemoryMapDescriptor (MemoryMapStart, MemoryMap, Size);
}
+ if (MergeGcdMapEntry.GcdMemoryType == EFI_GCD_MEMORY_TYPE_UNACCEPTED) {
+ //
+ // Page Align GCD range is required. When it is converted to EFI_MEMORY_DESCRIPTOR,
+ // it will be recorded as page PhysicalStart and NumberOfPages.
+ //
+ ASSERT ((MergeGcdMapEntry.BaseAddress & EFI_PAGE_MASK) == 0);
+ ASSERT (((MergeGcdMapEntry.EndAddress - MergeGcdMapEntry.BaseAddress + 1) & EFI_PAGE_MASK) == 0);
+
+ //
+ // Create EFI_MEMORY_DESCRIPTOR for every Unaccepted GCD entries
+ //
+ MemoryMap->PhysicalStart = MergeGcdMapEntry.BaseAddress;
+ MemoryMap->VirtualStart = 0;
+ MemoryMap->NumberOfPages = RShiftU64 ((MergeGcdMapEntry.EndAddress - MergeGcdMapEntry.BaseAddress + 1), EFI_PAGE_SHIFT);
+ MemoryMap->Attribute = MergeGcdMapEntry.Attributes |
+ (MergeGcdMapEntry.Capabilities & (EFI_MEMORY_RP | EFI_MEMORY_WP | EFI_MEMORY_XP | EFI_MEMORY_RO |
+ EFI_MEMORY_UC | EFI_MEMORY_UCE | EFI_MEMORY_WC | EFI_MEMORY_WT | EFI_MEMORY_WB));
+ MemoryMap->Type = EfiUnacceptedMemoryType;
+
+ //
+ // Check to see if the new Memory Map Descriptor can be merged with an
+ // existing descriptor if they are adjacent and have the same attributes
+ //
+ MemoryMap = MergeMemoryMapDescriptor (MemoryMapStart, MemoryMap, Size);
+ }
+
if (Link == &mGcdMemorySpaceMap) {
//
// break loop when arrive at head.
--
2.29.2.windows.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH V5 06/10] ShellPkg: Update shell command memmap to show unaccepted memory
2022-11-01 5:13 [PATCH V5 00/10] Introduce Lazy-accept for Tdx guest Min Xu
` (4 preceding siblings ...)
2022-11-01 5:13 ` [PATCH V5 05/10] MdeModulePkg: Update Dxe to handle unaccepted memory type Min Xu
@ 2022-11-01 5:13 ` Min Xu
2022-11-01 5:13 ` [PATCH V5 07/10] OvmfPkg: Introduce lazy accept in PlatformInitLib and PlatformPei Min Xu
` (5 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Min Xu @ 2022-11-01 5:13 UTC (permalink / raw)
To: devel
Cc: Min M Xu, Ray Ni, Zhichao Gao, Erdem Aktas, Gerd Hoffmann,
James Bottomley, Jiewen Yao, Tom Lendacky
From: Min M Xu <min.m.xu@intel.com>
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3937
ShellCommandRunMemMap() is updated to handle the case of unaccepted
memory type.
Cc: Ray Ni <ray.ni@intel.com>
Cc: Zhichao Gao <zhichao.gao@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>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Zhichao Gao <zhichao.gao@intel.com>
Signed-off-by: Min Xu <min.m.xu@intel.com>
---
.../Library/UefiShellDebug1CommandsLib/MemMap.c | 13 +++++++++++++
.../UefiShellDebug1CommandsLib.uni | 3 ++-
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c
index 72f3c58b0970..a089953b286f 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/MemMap.c
@@ -26,6 +26,7 @@ STATIC CONST CHAR16 NameEfiACPIMemoryNVS[] = L"ACPIMemoryNVS";
STATIC CONST CHAR16 NameEfiMemoryMappedIO[] = L"MemoryMappedIO";
STATIC CONST CHAR16 NameEfiMemoryMappedIOPortSpace[] = L"MemoryMappedIOPortSpace";
STATIC CONST CHAR16 NameEfiPalCode[] = L"PalCode";
+STATIC CONST CHAR16 NameEfiUnacceptedMemoryType[] = L"Unaccepted";
//
// Need short names for some memory types
@@ -151,6 +152,8 @@ ShellCommandRunMemMap (
UINT64 UnusableMemoryPagesSize;
UINT64 PalCodePages;
UINT64 PalCodePagesSize;
+ UINT64 UnacceptedPages;
+ UINT64 UnacceptedPagesSize;
UINT64 PersistentPages;
UINT64 PersistentPagesSize;
BOOLEAN Sfo;
@@ -175,6 +178,7 @@ ShellCommandRunMemMap (
PalCodePages = 0;
PersistentPages = 0;
Size = 0;
+ UnacceptedPages = 0;
Descriptors = NULL;
ShellStatus = SHELL_SUCCESS;
Status = EFI_SUCCESS;
@@ -303,6 +307,11 @@ ShellCommandRunMemMap (
TotalPages += Walker->NumberOfPages;
PalCodePages += Walker->NumberOfPages;
break;
+ case EfiUnacceptedMemoryType:
+ ShellPrintHiiEx (-1, -1, NULL, (EFI_STRING_ID)(!Sfo ? STRING_TOKEN (STR_MEMMAP_LIST_ITEM) : STRING_TOKEN (STR_MEMMAP_LIST_ITEM_SFO)), gShellDebug1HiiHandle, NameEfiUnacceptedMemoryType, Walker->PhysicalStart, Walker->PhysicalStart+MultU64x64 (SIZE_4KB, Walker->NumberOfPages)-1, Walker->NumberOfPages, Walker->Attribute);
+ TotalPages += Walker->NumberOfPages;
+ UnacceptedPages += Walker->NumberOfPages;
+ break;
default:
//
// Shell Spec defines the SFO format.
@@ -335,6 +344,7 @@ ShellCommandRunMemMap (
MmioSpacePagesSize = MultU64x64 (SIZE_4KB, MmioSpacePages);
MmioPortPagesSize = MultU64x64 (SIZE_4KB, MmioPortPages);
PalCodePagesSize = MultU64x64 (SIZE_4KB, PalCodePages);
+ UnacceptedPagesSize = MultU64x64 (SIZE_4KB, UnacceptedPages);
PersistentPagesSize = MultU64x64 (SIZE_4KB, PersistentPages);
UnusableMemoryPagesSize = MultU64x64 (SIZE_4KB, UnusableMemoryPages);
if (!Sfo) {
@@ -368,6 +378,8 @@ ShellCommandRunMemMap (
MmioPortPagesSize,
PalCodePages,
PalCodePagesSize,
+ UnacceptedPages,
+ UnacceptedPagesSize,
AvailPages,
AvailPagesSize,
PersistentPages,
@@ -422,6 +434,7 @@ ShellCommandRunMemMap (
AcpiReclaimPagesSize,
AcpiNvsPagesSize,
PalCodePagesSize,
+ UnacceptedPagesSize,
PersistentPagesSize
);
}
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.uni b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.uni
index 6693be26e699..b1d239ed37ea 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.uni
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.uni
@@ -88,13 +88,14 @@
" MMIO : %,14ld Pages (%,ld Bytes)\r\n"
" MMIO_Port : %,14ld Pages (%,ld Bytes)\r\n"
" PalCode : %,14ld Pages (%,ld Bytes)\r\n"
+ " Unaccepted: %,14ld Pages (%,ld Bytes)\r\n"
" Available : %,14ld Pages (%,ld Bytes)\r\n"
" Persistent: %,14ld Pages (%,ld Bytes)\r\n"
#string STR_MEMMAP_LIST_SUMM_OTHER #language en-US " %08x : %,14ld Pages (%,ld Bytes)\r\n"
#string STR_MEMMAP_LIST_SUMM2 #language en-US " -------------- \r\n"
"Total Memory: %,14ld MB (%,ld Bytes)\r\n"
#string STR_MEMMAP_LIST_ITEM_SFO #language en-US "MemoryMap,"%s","%LX","%LX","%LX","%LX"\r\n"
-#string STR_MEMMAP_LIST_SUMM_SFO #language en-US "MemoryMapSummary,"%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld"\r\n"
+#string STR_MEMMAP_LIST_SUMM_SFO #language en-US "MemoryMapSummary,"%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld","%Ld", "%Ld"\r\n"
#string STR_EFI_COMPRESS_FAIL #language en-US "Unable to compress: %r.\r\n"
#string STR_EFI_DECOMPRESS_FAIL #language en-US "Unable to decompress: %r.\r\n"
--
2.29.2.windows.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH V5 07/10] OvmfPkg: Introduce lazy accept in PlatformInitLib and PlatformPei
2022-11-01 5:13 [PATCH V5 00/10] Introduce Lazy-accept for Tdx guest Min Xu
` (5 preceding siblings ...)
2022-11-01 5:13 ` [PATCH V5 06/10] ShellPkg: Update shell command memmap to show unaccepted memory Min Xu
@ 2022-11-01 5:13 ` Min Xu
2022-11-01 5:13 ` [PATCH V5 08/10] MdePkg: The prototype definition of EdkiiMemoryAcceptProtocol Min Xu
` (4 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Min Xu @ 2022-11-01 5:13 UTC (permalink / raw)
To: devel
Cc: Min M Xu, Erdem Aktas, Gerd Hoffmann, James Bottomley, Jiewen Yao,
Tom Lendacky
From: Min M Xu <min.m.xu@intel.com>
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3937
There are below major changes in PlatformInitLib/PlatformPei
1. ProcessHobList
The unaccepted memory is accepted if it is under 4G address.
Please be noted: in current stage, we only accept the memory under 4G.
We will re-visit here in the future when on-demand accept memory is
required.
2. TransferTdxHobList
Transfer the unaccepted memory hob to EFI_RESOURCE_SYSTEM_MEMORY hob
if it is accepted.
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>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Min Xu <min.m.xu@intel.com>
---
OvmfPkg/Library/PlatformInitLib/IntelTdx.c | 88 ++++++++++++++++++---
OvmfPkg/Library/PlatformInitLib/MemDetect.c | 2 +
2 files changed, 81 insertions(+), 9 deletions(-)
diff --git a/OvmfPkg/Library/PlatformInitLib/IntelTdx.c b/OvmfPkg/Library/PlatformInitLib/IntelTdx.c
index 797f880df035..acd114e38e46 100644
--- a/OvmfPkg/Library/PlatformInitLib/IntelTdx.c
+++ b/OvmfPkg/Library/PlatformInitLib/IntelTdx.c
@@ -7,6 +7,7 @@
**/
+#include <Base.h>
#include <PiPei.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
@@ -25,6 +26,7 @@
#include <ConfidentialComputingGuestAttr.h>
#define ALIGNED_2MB_MASK 0x1fffff
+#define MEGABYTE_SHIFT 20
/**
This function will be called to accept pages. Only BSP accepts pages.
@@ -375,11 +377,15 @@ ProcessHobList (
EFI_STATUS Status;
EFI_PEI_HOB_POINTERS Hob;
EFI_PHYSICAL_ADDRESS PhysicalEnd;
+ UINT64 ResourceLength;
+ UINT64 AccumulateAcceptedMemory;
Status = EFI_SUCCESS;
ASSERT (VmmHobList != NULL);
Hob.Raw = (UINT8 *)VmmHobList;
+ AccumulateAcceptedMemory = 0;
+
//
// Parse the HOB list until end of list or matching type is found.
//
@@ -393,7 +399,15 @@ ProcessHobList (
DEBUG ((DEBUG_INFO, "ResourceLength: 0x%llx\n", Hob.ResourceDescriptor->ResourceLength));
DEBUG ((DEBUG_INFO, "Owner: %g\n\n", &Hob.ResourceDescriptor->Owner));
- PhysicalEnd = Hob.ResourceDescriptor->PhysicalStart + Hob.ResourceDescriptor->ResourceLength;
+ PhysicalEnd = Hob.ResourceDescriptor->PhysicalStart + Hob.ResourceDescriptor->ResourceLength;
+ ResourceLength = Hob.ResourceDescriptor->ResourceLength;
+
+ if (Hob.ResourceDescriptor->PhysicalStart >= BASE_4GB) {
+ //
+ // In current stage, we only accept the memory under 4G
+ //
+ break;
+ }
Status = BspAcceptMemoryResourceRange (
Hob.ResourceDescriptor->PhysicalStart,
@@ -402,6 +416,8 @@ ProcessHobList (
if (EFI_ERROR (Status)) {
break;
}
+
+ AccumulateAcceptedMemory += ResourceLength;
}
}
@@ -460,6 +476,60 @@ ProcessTdxHobList (
return Status;
}
+/**
+ * Build ResourceDescriptorHob for the unaccepted memory region.
+ * This memory region may be splitted into 2 parts because of lazy accept.
+ *
+ * @param Hob Point to the EFI_HOB_RESOURCE_DESCRIPTOR
+ * @return VOID
+ */
+VOID
+BuildResourceDescriptorHobForUnacceptedMemory (
+ IN EFI_HOB_RESOURCE_DESCRIPTOR *Hob
+ )
+{
+ EFI_PHYSICAL_ADDRESS PhysicalStart;
+ EFI_PHYSICAL_ADDRESS PhysicalEnd;
+ UINT64 ResourceLength;
+ EFI_RESOURCE_TYPE ResourceType;
+ EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute;
+ UINT64 MaxAcceptedMemoryAddress;
+
+ ASSERT (Hob->ResourceType == BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED);
+
+ ResourceType = BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED;
+ ResourceAttribute = Hob->ResourceAttribute;
+ PhysicalStart = Hob->PhysicalStart;
+ ResourceLength = Hob->ResourceLength;
+ PhysicalEnd = PhysicalStart + ResourceLength;
+
+ //
+ // In the first stage of lazy-accept, all the memory under 4G will be accepted.
+ // The memory above 4G will not be accepted.
+ //
+ MaxAcceptedMemoryAddress = BASE_4GB;
+
+ if (PhysicalEnd <= MaxAcceptedMemoryAddress) {
+ //
+ // This memory region has been accepted.
+ //
+ ResourceType = EFI_RESOURCE_SYSTEM_MEMORY;
+ ResourceAttribute |= (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_TESTED);
+ } else if (PhysicalStart >= MaxAcceptedMemoryAddress) {
+ //
+ // This memory region hasn't been accepted.
+ // So keep the ResourceType and ResourceAttribute unchange.
+ //
+ }
+
+ BuildResourceDescriptorHob (
+ ResourceType,
+ ResourceAttribute,
+ PhysicalStart,
+ ResourceLength
+ );
+}
+
/**
Transfer the incoming HobList for the TD to the final HobList for Dxe.
The Hobs transferred in this function are ResourceDescriptor hob and
@@ -489,16 +559,16 @@ TransferTdxHobList (
ResourceAttribute = Hob.ResourceDescriptor->ResourceAttribute;
if (ResourceType == BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED) {
- ResourceType = EFI_RESOURCE_SYSTEM_MEMORY;
- ResourceAttribute |= (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_TESTED);
+ BuildResourceDescriptorHobForUnacceptedMemory (Hob.ResourceDescriptor);
+ } else {
+ BuildResourceDescriptorHob (
+ ResourceType,
+ ResourceAttribute,
+ Hob.ResourceDescriptor->PhysicalStart,
+ Hob.ResourceDescriptor->ResourceLength
+ );
}
- BuildResourceDescriptorHob (
- ResourceType,
- ResourceAttribute,
- Hob.ResourceDescriptor->PhysicalStart,
- Hob.ResourceDescriptor->ResourceLength
- );
break;
case EFI_HOB_TYPE_MEMORY_ALLOCATION:
BuildMemoryAllocationHob (
diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/PlatformInitLib/MemDetect.c
index ae217d0242ed..b8feae4309de 100644
--- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c
+++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c
@@ -42,6 +42,8 @@ Module Name:
#include <Library/PlatformInitLib.h>
+#define MEGABYTE_SHIFT 20
+
VOID
EFIAPI
PlatformQemuUc32BaseInitialization (
--
2.29.2.windows.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH V5 08/10] MdePkg: The prototype definition of EdkiiMemoryAcceptProtocol
2022-11-01 5:13 [PATCH V5 00/10] Introduce Lazy-accept for Tdx guest Min Xu
` (6 preceding siblings ...)
2022-11-01 5:13 ` [PATCH V5 07/10] OvmfPkg: Introduce lazy accept in PlatformInitLib and PlatformPei Min Xu
@ 2022-11-01 5:13 ` Min Xu
2022-11-01 5:13 ` [PATCH V5 09/10] OvmfPkg: Realize EdkiiMemoryAcceptProtocol in TdxDxe Min Xu
` (3 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Min Xu @ 2022-11-01 5:13 UTC (permalink / raw)
To: devel
Cc: Jiaqi Gao, Michael D Kinney, Liming Gao, Zhiguang Liu,
Erdem Aktas, Gerd Hoffmann, James Bottomley, Jiewen Yao,
Tom Lendacky, Min Xu
From: Jiaqi Gao <jiaqi.gao@intel.com>
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3937
EdkiiMemoryAcceptProtocol is defined in MdePkg, the method AcceptMemory()
can be called when memory needs to be accepted.
EdkiiMemoryAcceptProtocol can be installed by architecture-specific
drivers such as TdxDxe. This allows different isolation architectures
to realize their own low-level methods to accept memory.
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@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>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Jiaqi Gao <jiaqi.gao@intel.com>
Signed-off-by: Min Xu <min.m.xu@intel.com>
---
MdePkg/Include/Protocol/MemoryAccept.h | 37 ++++++++++++++++++++++++++
MdePkg/MdePkg.dec | 3 +++
2 files changed, 40 insertions(+)
create mode 100644 MdePkg/Include/Protocol/MemoryAccept.h
diff --git a/MdePkg/Include/Protocol/MemoryAccept.h b/MdePkg/Include/Protocol/MemoryAccept.h
new file mode 100644
index 000000000000..f7646e04d8a1
--- /dev/null
+++ b/MdePkg/Include/Protocol/MemoryAccept.h
@@ -0,0 +1,37 @@
+/** @file
+ The file provides the protocol to provide interface to accept memory.
+
+ Copyright (c) 2021 - 2022, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef MEMORY_ACCEPT_H_
+#define MEMORY_ACCEPT_H_
+
+#define EDKII_MEMORY_ACCEPT_PROTOCOL_GUID \
+ { 0x38c74800, 0x5590, 0x4db4, { 0xa0, 0xf3, 0x67, 0x5d, 0x9b, 0x8e, 0x80, 0x26 } };
+
+typedef struct _EDKII_MEMORY_ACCEPT_PROTOCOL EDKII_MEMORY_ACCEPT_PROTOCOL;
+
+/**
+ @param This A pointer to a EDKII_MEMORY_ACCEPT_PROTOCOL.
+**/
+typedef
+EFI_STATUS
+(EFIAPI *EDKII_ACCEPT_MEMORY)(
+ IN EDKII_MEMORY_ACCEPT_PROTOCOL *This,
+ IN EFI_PHYSICAL_ADDRESS StartAddress,
+ IN UINTN Size
+ );
+
+///
+/// The EDKII_MEMORY_ACCEPT_PROTOCOL provides the ability for memory services
+/// to accept memory.
+///
+struct _EDKII_MEMORY_ACCEPT_PROTOCOL {
+ EDKII_ACCEPT_MEMORY AcceptMemory;
+};
+
+extern EFI_GUID gEdkiiMemoryAcceptProtocolGuid;
+
+#endif
diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
index 4c81cbd75ab2..ba287d9b3cfc 100644
--- a/MdePkg/MdePkg.dec
+++ b/MdePkg/MdePkg.dec
@@ -1023,6 +1023,9 @@
gEfiPeiDelayedDispatchPpiGuid = { 0x869c711d, 0x649c, 0x44fe, { 0x8b, 0x9e, 0x2c, 0xbb, 0x29, 0x11, 0xc3, 0xe6 }}
[Protocols]
+ ## Include/Protocol/MemoryAccept.h
+ gEdkiiMemoryAcceptProtocolGuid = { 0x38c74800, 0x5590, 0x4db4, { 0xa0, 0xf3, 0x67, 0x5d, 0x9b, 0x8e, 0x80, 0x26 }}
+
## Include/Protocol/Pcd.h
gPcdProtocolGuid = { 0x11B34006, 0xD85B, 0x4D0A, { 0xA2, 0x90, 0xD5, 0xA5, 0x71, 0x31, 0x0E, 0xF7 }}
--
2.29.2.windows.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH V5 09/10] OvmfPkg: Realize EdkiiMemoryAcceptProtocol in TdxDxe
2022-11-01 5:13 [PATCH V5 00/10] Introduce Lazy-accept for Tdx guest Min Xu
` (7 preceding siblings ...)
2022-11-01 5:13 ` [PATCH V5 08/10] MdePkg: The prototype definition of EdkiiMemoryAcceptProtocol Min Xu
@ 2022-11-01 5:13 ` Min Xu
2022-11-01 5:13 ` [PATCH V5 10/10] OvmfPkg: Call gEdkiiMemoryAcceptProtocolGuid to accept pages Min Xu
` (2 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: Min Xu @ 2022-11-01 5:13 UTC (permalink / raw)
To: devel
Cc: Min M Xu, Erdem Aktas, Gerd Hoffmann, James Bottomley, Jiewen Yao,
Tom Lendacky
From: Min M Xu <min.m.xu@intel.com>
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3937
Memory usage may exceed the amount accepted at the begining (SEC), TDVF
needs to accept memory dynamically when OUT_OF_RESOURCE occurs.
Another usage is in SetOrClearSharedBit. If a memory region is changed from
shared to private, it must be accepted again.
EdkiiMemoryAcceptProtocol is defined in MdePkg and is implementated /
installed in TdxDxe for Intel TDX memory acceptance.
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>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Min Xu <min.m.xu@intel.com>
---
OvmfPkg/TdxDxe/TdxDxe.c | 103 ++++++++++++++++++++++++++++++++++++++
OvmfPkg/TdxDxe/TdxDxe.inf | 2 +
2 files changed, 105 insertions(+)
diff --git a/OvmfPkg/TdxDxe/TdxDxe.c b/OvmfPkg/TdxDxe/TdxDxe.c
index 05cfb597dc64..30732f421bb6 100644
--- a/OvmfPkg/TdxDxe/TdxDxe.c
+++ b/OvmfPkg/TdxDxe/TdxDxe.c
@@ -24,6 +24,7 @@
#include <Library/HobLib.h>
#include <Protocol/Cpu.h>
#include <Protocol/MpInitLibDepProtocols.h>
+#include <Protocol/MemoryAccept.h>
#include <Library/UefiBootServicesTableLib.h>
#include <ConfidentialComputingGuestAttr.h>
#include <IndustryStandard/Tdx.h>
@@ -32,6 +33,95 @@
#include <TdxAcpiTable.h>
#include <Library/MemEncryptTdxLib.h>
+#define ALIGNED_2MB_MASK 0x1fffff
+EFI_HANDLE mTdxDxeHandle = NULL;
+
+EFI_STATUS
+EFIAPI
+TdxMemoryAccept (
+ IN EDKII_MEMORY_ACCEPT_PROTOCOL *This,
+ IN EFI_PHYSICAL_ADDRESS StartAddress,
+ IN UINTN Size
+ )
+{
+ EFI_STATUS Status;
+ UINT32 AcceptPageSize;
+ UINT64 StartAddress1;
+ UINT64 StartAddress2;
+ UINT64 StartAddress3;
+ UINT64 Length1;
+ UINT64 Length2;
+ UINT64 Length3;
+ UINT64 Pages;
+
+ AcceptPageSize = FixedPcdGet32 (PcdTdxAcceptPageSize);
+ StartAddress1 = 0;
+ StartAddress2 = 0;
+ StartAddress3 = 0;
+ Length1 = 0;
+ Length2 = 0;
+ Length3 = 0;
+
+ if (Size == 0) {
+ return EFI_SUCCESS;
+ }
+
+ if (ALIGN_VALUE (StartAddress, SIZE_2MB) != StartAddress) {
+ StartAddress1 = StartAddress;
+ Length1 = ALIGN_VALUE (StartAddress, SIZE_2MB) - StartAddress;
+ if (Length1 >= Size) {
+ Length1 = Size;
+ }
+
+ StartAddress += Length1;
+ Size -= Length1;
+ }
+
+ if (Size > SIZE_2MB) {
+ StartAddress2 = StartAddress;
+ Length2 = Size & ~(UINT64)ALIGNED_2MB_MASK;
+ StartAddress += Length2;
+ Size -= Length2;
+ }
+
+ if (Size) {
+ StartAddress3 = StartAddress;
+ Length3 = Size;
+ }
+
+ Status = EFI_SUCCESS;
+ if (Length1 > 0) {
+ Pages = Length1 / SIZE_4KB;
+ Status = TdAcceptPages (StartAddress1, Pages, SIZE_4KB);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ }
+
+ if (Length2 > 0) {
+ Pages = Length2 / AcceptPageSize;
+ Status = TdAcceptPages (StartAddress2, Pages, AcceptPageSize);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ }
+
+ if (Length3 > 0) {
+ Pages = Length3 / SIZE_4KB;
+ Status = TdAcceptPages (StartAddress3, Pages, SIZE_4KB);
+ ASSERT (!EFI_ERROR (Status));
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ }
+
+ return Status;
+}
+
+EDKII_MEMORY_ACCEPT_PROTOCOL mMemoryAcceptProtocol = {
+ TdxMemoryAccept
+};
+
VOID
SetPcdSettings (
EFI_HOB_PLATFORM_INFO *PlatformInfoHob
@@ -279,6 +369,19 @@ TdxDxeEntryPoint (
NULL
);
+ //
+ // Install MemoryAccept protocol for TDX
+ //
+ Status = gBS->InstallProtocolInterface (
+ &mTdxDxeHandle,
+ &gEdkiiMemoryAcceptProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ &mMemoryAcceptProtocol
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Install EdkiiMemoryAcceptProtocol failed.\n"));
+ }
+
//
// Call TDINFO to get actual number of cpus in domain
//
diff --git a/OvmfPkg/TdxDxe/TdxDxe.inf b/OvmfPkg/TdxDxe/TdxDxe.inf
index 3ce8a5c32c98..9793562884c7 100644
--- a/OvmfPkg/TdxDxe/TdxDxe.inf
+++ b/OvmfPkg/TdxDxe/TdxDxe.inf
@@ -52,6 +52,7 @@
gEfiAcpiTableProtocolGuid ## CONSUMES
gEfiMpInitLibMpDepProtocolGuid
gEfiMpInitLibUpDepProtocolGuid
+ gEdkiiMemoryAcceptProtocolGuid
[Pcd]
gUefiOvmfPkgTokenSpaceGuid.PcdPciIoBase
@@ -69,3 +70,4 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdTdxSharedBitMask
gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack
gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved
+ gUefiOvmfPkgTokenSpaceGuid.PcdTdxAcceptPageSize
--
2.29.2.windows.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH V5 10/10] OvmfPkg: Call gEdkiiMemoryAcceptProtocolGuid to accept pages
2022-11-01 5:13 [PATCH V5 00/10] Introduce Lazy-accept for Tdx guest Min Xu
` (8 preceding siblings ...)
2022-11-01 5:13 ` [PATCH V5 09/10] OvmfPkg: Realize EdkiiMemoryAcceptProtocol in TdxDxe Min Xu
@ 2022-11-01 5:13 ` Min Xu
2022-11-01 9:00 ` [PATCH V5 00/10] Introduce Lazy-accept for Tdx guest Yao, Jiewen
[not found] ` <17236A59BF264591.6436@groups.io>
11 siblings, 0 replies; 13+ messages in thread
From: Min Xu @ 2022-11-01 5:13 UTC (permalink / raw)
To: devel
Cc: Min M Xu, Erdem Aktas, James Bottomley, Jiewen Yao, Gerd Hoffmann,
Tom Lendacky
From: Min M Xu <min.m.xu@intel.com>
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3937
After EdkiiMemoryAcceptProtocol is implemented in TdxDxe driver, we can
call it to accept pages in DXE phase.
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Min Xu <min.m.xu@intel.com>
---
.../BaseMemEncryptTdxLib/BaseMemEncryptTdxLib.inf | 3 +++
.../Library/BaseMemEncryptTdxLib/MemoryEncryption.c | 12 +++++++++---
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxLib.inf b/OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxLib.inf
index a8abfec12fa3..11768825f8ca 100644
--- a/OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxLib.inf
+++ b/OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxLib.inf
@@ -42,3 +42,6 @@
[Pcd]
gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr
+
+[Protocols]
+ gEdkiiMemoryAcceptProtocolGuid
diff --git a/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c b/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c
index 9d11c6e4df72..503f626d75c6 100644
--- a/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c
+++ b/OvmfPkg/Library/BaseMemEncryptTdxLib/MemoryEncryption.c
@@ -27,6 +27,8 @@
#include "VirtualMemory.h"
#include <IndustryStandard/Tdx.h>
#include <Library/TdxLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Protocol/MemoryAccept.h>
#include <ConfidentialComputingGuestAttr.h>
typedef enum {
@@ -517,8 +519,9 @@ SetOrClearSharedBit (
IN UINT64 Length
)
{
- UINT64 AddressEncMask;
- UINT64 Status;
+ UINT64 AddressEncMask;
+ UINT64 Status;
+ EDKII_MEMORY_ACCEPT_PROTOCOL *MemoryAcceptProtocol;
AddressEncMask = GetMemEncryptionAddressMask ();
@@ -539,7 +542,10 @@ SetOrClearSharedBit (
// If changing shared to private, must accept-page again
//
if (Mode == ClearSharedBit) {
- TdAcceptPages (PhysicalAddress, Length / EFI_PAGE_SIZE, EFI_PAGE_SIZE);
+ Status = gBS->LocateProtocol (&gEdkiiMemoryAcceptProtocolGuid, NULL, (VOID **)&MemoryAcceptProtocol);
+ ASSERT (!EFI_ERROR (Status));
+ Status = MemoryAcceptProtocol->AcceptMemory (MemoryAcceptProtocol, PhysicalAddress, Length);
+ ASSERT (!EFI_ERROR (Status));
}
DEBUG ((
--
2.29.2.windows.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH V5 00/10] Introduce Lazy-accept for Tdx guest
2022-11-01 5:13 [PATCH V5 00/10] Introduce Lazy-accept for Tdx guest Min Xu
` (9 preceding siblings ...)
2022-11-01 5:13 ` [PATCH V5 10/10] OvmfPkg: Call gEdkiiMemoryAcceptProtocolGuid to accept pages Min Xu
@ 2022-11-01 9:00 ` Yao, Jiewen
[not found] ` <17236A59BF264591.6436@groups.io>
11 siblings, 0 replies; 13+ messages in thread
From: Yao, Jiewen @ 2022-11-01 9:00 UTC (permalink / raw)
To: Xu, Min M, devel@edk2.groups.io
Cc: Gao, Zhichao, Kinney, Michael D, Liu, Zhiguang, Wang, Jian J,
Gao, Liming, Ni, Ray, Aktas, Erdem, Gerd Hoffmann,
James Bottomley, Tom Lendacky, Gao, Jiaqi
For OvmfPkg, reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
> -----Original Message-----
> From: Xu, Min M <min.m.xu@intel.com>
> Sent: Tuesday, November 1, 2022 1:14 PM
> To: devel@edk2.groups.io
> Cc: Xu, Min M <min.m.xu@intel.com>; Gao, Zhichao
> <zhichao.gao@intel.com>; Kinney, Michael D
> <michael.d.kinney@intel.com>; Liu, Zhiguang <zhiguang.liu@intel.com>;
> Wang, Jian J <jian.j.wang@intel.com>; Gao, Liming
> <gaoliming@byosoft.com.cn>; Ni, Ray <ray.ni@intel.com>; Aktas, Erdem
> <erdemaktas@google.com>; Gerd Hoffmann <kraxel@redhat.com>; James
> Bottomley <jejb@linux.ibm.com>; Yao, Jiewen <jiewen.yao@intel.com>;
> Tom Lendacky <thomas.lendacky@amd.com>; Gao, Jiaqi
> <jiaqi.gao@intel.com>
> Subject: [PATCH V5 00/10] Introduce Lazy-accept for Tdx guest
>
> 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
>
> This patch-set is related to code first, so there is a edk2-staging branch.
> Please see https://github.com/tianocore/edk2-staging/tree/TDVF
>
> Patch 1-4:
> Introduce lazy-accept related definitions.
>
> Patch 5-6:
> Update Dxe and shell for unaccepted memory.
>
> Patch 7:
> Update OvmfPkg for unaccepted memory.
>
> Patch 8 - 10:
> Introduce EfiMemoryAcceptProtocol and realize it in TdxDxe.
>
> Code: https://github.com/mxu9/edk2/tree/lazyaccept.v5
>
> v5 changes:
> - Rebase the patch-set to commit df7ce74e6c75.
> - Add reviewed-by in MdeModulePkg/MdePkg related patches(#1/2/4/5/8).
> - Add acked-by in patch#7.
>
> v4 changes:
> - To follow the name convention of EDKII code first, the name of
> EFI_RESOURCE_MEMORY_UNACCEPTED is updated to
> BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED.
> - Remove the definition of MaxAcceptedMemoryAddress because in
> current
> stage we will accept all the memory under 4G. So
> MaxAcceptedMemoryAddress is not useable in this assumption.
> - Because this is related to code first, there is edk2-staging branch.
> The branch link is attached.
> https://github.com/tianocore/edk2-staging/tree/TDVF
>
> 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 <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 (1):
> MdePkg: The prototype definition of EdkiiMemoryAcceptProtocol
>
> Min M Xu (9):
> MdeModulePkg: Add PrePiHob.h
> MdePkg: Increase EFI_RESOURCE_MAX_MEMORY_TYPE
> OvmfPkg: Use BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED 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: Introduce lazy accept in PlatformInitLib and PlatformPei
> 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 +
> .../BaseMemEncryptTdxLib.inf | 3 +
> .../BaseMemEncryptTdxLib/MemoryEncryption.c | 12 +-
> OvmfPkg/Library/PeilessStartupLib/Hob.c | 5 +-
> OvmfPkg/Library/PlatformInitLib/IntelTdx.c | 98 ++++++++++++++---
> OvmfPkg/Library/PlatformInitLib/MemDetect.c | 2 +
> OvmfPkg/TdxDxe/TdxDxe.c | 103 ++++++++++++++++++
> OvmfPkg/TdxDxe/TdxDxe.inf | 2 +
> .../UefiShellDebug1CommandsLib/MemMap.c | 13 +++
> .../UefiShellDebug1CommandsLib.uni | 3 +-
> 18 files changed, 381 insertions(+), 40 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
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [edk2-devel] [PATCH V5 00/10] Introduce Lazy-accept for Tdx guest
[not found] ` <17236A59BF264591.6436@groups.io>
@ 2022-11-01 10:16 ` Yao, Jiewen
0 siblings, 0 replies; 13+ messages in thread
From: Yao, Jiewen @ 2022-11-01 10:16 UTC (permalink / raw)
To: devel@edk2.groups.io, Yao, Jiewen, Xu, Min M
Cc: Gao, Zhichao, Kinney, Michael D, Liu, Zhiguang, Wang, Jian J,
Gao, Liming, Ni, Ray, Aktas, Erdem, Gerd Hoffmann,
James Bottomley, Tom Lendacky, Gao, Jiaqi
Merged https://github.com/tianocore/edk2/pull/3572
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Yao,
> Jiewen
> Sent: Tuesday, November 1, 2022 5:00 PM
> To: Xu, Min M <min.m.xu@intel.com>; devel@edk2.groups.io
> Cc: Gao, Zhichao <zhichao.gao@intel.com>; Kinney, Michael D
> <michael.d.kinney@intel.com>; Liu, Zhiguang <zhiguang.liu@intel.com>;
> Wang, Jian J <jian.j.wang@intel.com>; Gao, Liming
> <gaoliming@byosoft.com.cn>; Ni, Ray <ray.ni@intel.com>; Aktas, Erdem
> <erdemaktas@google.com>; Gerd Hoffmann <kraxel@redhat.com>; James
> Bottomley <jejb@linux.ibm.com>; Tom Lendacky
> <thomas.lendacky@amd.com>; Gao, Jiaqi <jiaqi.gao@intel.com>
> Subject: Re: [edk2-devel] [PATCH V5 00/10] Introduce Lazy-accept for Tdx
> guest
>
> For OvmfPkg, reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
>
> > -----Original Message-----
> > From: Xu, Min M <min.m.xu@intel.com>
> > Sent: Tuesday, November 1, 2022 1:14 PM
> > To: devel@edk2.groups.io
> > Cc: Xu, Min M <min.m.xu@intel.com>; Gao, Zhichao
> > <zhichao.gao@intel.com>; Kinney, Michael D
> > <michael.d.kinney@intel.com>; Liu, Zhiguang <zhiguang.liu@intel.com>;
> > Wang, Jian J <jian.j.wang@intel.com>; Gao, Liming
> > <gaoliming@byosoft.com.cn>; Ni, Ray <ray.ni@intel.com>; Aktas, Erdem
> > <erdemaktas@google.com>; Gerd Hoffmann <kraxel@redhat.com>;
> James
> > Bottomley <jejb@linux.ibm.com>; Yao, Jiewen <jiewen.yao@intel.com>;
> > Tom Lendacky <thomas.lendacky@amd.com>; Gao, Jiaqi
> > <jiaqi.gao@intel.com>
> > Subject: [PATCH V5 00/10] Introduce Lazy-accept for Tdx guest
> >
> > 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
> >
> > This patch-set is related to code first, so there is a edk2-staging branch.
> > Please see https://github.com/tianocore/edk2-staging/tree/TDVF
> >
> > Patch 1-4:
> > Introduce lazy-accept related definitions.
> >
> > Patch 5-6:
> > Update Dxe and shell for unaccepted memory.
> >
> > Patch 7:
> > Update OvmfPkg for unaccepted memory.
> >
> > Patch 8 - 10:
> > Introduce EfiMemoryAcceptProtocol and realize it in TdxDxe.
> >
> > Code: https://github.com/mxu9/edk2/tree/lazyaccept.v5
> >
> > v5 changes:
> > - Rebase the patch-set to commit df7ce74e6c75.
> > - Add reviewed-by in MdeModulePkg/MdePkg related
> patches(#1/2/4/5/8).
> > - Add acked-by in patch#7.
> >
> > v4 changes:
> > - To follow the name convention of EDKII code first, the name of
> > EFI_RESOURCE_MEMORY_UNACCEPTED is updated to
> > BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED.
> > - Remove the definition of MaxAcceptedMemoryAddress because in
> > current
> > stage we will accept all the memory under 4G. So
> > MaxAcceptedMemoryAddress is not useable in this assumption.
> > - Because this is related to code first, there is edk2-staging branch.
> > The branch link is attached.
> > https://github.com/tianocore/edk2-staging/tree/TDVF
> >
> > 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 <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 (1):
> > MdePkg: The prototype definition of EdkiiMemoryAcceptProtocol
> >
> > Min M Xu (9):
> > MdeModulePkg: Add PrePiHob.h
> > MdePkg: Increase EFI_RESOURCE_MAX_MEMORY_TYPE
> > OvmfPkg: Use BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED 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: Introduce lazy accept in PlatformInitLib and PlatformPei
> > 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 +
> > .../BaseMemEncryptTdxLib.inf | 3 +
> > .../BaseMemEncryptTdxLib/MemoryEncryption.c | 12 +-
> > OvmfPkg/Library/PeilessStartupLib/Hob.c | 5 +-
> > OvmfPkg/Library/PlatformInitLib/IntelTdx.c | 98 ++++++++++++++---
> > OvmfPkg/Library/PlatformInitLib/MemDetect.c | 2 +
> > OvmfPkg/TdxDxe/TdxDxe.c | 103 ++++++++++++++++++
> > OvmfPkg/TdxDxe/TdxDxe.inf | 2 +
> > .../UefiShellDebug1CommandsLib/MemMap.c | 13 +++
> > .../UefiShellDebug1CommandsLib.uni | 3 +-
> > 18 files changed, 381 insertions(+), 40 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
>
>
>
>
>
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2022-11-01 10:16 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-01 5:13 [PATCH V5 00/10] Introduce Lazy-accept for Tdx guest Min Xu
2022-11-01 5:13 ` [PATCH V5 01/10] MdeModulePkg: Add PrePiHob.h Min Xu
2022-11-01 5:13 ` [PATCH V5 02/10] MdePkg: Increase EFI_RESOURCE_MAX_MEMORY_TYPE Min Xu
2022-11-01 5:13 ` [PATCH V5 03/10] OvmfPkg: Use BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED defined in MdeModulePkg Min Xu
2022-11-01 5:13 ` [PATCH V5 04/10] MdePkg: Add UEFI Unaccepted memory definition Min Xu
2022-11-01 5:13 ` [PATCH V5 05/10] MdeModulePkg: Update Dxe to handle unaccepted memory type Min Xu
2022-11-01 5:13 ` [PATCH V5 06/10] ShellPkg: Update shell command memmap to show unaccepted memory Min Xu
2022-11-01 5:13 ` [PATCH V5 07/10] OvmfPkg: Introduce lazy accept in PlatformInitLib and PlatformPei Min Xu
2022-11-01 5:13 ` [PATCH V5 08/10] MdePkg: The prototype definition of EdkiiMemoryAcceptProtocol Min Xu
2022-11-01 5:13 ` [PATCH V5 09/10] OvmfPkg: Realize EdkiiMemoryAcceptProtocol in TdxDxe Min Xu
2022-11-01 5:13 ` [PATCH V5 10/10] OvmfPkg: Call gEdkiiMemoryAcceptProtocolGuid to accept pages Min Xu
2022-11-01 9:00 ` [PATCH V5 00/10] Introduce Lazy-accept for Tdx guest Yao, Jiewen
[not found] ` <17236A59BF264591.6436@groups.io>
2022-11-01 10:16 ` [edk2-devel] " Yao, Jiewen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox