From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.93; helo=mga11.intel.com; envelope-from=liming.gao@intel.com; receiver=edk2-devel@lists.01.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 6DAE7211F8866 for ; Thu, 28 Jun 2018 06:26:14 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Jun 2018 06:26:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,283,1526367600"; d="scan'208";a="211879189" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by orsmga004.jf.intel.com with ESMTP; 28 Jun 2018 06:26:07 -0700 Received: from fmsmsx117.amr.corp.intel.com (10.18.116.17) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 28 Jun 2018 06:26:07 -0700 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by fmsmsx117.amr.corp.intel.com (10.18.116.17) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 28 Jun 2018 06:26:06 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.87]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.70]) with mapi id 14.03.0319.002; Thu, 28 Jun 2018 21:26:04 +0800 From: "Gao, Liming" To: "Zeng, Star" , "edk2-devel@lists.01.org" Thread-Topic: [PATCH] MdeModulePkg PeiCore: Not assume PpiDescriptor and Ppi in same range Thread-Index: AQHUDr3dgzLtaZ8wlUWFIh0l1713EKR1qZ1g Date: Thu, 28 Jun 2018 13:26:04 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14E29F882@SHSMSX104.ccr.corp.intel.com> References: <1530176157-157512-1-git-send-email-star.zeng@intel.com> In-Reply-To: <1530176157-157512-1-git-send-email-star.zeng@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ctpclassification: CTP_NT x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMGFiM2YzNmItNWIxMC00Y2U4LTllNWItNDE5MzMwODA1ZDQwIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoibXQrQURWOWtKKzFuM29pNkk4REpiVFwvM0kwejNHWlwvQkRkWHhhNjBpalJOcnN4Sk9pa2FyXC9Vc2hwUVN2eE9SNyJ9 dlp-product: dlpe-windows dlp-version: 11.0.200.100 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH] MdeModulePkg PeiCore: Not assume PpiDescriptor and Ppi in same range X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Jun 2018 13:26:14 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Liming Gao > -----Original Message----- > From: Zeng, Star > Sent: Thursday, June 28, 2018 4:56 PM > To: edk2-devel@lists.01.org > Cc: Zeng, Star ; Gao, Liming ;= Huang, Qing > Subject: [PATCH] MdeModulePkg PeiCore: Not assume PpiDescriptor and Ppi i= n same range >=20 > Current code assumes PpiDescriptor and Ppi are in same range > (heap/stack/hole). >=20 > This patch removes the assumption. >=20 > Descriptor needs to be converted first. It is also handled by this patch. >=20 > Cc: Liming Gao > Cc: Qing Huang > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Star Zeng > --- > MdeModulePkg/Core/Pei/Ppi/Ppi.c | 204 ++++++++++++++++++++++------------= ------ > 1 file changed, 115 insertions(+), 89 deletions(-) >=20 > diff --git a/MdeModulePkg/Core/Pei/Ppi/Ppi.c b/MdeModulePkg/Core/Pei/Ppi/= Ppi.c > index 139cfeda0575..d8ba2dd42b59 100644 > --- a/MdeModulePkg/Core/Pei/Ppi/Ppi.c > +++ b/MdeModulePkg/Core/Pei/Ppi/Ppi.c > @@ -38,9 +38,9 @@ InitializePpiServices ( >=20 > /** >=20 > - Migrate Single PPI Pointer from the temporary memory to PEI installed = memory. > + Migrate Pointer from the temporary memory to PEI installed memory. >=20 > - @param PpiPointer Pointer to Ppi > + @param Pointer Pointer to the Pointer needs to be converted. > @param TempBottom Base of old temporary memory > @param TempTop Top of old temporary memory > @param Offset Offset of new memory to old temporary memory. > @@ -48,64 +48,138 @@ InitializePpiServices ( >=20 > **/ > VOID > -ConvertSinglePpiPointer ( > - IN PEI_PPI_LIST_POINTERS *PpiPointer, > +ConvertPointer ( > + IN OUT VOID **Pointer, > IN UINTN TempBottom, > IN UINTN TempTop, > IN UINTN Offset, > IN BOOLEAN OffsetPositive > ) > { > - if (((UINTN)PpiPointer->Raw < TempTop) && > - ((UINTN)PpiPointer->Raw >=3D TempBottom)) { > - // > - // Convert the pointer to the PPI descriptor from the old TempRam > - // to the relocated physical memory. > - // > + if (((UINTN) *Pointer < TempTop) && > + ((UINTN) *Pointer >=3D TempBottom)) { > if (OffsetPositive) { > - PpiPointer->Raw =3D (VOID *) ((UINTN)PpiPointer->Raw + Offset); > + *Pointer =3D (VOID *) ((UINTN) *Pointer + Offset); > } else { > - PpiPointer->Raw =3D (VOID *) ((UINTN)PpiPointer->Raw - Offset); > + *Pointer =3D (VOID *) ((UINTN) *Pointer - Offset); > } > + } > +} >=20 > - // > - // Only when the PEIM descriptor is in the old TempRam should it be = necessary > - // to try to convert the pointers in the PEIM descriptor > - // > +/** >=20 > - if (((UINTN)PpiPointer->Ppi->Guid < TempTop) && > - ((UINTN)PpiPointer->Ppi->Guid >=3D TempBottom)) { > - // > - // Convert the pointer to the GUID in the PPI or NOTIFY descriptor > - // from the old TempRam to the relocated physical memory. > - // > - if (OffsetPositive) { > - PpiPointer->Ppi->Guid =3D (VOID *) ((UINTN)PpiPointer->Ppi->Guid= + Offset); > - } else { > - PpiPointer->Ppi->Guid =3D (VOID *) ((UINTN)PpiPointer->Ppi->Guid= - Offset); > - } > - } > + Migrate Pointer in ranges of the temporary memory to PEI installed mem= ory. > + > + @param SecCoreData Points to a data structure containing SEC to PE= I handoff data, such as the size > + and location of temporary RAM, the stack locati= on and the BFV location. > + @param PrivateData Pointer to PeiCore's private data structure. > + @param Pointer Pointer to the Pointer needs to be converted. > + > +**/ > +VOID > +ConvertPointerInRanges ( > + IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData, > + IN PEI_CORE_INSTANCE *PrivateData, > + IN OUT VOID **Pointer > + ) > +{ > + UINT8 IndexHole; >=20 > + if (PrivateData->MemoryPages.Size !=3D 0) { > // > - // Convert the pointer to the PPI interface structure in the PPI des= criptor > - // from the old TempRam to the relocated physical memory. > + // Convert PPI pointer in old memory pages > + // It needs to be done before Convert PPI pointer in old Heap > // > - if ((UINTN)PpiPointer->Ppi->Ppi < TempTop && > - (UINTN)PpiPointer->Ppi->Ppi >=3D TempBottom) { > - if (OffsetPositive) { > - PpiPointer->Ppi->Ppi =3D (VOID *) ((UINTN)PpiPointer->Ppi->Ppi += Offset); > - } else { > - PpiPointer->Ppi->Ppi =3D (VOID *) ((UINTN)PpiPointer->Ppi->Ppi -= Offset); > - } > + ConvertPointer ( > + Pointer, > + (UINTN)PrivateData->MemoryPages.Base, > + (UINTN)PrivateData->MemoryPages.Base + PrivateData->MemoryPages.Si= ze, > + PrivateData->MemoryPages.Offset, > + PrivateData->MemoryPages.OffsetPositive > + ); > + } > + > + // > + // Convert PPI pointer in old Heap > + // > + ConvertPointer ( > + Pointer, > + (UINTN)SecCoreData->PeiTemporaryRamBase, > + (UINTN)SecCoreData->PeiTemporaryRamBase + SecCoreData->PeiTemporaryR= amSize, > + PrivateData->HeapOffset, > + PrivateData->HeapOffsetPositive > + ); > + > + // > + // Convert PPI pointer in old Stack > + // > + ConvertPointer ( > + Pointer, > + (UINTN)SecCoreData->StackBase, > + (UINTN)SecCoreData->StackBase + SecCoreData->StackSize, > + PrivateData->StackOffset, > + PrivateData->StackOffsetPositive > + ); > + > + // > + // Convert PPI pointer in old TempRam Hole > + // > + for (IndexHole =3D 0; IndexHole < HOLE_MAX_NUMBER; IndexHole ++) { > + if (PrivateData->HoleData[IndexHole].Size =3D=3D 0) { > + continue; > } > + > + ConvertPointer ( > + Pointer, > + (UINTN)PrivateData->HoleData[IndexHole].Base, > + (UINTN)PrivateData->HoleData[IndexHole].Base + PrivateData->HoleDa= ta[IndexHole].Size, > + PrivateData->HoleData[IndexHole].Offset, > + PrivateData->HoleData[IndexHole].OffsetPositive > + ); > } > } >=20 > /** >=20 > + Migrate Single PPI Pointer from the temporary memory to PEI installed = memory. > + > + @param SecCoreData Points to a data structure containing SEC to PE= I handoff data, such as the size > + and location of temporary RAM, the stack locati= on and the BFV location. > + @param PrivateData Pointer to PeiCore's private data structure. > + @param PpiPointer Pointer to Ppi > + > +**/ > +VOID > +ConvertSinglePpiPointer ( > + IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData, > + IN PEI_CORE_INSTANCE *PrivateData, > + IN PEI_PPI_LIST_POINTERS *PpiPointer > + ) > +{ > + // > + // 1. Convert the pointer to the PPI descriptor from the old TempRam > + // to the relocated physical memory. > + // It (for the pointer to the PPI descriptor) needs to be done before = 2 (for > + // the pointer to the GUID) and 3 (for the pointer to the PPI interfac= e structure). > + // > + ConvertPointerInRanges (SecCoreData, PrivateData, &PpiPointer->Raw); > + // > + // 2. Convert the pointer to the GUID in the PPI or NOTIFY descriptor > + // from the old TempRam to the relocated physical memory. > + // > + ConvertPointerInRanges (SecCoreData, PrivateData, (VOID **) &PpiPointe= r->Ppi->Guid); > + // > + // 3. Convert the pointer to the PPI interface structure in the PPI de= scriptor > + // from the old TempRam to the relocated physical memory. > + // > + ConvertPointerInRanges (SecCoreData, PrivateData, (VOID **) &PpiPointe= r->Ppi->Ppi); > +} > + > +/** > + > Migrate PPI Pointers from the temporary memory to PEI installed memory= . >=20 > - @param SecCoreData Points to a data structure containing SEC to PE= I handoff data, such as the size > + @param SecCoreData Points to a data structure containing SEC to PE= I handoff data, such as the size > and location of temporary RAM, the stack locati= on and the BFV location. > @param PrivateData Pointer to PeiCore's private data structure. >=20 > @@ -117,62 +191,14 @@ ConvertPpiPointers ( > ) > { > UINT8 Index; > - UINT8 IndexHole; >=20 > for (Index =3D 0; Index < PcdGet32 (PcdPeiCoreMaxPpiSupported); Index+= +) { > if (Index < PrivateData->PpiData.PpiListEnd || Index > PrivateData->= PpiData.NotifyListEnd) { > - if (PrivateData->MemoryPages.Size !=3D 0) { > - // > - // Convert PPI pointer in old memory pages > - // It needs to be done before Convert PPI pointer in old Heap > - // > - ConvertSinglePpiPointer ( > - &PrivateData->PpiData.PpiListPtrs[Index], > - (UINTN)PrivateData->MemoryPages.Base, > - (UINTN)PrivateData->MemoryPages.Base + PrivateData->MemoryPage= s.Size, > - PrivateData->MemoryPages.Offset, > - PrivateData->MemoryPages.OffsetPositive > - ); > - } > - > - // > - // Convert PPI pointer in old Heap > - // > ConvertSinglePpiPointer ( > - &PrivateData->PpiData.PpiListPtrs[Index], > - (UINTN)SecCoreData->PeiTemporaryRamBase, > - (UINTN)SecCoreData->PeiTemporaryRamBase + SecCoreData->PeiTempor= aryRamSize, > - PrivateData->HeapOffset, > - PrivateData->HeapOffsetPositive > - ); > - > - // > - // Convert PPI pointer in old Stack > - // > - ConvertSinglePpiPointer ( > - &PrivateData->PpiData.PpiListPtrs[Index], > - (UINTN)SecCoreData->StackBase, > - (UINTN)SecCoreData->StackBase + SecCoreData->StackSize, > - PrivateData->StackOffset, > - PrivateData->StackOffsetPositive > + SecCoreData, > + PrivateData, > + &PrivateData->PpiData.PpiListPtrs[Index] > ); > - > - // > - // Convert PPI pointer in old TempRam Hole > - // > - for (IndexHole =3D 0; IndexHole < HOLE_MAX_NUMBER; IndexHole ++) { > - if (PrivateData->HoleData[IndexHole].Size =3D=3D 0) { > - continue; > - } > - > - ConvertSinglePpiPointer ( > - &PrivateData->PpiData.PpiListPtrs[Index], > - (UINTN)PrivateData->HoleData[IndexHole].Base, > - (UINTN)PrivateData->HoleData[IndexHole].Base + PrivateData->Ho= leData[IndexHole].Size, > - PrivateData->HoleData[IndexHole].Offset, > - PrivateData->HoleData[IndexHole].OffsetPositive > - ); > - } > } > } > } > -- > 2.7.0.windows.1