From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id C1D917803D0 for ; Tue, 12 Dec 2023 00:46:36 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=EgbhV7spO6no4+VHUESoHGm/BgujgIOUfqjoSm5EqW0=; c=relaxed/simple; d=groups.io; h=From:To:Cc:References:In-Reply-To:Subject:Date:Message-ID:MIME-Version:Thread-Index:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type:Content-Transfer-Encoding:Content-Language; s=20140610; t=1702341995; v=1; b=eSDTL+5g4litG8CSthDGL6Y3X1xDUo2cw56nmASWxpqwE0fm5ofmm3QGDyR390AXE/M815/F GKGUcimbgFvehgDE7JoLHPm+7Oj/7pp86YBM5hdoYosBH2eo6CJgVXMSznY/AZ2VEAZQzWFwOd1 3sALJzNd8A8sf3bkjfa//PYs= X-Received: by 127.0.0.2 with SMTP id ibUwYY7687511xf0ngtSg6wZ; Mon, 11 Dec 2023 16:46:35 -0800 X-Received: from cxsh.intel-email.com (cxsh.intel-email.com [121.46.250.151]) by mx.groups.io with SMTP id smtpd.web11.1375.1702341994103673326 for ; Mon, 11 Dec 2023 16:46:34 -0800 X-Received: from cxsh.intel-email.com (localhost [127.0.0.1]) by cxsh.intel-email.com (Postfix) with ESMTP id D4FB5DDA7C8 for ; Tue, 12 Dec 2023 08:46:30 +0800 (CST) X-Received: from localhost (localhost [127.0.0.1]) by cxsh.intel-email.com (Postfix) with ESMTP id D0514DDA785 for ; Tue, 12 Dec 2023 08:46:30 +0800 (CST) X-Received: from mail.byosoft.com.cn (mail.byosoft.com.cn [58.240.74.242]) by cxsh.intel-email.com (Postfix) with SMTP id 2342ADDA7C4 for ; Tue, 12 Dec 2023 08:46:27 +0800 (CST) X-Received: from DESKTOPS6D0PVI ([58.246.60.130]) (envelope-sender ) by 192.168.6.13 with ESMTP(SSL) for ; Tue, 12 Dec 2023 08:46:25 +0800 X-WM-Sender: gaoliming@byosoft.com.cn X-Originating-IP: 58.246.60.130 X-WM-AuthFlag: YES X-WM-AuthUser: gaoliming@byosoft.com.cn From: "gaoliming via groups.io" To: , Cc: "'Michael D Kinney'" , "'Ray Ni'" , "'Guomin Jiang'" , "'Jian J Wang'" References: <20231211090611.3780-1-fan.wang@intel.com> In-Reply-To: <20231211090611.3780-1-fan.wang@intel.com> Subject: =?UTF-8?B?5Zue5aSNOiBbZWRrMi1kZXZlbF0gW1BBVENIIHY0IDEvMV0gTWRlTW9kdWxlUGtnOiBTdXBwb3J0IGN1c3RvbWl6ZWQgRlYgTWlncmF0aW9uIEluZm9ybWF0aW9u?= Date: Tue, 12 Dec 2023 08:46:26 +0800 Message-ID: <008501da2c94$a3831630$ea894290$@byosoft.com.cn> MIME-Version: 1.0 Thread-Index: AQH/A4MfIk6JRnU0q8R1pgDKMN7vZrBbIh/w Precedence: Bulk 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,gaoliming@byosoft.com.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 735TXFXOIzlE368Fzv9eZdu1x7686176AA= Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: quoted-printable Content-Language: zh-cn X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=eSDTL+5g; dmarc=none; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io Fan: Please separate the patch for the different packages.=20 Thanks Liming > -----=D3=CA=BC=FE=D4=AD=BC=FE----- > =B7=A2=BC=FE=C8=CB: devel@edk2.groups.io =B4=FA=B1= =ED Wang Fan > =B7=A2=CB=CD=CA=B1=BC=E4: 2023=C4=EA12=D4=C211=C8=D5 17:06 > =CA=D5=BC=FE=C8=CB: devel@edk2.groups.io > =B3=AD=CB=CD: Fan Wang ; Michael D Kinney > ; Liming Gao ; > Ray Ni ; Guomin Jiang ; Jian J > Wang > =D6=F7=CC=E2: [edk2-devel] [PATCH v4 1/1] MdeModulePkg: Support customize= d FV > Migration Information >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4533 >=20 > There are use cases which not all FVs need be migrated from TempRam to > permanent memory before TempRam tears down. This new guid is introduced > to avoid unnecessary FV migration to improve boot performance. Platform > can publish MigrationInfo hob with this guid to customize FV migration > info, and PeiCore will only migrate FVs indicated by this Hob info. >=20 > This is a backwards compatible change, PeiCore will check MigrationInfo > hob before migration. If MigrationInfo hobs exists, only migrate FVs > recorded by hobs. If MigrationInfo hobs not exists, migrate all FVs to > permanent memory. >=20 > Cc: Michael D Kinney > Cc: Liming Gao > Cc: Ray Ni > Cc: Guomin Jiang > Cc: Jian J Wang > Signed-off-by: Fan Wang > --- > MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c | 79 > +++++++++++++------ > MdeModulePkg/Core/Pei/PeiMain.inf | 1 + > MdeModulePkg/Include/Guid/MigratedFvInfo.h | 42 +++++++++- > MdeModulePkg/MdeModulePkg.dec | 3 +- > SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c | 7 +- > SecurityPkg/Tcg/TcgPei/TcgPei.c | 7 +- > 6 files changed, 111 insertions(+), 28 deletions(-) >=20 > diff --git a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c > b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c > index 5f32ebb560..0086087e82 100644 > --- a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c > +++ b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c > @@ -1184,7 +1184,12 @@ EvacuateTempRam ( >=20 >=20 > PEI_CORE_FV_HANDLE PeiCoreFvHandle; >=20 > EFI_PEI_CORE_FV_LOCATION_PPI *PeiCoreFvLocationPpi; >=20 > + EFI_PEI_HOB_POINTERS Hob; >=20 > + EDKII_MIGRATION_INFO *MigrationInfo; >=20 > + TO_MIGRATE_FV_INFO *ToMigrateFvInfo; >=20 > + UINT32 FvMigrationFlags; >=20 > EDKII_MIGRATED_FV_INFO MigratedFvInfo; >=20 > + UINTN Index; >=20 >=20 >=20 > ASSERT (Private->PeiMemoryInstalled); >=20 >=20 >=20 > @@ -1211,6 +1216,13 @@ EvacuateTempRam ( >=20 >=20 > ConvertPeiCorePpiPointers (Private, &PeiCoreFvHandle); >=20 >=20 >=20 > + Hob.Raw =3D GetFirstGuidHob (&gEdkiiMigrationInfoGuid); >=20 > + if (Hob.Raw !=3D NULL) { >=20 > + MigrationInfo =3D GET_GUID_HOB_DATA (Hob); >=20 > + } else { >=20 > + MigrationInfo =3D NULL; >=20 > + } >=20 > + >=20 > for (FvIndex =3D 0; FvIndex < Private->FvCount; FvIndex++) { >=20 > FvHeader =3D Private->Fv[FvIndex].FvHeader; >=20 > ASSERT (FvHeader !=3D NULL); >=20 > @@ -1224,20 +1236,27 @@ EvacuateTempRam ( > ) >=20 > ) >=20 > { >=20 > - // >=20 > - // Allocate page to save the rebased PEIMs, the PEIMs will get > dispatched later. >=20 > - // >=20 > - Status =3D PeiServicesAllocatePages ( >=20 > - EfiBootServicesCode, >=20 > - EFI_SIZE_TO_PAGES ((UINTN)FvHeader->FvLength), >=20 > - &FvHeaderAddress >=20 > - ); >=20 > - ASSERT_EFI_ERROR (Status); >=20 > - MigratedFvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER > *)(UINTN)FvHeaderAddress; >=20 > + if ((MigrationInfo =3D=3D NULL) || (MigrationInfo->MigrateAll =3D= =3D TRUE)) { >=20 > + // Migrate all FVs and copy raw data >=20 > + FvMigrationFlags =3D FLAGS_FV_RAW_DATA_COPY; >=20 > + } else { >=20 > + for (Index =3D 0; Index < MigrationInfo->ToMigrateFvCount; Index= ++) > { >=20 > + ToMigrateFvInfo =3D ((TO_MIGRATE_FV_INFO *)(MigrationInfo + > 1)) + Index; >=20 > + if (ToMigrateFvInfo->FvOrgBaseOnTempRam =3D=3D > (UINT32)(UINTN)FvHeader) { >=20 > + // This FV is to migrate >=20 > + FvMigrationFlags =3D ToMigrateFvInfo->FvMigrationFlags; >=20 > + break; >=20 > + } >=20 > + } >=20 > + >=20 > + if (Index =3D=3D MigrationInfo->ToMigrateFvCount) { >=20 > + // This FV is not expected to migrate >=20 > + continue; >=20 > + } >=20 > + } >=20 >=20 >=20 > // >=20 > - // Allocate pool to save the raw PEIMs, which is used to keep > consistent context across >=20 > - // multiple boot and PCR0 will keep the same no matter if the > address of allocated page is changed. >=20 > + // Allocate pages to save the rebased PEIMs, the PEIMs will get > dispatched later. >=20 > // >=20 > Status =3D PeiServicesAllocatePages ( >=20 > EfiBootServicesCode, >=20 > @@ -1245,7 +1264,8 @@ EvacuateTempRam ( > &FvHeaderAddress >=20 > ); >=20 > ASSERT_EFI_ERROR (Status); >=20 > - RawDataFvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER > *)(UINTN)FvHeaderAddress; >=20 > + MigratedFvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER > *)(UINTN)FvHeaderAddress; >=20 > + CopyMem (MigratedFvHeader, FvHeader, > (UINTN)FvHeader->FvLength); >=20 >=20 >=20 > DEBUG (( >=20 > DEBUG_VERBOSE, >=20 > @@ -1256,17 +1276,34 @@ EvacuateTempRam ( > )); >=20 >=20 >=20 > // >=20 > - // Copy the context to the rebased pages and raw pages, and create > hob to save the >=20 > - // information. The MigratedFvInfo HOB will never be produced when >=20 > - // PcdMigrateTemporaryRamFirmwareVolumes is FALSE, because the > PCD control the >=20 > - // feature. >=20 > + // Create hob to save MigratedFvInfo, this hob will only be produced > when >=20 > + // Migration feature PCD > PcdMigrateTemporaryRamFirmwareVolumes is set to TRUE. >=20 > // >=20 > - CopyMem (MigratedFvHeader, FvHeader, > (UINTN)FvHeader->FvLength); >=20 > - CopyMem (RawDataFvHeader, MigratedFvHeader, > (UINTN)FvHeader->FvLength); >=20 > MigratedFvInfo.FvOrgBase =3D (UINT32)(UINTN)FvHeader; >=20 > MigratedFvInfo.FvNewBase =3D (UINT32)(UINTN)MigratedFvHeader; >=20 > - MigratedFvInfo.FvDataBase =3D (UINT32)(UINTN)RawDataFvHeader; >=20 > + MigratedFvInfo.FvDataBase =3D 0; >=20 > MigratedFvInfo.FvLength =3D > (UINT32)(UINTN)FvHeader->FvLength; >=20 > + >=20 > + // >=20 > + // When FLAGS_FV_RAW_DATA_COPY bit is set, copy the context to > the raw pages and >=20 > + // reset raw data base address in MigratedFvInfo hob. >=20 > + // >=20 > + if ((FvMigrationFlags & FLAGS_FV_RAW_DATA_COPY) =3D=3D > FLAGS_FV_RAW_DATA_COPY) { >=20 > + DEBUG ((DEBUG_INFO, " Copying Raw Data ...\n")); >=20 > + // >=20 > + // Allocate pages to save the raw PEIMs >=20 > + // >=20 > + Status =3D PeiServicesAllocatePages ( >=20 > + EfiBootServicesCode, >=20 > + EFI_SIZE_TO_PAGES ((UINTN)FvHeader->FvLength), >=20 > + &FvHeaderAddress >=20 > + ); >=20 > + ASSERT_EFI_ERROR (Status); >=20 > + RawDataFvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER > *)(UINTN)FvHeaderAddress; >=20 > + CopyMem (RawDataFvHeader, MigratedFvHeader, > (UINTN)FvHeader->FvLength); >=20 > + MigratedFvInfo.FvDataBase =3D > (UINT32)(UINTN)RawDataFvHeader; >=20 > + } >=20 > + >=20 > BuildGuidDataHob (&gEdkiiMigratedFvInfoGuid, &MigratedFvInfo, > sizeof (MigratedFvInfo)); >=20 >=20 >=20 > // >=20 > @@ -1330,8 +1367,6 @@ EvacuateTempRam ( > } >=20 > } >=20 >=20 >=20 > - RemoveFvHobsInTemporaryMemory (Private); >=20 > - >=20 > return Status; >=20 > } >=20 >=20 >=20 > diff --git a/MdeModulePkg/Core/Pei/PeiMain.inf > b/MdeModulePkg/Core/Pei/PeiMain.inf > index 0cf357371a..893bdc0527 100644 > --- a/MdeModulePkg/Core/Pei/PeiMain.inf > +++ b/MdeModulePkg/Core/Pei/PeiMain.inf > @@ -78,6 +78,7 @@ > gEfiFirmwareFileSystem3Guid >=20 > gStatusCodeCallbackGuid >=20 > gEdkiiMigratedFvInfoGuid ## > SOMETIMES_PRODUCES ## HOB >=20 > + gEdkiiMigrationInfoGuid ## > SOMETIMES_CONSUMES ## HOB >=20 >=20 >=20 > [Ppis] >=20 > gEfiPeiStatusCodePpiGuid ## > SOMETIMES_CONSUMES # PeiReportStatusService is not ready if this PPI > doesn't exist >=20 > diff --git a/MdeModulePkg/Include/Guid/MigratedFvInfo.h > b/MdeModulePkg/Include/Guid/MigratedFvInfo.h > index aca2332a0e..1c8b0dfefc 100644 > --- a/MdeModulePkg/Include/Guid/MigratedFvInfo.h > +++ b/MdeModulePkg/Include/Guid/MigratedFvInfo.h > @@ -9,13 +9,53 @@ SPDX-License-Identifier: BSD-2-Clause-Patent > #ifndef __EDKII_MIGRATED_FV_INFO_GUID_H__ >=20 > #define __EDKII_MIGRATED_FV_INFO_GUID_H__ >=20 >=20 >=20 > +// >=20 > +// FLAGS_FV_RAW_DATA_COPY indicates FV raw data will be copied to > permanent memory >=20 > +// or not. When FV is migrated to permanent memory, it will be rebased and > raw >=20 > +// data will be lost. This bit can be configured as below values: >=20 > +// 0: FV raw data will not be used in later phase, and the copy will be skipped > to >=20 > +// optimize boot performance. >=20 > +// 1: FV raw data will be copied to permanent memory for later phase use > (such as >=20 > +// FV measurement). >=20 > +// >=20 > +#define FLAGS_FV_RAW_DATA_COPY BIT0 >=20 > + >=20 > +/// >=20 > +/// In real use cases, not all FVs need migrate to permanent memory before > TempRam tears >=20 > +/// down. EDKII_MIGRATION_INFO hob should be published by platform to > indicate which >=20 > +/// FVs need migration to optimize boot performance. If this hob is not > detected by Pei >=20 > +/// Core, all FVs on TempRam will be migrated and FV raw data will also be > copied. >=20 > +/// Only one EDKII_MIGRATION_INFO hob should be published by platform, > and this hob will >=20 > +/// take effect only when migration feature is enabled by PCD. >=20 > +/// >=20 > +typedef struct { >=20 > + UINT32 FvOrgBaseOnTempRam; // Original FV address on > Temporary Ram >=20 > + // >=20 > + // FV Migration Flags: >=20 > + // Bit0: Indicate to copy FV raw data or not >=20 > + // Others: Reserved bits >=20 > + // >=20 > + UINT32 FvMigrationFlags; >=20 > +} TO_MIGRATE_FV_INFO; >=20 > + >=20 > +typedef struct { >=20 > + BOOLEAN MigrateAll; // Migrate all FVs and > also copy FV raw data >=20 > + // >=20 > + // ToMigrateFvCount and ToMigrateFvInfo array indicate which FVs need > be migrated, and >=20 > + // these info should be ignored when MigrateAll field is set to TRUE. >=20 > + // >=20 > + UINT32 ToMigrateFvCount; >=20 > + // TO_MIGRATE_FV_INFO ToMigrateFvInfo[]; >=20 > +} EDKII_MIGRATION_INFO; >=20 > + >=20 > typedef struct { >=20 > UINT32 FvOrgBase; // original FV address >=20 > UINT32 FvNewBase; // new FV address >=20 > - UINT32 FvDataBase; // original FV data >=20 > + UINT32 FvDataBase; // original FV data, 0 means raw data is > not copied >=20 > UINT32 FvLength; // Fv Length >=20 > } EDKII_MIGRATED_FV_INFO; >=20 >=20 >=20 > +extern EFI_GUID gEdkiiMigrationInfoGuid; >=20 > extern EFI_GUID gEdkiiMigratedFvInfoGuid; >=20 >=20 >=20 > #endif // #ifndef __EDKII_MIGRATED_FV_INFO_GUID_H__ >=20 > diff --git a/MdeModulePkg/MdeModulePkg.dec > b/MdeModulePkg/MdeModulePkg.dec > index 1a162e97e6..a2cd83345f 100644 > --- a/MdeModulePkg/MdeModulePkg.dec > +++ b/MdeModulePkg/MdeModulePkg.dec > @@ -421,7 +421,8 @@ > gEdkiiCapsuleOnDiskNameGuid =3D { 0x98c80a4f, 0xe16b, 0x4d11, { 0x93, > 0x9a, 0xab, 0xe5, 0x61, 0x26, 0x3, 0x30 } } >=20 >=20 >=20 > ## Include/Guid/MigratedFvInfo.h >=20 > - gEdkiiMigratedFvInfoGuid =3D { 0xc1ab12f7, 0x74aa, 0x408d, { 0xa2, 0xf= 4, > 0xc6, 0xce, 0xfd, 0x17, 0x98, 0x71 } } >=20 > + gEdkiiMigrationInfoGuid =3D { 0xb4b140a5, 0x72f6, 0x4c21, { 0x93, 0x= e4, > 0xac, 0xc4, 0xec, 0xcb, 0x23, 0x23 } } >=20 > + gEdkiiMigratedFvInfoGuid =3D { 0xc1ab12f7, 0x74aa, 0x408d, { 0xa2, 0x= f4, > 0xc6, 0xce, 0xfd, 0x17, 0x98, 0x71 } } >=20 >=20 >=20 > ## Include/Guid/RngAlgorithm.h >=20 > gEdkiiRngAlgorithmUnSafe =3D { 0x869f728c, 0x409d, 0x4ab4, {0xac, 0x03= , > 0x71, 0xd3, 0x09, 0xc1, 0xb3, 0xf4 }} >=20 > diff --git a/SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c > b/SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c > index 1caaa4e319..daaf49e644 100644 > --- a/SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c > +++ b/SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c > @@ -726,8 +726,11 @@ MeasureFvImage ( > // >=20 > // Found the migrated FV info >=20 > // >=20 > - FvOrgBase =3D > (EFI_PHYSICAL_ADDRESS)(UINTN)MigratedFvInfo->FvOrgBase; >=20 > - FvDataBase =3D > (EFI_PHYSICAL_ADDRESS)(UINTN)MigratedFvInfo->FvDataBase; >=20 > + FvOrgBase =3D > (EFI_PHYSICAL_ADDRESS)(UINTN)MigratedFvInfo->FvOrgBase; >=20 > + if (MigratedFvInfo->FvDataBase !=3D 0) { >=20 > + FvDataBase =3D > (EFI_PHYSICAL_ADDRESS)(UINTN)MigratedFvInfo->FvDataBase; >=20 > + } >=20 > + >=20 > break; >=20 > } >=20 >=20 >=20 > diff --git a/SecurityPkg/Tcg/TcgPei/TcgPei.c b/SecurityPkg/Tcg/TcgPei/TcgPei.c > index 5aa80511aa..d35c2ad0bc 100644 > --- a/SecurityPkg/Tcg/TcgPei/TcgPei.c > +++ b/SecurityPkg/Tcg/TcgPei/TcgPei.c > @@ -463,8 +463,11 @@ MeasureFvImage ( > // >=20 > // Found the migrated FV info >=20 > // >=20 > - FvOrgBase =3D > (EFI_PHYSICAL_ADDRESS)(UINTN)MigratedFvInfo->FvOrgBase; >=20 > - FvDataBase =3D > (EFI_PHYSICAL_ADDRESS)(UINTN)MigratedFvInfo->FvDataBase; >=20 > + FvOrgBase =3D > (EFI_PHYSICAL_ADDRESS)(UINTN)MigratedFvInfo->FvOrgBase; >=20 > + if (MigratedFvInfo->FvDataBase !=3D 0) { >=20 > + FvDataBase =3D > (EFI_PHYSICAL_ADDRESS)(UINTN)MigratedFvInfo->FvDataBase; >=20 > + } >=20 > + >=20 > break; >=20 > } >=20 >=20 >=20 > -- > 2.26.2.windows.1 >=20 >=20 >=20 > -=3D-=3D-=3D-=3D-=3D-=3D > Groups.io Links: You receive all messages sent to this group. > View/Reply Online (#112276): > https://edk2.groups.io/g/devel/message/112276 > Mute This Topic: https://groups.io/mt/103105558/4905953 > Group Owner: devel+owner@edk2.groups.io > Unsubscribe: https://edk2.groups.io/g/devel/unsub > [gaoliming@byosoft.com.cn] > -=3D-=3D-=3D-=3D-=3D-=3D >=20 -=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 (#112350): https://edk2.groups.io/g/devel/message/112350 Mute This Topic: https://groups.io/mt/103121557/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-