From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web09.22417.1662366920227192887 for ; Mon, 05 Sep 2022 01:35:39 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=ju5EZOrn; spf=permerror, err=too many SPF records (domain: intel.com, ip: 134.134.136.126, mailfrom: min.m.xu@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662366939; x=1693902939; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9sfdi1JC8mpZpQ3tmi0OCynFIQwFukQq+XJGbvY5LkI=; b=ju5EZOrnrm+wWgdN3+bO2uVlF9uqno1xT/v2oIdFXhJuDzeBBpcDZleH vCDityd56FFxIJfZyh1Bi67rTHgd8fx9IwtFXAcrDIOKA9eIHkTyQzb7x klEEVQqeo6O+iseKNwWd5Ywg5MTPG1DDXJp6El+B3dqKM5Z3W0V7SttMO yB6ZwJtj6FEh+JMK9yFQqJvxZM9SJXxPnL1CV+M6OADbGPB651hxZE6fW 0U71Bdngeji3oPWE87/h7TxrhuypGW2TvNAWoqvFjVlA8GfhypJNeR3Ur VKJ3XUj9iL08VA7dZ7Q1I1CILkiGSaocKltlJ/7TqfNvaFbn4wAH+I2RL g==; X-IronPort-AV: E=McAfee;i="6500,9779,10460"; a="279355930" X-IronPort-AV: E=Sophos;i="5.93,290,1654585200"; d="scan'208";a="279355930" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Sep 2022 01:35:38 -0700 X-IronPort-AV: E=Sophos;i="5.93,290,1654585200"; d="scan'208";a="675194465" Received: from mxu9-mobl1.ccr.corp.intel.com ([10.255.30.119]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Sep 2022 01:35:37 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Erdem Aktas , Gerd Hoffmann , James Bottomley , Jiewen Yao , Tom Lendacky Subject: [PATCH V3 09/12] OvmfPkg: Update ConstructFwHobList for lazy accept Date: Mon, 5 Sep 2022 16:35:03 +0800 Message-Id: <5f53ebaa41c5231ff9bb0031ca95afd7e05684c1.1662365866.git.min.m.xu@intel.com> X-Mailer: git-send-email 2.29.2.windows.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Min M Xu 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 Cc: Gerd Hoffmann Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Signed-off-by: Min Xu --- 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 #include #include +#include #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