From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 1A01E82266 for ; Mon, 27 Feb 2017 21:42:42 -0800 (PST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Feb 2017 21:42:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,217,1484035200"; d="scan'208";a="1103046071" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by orsmga001.jf.intel.com with ESMTP; 27 Feb 2017 21:42:39 -0800 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.248.2; Mon, 27 Feb 2017 21:42:19 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.88]) by SHSMSX104.ccr.corp.intel.com ([10.239.4.70]) with mapi id 14.03.0248.002; Tue, 28 Feb 2017 13:42:07 +0800 From: "Gao, Liming" To: Ard Biesheuvel , "edk2-devel@lists.01.org" , "afish@apple.com" , "leif.lindholm@linaro.org" , "Kinney, Michael D" , "Yao, Jiewen" CC: "lersek@redhat.com" , "Tian, Feng" , "Zeng, Star" Thread-Topic: [PATCH v4 2/7] MdeModulePkg/PeiCore: allocate BootServicesCode memory for PE/COFF images Thread-Index: AQHSkQcvgeRK8EWU8kmbCWe0Qb+yEaF96KrQ Date: Tue, 28 Feb 2017 05:42:06 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14D6E57D2@shsmsx102.ccr.corp.intel.com> References: <1488206291-25768-1-git-send-email-ard.biesheuvel@linaro.org> <1488206291-25768-3-git-send-email-ard.biesheuvel@linaro.org> In-Reply-To: <1488206291-25768-3-git-send-email-ard.biesheuvel@linaro.org> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH v4 2/7] MdeModulePkg/PeiCore: allocate BootServicesCode memory for PE/COFF images X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Feb 2017 05:42:42 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Liming Gao >-----Original Message----- >From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] >Sent: Monday, February 27, 2017 10:38 PM >To: edk2-devel@lists.01.org; afish@apple.com; leif.lindholm@linaro.org; >Kinney, Michael D ; Gao, Liming >; Yao, Jiewen >Cc: lersek@redhat.com; Tian, Feng ; Zeng, Star >; Ard Biesheuvel >Subject: [PATCH v4 2/7] MdeModulePkg/PeiCore: allocate BootServicesCode >memory for PE/COFF images > >Ensure that any memory allocated for PE/COFF images is identifiable as >a boot services code region, so that we know it requires its executable >permissions to be preserved when we tighten mapping permissions later on. > >Contributed-under: TianoCore Contribution Agreement 1.0 >Signed-off-by: Ard Biesheuvel >Reviewed-by: Jiewen Yao >--- > MdeModulePkg/Core/Pei/Image/Image.c | 23 ++++++++++++-------- > 1 file changed, 14 insertions(+), 9 deletions(-) > >diff --git a/MdeModulePkg/Core/Pei/Image/Image.c >b/MdeModulePkg/Core/Pei/Image/Image.c >index d659de8b3e64..68e40c027e63 100644 >--- a/MdeModulePkg/Core/Pei/Image/Image.c >+++ b/MdeModulePkg/Core/Pei/Image/Image.c >@@ -112,11 +112,12 @@ GetImageReadFunction ( > IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext > ) > { >- PEI_CORE_INSTANCE *Private; >- VOID* MemoryBuffer; >+ PEI_CORE_INSTANCE *Private; >+ EFI_PHYSICAL_ADDRESS MemoryBuffer; > > Private =3D PEI_CORE_INSTANCE_FROM_PS_THIS >(GetPeiServicesTablePointer ()); >- >+ MemoryBuffer =3D 0; >+ > if (Private->PeiMemoryInstalled && (((Private- >>HobList.HandoffInformationTable->BootMode !=3D BOOT_ON_S3_RESUME) >&& PcdGetBool (PcdShadowPeimOnBoot)) || > ((Private->HobList.HandoffInformationTable->BootMode =3D=3D >BOOT_ON_S3_RESUME) && PcdGetBool (PcdShadowPeimOnS3Boot))) && > (EFI_IMAGE_MACHINE_TYPE_SUPPORTED(EFI_IMAGE_MACHINE_X64) || >EFI_IMAGE_MACHINE_TYPE_SUPPORTED(EFI_IMAGE_MACHINE_IA32))) { >@@ -125,9 +126,9 @@ GetImageReadFunction ( > // compilers that have been tested > // > if (Private->ShadowedImageRead =3D=3D NULL) { >- MemoryBuffer =3D AllocatePages (0x400 / EFI_PAGE_SIZE + 1); >- ASSERT (MemoryBuffer !=3D NULL); >- CopyMem (MemoryBuffer, (CONST VOID *) (UINTN) >PeiImageReadForShadow, 0x400); >+ PeiServicesAllocatePages (EfiBootServicesCode, 0x400 / EFI_PAGE_SIZ= E + >1, &MemoryBuffer); >+ ASSERT (MemoryBuffer !=3D 0); >+ CopyMem ((VOID *)(UINTN)MemoryBuffer, (CONST VOID *) (UINTN) >PeiImageReadForShadow, 0x400); > Private->ShadowedImageRead =3D (PE_COFF_LOADER_READ_FILE) (UINTN) >MemoryBuffer; > } > >@@ -453,12 +454,16 @@ LoadAndRelocatePeCoffImage ( > // > // The PEIM is not assiged valid address, try to allocate page to= load it. > // >- ImageContext.ImageAddress =3D (EFI_PHYSICAL_ADDRESS)(UINTN) >AllocatePages (EFI_SIZE_TO_PAGES ((UINT32) AlignImageSize)); >+ Status =3D PeiServicesAllocatePages (EfiBootServicesCode, >+ EFI_SIZE_TO_PAGES ((UINT32) Al= ignImageSize), >+ &ImageContext.ImageAddress); > } > } else { >- ImageContext.ImageAddress =3D (EFI_PHYSICAL_ADDRESS)(UINTN) >AllocatePages (EFI_SIZE_TO_PAGES ((UINT32) AlignImageSize)); >+ Status =3D PeiServicesAllocatePages (EfiBootServicesCode, >+ EFI_SIZE_TO_PAGES ((UINT32) Alig= nImageSize), >+ &ImageContext.ImageAddress); > } >- if (ImageContext.ImageAddress !=3D 0) { >+ if (!EFI_ERROR (Status)) { > // > // Adjust the Image Address to make sure it is section alignment. > // >-- >2.7.4