public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Min Xu" <min.m.xu@intel.com>
To: devel@edk2.groups.io
Cc: Min M Xu <min.m.xu@intel.com>,
	Erdem Aktas <erdemaktas@google.com>,
	Gerd Hoffmann <kraxel@redhat.com>,
	James Bottomley <jejb@linux.ibm.com>,
	Jiewen Yao <jiewen.yao@intel.com>,
	Tom Lendacky <thomas.lendacky@amd.com>
Subject: [PATCH V1 1/3] OvmfPkg: Customize lazy-accept's end address
Date: Mon, 26 Dec 2022 09:33:36 +0800	[thread overview]
Message-ID: <20221226013338.1924-2-min.m.xu@intel.com> (raw)
In-Reply-To: <20221226013338.1924-1-min.m.xu@intel.com>

From: Min M Xu <min.m.xu@intel.com>

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4181

Current lazy-accept accepts the memory under address of 4G. To improve
boot performance further more, we introduce the feature of customizing
the physical end address of lazy-accept.

The end address is indicated by PcdAcceptMemoryEndAddress. It means it
accepts the memory under PcdAcceptMemoryEndAddress. The default value
is 4G.

In IntelTdxX64 PcdAcceptMemoryEndAddress can be customized on-demand in
build-time by adding -D ACCEPT_MEMORY_END_ADDRESS=512 in build command.

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/IntelTdx/IntelTdxX64.dsc              |  8 ++++
 OvmfPkg/Library/PlatformInitLib/IntelTdx.c    | 37 ++++++++++++++-----
 .../PlatformInitLib/PlatformInitLib.inf       |  1 +
 OvmfPkg/OvmfPkg.dec                           |  2 +
 4 files changed, 39 insertions(+), 9 deletions(-)

diff --git a/OvmfPkg/IntelTdx/IntelTdxX64.dsc b/OvmfPkg/IntelTdx/IntelTdxX64.dsc
index 6ec64df91871..46b0b96ad671 100644
--- a/OvmfPkg/IntelTdx/IntelTdxX64.dsc
+++ b/OvmfPkg/IntelTdx/IntelTdxX64.dsc
@@ -62,6 +62,11 @@
   #
   DEFINE UP_CPU_DXE_GUID  = 6490f1c5-ebcc-4665-8892-0075b9bb49b7
 
+  #
+  # Define the end of physical address of memory to be accepted. The unit is M.
+  #
+  DEFINE ACCEPT_MEMORY_END_ADDRESS = 512
+
 [BuildOptions]
   GCC:RELEASE_*_*_CC_FLAGS             = -DMDEPKG_NDEBUG
   INTEL:RELEASE_*_*_CC_FLAGS           = /D MDEPKG_NDEBUG
@@ -457,6 +462,9 @@
   # TDX need 1G PageTable support
   gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable|TRUE
 
+  ## End of physical address of memory to be accepted.
+  gUefiOvmfPkgTokenSpaceGuid.PcdAcceptMemoryEndAddress|($(ACCEPT_MEMORY_END_ADDRESS)*0x100000)
+
   gEfiShellPkgTokenSpaceGuid.PcdShellFileOperationSize|0x20000
 
   # IRQs 5, 9, 10, 11 are level-triggered
