From nobody Wed May 15 21:46:12 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+108361+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+108361+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1694069718; cv=none; d=zohomail.com; s=zohoarc; b=KQ1qQLL9hMnYdsABWNkYcJPlm6OMvWIv23iyy+a3+HxaguxcKQreWY7ohsTd87hlsf3w09HPL9K9FeIBfdfUKWbDicCQKyAzLo3Xz8Z4WledTBejLMVpq+WTCWKKjgISfBYEImscHxk/kIbUKTufzypb+y9qlPT/6ylcJFya/1E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694069718; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=h8QlGPFWhVmlbNPwzi+uxHvNlUad6vQGQu4ttxwXAiA=; b=OEl6MmmUVrrsLLb/+oNJMik/4/Z04BnFJAtCT0ur3ftwmKB2AZYZiT004p/uOci3u7r4D/a27jMXN8uXugD1XuSp2jbN+ZoPEW9k7Wf2m2fFr8XntR4apVSpsJwXFUKNw/T4x2I4crnWY28mxTMD3imP2euuTo/M6MY/Zm2YRM0= 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+108361+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 1694069718200602.0335249717799; Wed, 6 Sep 2023 23:55:18 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=IrtxMBgH5b6rGB0eTvZ21xg+UVs0gGsuX29Lb3et/vA=; 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=1694069717; v=1; b=Y24g8VCdfTJsAKTh6NkLio30gCVVI6BiPrj+GYvCicWXYdpQOt5tICKIkiWEUmTZre72DchA kpdwBJklvr/U83h7ONXa6rwyljaqXP05oFy3nVDh3OXwN67510fuczrmiFx7439F+3Pn4Gplqtt YgpiWQPlaSJT2X0kPtj1ppuQ= X-Received: by 127.0.0.2 with SMTP id O7o1YY1788612xNMuuiluOtW; Wed, 06 Sep 2023 23:55:17 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web10.7537.1694069716732309162 for ; Wed, 06 Sep 2023 23:55:17 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10825"; a="367497977" X-IronPort-AV: E=Sophos;i="6.02,234,1688454000"; d="scan'208";a="367497977" X-Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Sep 2023 23:55:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10825"; a="691654162" X-IronPort-AV: E=Sophos;i="6.02,234,1688454000"; d="scan'208";a="691654162" X-Received: from sh1gapp1015.ccr.corp.intel.com ([10.239.189.85]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Sep 2023 23:55:09 -0700 From: "Wang Fan" To: devel@edk2.groups.io Cc: Wang Fan , Michael D Kinney , Liming Gao , Guomin Jiang , Dandan Bi Subject: [edk2-devel] [PATCH] MdeModulePkg: Support customized FV Migration Information Date: Thu, 7 Sep 2023 14:54:53 +0800 Message-Id: <20230907065453.3804-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: kwEHqAeixuZ2DZd4Y62P8tcHx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1694069719422100002 Content-Type: text/plain; charset="utf-8" From: Wang Fan 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 hob with this guid to customize FV migration info, and PEI Core will only migrate FVs indicated by this Hob info. Cc: Michael D Kinney Cc: Liming Gao Cc: Guomin Jiang Cc: Dandan Bi Signed-off-by: Wang Fan --- MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c | 82 +++++++++++++------ MdeModulePkg/Core/Pei/PeiMain.inf | 1 + MdeModulePkg/Include/Guid/MigratedFvInfo.h | 19 +++++ MdeModulePkg/MdeModulePkg.dec | 3 +- 4 files changed, 79 insertions(+), 26 deletions(-) diff --git a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c b/MdeModulePkg/C= ore/Pei/Dispatcher/Dispatcher.c index 5f32ebb560..a9e4f8fcca 100644 --- a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c +++ b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c @@ -1184,7 +1184,11 @@ EvacuateTempRam ( =20 PEI_CORE_FV_HANDLE PeiCoreFvHandle; EFI_PEI_CORE_FV_LOCATION_PPI *PeiCoreFvLocationPpi; + EDKII_TO_MIGRATE_FV_INFO *ToMigrateFvInfo; EDKII_MIGRATED_FV_INFO MigratedFvInfo; + EFI_PEI_HOB_POINTERS Hob; + BOOLEAN MigrateAllFvs; + UINT32 MigrationFlags; =20 ASSERT (Private->PeiMemoryInstalled); =20 @@ -1211,6 +1215,17 @@ EvacuateTempRam ( =20 ConvertPeiCorePpiPointers (Private, &PeiCoreFvHandle); =20 + // + // Check if platform defined hobs to indicate which FVs are expected to = migrate or keep raw data. + // If ToMigrateFvInfo hobs exists, only migrate FVs recorded by hobs. + // If ToMigrateFvInfo hobs not exists, migrate all FVs to permanant memo= ry. + // + MigrateAllFvs =3D TRUE; + Hob.Raw =3D GetFirstGuidHob (&gEdkiiToMigrateFvInfoGuid); + if (Hob.Raw !=3D NULL) { + MigrateAllFvs =3D FALSE; + } + for (FvIndex =3D 0; FvIndex < Private->FvCount; FvIndex++) { FvHeader =3D Private->Fv[FvIndex].FvHeader; ASSERT (FvHeader !=3D NULL); @@ -1224,6 +1239,25 @@ EvacuateTempRam ( ) ) { + if (MigrateAllFvs) { + MigrationFlags =3D 0; + } else { + MigrationFlags =3D FLAGS_SKIP_FV_MIGRATION | FLAGS_SKIP_FV_RAW_DAT= A_COPY; + Hob.Raw =3D GetFirstGuidHob (&gEdkiiToMigrateFvInfoGuid); + while (Hob.Raw !=3D NULL) { + ToMigrateFvInfo =3D GET_GUID_HOB_DATA (Hob); + if (ToMigrateFvInfo->FvOrgBase =3D=3D (UINT32)(UINTN)FvHeader) { + MigrationFlags =3D ToMigrateFvInfo->MigrationFlags; + break; + } + Hob.Raw =3D GET_NEXT_HOB (Hob); + Hob.Raw =3D GetNextGuidHob (&gEdkiiToMigrateFvInfoGuid, Hob.Raw); + } + } + if (MigrationFlags & FLAGS_SKIP_FV_MIGRATION) { + continue; + } + // // Allocate page to save the rebased PEIMs, the PEIMs will get dispa= tched later. // @@ -1234,18 +1268,7 @@ EvacuateTempRam ( ); ASSERT_EFI_ERROR (Status); MigratedFvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)FvHeaderAd= dress; - - // - // Allocate pool to save the raw PEIMs, which is used to keep consis= tent context across - // multiple boot and PCR0 will keep the same no matter if the addres= s of allocated page is changed. - // - Status =3D PeiServicesAllocatePages ( - EfiBootServicesCode, - EFI_SIZE_TO_PAGES ((UINTN)FvHeader->FvLength), - &FvHeaderAddress - ); - ASSERT_EFI_ERROR (Status); - RawDataFvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)FvHeaderAdd= ress; + CopyMem (MigratedFvHeader, FvHeader, (UINTN)FvHeader->FvLength); =20 DEBUG (( DEBUG_VERBOSE, @@ -1256,18 +1279,29 @@ EvacuateTempRam ( )); =20 // - // Copy the context to the rebased pages and raw pages, and create h= ob to save the - // information. The MigratedFvInfo HOB will never be produced when - // PcdMigrateTemporaryRamFirmwareVolumes is FALSE, because the PCD c= ontrol the - // feature. + // Copy the context to the raw pages, and create hob to save the inf= ormation. The MigratedFvInfo + // HOB will never be produced when PcdMigrateTemporaryRamFirmwareVol= umes is FALSE, because the PCD + // controls the feature. // - CopyMem (MigratedFvHeader, FvHeader, (UINTN)FvHeader->FvLength); - CopyMem (RawDataFvHeader, MigratedFvHeader, (UINTN)FvHeader->FvLengt= h); - MigratedFvInfo.FvOrgBase =3D (UINT32)(UINTN)FvHeader; - MigratedFvInfo.FvNewBase =3D (UINT32)(UINTN)MigratedFvHeader; - MigratedFvInfo.FvDataBase =3D (UINT32)(UINTN)RawDataFvHeader; - MigratedFvInfo.FvLength =3D (UINT32)(UINTN)FvHeader->FvLength; - BuildGuidDataHob (&gEdkiiMigratedFvInfoGuid, &MigratedFvInfo, sizeof= (MigratedFvInfo)); + if ((MigrationFlags & FLAGS_SKIP_FV_RAW_DATA_COPY) !=3D FLAGS_SKIP_F= V_RAW_DATA_COPY) { + // + // Allocate pool to save the raw PEIMs, which is used to keep cons= istent context across + // multiple boot and PCR0 will keep the same no matter if the addr= ess of allocated page is changed. + // + Status =3D PeiServicesAllocatePages ( + EfiBootServicesCode, + EFI_SIZE_TO_PAGES ((UINTN)FvHeader->FvLength), + &FvHeaderAddress + ); + ASSERT_EFI_ERROR (Status); + RawDataFvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)FvHeaderA= ddress; + CopyMem (RawDataFvHeader, MigratedFvHeader, (UINTN)FvHeader->FvLen= gth); + MigratedFvInfo.FvOrgBase =3D (UINT32)(UINTN)FvHeader; + MigratedFvInfo.FvNewBase =3D (UINT32)(UINTN)MigratedFvHeader; + MigratedFvInfo.FvDataBase =3D (UINT32)(UINTN)RawDataFvHeader; + MigratedFvInfo.FvLength =3D (UINT32)(UINTN)FvHeader->FvLength; + BuildGuidDataHob (&gEdkiiMigratedFvInfoGuid, &MigratedFvInfo, size= of (MigratedFvInfo)); + } =20 // // Migrate any children for this FV now @@ -1330,8 +1364,6 @@ EvacuateTempRam ( } } =20 - RemoveFvHobsInTemporaryMemory (Private); - return Status; } =20 diff --git a/MdeModulePkg/Core/Pei/PeiMain.inf b/MdeModulePkg/Core/Pei/PeiM= ain.inf index 0cf357371a..944b230b0e 100644 --- a/MdeModulePkg/Core/Pei/PeiMain.inf +++ b/MdeModulePkg/Core/Pei/PeiMain.inf @@ -78,6 +78,7 @@ gEfiFirmwareFileSystem3Guid gStatusCodeCallbackGuid gEdkiiMigratedFvInfoGuid ## SOMETIMES_PRODUCES = ## HOB + gEdkiiToMigrateFvInfoGuid ## SOMETIMES_CONSUMES = ## HOB =20 [Ppis] gEfiPeiStatusCodePpiGuid ## SOMETIMES_CONSUMES # Pe= iReportStatusService is not ready if this PPI doesn't exist diff --git a/MdeModulePkg/Include/Guid/MigratedFvInfo.h b/MdeModulePkg/Incl= ude/Guid/MigratedFvInfo.h index aca2332a0e..543cd9ba7d 100644 --- a/MdeModulePkg/Include/Guid/MigratedFvInfo.h +++ b/MdeModulePkg/Include/Guid/MigratedFvInfo.h @@ -9,6 +9,24 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #ifndef __EDKII_MIGRATED_FV_INFO_GUID_H__ #define __EDKII_MIGRATED_FV_INFO_GUID_H__ =20 +#define FLAGS_SKIP_FV_MIGRATION BIT0 +#define FLAGS_SKIP_FV_RAW_DATA_COPY BIT1 + +/// +/// EDKII_TO_MIGRATE_FV_INFO Hob information should be published by platfo= rm to indicate +/// one FV is expected to migrate to permarnant memory or not before TempR= am tears down. +/// +typedef struct { + UINT32 FvOrgBase; // original FV address + // + // Migration Flags: + // Bit0: Indicate to skip FV migration or not + // Bit1: Indicate to skip FV raw data copy or not + // Others: Reserved bits + // + UINT32 MigrationFlags; +} EDKII_TO_MIGRATE_FV_INFO; + typedef struct { UINT32 FvOrgBase; // original FV address UINT32 FvNewBase; // new FV address @@ -16,6 +34,7 @@ typedef struct { UINT32 FvLength; // Fv Length } EDKII_MIGRATED_FV_INFO; =20 +extern EFI_GUID gEdkiiToMigrateFvInfoGuid; extern EFI_GUID gEdkiiMigratedFvInfoGuid; =20 #endif // #ifndef __EDKII_MIGRATED_FV_INFO_GUID_H__ diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 0ff058b0a9..02b4a3ba3c 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -416,7 +416,8 @@ gEdkiiCapsuleOnDiskNameGuid =3D { 0x98c80a4f, 0xe16b, 0x4d11, { 0x93, 0x= 9a, 0xab, 0xe5, 0x61, 0x26, 0x3, 0x30 } } =20 ## Include/Guid/MigratedFvInfo.h - gEdkiiMigratedFvInfoGuid =3D { 0xc1ab12f7, 0x74aa, 0x408d, { 0xa2, 0xf4,= 0xc6, 0xce, 0xfd, 0x17, 0x98, 0x71 } } + gEdkiiToMigrateFvInfoGuid =3D { 0xb4b140a5, 0x72f6, 0x4c21, { 0x93, 0xe4= , 0xac, 0xc4, 0xec, 0xcb, 0x23, 0x23 } } + gEdkiiMigratedFvInfoGuid =3D { 0xc1ab12f7, 0x74aa, 0x408d, { 0xa2, 0xf4= , 0xc6, 0xce, 0xfd, 0x17, 0x98, 0x71 } } =20 # # GUID defined in UniversalPayload --=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 (#108361): https://edk2.groups.io/g/devel/message/108361 Mute This Topic: https://groups.io/mt/101210068/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-