From nobody Fri Nov 15 12:45:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+95800+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95800+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1667279659; cv=none; d=zohomail.com; s=zohoarc; b=PtAVuKVEU04Oiznwf4rxl4BOmWfOfyg47yTyCF9d2XyeS5x2NZBubS1LO50Iidgi8O8qSgwHG9v+OwRWFV38RwLI3B8P/qN5t30S+a9kMgRQg8Z0UpDWwmhnCPrKa4fqEbouexE/m/39tQVzbv8Cp1isJ5rTZLWSEYeNV50q+sY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667279659; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=aZLBpEBVQGgGq9AUtsw48/NpHecn5NuaAGIwCcC+IZI=; b=V4yiU+FMPf76nQ32S15eU9cfx03+lX0M86zwe+ycy6ulPOG/EDr7TsTP8+It2sdQXC6SaTaCfQDxKjbY/XVFBQqzfw/O2mpQsrzAsk2jnd38Vl0IkSdwJ3q+xUYZeIHJJOInQXQQ/io2lhNDl5o6R7gJjkSQ7qRg/b7vgJBCFuk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95800+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 166727965955389.70305423875345; Mon, 31 Oct 2022 22:14:19 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 5rdmYY1788612xryvoFiSxKa; Mon, 31 Oct 2022 22:14:19 -0700 X-Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web11.2818.1667279643333273629 for ; Mon, 31 Oct 2022 22:14:18 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10517"; a="310162759" X-IronPort-AV: E=Sophos;i="5.95,229,1661842800"; d="scan'208";a="310162759" X-Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Oct 2022 22:14:18 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10517"; a="878985532" X-IronPort-AV: E=Sophos;i="5.95,229,1661842800"; d="scan'208";a="878985532" X-Received: from mxu9-mobl1.ccr.corp.intel.com ([10.255.29.119]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Oct 2022 22:14:16 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min M Xu , Erdem Aktas , Gerd Hoffmann , James Bottomley , Jiewen Yao , Tom Lendacky Subject: [edk2-devel] [PATCH V5 07/10] OvmfPkg: Introduce lazy accept in PlatformInitLib and PlatformPei Date: Tue, 1 Nov 2022 13:13:46 +0800 Message-Id: <20221101051349.13-8-min.m.xu@intel.com> In-Reply-To: <20221101051349.13-1-min.m.xu@intel.com> References: <20221101051349.13-1-min.m.xu@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,min.m.xu@intel.com X-Gm-Message-State: 28uHJLmWgsyi9mpAGyjWtZCfx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1667279659; bh=uJNjFoxG/KOgpeP6NhcJBEEUx1eWqra4/JXPmLALfBA=; h=Cc:Date:From:Reply-To:Subject:To; b=TFun5g14B7VoAFzRpCu7PNjYYlhiEGiFYOVhxWPylnQ+2bE6iObUKfevkNp8yFFS0dt DJyqGfkZwW8hYSBfUwBxofq42TauI+FE9jEAnR3yZKc+uz0Q5g7M52BX1kmhsIdal3XY6 sCaeMpVjgdzkNxBwLLv10++mu5ozfb2esFU= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1667279660487100014 Content-Type: text/plain; charset="utf-8" From: Min M Xu RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3937 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 Cc: Gerd Hoffmann Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Acked-by: Gerd Hoffmann Signed-off-by: Min Xu --- 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/P= latformInitLib/IntelTdx.c index 797f880df035..acd114e38e46 100644 --- a/OvmfPkg/Library/PlatformInitLib/IntelTdx.c +++ b/OvmfPkg/Library/PlatformInitLib/IntelTdx.c @@ -7,6 +7,7 @@ =20 **/ =20 +#include #include #include #include @@ -25,6 +26,7 @@ #include =20 #define ALIGNED_2MB_MASK 0x1fffff +#define MEGABYTE_SHIFT 20 =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; =20 Status =3D EFI_SUCCESS; ASSERT (VmmHobList !=3D NULL); Hob.Raw =3D (UINT8 *)VmmHobList; =20 + AccumulateAcceptedMemory =3D 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.ResourceDescri= ptor->ResourceLength)); DEBUG ((DEBUG_INFO, "Owner: %g\n\n", &Hob.ResourceDescriptor->Owne= r)); =20 - PhysicalEnd =3D Hob.ResourceDescriptor->PhysicalStart + Hob.Resour= ceDescriptor->ResourceLength; + PhysicalEnd =3D Hob.ResourceDescriptor->PhysicalStart + Hob.Res= ourceDescriptor->ResourceLength; + ResourceLength =3D Hob.ResourceDescriptor->ResourceLength; + + if (Hob.ResourceDescriptor->PhysicalStart >=3D BASE_4GB) { + // + // In current stage, we only accept the memory under 4G + // + break; + } =20 Status =3D BspAcceptMemoryResourceRange ( Hob.ResourceDescriptor->PhysicalStart, @@ -402,6 +416,8 @@ ProcessHobList ( if (EFI_ERROR (Status)) { break; } + + AccumulateAcceptedMemory +=3D ResourceLength; } } =20 @@ -460,6 +476,60 @@ ProcessTdxHobList ( return Status; } =20 +/** + * 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 =3D=3D BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED); + + ResourceType =3D BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED; + ResourceAttribute =3D Hob->ResourceAttribute; + PhysicalStart =3D Hob->PhysicalStart; + ResourceLength =3D Hob->ResourceLength; + PhysicalEnd =3D PhysicalStart + ResourceLength; + + // + // In the first stage of lazy-accept, all the memory under 4G will be ac= cepted. + // The memory above 4G will not be accepted. + // + MaxAcceptedMemoryAddress =3D BASE_4GB; + + if (PhysicalEnd <=3D MaxAcceptedMemoryAddress) { + // + // This memory region has been accepted. + // + ResourceType =3D EFI_RESOURCE_SYSTEM_MEMORY; + ResourceAttribute |=3D (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_= ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_TESTED); + } else if (PhysicalStart >=3D 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 =3D Hob.ResourceDescriptor->ResourceAttribute; =20 if (ResourceType =3D=3D BZ3937_EFI_RESOURCE_MEMORY_UNACCEPTED) { - ResourceType =3D EFI_RESOURCE_SYSTEM_MEMORY; - ResourceAttribute |=3D (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RES= OURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_TESTED); + BuildResourceDescriptorHobForUnacceptedMemory (Hob.ResourceDescr= iptor); + } else { + BuildResourceDescriptorHob ( + ResourceType, + ResourceAttribute, + Hob.ResourceDescriptor->PhysicalStart, + Hob.ResourceDescriptor->ResourceLength + ); } =20 - 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: =20 #include =20 +#define MEGABYTE_SHIFT 20 + VOID EFIAPI PlatformQemuUc32BaseInitialization ( --=20 2.29.2.windows.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95800): https://edk2.groups.io/g/devel/message/95800 Mute This Topic: https://groups.io/mt/94703263/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-