diff --git a/OvmfPkg/Library/PlatformInitLib/IntelTdx.c b/OvmfPkg/Library/PlatformInitLib/IntelTdx.c
index 6cb63139cba0..9514badb8ef6 100644
--- a/OvmfPkg/Library/PlatformInitLib/IntelTdx.c
+++ b/OvmfPkg/Library/PlatformInitLib/IntelTdx.c
@@ -375,7 +375,8 @@ AcceptMemoryForAPsStack (
 }
 
 /**
-  BSP and APs work togeter to accept memory which is under the address of 4G.
+  BSP and APs work togeter to accept memory which is under the address
+  indicated by PcdAcceptMemoryEndAddress.
 
   @param[in] VmmHobList           The Hoblist pass the firmware
   @param[in] CpusNum              Number of vCPUs
@@ -400,13 +401,22 @@ AcceptMemory (
   EFI_PHYSICAL_ADDRESS  PhysicalEnd;
   EFI_PHYSICAL_ADDRESS  AcceptMemoryEndAddress;
 
-  Status                 = EFI_SUCCESS;
-  AcceptMemoryEndAddress = BASE_4GB;
+  Status = EFI_SUCCESS;
 
   ASSERT (VmmHobList != NULL);
   Hob.Raw = (UINT8 *)VmmHobList;
 
-  DEBUG ((DEBUG_INFO, "AcceptMemory under address of 4G\n"));
+  AcceptMemoryEndAddress = (PHYSICAL_ADDRESS)FixedPcdGet64 (PcdAcceptMemoryEndAddress);
+  if (AcceptMemoryEndAddress == 0) {
+    AcceptMemoryEndAddress = MAX_UINT64;
+  }
+
+  if (AcceptMemoryEndAddress <= PhysicalAddressStart) {
+    ASSERT (FALSE);
+    return EFI_SUCCESS;
+  }
+
+  DEBUG ((DEBUG_INFO, "AcceptMemory till 0x%llx\n", AcceptMemoryEndAddress));
 
   //
   // Parse the HOB list until end of list or matching type is found.
@@ -816,11 +826,7 @@ BuildResourceDescriptorHobForUnacceptedMemory (
   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;
+  MaxAcceptedMemoryAddress = FixedPcdGet64 (PcdAcceptMemoryEndAddress);
 
   if (PhysicalEnd <= MaxAcceptedMemoryAddress) {
     //
@@ -833,6 +839,19 @@ BuildResourceDescriptorHobForUnacceptedMemory (
     // This memory region hasn't been accepted.
     // So keep the ResourceType and ResourceAttribute unchange.
     //
+  } else if ((PhysicalStart < MaxAcceptedMemoryAddress) && (PhysicalEnd > MaxAcceptedMemoryAddress)) {
+    //
+    // Left part of the memory region is accepted. The right part is unaccepted.
+    //
+    BuildResourceDescriptorHob (
+      EFI_RESOURCE_SYSTEM_MEMORY,
+      ResourceAttribute | (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_TESTED),
+      PhysicalStart,
+      MaxAcceptedMemoryAddress - PhysicalStart
+      );
+
+    PhysicalStart  = MaxAcceptedMemoryAddress;
+    ResourceLength = PhysicalEnd - MaxAcceptedMemoryAddress;
   }
 
   BuildResourceDescriptorHob (
diff --git a/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf b/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf
index 140216979a54..2a909ade895b 100644
--- a/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf
+++ b/OvmfPkg/Library/PlatformInitLib/PlatformInitLib.inf
@@ -100,6 +100,7 @@
   gUefiOvmfPkgTokenSpaceGuid.PcdTdxAcceptPageSize
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashNvStorageVariableBase
   gUefiOvmfPkgTokenSpaceGuid.PcdCfvRawDataSize
+  gUefiOvmfPkgTokenSpaceGuid.PcdAcceptMemoryEndAddress
 
 [FeaturePcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode
diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec
index 693925a1dc7a..e6cc524e0f7f 100644
--- a/OvmfPkg/OvmfPkg.dec
+++ b/OvmfPkg/OvmfPkg.dec
@@ -408,6 +408,8 @@
 
   ## The Tdx accept page size. 0x1000(4k),0x200000(2M)
   gUefiOvmfPkgTokenSpaceGuid.PcdTdxAcceptPageSize|0x200000|UINT32|0x65
+  ## End of physical address of memory to be accepted
+  gUefiOvmfPkgTokenSpaceGuid.PcdAcceptMemoryEndAddress|0x100000000|UINT64|0x69
 
   ## The QEMU fw_cfg variable that UefiDriverEntryPointFwCfgOverrideLib will
   #  check to decide whether to abort dispatch of the driver it is linked into.
-- 
2.29.2.windows.2


  reply	other threads:[~2022-12-26  1:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-26  1:33 [PATCH V1 0/3] Customize lazy-accepted memory size for TDVF Min Xu
2022-12-26  1:33 ` Min Xu [this message]
2022-12-26  1:33 ` [PATCH V1 2/3] OvmfPkg/PeilessStartupLib: Update ConstructFwHobList for lazy-accept Min Xu
2022-12-26  1:33 ` [PATCH V1 3/3] OvmfPkg/PlatformPei: Adjust LowerMemorySize in PublishPeiMemory Min Xu
2023-01-02 10:36 ` [PATCH V1 0/3] Customize lazy-accepted memory size for TDVF Gerd Hoffmann
2023-01-16 12:01   ` [edk2-devel] " Min Xu
2023-01-17  9:43     ` Gerd Hoffmann
2023-01-03 15:39 ` Lendacky, Thomas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221226013338.1924-2-min.m.xu@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox