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 C07D3D81112 for ; Mon, 11 Dec 2023 09:06:18 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=FQy/ZNOCDb0WIi6iPBAZYCwFX/W7FM8iUj1Yl6GuP/8=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1702285577; v=1; b=Eao6uursFSx/y94pb6oOeWBNnp9c1qVt1m/D1FjKt515Gr7JzrcMq7yDJLtVxWFuLFK79Sn5 P8j0pzfIHOZ77L0hLtgxO+aTvx3WD+2bOEhtdnyVrOIIPPLgQN6ayQgbr1fDx5VgMKiTJENIPc+ hLADlBcqwyPY8o/SfjX2HDDs= X-Received: by 127.0.0.2 with SMTP id 8DHjYY7687511x3E3R0QuTKV; Mon, 11 Dec 2023 01:06:17 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web10.4362.1702285576669671258 for ; Mon, 11 Dec 2023 01:06:16 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10920"; a="374121005" X-IronPort-AV: E=Sophos;i="6.04,267,1695711600"; d="scan'208";a="374121005" X-Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Dec 2023 01:06:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10920"; a="807226659" X-IronPort-AV: E=Sophos;i="6.04,267,1695711600"; d="scan'208";a="807226659" X-Received: from sh1gapp1015.ccr.corp.intel.com ([10.239.189.85]) by orsmga001.jf.intel.com with ESMTP; 11 Dec 2023 01:06:13 -0800 From: "Wang Fan" To: devel@edk2.groups.io Cc: Fan Wang , Michael D Kinney , Liming Gao , Ray Ni , Guomin Jiang , Jian J Wang Subject: [edk2-devel] [PATCH v4 1/1] MdeModulePkg: Support customized FV Migration Information Date: Mon, 11 Dec 2023 17:06:11 +0800 Message-Id: <20231211090611.3780-1-fan.wang@intel.com> MIME-Version: 1.0 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,fan.wang@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: X0aF7VSvQc4rXWlGxccYgmvCx7686176AA= Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=Eao6uurs; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none) REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4533 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. 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. 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(-) diff --git a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c b/MdeModulePkg/C= ore/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 ( =0D PEI_CORE_FV_HANDLE PeiCoreFvHandle;=0D EFI_PEI_CORE_FV_LOCATION_PPI *PeiCoreFvLocationPpi;=0D + EFI_PEI_HOB_POINTERS Hob;=0D + EDKII_MIGRATION_INFO *MigrationInfo;=0D + TO_MIGRATE_FV_INFO *ToMigrateFvInfo;=0D + UINT32 FvMigrationFlags;=0D EDKII_MIGRATED_FV_INFO MigratedFvInfo;=0D + UINTN Index;=0D =0D ASSERT (Private->PeiMemoryInstalled);=0D =0D @@ -1211,6 +1216,13 @@ EvacuateTempRam ( =0D ConvertPeiCorePpiPointers (Private, &PeiCoreFvHandle);=0D =0D + Hob.Raw =3D GetFirstGuidHob (&gEdkiiMigrationInfoGuid);=0D + if (Hob.Raw !=3D NULL) {=0D + MigrationInfo =3D GET_GUID_HOB_DATA (Hob);=0D + } else {=0D + MigrationInfo =3D NULL;=0D + }=0D +=0D for (FvIndex =3D 0; FvIndex < Private->FvCount; FvIndex++) {=0D FvHeader =3D Private->Fv[FvIndex].FvHeader;=0D ASSERT (FvHeader !=3D NULL);=0D @@ -1224,20 +1236,27 @@ EvacuateTempRam ( )=0D )=0D {=0D - //=0D - // Allocate page to save the rebased PEIMs, the PEIMs will get dispa= tched later.=0D - //=0D - Status =3D PeiServicesAllocatePages (=0D - EfiBootServicesCode,=0D - EFI_SIZE_TO_PAGES ((UINTN)FvHeader->FvLength),=0D - &FvHeaderAddress=0D - );=0D - ASSERT_EFI_ERROR (Status);=0D - MigratedFvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)FvHeaderAd= dress;=0D + if ((MigrationInfo =3D=3D NULL) || (MigrationInfo->MigrateAll =3D=3D= TRUE)) {=0D + // Migrate all FVs and copy raw data=0D + FvMigrationFlags =3D FLAGS_FV_RAW_DATA_COPY;=0D + } else {=0D + for (Index =3D 0; Index < MigrationInfo->ToMigrateFvCount; Index++= ) {=0D + ToMigrateFvInfo =3D ((TO_MIGRATE_FV_INFO *)(MigrationInfo + 1)) = + Index;=0D + if (ToMigrateFvInfo->FvOrgBaseOnTempRam =3D=3D (UINT32)(UINTN)Fv= Header) {=0D + // This FV is to migrate=0D + FvMigrationFlags =3D ToMigrateFvInfo->FvMigrationFlags;=0D + break;=0D + }=0D + }=0D +=0D + if (Index =3D=3D MigrationInfo->ToMigrateFvCount) {=0D + // This FV is not expected to migrate=0D + continue;=0D + }=0D + }=0D =0D //=0D - // Allocate pool to save the raw PEIMs, which is used to keep consis= tent context across=0D - // multiple boot and PCR0 will keep the same no matter if the addres= s of allocated page is changed.=0D + // Allocate pages to save the rebased PEIMs, the PEIMs will get disp= atched later.=0D //=0D Status =3D PeiServicesAllocatePages (=0D EfiBootServicesCode,=0D @@ -1245,7 +1264,8 @@ EvacuateTempRam ( &FvHeaderAddress=0D );=0D ASSERT_EFI_ERROR (Status);=0D - RawDataFvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)FvHeaderAdd= ress;=0D + MigratedFvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)FvHeaderAd= dress;=0D + CopyMem (MigratedFvHeader, FvHeader, (UINTN)FvHeader->FvLength);=0D =0D DEBUG ((=0D DEBUG_VERBOSE,=0D @@ -1256,17 +1276,34 @@ EvacuateTempRam ( ));=0D =0D //=0D - // Copy the context to the rebased pages and raw pages, and create h= ob to save the=0D - // information. The MigratedFvInfo HOB will never be produced when=0D - // PcdMigrateTemporaryRamFirmwareVolumes is FALSE, because the PCD c= ontrol the=0D - // feature.=0D + // Create hob to save MigratedFvInfo, this hob will only be produced= when=0D + // Migration feature PCD PcdMigrateTemporaryRamFirmwareVolumes is se= t to TRUE.=0D //=0D - CopyMem (MigratedFvHeader, FvHeader, (UINTN)FvHeader->FvLength);=0D - CopyMem (RawDataFvHeader, MigratedFvHeader, (UINTN)FvHeader->FvLengt= h);=0D MigratedFvInfo.FvOrgBase =3D (UINT32)(UINTN)FvHeader;=0D MigratedFvInfo.FvNewBase =3D (UINT32)(UINTN)MigratedFvHeader;=0D - MigratedFvInfo.FvDataBase =3D (UINT32)(UINTN)RawDataFvHeader;=0D + MigratedFvInfo.FvDataBase =3D 0;=0D MigratedFvInfo.FvLength =3D (UINT32)(UINTN)FvHeader->FvLength;=0D +=0D + //=0D + // When FLAGS_FV_RAW_DATA_COPY bit is set, copy the context to the r= aw pages and=0D + // reset raw data base address in MigratedFvInfo hob.=0D + //=0D + if ((FvMigrationFlags & FLAGS_FV_RAW_DATA_COPY) =3D=3D FLAGS_FV_RAW_= DATA_COPY) {=0D + DEBUG ((DEBUG_INFO, " Copying Raw Data ...\n"));=0D + //=0D + // Allocate pages to save the raw PEIMs=0D + //=0D + Status =3D PeiServicesAllocatePages (=0D + EfiBootServicesCode,=0D + EFI_SIZE_TO_PAGES ((UINTN)FvHeader->FvLength),=0D + &FvHeaderAddress=0D + );=0D + ASSERT_EFI_ERROR (Status);=0D + RawDataFvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)FvHeaderA= ddress;=0D + CopyMem (RawDataFvHeader, MigratedFvHeader, (UINTN)FvHeader->FvLen= gth);=0D + MigratedFvInfo.FvDataBase =3D (UINT32)(UINTN)RawDataFvHeader;=0D + }=0D +=0D BuildGuidDataHob (&gEdkiiMigratedFvInfoGuid, &MigratedFvInfo, sizeof= (MigratedFvInfo));=0D =0D //=0D @@ -1330,8 +1367,6 @@ EvacuateTempRam ( }=0D }=0D =0D - RemoveFvHobsInTemporaryMemory (Private);=0D -=0D return Status;=0D }=0D =0D diff --git a/MdeModulePkg/Core/Pei/PeiMain.inf b/MdeModulePkg/Core/Pei/PeiM= ain.inf index 0cf357371a..893bdc0527 100644 --- a/MdeModulePkg/Core/Pei/PeiMain.inf +++ b/MdeModulePkg/Core/Pei/PeiMain.inf @@ -78,6 +78,7 @@ gEfiFirmwareFileSystem3Guid=0D gStatusCodeCallbackGuid=0D gEdkiiMigratedFvInfoGuid ## SOMETIMES_PRODUCES = ## HOB=0D + gEdkiiMigrationInfoGuid ## SOMETIMES_CONSUMES = ## HOB=0D =0D [Ppis]=0D gEfiPeiStatusCodePpiGuid ## SOMETIMES_CONSUMES # Pe= iReportStatusService is not ready if this PPI doesn't exist=0D diff --git a/MdeModulePkg/Include/Guid/MigratedFvInfo.h b/MdeModulePkg/Incl= ude/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__=0D #define __EDKII_MIGRATED_FV_INFO_GUID_H__=0D =0D +//=0D +// FLAGS_FV_RAW_DATA_COPY indicates FV raw data will be copied to permanen= t memory=0D +// or not. When FV is migrated to permanent memory, it will be rebased and= raw=0D +// data will be lost. This bit can be configured as below values:=0D +// 0: FV raw data will not be used in later phase, and the copy will be sk= ipped to=0D +// optimize boot performance.=0D +// 1: FV raw data will be copied to permanent memory for later phase use (= such as=0D +// FV measurement).=0D +//=0D +#define FLAGS_FV_RAW_DATA_COPY BIT0=0D +=0D +///=0D +/// In real use cases, not all FVs need migrate to permanent memory before= TempRam tears=0D +/// down. EDKII_MIGRATION_INFO hob should be published by platform to indi= cate which=0D +/// FVs need migration to optimize boot performance. If this hob is not de= tected by Pei=0D +/// Core, all FVs on TempRam will be migrated and FV raw data will also be= copied.=0D +/// Only one EDKII_MIGRATION_INFO hob should be published by platform, and= this hob will=0D +/// take effect only when migration feature is enabled by PCD.=0D +///=0D +typedef struct {=0D + UINT32 FvOrgBaseOnTempRam; // Original FV address on Temporary= Ram=0D + //=0D + // FV Migration Flags:=0D + // Bit0: Indicate to copy FV raw data or not=0D + // Others: Reserved bits=0D + //=0D + UINT32 FvMigrationFlags;=0D +} TO_MIGRATE_FV_INFO;=0D +=0D +typedef struct {=0D + BOOLEAN MigrateAll; // Migrate all FVs and also co= py FV raw data=0D + //=0D + // ToMigrateFvCount and ToMigrateFvInfo array indicate which FVs need be= migrated, and=0D + // these info should be ignored when MigrateAll field is set to TRUE.=0D + //=0D + UINT32 ToMigrateFvCount;=0D + // TO_MIGRATE_FV_INFO ToMigrateFvInfo[];=0D +} EDKII_MIGRATION_INFO;=0D +=0D typedef struct {=0D UINT32 FvOrgBase; // original FV address=0D UINT32 FvNewBase; // new FV address=0D - UINT32 FvDataBase; // original FV data=0D + UINT32 FvDataBase; // original FV data, 0 means raw data is no= t copied=0D UINT32 FvLength; // Fv Length=0D } EDKII_MIGRATED_FV_INFO;=0D =0D +extern EFI_GUID gEdkiiMigrationInfoGuid;=0D extern EFI_GUID gEdkiiMigratedFvInfoGuid;=0D =0D #endif // #ifndef __EDKII_MIGRATED_FV_INFO_GUID_H__=0D 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, 0x= 9a, 0xab, 0xe5, 0x61, 0x26, 0x3, 0x30 } }=0D =0D ## Include/Guid/MigratedFvInfo.h=0D - gEdkiiMigratedFvInfoGuid =3D { 0xc1ab12f7, 0x74aa, 0x408d, { 0xa2, 0xf4,= 0xc6, 0xce, 0xfd, 0x17, 0x98, 0x71 } }=0D + gEdkiiMigrationInfoGuid =3D { 0xb4b140a5, 0x72f6, 0x4c21, { 0x93, 0xe4= , 0xac, 0xc4, 0xec, 0xcb, 0x23, 0x23 } }=0D + gEdkiiMigratedFvInfoGuid =3D { 0xc1ab12f7, 0x74aa, 0x408d, { 0xa2, 0xf4= , 0xc6, 0xce, 0xfd, 0x17, 0x98, 0x71 } }=0D =0D ## Include/Guid/RngAlgorithm.h=0D gEdkiiRngAlgorithmUnSafe =3D { 0x869f728c, 0x409d, 0x4ab4, {0xac, 0x03, = 0x71, 0xd3, 0x09, 0xc1, 0xb3, 0xf4 }}=0D diff --git a/SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c b/SecurityPkg/Tcg/Tcg2Pei/Tc= g2Pei.c index 1caaa4e319..daaf49e644 100644 --- a/SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c +++ b/SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.c @@ -726,8 +726,11 @@ MeasureFvImage ( //=0D // Found the migrated FV info=0D //=0D - FvOrgBase =3D (EFI_PHYSICAL_ADDRESS)(UINTN)MigratedFvInfo->FvOrgBas= e;=0D - FvDataBase =3D (EFI_PHYSICAL_ADDRESS)(UINTN)MigratedFvInfo->FvDataBa= se;=0D + FvOrgBase =3D (EFI_PHYSICAL_ADDRESS)(UINTN)MigratedFvInfo->FvOrgBase= ;=0D + if (MigratedFvInfo->FvDataBase !=3D 0) {=0D + FvDataBase =3D (EFI_PHYSICAL_ADDRESS)(UINTN)MigratedFvInfo->FvData= Base;=0D + }=0D +=0D break;=0D }=0D =0D diff --git a/SecurityPkg/Tcg/TcgPei/TcgPei.c b/SecurityPkg/Tcg/TcgPei/TcgPe= i.c index 5aa80511aa..d35c2ad0bc 100644 --- a/SecurityPkg/Tcg/TcgPei/TcgPei.c +++ b/SecurityPkg/Tcg/TcgPei/TcgPei.c @@ -463,8 +463,11 @@ MeasureFvImage ( //=0D // Found the migrated FV info=0D //=0D - FvOrgBase =3D (EFI_PHYSICAL_ADDRESS)(UINTN)MigratedFvInfo->FvOrgBas= e;=0D - FvDataBase =3D (EFI_PHYSICAL_ADDRESS)(UINTN)MigratedFvInfo->FvDataBa= se;=0D + FvOrgBase =3D (EFI_PHYSICAL_ADDRESS)(UINTN)MigratedFvInfo->FvOrgBase= ;=0D + if (MigratedFvInfo->FvDataBase !=3D 0) {=0D + FvDataBase =3D (EFI_PHYSICAL_ADDRESS)(UINTN)MigratedFvInfo->FvData= Base;=0D + }=0D +=0D break;=0D }=0D =0D --=20 2.26.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- 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/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-