* [PATCH V3 00/12] Introduce Lazy-accept for Tdx guest
@ 2022-09-05 8:34 Min Xu
2022-09-05 8:34 ` [PATCH V3 01/12] MdeModulePkg: Add PrePiHob.h Min Xu
` (11 more replies)
0 siblings, 12 replies; 25+ messages in thread
From: Min Xu @ 2022-09-05 8:34 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
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 <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 (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
^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH V3 01/12] MdeModulePkg: Add PrePiHob.h
2022-09-05 8:34 [PATCH V3 00/12] Introduce Lazy-accept for Tdx guest Min Xu
@ 2022-09-05 8:34 ` Min Xu
2022-09-07 5:31 ` Gerd Hoffmann
2022-09-05 8:34 ` [PATCH V3 02/12] MdePkg: Increase EFI_RESOURCE_MAX_MEMORY_TYPE Min Xu
` (10 subsequent siblings)
11 siblings, 1 reply; 25+ messages in thread
From: Min Xu @ 2022-09-05 8:34 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
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.
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: 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..38a8f1be149d
--- /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_
+
+//
+// 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.
+//
+#define EFI_RESOURCE_MEMORY_UNACCEPTED 0x00000007
+
+#endif
--
2.29.2.windows.2
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH V3 02/12] MdePkg: Increase EFI_RESOURCE_MAX_MEMORY_TYPE
2022-09-05 8:34 [PATCH V3 00/12] Introduce Lazy-accept for Tdx guest Min Xu
2022-09-05 8:34 ` [PATCH V3 01/12] MdeModulePkg: Add PrePiHob.h Min Xu
@ 2022-09-05 8:34 ` Min Xu
2022-09-06 18:44 ` Michael D Kinney
2022-09-05 8:34 ` [PATCH V3 03/12] OvmfPkg: Use EFI_RESOURCE_MEMORY_UNACCEPTED which defined in MdeModulePkg Min Xu
` (9 subsequent siblings)
11 siblings, 1 reply; 25+ messages in thread
From: Min Xu @ 2022-09-05 8:34 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
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 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>
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..9af2e957fee5 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
+//
+// 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 EFI_RESOURCE_MEMORY_UNACCEPTED is officially published
+// in PI spec, we will re-visit here.
+//
+// #define 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] 25+ messages in thread
* [PATCH V3 03/12] OvmfPkg: Use EFI_RESOURCE_MEMORY_UNACCEPTED which defined in MdeModulePkg
2022-09-05 8:34 [PATCH V3 00/12] Introduce Lazy-accept for Tdx guest Min Xu
2022-09-05 8:34 ` [PATCH V3 01/12] MdeModulePkg: Add PrePiHob.h Min Xu
2022-09-05 8:34 ` [PATCH V3 02/12] MdePkg: Increase EFI_RESOURCE_MAX_MEMORY_TYPE Min Xu
@ 2022-09-05 8:34 ` Min Xu
2022-09-07 5:31 ` Gerd Hoffmann
2022-09-05 8:34 ` [PATCH V3 04/12] MdePkg: Add UEFI Unaccepted memory definition Min Xu
` (8 subsequent siblings)
11 siblings, 1 reply; 25+ messages in thread
From: Min Xu @ 2022-09-05 8:34 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
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>
Signed-off-by: Min Xu <min.m.xu@intel.com>
---
OvmfPkg/Library/PeilessStartupLib/Hob.c | 3 +--
OvmfPkg/Library/PlatformInitLib/IntelTdx.c | 2 +-
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/OvmfPkg/Library/PeilessStartupLib/Hob.c b/OvmfPkg/Library/PeilessStartupLib/Hob.c
index 5fc84a809025..a9b92b5fbaba 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.
*
diff --git a/OvmfPkg/Library/PlatformInitLib/IntelTdx.c b/OvmfPkg/Library/PlatformInitLib/IntelTdx.c
index c6d7c8bb6e0e..396b14d919d2 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
/**
This function will be called to accept pages. Only BSP accepts pages.
--
2.29.2.windows.2
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH V3 04/12] MdePkg: Add UEFI Unaccepted memory definition
2022-09-05 8:34 [PATCH V3 00/12] Introduce Lazy-accept for Tdx guest Min Xu
` (2 preceding siblings ...)
2022-09-05 8:34 ` [PATCH V3 03/12] OvmfPkg: Use EFI_RESOURCE_MEMORY_UNACCEPTED which defined in MdeModulePkg Min Xu
@ 2022-09-05 8:34 ` Min Xu
2022-09-07 5:32 ` Gerd Hoffmann
2022-09-05 8:34 ` [PATCH V3 05/12] MdeModulePkg: Update Dxe to handle unaccepted memory type Min Xu
` (7 subsequent siblings)
11 siblings, 1 reply; 25+ messages in thread
From: Min Xu @ 2022-09-05 8:34 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>
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] 25+ messages in thread
* [PATCH V3 05/12] MdeModulePkg: Update Dxe to handle unaccepted memory type
2022-09-05 8:34 [PATCH V3 00/12] Introduce Lazy-accept for Tdx guest Min Xu
` (3 preceding siblings ...)
2022-09-05 8:34 ` [PATCH V3 04/12] MdePkg: Add UEFI Unaccepted memory definition Min Xu
@ 2022-09-05 8:34 ` Min Xu
2022-09-07 5:32 ` Gerd Hoffmann
2022-09-05 8:35 ` [PATCH V3 06/12] ShellPkg: Update shell command memmap to show unaccepted memory Min Xu
` (6 subsequent siblings)
11 siblings, 1 reply; 25+ messages in thread
From: Min Xu @ 2022-09-05 8:34 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>
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..9ba73d148af3 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 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] 25+ messages in thread
* [PATCH V3 06/12] ShellPkg: Update shell command memmap to show unaccepted memory
2022-09-05 8:34 [PATCH V3 00/12] Introduce Lazy-accept for Tdx guest Min Xu
` (4 preceding siblings ...)
2022-09-05 8:34 ` [PATCH V3 05/12] MdeModulePkg: Update Dxe to handle unaccepted memory type Min Xu
@ 2022-09-05 8:35 ` Min Xu
2022-09-05 9:19 ` [edk2-devel] " Gao, Zhichao
2022-09-05 8:35 ` [PATCH V3 07/12] OvmfPkg: Add MaxAcceptedMemoryAddress in TDX work area Min Xu
` (5 subsequent siblings)
11 siblings, 1 reply; 25+ messages in thread
From: Min Xu @ 2022-09-05 8:35 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>
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] 25+ messages in thread
* [PATCH V3 07/12] OvmfPkg: Add MaxAcceptedMemoryAddress in TDX work area
2022-09-05 8:34 [PATCH V3 00/12] Introduce Lazy-accept for Tdx guest Min Xu
` (5 preceding siblings ...)
2022-09-05 8:35 ` [PATCH V3 06/12] ShellPkg: Update shell command memmap to show unaccepted memory Min Xu
@ 2022-09-05 8:35 ` Min Xu
2022-09-05 8:35 ` [PATCH V3 08/12] OvmfPkg: Introduce lazy accept in PlatformInitLib and PlatformPei Min Xu
` (4 subsequent siblings)
11 siblings, 0 replies; 25+ messages in thread
From: Min Xu @ 2022-09-05 8:35 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
In lazy-accept the MaxAcceptedMemoryAddress is needed in
TransferTdxHobList and ContructFwHobList(at PeilessStartupLib). But in
SEC phase we cannot use a global variable to pass this value. So we add
a new field (MaxAcceptedMemoryAddress) in Tdx work area.
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: Min Xu <min.m.xu@intel.com>
---
OvmfPkg/Include/WorkArea.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/OvmfPkg/Include/WorkArea.h b/OvmfPkg/Include/WorkArea.h
index bf56fc4a6f65..2c2a5816b0dc 100644
--- a/OvmfPkg/Include/WorkArea.h
+++ b/OvmfPkg/Include/WorkArea.h
@@ -71,6 +71,7 @@ typedef struct _SEC_TDX_WORK_AREA {
UINT32 PageTableReady;
UINT32 Gpaw;
UINT64 HobList;
+ UINT64 MaxAcceptedMemoryAddress;
} SEC_TDX_WORK_AREA;
typedef struct _TDX_WORK_AREA {
--
2.29.2.windows.2
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH V3 08/12] OvmfPkg: Introduce lazy accept in PlatformInitLib and PlatformPei
2022-09-05 8:34 [PATCH V3 00/12] Introduce Lazy-accept for Tdx guest Min Xu
` (6 preceding siblings ...)
2022-09-05 8:35 ` [PATCH V3 07/12] OvmfPkg: Add MaxAcceptedMemoryAddress in TDX work area Min Xu
@ 2022-09-05 8:35 ` Min Xu
2022-09-07 5:37 ` Gerd Hoffmann
2022-09-05 8:35 ` [PATCH V3 09/12] OvmfPkg: Update ConstructFwHobList for lazy accept Min Xu
` (3 subsequent siblings)
11 siblings, 1 reply; 25+ messages in thread
From: Min Xu @ 2022-09-05 8:35 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.If an
EFI_RESOURCE_MEMORY_UNACCEPTED memory region is cross the 4G address,
it will be split into 2 parts and only the left one (<4G) is accepted.
The max accepted memory address is stored in Tdx workarea which will
be used in TransferTdxHobList.
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. As it is mentioned in 1), there may be a
EFI_RESOURCE_MEMORY_UNACCEPTED hob which only part of the memory
describes in the hob is accepted. We also handles this situation
in TransferTdxHobList.
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: Min Xu <min.m.xu@intel.com>
---
OvmfPkg/Library/PlatformInitLib/IntelTdx.c | 129 ++++++++++++++++++--
OvmfPkg/Library/PlatformInitLib/MemDetect.c | 2 +
2 files changed, 121 insertions(+), 10 deletions(-)
diff --git a/OvmfPkg/Library/PlatformInitLib/IntelTdx.c b/OvmfPkg/Library/PlatformInitLib/IntelTdx.c
index 396b14d919d2..333c69d1a854 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>
@@ -24,7 +25,8 @@
#include <WorkArea.h>
#include <ConfidentialComputingGuestAttr.h>
-#define ALIGNED_2MB_MASK 0x1fffff
+#define ALIGNED_2MB_MASK 0x1fffff
+#define MEGABYTE_SHIFT 20
/**
This function will be called to accept pages. Only BSP accepts pages.
@@ -375,11 +377,18 @@ ProcessHobList (
EFI_STATUS Status;
EFI_PEI_HOB_POINTERS Hob;
EFI_PHYSICAL_ADDRESS PhysicalEnd;
+ TDX_WORK_AREA *WorkArea;
+ UINT64 ResourceLength;
+ UINT64 AccumulateAcceptedMemory;
+ UINT64 MaxAcceptedMemoryAddress;
Status = EFI_SUCCESS;
ASSERT (VmmHobList != NULL);
Hob.Raw = (UINT8 *)VmmHobList;
+ AccumulateAcceptedMemory = 0;
+ MaxAcceptedMemoryAddress = 0;
+
//
// Parse the HOB list until end of list or matching type is found.
//
@@ -393,7 +402,16 @@ 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 (PhysicalEnd > SIZE_4GB) {
+ //
+ // In current stage, we only accept the memory under 4G
+ //
+ ResourceLength -= (PhysicalEnd - SIZE_4GB);
+ PhysicalEnd = SIZE_4GB;
+ }
Status = BspAcceptMemoryResourceRange (
Hob.ResourceDescriptor->PhysicalStart,
@@ -402,12 +420,25 @@ ProcessHobList (
if (EFI_ERROR (Status)) {
break;
}
+
+ AccumulateAcceptedMemory += ResourceLength;
+ MaxAcceptedMemoryAddress = PhysicalEnd;
}
}
Hob.Raw = GET_NEXT_HOB (Hob);
}
+ //
+ // Record MaxAcceptedMemoryAddress in OvmfWorkArea.
+ // This information is useful later but in SEC phase we cannot use a global
+ // variable to pass this value. So it is stored in OvmfWorkarea.
+ //
+ WorkArea = (TDX_WORK_AREA *)FixedPcdGet32 (PcdOvmfWorkAreaBase);
+ ASSERT (WorkArea != NULL);
+ ASSERT (WorkArea->Header.GuestType == CcGuestTypeIntelTdx);
+ WorkArea->SecTdxWorkArea.MaxAcceptedMemoryAddress = MaxAcceptedMemoryAddress;
+
return Status;
}
@@ -460,6 +491,74 @@ 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
+ * @param MaxAcceptedMemoryAddress The max accepted memory address
+ * @return VOID
+ */
+VOID
+BuildResourceDescriptorHobForUnacceptedMemory (
+ IN EFI_HOB_RESOURCE_DESCRIPTOR *Hob,
+ IN UINT64 MaxAcceptedMemoryAddress
+ )
+{
+ EFI_PHYSICAL_ADDRESS PhysicalStart;
+ EFI_PHYSICAL_ADDRESS PhysicalEnd;
+ UINT64 ResourceLength;
+ EFI_RESOURCE_TYPE ResourceType;
+ EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute;
+ UINT64 AcceptedResourceLength;
+
+ ASSERT (Hob->ResourceType == EFI_RESOURCE_MEMORY_UNACCEPTED);
+
+ ResourceType = EFI_RESOURCE_MEMORY_UNACCEPTED;
+ ResourceAttribute = Hob->ResourceAttribute;
+ PhysicalStart = Hob->PhysicalStart;
+ ResourceLength = Hob->ResourceLength;
+ PhysicalEnd = PhysicalStart + ResourceLength;
+
+ 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.
+ //
+ } else {
+ //
+ // This memory region is splitted into 2 parts:
+ // the accepted and unaccepted.
+ //
+ AcceptedResourceLength = MaxAcceptedMemoryAddress - Hob->PhysicalStart;
+
+ // We build the ResourceDescriptorHob for the accepted part.
+ // The unaccepted part will be build out side the if-else block.
+ BuildResourceDescriptorHob (
+ EFI_RESOURCE_SYSTEM_MEMORY,
+ ResourceAttribute | (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_TESTED),
+ Hob->PhysicalStart,
+ AcceptedResourceLength
+ );
+
+ PhysicalStart = Hob->PhysicalStart + AcceptedResourceLength;
+ ResourceLength -= AcceptedResourceLength;
+ }
+
+ 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
@@ -477,6 +576,16 @@ TransferTdxHobList (
EFI_PEI_HOB_POINTERS Hob;
EFI_RESOURCE_TYPE ResourceType;
EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute;
+ UINT64 MaxAcceptedMemoryAddress;
+ TDX_WORK_AREA *WorkArea;
+
+ WorkArea = (TDX_WORK_AREA *)FixedPcdGet32 (PcdOvmfWorkAreaBase);
+ ASSERT (WorkArea != NULL);
+ ASSERT (WorkArea->Header.GuestType == CcGuestTypeIntelTdx);
+ MaxAcceptedMemoryAddress = WorkArea->SecTdxWorkArea.MaxAcceptedMemoryAddress;
+ if (MaxAcceptedMemoryAddress == 0) {
+ MaxAcceptedMemoryAddress = MAX_UINT64;
+ }
//
// PcdOvmfSecGhcbBase is used as the TD_HOB in Tdx guest.
@@ -489,16 +598,16 @@ TransferTdxHobList (
ResourceAttribute = Hob.ResourceDescriptor->ResourceAttribute;
if (ResourceType == 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, MaxAcceptedMemoryAddress);
+ } 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 942eaf89cfcf..62132f9cacfa 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] 25+ messages in thread
* [PATCH V3 09/12] OvmfPkg: Update ConstructFwHobList for lazy accept
2022-09-05 8:34 [PATCH V3 00/12] Introduce Lazy-accept for Tdx guest Min Xu
` (7 preceding siblings ...)
2022-09-05 8:35 ` [PATCH V3 08/12] OvmfPkg: Introduce lazy accept in PlatformInitLib and PlatformPei Min Xu
@ 2022-09-05 8:35 ` Min Xu
2022-09-07 5:41 ` Gerd Hoffmann
2022-09-05 8:35 ` [PATCH V3 10/12] MdePkg: The prototype definition of EdkiiMemoryAcceptProtocol Min Xu
` (2 subsequent siblings)
11 siblings, 1 reply; 25+ messages in thread
From: Min Xu @ 2022-09-05 8:35 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
In TDVF the hob list is constructed at the memory region which is the
largest one below 4GB. After lazy accept is introduced, the
MaxAcceptedMemoryAddress (which is tha max accpeted memory address in
lazy accept) should be considered.
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: Min Xu <min.m.xu@intel.com>
---
OvmfPkg/Library/PeilessStartupLib/Hob.c | 23 ++++++++++++++++++-
.../PeilessStartupLib/PeilessStartupLib.inf | 1 +
2 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/OvmfPkg/Library/PeilessStartupLib/Hob.c b/OvmfPkg/Library/PeilessStartupLib/Hob.c
index a9b92b5fbaba..884490af68fd 100644
--- a/OvmfPkg/Library/PeilessStartupLib/Hob.c
+++ b/OvmfPkg/Library/PeilessStartupLib/Hob.c
@@ -21,6 +21,7 @@
#include <Library/PlatformInitLib.h>
#include <OvmfPlatforms.h>
#include <Pi/PrePiHob.h>
+#include <WorkArea.h>
#include "PeilessStartupInternal.h"
/**
@@ -74,10 +75,13 @@ ConstructFwHobList (
)
{
EFI_PEI_HOB_POINTERS Hob;
+ EFI_PHYSICAL_ADDRESS PhysicalStart;
EFI_PHYSICAL_ADDRESS PhysicalEnd;
UINT64 ResourceLength;
EFI_PHYSICAL_ADDRESS LowMemoryStart;
UINT64 LowMemoryLength;
+ UINT64 MaxAcceptedMemoryAddress;
+ TDX_WORK_AREA *WorkArea;
ASSERT (VmmHobList != NULL);
@@ -86,14 +90,31 @@ ConstructFwHobList (
LowMemoryLength = 0;
LowMemoryStart = 0;
+ WorkArea = (TDX_WORK_AREA *)FixedPcdGet32 (PcdOvmfWorkAreaBase);
+ ASSERT (WorkArea != NULL);
+ ASSERT (WorkArea->Header.GuestType == CcGuestTypeIntelTdx);
+ MaxAcceptedMemoryAddress = WorkArea->SecTdxWorkArea.MaxAcceptedMemoryAddress;
+ if (MaxAcceptedMemoryAddress == 0) {
+ MaxAcceptedMemoryAddress = MAX_UINT64;
+ }
+
//
// Parse the HOB list until end of list or matching type is found.
//
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 == EFI_RESOURCE_MEMORY_UNACCEPTED) && (Hob.ResourceDescriptor->PhysicalStart < MaxAcceptedMemoryAddress)) {
PhysicalEnd = Hob.ResourceDescriptor->PhysicalStart + Hob.ResourceDescriptor->ResourceLength;
ResourceLength = Hob.ResourceDescriptor->ResourceLength;
+ PhysicalStart = Hob.ResourceDescriptor->PhysicalStart;
+
+ if ((PhysicalEnd >= MaxAcceptedMemoryAddress) && (PhysicalStart < MaxAcceptedMemoryAddress)) {
+ //
+ // This memory region is split into 2 parts. The left part is accepted.
+ //
+ PhysicalEnd = MaxAcceptedMemoryAddress;
+ ResourceLength = PhysicalEnd - PhysicalStart;
+ }
if (PhysicalEnd <= BASE_4GB) {
if (ResourceLength > LowMemoryLength) {
diff --git a/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf b/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf
index def50b4b019e..eed9f27d3d01 100644
--- a/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf
+++ b/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf
@@ -88,3 +88,4 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask ## CONSUMES
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvBase
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvSize
+ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase
--
2.29.2.windows.2
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH V3 10/12] MdePkg: The prototype definition of EdkiiMemoryAcceptProtocol
2022-09-05 8:34 [PATCH V3 00/12] Introduce Lazy-accept for Tdx guest Min Xu
` (8 preceding siblings ...)
2022-09-05 8:35 ` [PATCH V3 09/12] OvmfPkg: Update ConstructFwHobList for lazy accept Min Xu
@ 2022-09-05 8:35 ` Min Xu
2022-09-05 8:35 ` [PATCH V3 11/12] OvmfPkg: Realize EdkiiMemoryAcceptProtocol in TdxDxe Min Xu
2022-09-05 8:35 ` [PATCH V3 12/12] OvmfPkg: Call gEdkiiMemoryAcceptProtocolGuid to accept pages Min Xu
11 siblings, 0 replies; 25+ messages in thread
From: Min Xu @ 2022-09-05 8:35 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>
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 f1ebf9e251c1..6b6bfbec29b3 100644
--- a/MdePkg/MdePkg.dec
+++ b/MdePkg/MdePkg.dec
@@ -1019,6 +1019,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] 25+ messages in thread
* [PATCH V3 11/12] OvmfPkg: Realize EdkiiMemoryAcceptProtocol in TdxDxe
2022-09-05 8:34 [PATCH V3 00/12] Introduce Lazy-accept for Tdx guest Min Xu
` (9 preceding siblings ...)
2022-09-05 8:35 ` [PATCH V3 10/12] MdePkg: The prototype definition of EdkiiMemoryAcceptProtocol Min Xu
@ 2022-09-05 8:35 ` Min Xu
2022-09-05 8:35 ` [PATCH V3 12/12] OvmfPkg: Call gEdkiiMemoryAcceptProtocolGuid to accept pages Min Xu
11 siblings, 0 replies; 25+ messages in thread
From: Min Xu @ 2022-09-05 8:35 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 2318db989792..ca948522a42c 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
@@ -277,6 +367,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 a7e0abda1522..9be021f28648 100644
--- a/OvmfPkg/TdxDxe/TdxDxe.inf
+++ b/OvmfPkg/TdxDxe/TdxDxe.inf
@@ -52,6 +52,7 @@
gEfiAcpiTableProtocolGuid ## CONSUMES
gEfiMpInitLibMpDepProtocolGuid
gEfiMpInitLibUpDepProtocolGuid
+ gEdkiiMemoryAcceptProtocolGuid
[Pcd]
gUefiOvmfPkgTokenSpaceGuid.PcdPciIoBase
@@ -68,3 +69,4 @@
gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr
gEfiMdeModulePkgTokenSpaceGuid.PcdTdxSharedBitMask
gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack
+ gUefiOvmfPkgTokenSpaceGuid.PcdTdxAcceptPageSize
--
2.29.2.windows.2
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH V3 12/12] OvmfPkg: Call gEdkiiMemoryAcceptProtocolGuid to accept pages
2022-09-05 8:34 [PATCH V3 00/12] Introduce Lazy-accept for Tdx guest Min Xu
` (10 preceding siblings ...)
2022-09-05 8:35 ` [PATCH V3 11/12] OvmfPkg: Realize EdkiiMemoryAcceptProtocol in TdxDxe Min Xu
@ 2022-09-05 8:35 ` Min Xu
11 siblings, 0 replies; 25+ messages in thread
From: Min Xu @ 2022-09-05 8:35 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] 25+ messages in thread
* Re: [edk2-devel] [PATCH V3 06/12] ShellPkg: Update shell command memmap to show unaccepted memory
2022-09-05 8:35 ` [PATCH V3 06/12] ShellPkg: Update shell command memmap to show unaccepted memory Min Xu
@ 2022-09-05 9:19 ` Gao, Zhichao
0 siblings, 0 replies; 25+ messages in thread
From: Gao, Zhichao @ 2022-09-05 9:19 UTC (permalink / raw)
To: devel@edk2.groups.io, Xu, Min M
Cc: Ni, Ray, Aktas, Erdem, Gerd Hoffmann, James Bottomley,
Yao, Jiewen, Tom Lendacky
Reviewed-by: Zhichao Gao <zhichao.gao@intel.com>
Thanks,
Zhichao
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Min Xu
> Sent: Monday, September 5, 2022 4:35 PM
> To: devel@edk2.groups.io
> Cc: Xu, Min M <min.m.xu@intel.com>; Ni, Ray <ray.ni@intel.com>; Gao,
> Zhichao <zhichao.gao@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>
> Subject: [edk2-devel] [PATCH V3 06/12] ShellPkg: Update shell command
> memmap to show unaccepted memory
>
> 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>
> 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/UefiShellDebug1Comman
> dsLib.uni
> b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman
> dsLib.uni
> index 6693be26e699..b1d239ed37ea 100644
> ---
> a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman
> dsLib.uni
> +++
> b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Comman
> d
> +++ sLib.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 [flat|nested] 25+ messages in thread
* Re: [PATCH V3 02/12] MdePkg: Increase EFI_RESOURCE_MAX_MEMORY_TYPE
2022-09-05 8:34 ` [PATCH V3 02/12] MdePkg: Increase EFI_RESOURCE_MAX_MEMORY_TYPE Min Xu
@ 2022-09-06 18:44 ` Michael D Kinney
2022-09-07 0:19 ` Min Xu
0 siblings, 1 reply; 25+ messages in thread
From: Michael D Kinney @ 2022-09-06 18:44 UTC (permalink / raw)
To: Xu, Min M, devel@edk2.groups.io, Kinney, Michael D
Cc: Gao, Liming, Liu, Zhiguang, Aktas, Erdem, Gerd Hoffmann,
James Bottomley, Yao, Jiewen, Tom Lendacky
Hi,
If this is related to code first, are these patches for an edk2-staging branch. If so, that should be part of email subject.
Also, the naming convention for the new values do not follow code first with the BZ in new names.
https://github.com/tianocore/tianocore.github.io/wiki/EDK-II-Code-First-Process#source-code
Mike
> -----Original Message-----
> From: Xu, Min M <min.m.xu@intel.com>
> Sent: Monday, September 5, 2022 1:35 AM
> To: devel@edk2.groups.io
> Cc: Xu, Min M <min.m.xu@intel.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Gao, Liming <gaoliming@byosoft.com.cn>;
> Liu, Zhiguang <zhiguang.liu@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>
> Subject: [PATCH V3 02/12] MdePkg: Increase EFI_RESOURCE_MAX_MEMORY_TYPE
>
> From: Min M Xu <min.m.xu@intel.com>
>
> RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3937
>
> 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 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>
> 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..9af2e957fee5 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
> +//
> +// 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 EFI_RESOURCE_MEMORY_UNACCEPTED is officially published
> +// in PI spec, we will re-visit here.
> +//
> +// #define 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 [flat|nested] 25+ messages in thread
* Re: [PATCH V3 02/12] MdePkg: Increase EFI_RESOURCE_MAX_MEMORY_TYPE
2022-09-06 18:44 ` Michael D Kinney
@ 2022-09-07 0:19 ` Min Xu
0 siblings, 0 replies; 25+ messages in thread
From: Min Xu @ 2022-09-07 0:19 UTC (permalink / raw)
To: Kinney, Michael D, devel@edk2.groups.io
Cc: Gao, Liming, Liu, Zhiguang, Aktas, Erdem, Gerd Hoffmann,
James Bottomley, Yao, Jiewen, Tom Lendacky
On September 7, 2022 2:45 AM, Kinney, Michael D wrote:
>
> Hi,
>
> If this is related to code first, are these patches for an edk2-staging branch. If
> so, that should be part of email subject.
Yes, it is in edk2-staging TDVF branch. https://github.com/tianocore/edk2-staging/tree/TDVF
>
> Also, the naming convention for the new values do not follow code first with
> the BZ in new names.
>
> https://github.com/tianocore/tianocore.github.io/wiki/EDK-II-Code-First-
> Process#source-code
Thanks for reminder. The name will be updated based on the above wik.
Thanks
Min
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH V3 01/12] MdeModulePkg: Add PrePiHob.h
2022-09-05 8:34 ` [PATCH V3 01/12] MdeModulePkg: Add PrePiHob.h Min Xu
@ 2022-09-07 5:31 ` Gerd Hoffmann
0 siblings, 0 replies; 25+ messages in thread
From: Gerd Hoffmann @ 2022-09-07 5:31 UTC (permalink / raw)
To: Min Xu
Cc: devel, Jian J Wang, Liming Gao, Ray Ni, Erdem Aktas,
James Bottomley, Jiewen Yao, Tom Lendacky
On Mon, Sep 05, 2022 at 04:34:55PM +0800, Min Xu wrote:
> From: Min M Xu <min.m.xu@intel.com>
>
> RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3937
>
> 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.
>
> 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: Min Xu <min.m.xu@intel.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH V3 03/12] OvmfPkg: Use EFI_RESOURCE_MEMORY_UNACCEPTED which defined in MdeModulePkg
2022-09-05 8:34 ` [PATCH V3 03/12] OvmfPkg: Use EFI_RESOURCE_MEMORY_UNACCEPTED which defined in MdeModulePkg Min Xu
@ 2022-09-07 5:31 ` Gerd Hoffmann
0 siblings, 0 replies; 25+ messages in thread
From: Gerd Hoffmann @ 2022-09-07 5:31 UTC (permalink / raw)
To: Min Xu; +Cc: devel, Erdem Aktas, James Bottomley, Jiewen Yao, Tom Lendacky
On Mon, Sep 05, 2022 at 04:34:57PM +0800, Min Xu wrote:
> From: Min M Xu <min.m.xu@intel.com>
>
> RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3937
>
> EFI_RESOURCE_MEMORY_UNACCEPTED is defined in MdeModulePkg. The files
> which use the definition are updated as well.
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH V3 04/12] MdePkg: Add UEFI Unaccepted memory definition
2022-09-05 8:34 ` [PATCH V3 04/12] MdePkg: Add UEFI Unaccepted memory definition Min Xu
@ 2022-09-07 5:32 ` Gerd Hoffmann
0 siblings, 0 replies; 25+ messages in thread
From: Gerd Hoffmann @ 2022-09-07 5:32 UTC (permalink / raw)
To: Min Xu
Cc: devel, Michael D Kinney, Liming Gao, Zhiguang Liu, Erdem Aktas,
James Bottomley, Jiewen Yao, Tom Lendacky
On Mon, Sep 05, 2022 at 04:34:58PM +0800, Min Xu wrote:
> 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>
> Signed-off-by: Min Xu <min.m.xu@intel.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH V3 05/12] MdeModulePkg: Update Dxe to handle unaccepted memory type
2022-09-05 8:34 ` [PATCH V3 05/12] MdeModulePkg: Update Dxe to handle unaccepted memory type Min Xu
@ 2022-09-07 5:32 ` Gerd Hoffmann
0 siblings, 0 replies; 25+ messages in thread
From: Gerd Hoffmann @ 2022-09-07 5:32 UTC (permalink / raw)
To: Min Xu
Cc: devel, Jian J Wang, Liming Gao, Ray Ni, Erdem Aktas,
James Bottomley, Jiewen Yao, Tom Lendacky
On Mon, Sep 05, 2022 at 04:34:59PM +0800, Min Xu wrote:
> 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>
> Signed-off-by: Min Xu <min.m.xu@intel.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH V3 08/12] OvmfPkg: Introduce lazy accept in PlatformInitLib and PlatformPei
2022-09-05 8:35 ` [PATCH V3 08/12] OvmfPkg: Introduce lazy accept in PlatformInitLib and PlatformPei Min Xu
@ 2022-09-07 5:37 ` Gerd Hoffmann
2022-09-08 1:13 ` [edk2-devel] " Min Xu
0 siblings, 1 reply; 25+ messages in thread
From: Gerd Hoffmann @ 2022-09-07 5:37 UTC (permalink / raw)
To: Min Xu; +Cc: devel, Erdem Aktas, James Bottomley, Jiewen Yao, Tom Lendacky
On Mon, Sep 05, 2022 at 04:35:02PM +0800, Min Xu wrote:
> 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.
Good.
> If an EFI_RESOURCE_MEMORY_UNACCEPTED memory region is cross the 4G
> address, it will be split into 2 parts and only the left one (<4G)
> is accepted.
Looks pointless to me. I doubt this will ever happen given the address
space just below 4G is populated with firmware rom/flash, lapic, ioapic
and other devices.
take care,
Gerd
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH V3 09/12] OvmfPkg: Update ConstructFwHobList for lazy accept
2022-09-05 8:35 ` [PATCH V3 09/12] OvmfPkg: Update ConstructFwHobList for lazy accept Min Xu
@ 2022-09-07 5:41 ` Gerd Hoffmann
2022-09-08 0:48 ` Min Xu
0 siblings, 1 reply; 25+ messages in thread
From: Gerd Hoffmann @ 2022-09-07 5:41 UTC (permalink / raw)
To: Min Xu; +Cc: devel, Erdem Aktas, James Bottomley, Jiewen Yao, Tom Lendacky
Hi,
> + //
> + // This memory region is split into 2 parts. The left part is accepted.
> + //
> + PhysicalEnd = MaxAcceptedMemoryAddress;
> + ResourceLength = PhysicalEnd - PhysicalStart;
Same comment here. Can't happen when all memory below 4G is accepted,
and I think MaxAcceptedMemoryAddress is not needed either.
take care,
Gerd
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH V3 09/12] OvmfPkg: Update ConstructFwHobList for lazy accept
2022-09-07 5:41 ` Gerd Hoffmann
@ 2022-09-08 0:48 ` Min Xu
2022-09-08 7:43 ` Gerd Hoffmann
0 siblings, 1 reply; 25+ messages in thread
From: Min Xu @ 2022-09-08 0:48 UTC (permalink / raw)
To: Gerd Hoffmann
Cc: devel@edk2.groups.io, Aktas, Erdem, James Bottomley, Yao, Jiewen,
Tom Lendacky
On September 7, 2022 1:42 PM, Gerd Hoffmann wrote:
> Hi,
>
> > + //
> > + // This memory region is split into 2 parts. The left part is accepted.
> > + //
> > + PhysicalEnd = MaxAcceptedMemoryAddress;
> > + ResourceLength = PhysicalEnd - PhysicalStart;
>
> Same comment here. Can't happen when all memory below 4G is accepted,
> and I think MaxAcceptedMemoryAddress is not needed either.
>
It may happen. For example, a TD VM is created with 2G memory, then the MaxAcceptedMemoryAddress is 0x80000000. If it is created with 1G memory, MaxAcceptedMemoryAddress is 0x40000000. This information can be retrieved by walking thru the TD-Hob and read the largest address of the unaccept-mem-region under 4G.
But I think it's easier to record the value in MaxAcceptedMemoryAddress. And it can be used when not all memory below 4G is accepted.
Thanks
Min
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [edk2-devel] [PATCH V3 08/12] OvmfPkg: Introduce lazy accept in PlatformInitLib and PlatformPei
2022-09-07 5:37 ` Gerd Hoffmann
@ 2022-09-08 1:13 ` Min Xu
0 siblings, 0 replies; 25+ messages in thread
From: Min Xu @ 2022-09-08 1:13 UTC (permalink / raw)
To: devel@edk2.groups.io, kraxel@redhat.com
Cc: Aktas, Erdem, James Bottomley, Yao, Jiewen, Tom Lendacky
On September 7, 2022 1:37 PM, Gerd Hoffmann wrote:
> On Mon, Sep 05, 2022 at 04:35:02PM +0800, Min Xu wrote:
> > 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.
>
> Good.
>
> > If an EFI_RESOURCE_MEMORY_UNACCEPTED memory region is cross the
> 4G
> > address, it will be split into 2 parts and only the left one (<4G)
> > is accepted.
>
> Looks pointless to me. I doubt this will ever happen given the address space
> just below 4G is populated with firmware rom/flash, lapic, ioapic and other
> devices.
Yes, you're right. It will be fixed in the next version.
Thanks
Min
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH V3 09/12] OvmfPkg: Update ConstructFwHobList for lazy accept
2022-09-08 0:48 ` Min Xu
@ 2022-09-08 7:43 ` Gerd Hoffmann
0 siblings, 0 replies; 25+ messages in thread
From: Gerd Hoffmann @ 2022-09-08 7:43 UTC (permalink / raw)
To: Xu, Min M
Cc: devel@edk2.groups.io, Aktas, Erdem, James Bottomley, Yao, Jiewen,
Tom Lendacky
On Thu, Sep 08, 2022 at 12:48:05AM +0000, Xu, Min M wrote:
> On September 7, 2022 1:42 PM, Gerd Hoffmann wrote:
> > Hi,
> >
> > > + //
> > > + // This memory region is split into 2 parts. The left part is accepted.
> > > + //
> > > + PhysicalEnd = MaxAcceptedMemoryAddress;
> > > + ResourceLength = PhysicalEnd - PhysicalStart;
> >
> > Same comment here. Can't happen when all memory below 4G is accepted,
> > and I think MaxAcceptedMemoryAddress is not needed either.
> It may happen. For example, a TD VM is created with 2G memory, then
> the MaxAcceptedMemoryAddress is 0x80000000. If it is created with 1G
> memory, MaxAcceptedMemoryAddress is 0x40000000. This information can
> be retrieved by walking thru the TD-Hob and read the largest address
> of the unaccept-mem-region under 4G. But I think it's easier to
> record the value in MaxAcceptedMemoryAddress. And it can be used when
> not all memory below 4G is accepted.
Memory regions wouldn't cross the 4G border, they are either completely
below 4G or completely above 4G. So when we accept all memory below 4G
we will never have to split a memory region and you can easily figure
whenever an region is accepted or not by checking whenever it is above
or below 4G.
I still don't see what MaxAcceptedMemoryAddress would be needed for
given that when we never have to split memory regions.
take care,
Gerd
^ permalink raw reply [flat|nested] 25+ messages in thread
end of thread, other threads:[~2022-09-08 7:43 UTC | newest]
Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-05 8:34 [PATCH V3 00/12] Introduce Lazy-accept for Tdx guest Min Xu
2022-09-05 8:34 ` [PATCH V3 01/12] MdeModulePkg: Add PrePiHob.h Min Xu
2022-09-07 5:31 ` Gerd Hoffmann
2022-09-05 8:34 ` [PATCH V3 02/12] MdePkg: Increase EFI_RESOURCE_MAX_MEMORY_TYPE Min Xu
2022-09-06 18:44 ` Michael D Kinney
2022-09-07 0:19 ` Min Xu
2022-09-05 8:34 ` [PATCH V3 03/12] OvmfPkg: Use EFI_RESOURCE_MEMORY_UNACCEPTED which defined in MdeModulePkg Min Xu
2022-09-07 5:31 ` Gerd Hoffmann
2022-09-05 8:34 ` [PATCH V3 04/12] MdePkg: Add UEFI Unaccepted memory definition Min Xu
2022-09-07 5:32 ` Gerd Hoffmann
2022-09-05 8:34 ` [PATCH V3 05/12] MdeModulePkg: Update Dxe to handle unaccepted memory type Min Xu
2022-09-07 5:32 ` Gerd Hoffmann
2022-09-05 8:35 ` [PATCH V3 06/12] ShellPkg: Update shell command memmap to show unaccepted memory Min Xu
2022-09-05 9:19 ` [edk2-devel] " Gao, Zhichao
2022-09-05 8:35 ` [PATCH V3 07/12] OvmfPkg: Add MaxAcceptedMemoryAddress in TDX work area Min Xu
2022-09-05 8:35 ` [PATCH V3 08/12] OvmfPkg: Introduce lazy accept in PlatformInitLib and PlatformPei Min Xu
2022-09-07 5:37 ` Gerd Hoffmann
2022-09-08 1:13 ` [edk2-devel] " Min Xu
2022-09-05 8:35 ` [PATCH V3 09/12] OvmfPkg: Update ConstructFwHobList for lazy accept Min Xu
2022-09-07 5:41 ` Gerd Hoffmann
2022-09-08 0:48 ` Min Xu
2022-09-08 7:43 ` Gerd Hoffmann
2022-09-05 8:35 ` [PATCH V3 10/12] MdePkg: The prototype definition of EdkiiMemoryAcceptProtocol Min Xu
2022-09-05 8:35 ` [PATCH V3 11/12] OvmfPkg: Realize EdkiiMemoryAcceptProtocol in TdxDxe Min Xu
2022-09-05 8:35 ` [PATCH V3 12/12] OvmfPkg: Call gEdkiiMemoryAcceptProtocolGuid to accept pages Min Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox