From nobody Sat May 18 20:15:36 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+105363+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+105363+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1685355447; cv=none; d=zohomail.com; s=zohoarc; b=FjLsRr8Utz/9ZlHa2dVN5T8oGrROsAT3VW7CMsy8mPiZ1X4Jp7tEj87Qi1c7oIlUcWhf2vmc3NBfptvNHqtgZqfjzQdxqejZjQSkBHP7gwBqPsuV3dHWDMxbRpVMHppDU+Lf/DCUlKeC769UcWqznyXa1MEeJ/aIvn2j30gSYDw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685355447; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=qMph6ZtNJP+sISrL/f+8DBgd75cjoQGKtapNDxJ5uxo=; b=b2e1woBbGPXD4nkGjo7ot/AyqIg/m6pOfBOl56F+L72zWTk70ltX1K7PnqPo5DGl3Esk7/wgVZ3Ole/BNVsuSnAySfnpA1iVNPGE6kru+xUbS43zRbo3oN+ILM/leg/4/DfYu8GgA19DVbDsdveHCoDyJagb9IXuXYmzcqDwpkA= 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+105363+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 1685355447720252.1943803485898; Mon, 29 May 2023 03:17:27 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id pJ2yYY1788612xyHuQV57ufm; Mon, 29 May 2023 03:17:22 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web10.46498.1685355441481519688 for ; Mon, 29 May 2023 03:17:21 -0700 X-Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0E02961336; Mon, 29 May 2023 10:17:21 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 15AAEC433EF; Mon, 29 May 2023 10:17:17 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Ray Ni , Jiewen Yao , Gerd Hoffmann , Taylor Beebe , Oliver Smith-Denny , Dandan Bi , Liming Gao , "Kinney, Michael D" , Leif Lindholm , Michael Kubacki Subject: [edk2-devel] [RFC PATCH 01/11] MdeModulePkg/DxeCore: Remove unused 'EntryPoint' argument to LoadImage Date: Mon, 29 May 2023 12:16:55 +0200 Message-Id: <20230529101705.2476949-2-ardb@kernel.org> In-Reply-To: <20230529101705.2476949-1-ardb@kernel.org> References: <20230529101705.2476949-1-ardb@kernel.org> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ardb@kernel.org X-Gm-Message-State: UfWoYnGekMzmoUaGFLJgsHnvx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685355442; bh=RLkL4AbgtVwDuvIH8GgkXWuOTqO8PQ3ORf/D7R217rE=; h=Cc:Date:From:Reply-To:Subject:To; b=XHEuKegd0/m9HLSg1mGTfnh5UaHpzPAOdFvxu8uPifRAWQ+hFGcw9vPKKIZp14CFu0Z 3R+byaEZ4SmYxg8WB954QlBC3WDR8rZ9K/HWCRT6KTcIEvjzaarlAFG7vEN3vk7Sq537M SJ8TIFdZPK4RcGt/0PPTkgzu9LrvBe01qks= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685355449815100003 Content-Type: text/plain; charset="utf-8" CoreLoadImageCommon's only user passes NULL for its EntryPoint argument, so it has no purpose and can simply be dropped. While at it, make CoreLoadImageCommon STATIC to prevent it from being accessed from other translation units. Signed-off-by: Ard Biesheuvel --- MdeModulePkg/Core/Dxe/Image/Image.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Im= age/Image.c index 9dbfb2a1fad22ced..2f2dfe5d0496dc4f 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -560,7 +560,6 @@ CoreIsImageTypeSupported ( @param Pe32Handle The handle of PE32 image @param Image PE image to be loaded @param DstBuffer The buffer to store the image - @param EntryPoint A pointer to the entry point @param Attribute The bit mask of attributes to set for th= e load PE image =20 @@ -577,7 +576,6 @@ CoreLoadPeImage ( IN VOID *Pe32Handle, IN LOADED_IMAGE_PRIVATE_DATA *Image, IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL, - OUT EFI_PHYSICAL_ADDRESS *EntryPoint OPTIONAL, IN UINT32 Attribute ) { @@ -810,13 +808,6 @@ CoreLoadPeImage ( } } =20 - // - // Fill in the entry point of the image if it is available - // - if (EntryPoint !=3D NULL) { - *EntryPoint =3D Image->ImageContext.EntryPoint; - } - // // Print the load address and the PDB file name if it is available // @@ -1111,7 +1102,6 @@ CoreUnloadAndCloseImage ( this parameter contains the required num= ber. @param ImageHandle Pointer to the returned image handle tha= t is created when the image is successfully l= oaded. - @param EntryPoint A pointer to the entry point @param Attribute The bit mask of attributes to set for th= e load PE image =20 @@ -1134,6 +1124,7 @@ CoreUnloadAndCloseImage ( platform policy specifies that the image= should not be started. =20 **/ +STATIC EFI_STATUS CoreLoadImageCommon ( IN BOOLEAN BootPolicy, @@ -1144,7 +1135,6 @@ CoreLoadImageCommon ( IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL, IN OUT UINTN *NumberOfPages OPTIONAL, OUT EFI_HANDLE *ImageHandle, - OUT EFI_PHYSICAL_ADDRESS *EntryPoint OPTIONAL, IN UINT32 Attribute ) { @@ -1375,9 +1365,9 @@ CoreLoadImageCommon ( } =20 // - // Load the image. If EntryPoint is Null, it will not be set. + // Load the image. // - Status =3D CoreLoadPeImage (BootPolicy, &FHand, Image, DstBuffer, EntryP= oint, Attribute); + Status =3D CoreLoadPeImage (BootPolicy, &FHand, Image, DstBuffer, Attrib= ute); if (EFI_ERROR (Status)) { if ((Status =3D=3D EFI_BUFFER_TOO_SMALL) || (Status =3D=3D EFI_OUT_OF_= RESOURCES)) { if (NumberOfPages !=3D NULL) { @@ -1559,7 +1549,6 @@ CoreLoadImage ( (EFI_PHYSICAL_ADDRESS)(UINTN)NULL, NULL, ImageHandle, - NULL, EFI_LOAD_PE_IMAGE_ATTRIBUTE_RUNTIME_REGISTRATION | EFI_LOAD_P= E_IMAGE_ATTRIBUTE_DEBUG_IMAGE_INFO_TABLE_REGISTRATION ); =20 --=20 2.39.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 (#105363): https://edk2.groups.io/g/devel/message/105363 Mute This Topic: https://groups.io/mt/99197133/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- From nobody Sat May 18 20:15:36 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+105364+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+105364+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1685355448; cv=none; d=zohomail.com; s=zohoarc; b=mfGmRbTR5Wju3lV1IsCxv7J0R0+MiuvMddy5k98mFT+06BW2f2/npOdBNZq+GU/NfaYnrxYvfeAy8V2cHMqQ5xGl5G8ksPG5MreG/MeE7Lin6+nGbZ2LlX+TQK36ABviZPo+0hann1xN4QX8/e3ZGKQq+lwPisVzDpMfEs0GW5M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685355448; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=tgCL3hKgDvxyBacRcvpVgDFCtHag5JtMai21cMVkQ2g=; b=Ol18g2ahsu4t7PW0H9M+qUugIX0UTbqNS+9EPQRmFHaVr2jOOIlSCeBJ/a9JXFM+iMHBByQBr5cFbjKBwpZiQOQGnX5ARhHpuP3G8OiyAKHk1muJ1/RPxqjjkwEpfHs7TMAdveavYM0FKhrVE9n+ePYlIP8dS0hVY7aiYYp9zks= 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+105364+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 1685355448126409.8286302826175; Mon, 29 May 2023 03:17:28 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id fXSlYY1788612xWy5pDuiFDc; Mon, 29 May 2023 03:17:27 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web11.46671.1685355444391069298 for ; Mon, 29 May 2023 03:17:24 -0700 X-Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E126F613EA; Mon, 29 May 2023 10:17:23 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id E293EC433A0; Mon, 29 May 2023 10:17:20 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Ray Ni , Jiewen Yao , Gerd Hoffmann , Taylor Beebe , Oliver Smith-Denny , Dandan Bi , Liming Gao , "Kinney, Michael D" , Leif Lindholm , Michael Kubacki Subject: [edk2-devel] [RFC PATCH 02/11] MdeModulePkg/DxeCore: Remove unused DstBuffer arg from LoadImage Date: Mon, 29 May 2023 12:16:56 +0200 Message-Id: <20230529101705.2476949-3-ardb@kernel.org> In-Reply-To: <20230529101705.2476949-1-ardb@kernel.org> References: <20230529101705.2476949-1-ardb@kernel.org> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ardb@kernel.org X-Gm-Message-State: 7uVA9i6qhHRk9e4jhhLceCFRx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685355447; bh=ESxEnSmuYXwl1YM+X7iRFYDw5dKy6XzEMGjrlRl1MiQ=; h=Cc:Date:From:Reply-To:Subject:To; b=EIMiNQU8JcpPfqJJmuNX0r9WgA9okkYUa7c7uIM0vmLdYdQUxBpnrv0JovT6WElSqFG ka/bLqm4fic3X9fBS4MczPGfCKUhOLX2PvcLhGtMHNUuyAJ8dl3QSMIfVlr281WKEJUAv oI+nb9P+4jVdg5CNrumfJi9l7xZ7xvKlR3s= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685355449881100005 Content-Type: text/plain; charset="utf-8" The DstBuffer and NumberOfPages arguments to CoreLoadImageCommon () are never set by its only caller CoreLoadImage() so let's drop them from the prototype. Signed-off-by: Ard Biesheuvel Reviewed-by: Ray Ni --- MdeModulePkg/Core/Dxe/Image/Image.c | 174 +++++++------------- 1 file changed, 56 insertions(+), 118 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Im= age/Image.c index 2f2dfe5d0496dc4f..6625d0cd0ff82107 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -559,7 +559,6 @@ CoreIsImageTypeSupported ( boot selection. @param Pe32Handle The handle of PE32 image @param Image PE image to be loaded - @param DstBuffer The buffer to store the image @param Attribute The bit mask of attributes to set for th= e load PE image =20 @@ -570,17 +569,16 @@ CoreIsImageTypeSupported ( @retval EFI_BUFFER_TOO_SMALL Buffer for image is too small =20 **/ +STATIC EFI_STATUS CoreLoadPeImage ( IN BOOLEAN BootPolicy, IN VOID *Pe32Handle, IN LOADED_IMAGE_PRIVATE_DATA *Image, - IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL, IN UINT32 Attribute ) { EFI_STATUS Status; - BOOLEAN DstBufAlocated; UINTN Size; =20 ZeroMem (&Image->ImageContext, sizeof (Image->ImageContext)); @@ -633,99 +631,67 @@ CoreLoadPeImage ( } =20 // - // Allocate memory of the correct memory type aligned on the required im= age boundary + // Allocate Destination Buffer as caller did not pass it in // - DstBufAlocated =3D FALSE; - if (DstBuffer =3D=3D 0) { - // - // Allocate Destination Buffer as caller did not pass it in - // =20 - if (Image->ImageContext.SectionAlignment > EFI_PAGE_SIZE) { - Size =3D (UINTN)Image->ImageContext.ImageSize + Image->ImageContext.= SectionAlignment; - } else { - Size =3D (UINTN)Image->ImageContext.ImageSize; - } + if (Image->ImageContext.SectionAlignment > EFI_PAGE_SIZE) { + Size =3D (UINTN)Image->ImageContext.ImageSize + Image->ImageContext.Se= ctionAlignment; + } else { + Size =3D (UINTN)Image->ImageContext.ImageSize; + } =20 - Image->NumberOfPages =3D EFI_SIZE_TO_PAGES (Size); + Image->NumberOfPages =3D EFI_SIZE_TO_PAGES (Size); =20 - // - // If the image relocations have not been stripped, then load at any a= ddress. - // Otherwise load at the address at which it was linked. - // - // Memory below 1MB should be treated reserved for CSM and there shoul= d be - // no modules whose preferred load addresses are below 1MB. - // - Status =3D EFI_OUT_OF_RESOURCES; - // - // If Loading Module At Fixed Address feature is enabled, the module s= hould be loaded to - // a specified address. - // - if (PcdGet64 (PcdLoadModuleAtFixAddressEnable) !=3D 0 ) { - Status =3D GetPeCoffImageFixLoadingAssignedAddress (&(Image->ImageCo= ntext)); - - if (EFI_ERROR (Status)) { - // - // If the code memory is not ready, invoke CoreAllocatePage with A= llocateAnyPages to load the driver. - // - DEBUG ((DEBUG_INFO|DEBUG_LOAD, "LOADING MODULE FIXED ERROR: Loadin= g module at fixed address failed since specified memory is not available.\n= ")); - - Status =3D CoreAllocatePages ( - AllocateAnyPages, - (EFI_MEMORY_TYPE)(Image->ImageContext.ImageCodeMemoryTy= pe), - Image->NumberOfPages, - &Image->ImageContext.ImageAddress - ); - } - } else { - if ((Image->ImageContext.ImageAddress >=3D 0x100000) || Image->Image= Context.RelocationsStripped) { - Status =3D CoreAllocatePages ( - AllocateAddress, - (EFI_MEMORY_TYPE)(Image->ImageContext.ImageCodeMemoryTy= pe), - Image->NumberOfPages, - &Image->ImageContext.ImageAddress - ); - } - - if (EFI_ERROR (Status) && !Image->ImageContext.RelocationsStripped) { - Status =3D CoreAllocatePages ( - AllocateAnyPages, - (EFI_MEMORY_TYPE)(Image->ImageContext.ImageCodeMemoryTy= pe), - Image->NumberOfPages, - &Image->ImageContext.ImageAddress - ); - } - } + // + // If the image relocations have not been stripped, then load at any add= ress. + // Otherwise load at the address at which it was linked. + // + // Memory below 1MB should be treated reserved for CSM and there should = be + // no modules whose preferred load addresses are below 1MB. + // + Status =3D EFI_OUT_OF_RESOURCES; + // + // If Loading Module At Fixed Address feature is enabled, the module sho= uld be loaded to + // a specified address. + // + if (PcdGet64 (PcdLoadModuleAtFixAddressEnable) !=3D 0 ) { + Status =3D GetPeCoffImageFixLoadingAssignedAddress (&(Image->ImageCont= ext)); =20 if (EFI_ERROR (Status)) { - return Status; - } + // + // If the code memory is not ready, invoke CoreAllocatePage with All= ocateAnyPages to load the driver. + // + DEBUG ((DEBUG_INFO|DEBUG_LOAD, "LOADING MODULE FIXED ERROR: Loading = module at fixed address failed since specified memory is not available.\n")= ); =20 - DstBufAlocated =3D TRUE; + Status =3D CoreAllocatePages ( + AllocateAnyPages, + (EFI_MEMORY_TYPE)(Image->ImageContext.ImageCodeMemoryType= ), + Image->NumberOfPages, + &Image->ImageContext.ImageAddress + ); + } } else { - // - // Caller provided the destination buffer - // - - if (Image->ImageContext.RelocationsStripped && (Image->ImageContext.Im= ageAddress !=3D DstBuffer)) { - // - // If the image relocations were stripped, and the caller provided a - // destination buffer address that does not match the address that t= he - // image is linked at, then the image cannot be loaded. - // - return EFI_INVALID_PARAMETER; + if ((Image->ImageContext.ImageAddress >=3D 0x100000) || Image->ImageCo= ntext.RelocationsStripped) { + Status =3D CoreAllocatePages ( + AllocateAddress, + (EFI_MEMORY_TYPE)(Image->ImageContext.ImageCodeMemoryType= ), + Image->NumberOfPages, + &Image->ImageContext.ImageAddress + ); } =20 - if ((Image->NumberOfPages !=3D 0) && - (Image->NumberOfPages < - (EFI_SIZE_TO_PAGES ((UINTN)Image->ImageContext.ImageSize + Image-= >ImageContext.SectionAlignment)))) - { - Image->NumberOfPages =3D EFI_SIZE_TO_PAGES ((UINTN)Image->ImageConte= xt.ImageSize + Image->ImageContext.SectionAlignment); - return EFI_BUFFER_TOO_SMALL; + if (EFI_ERROR (Status) && !Image->ImageContext.RelocationsStripped) { + Status =3D CoreAllocatePages ( + AllocateAnyPages, + (EFI_MEMORY_TYPE)(Image->ImageContext.ImageCodeMemoryType= ), + Image->NumberOfPages, + &Image->ImageContext.ImageAddress + ); } + } =20 - Image->NumberOfPages =3D EFI_SIZE_TO_PAGES ((UINTN)Image->= ImageContext.ImageSize + Image->ImageContext.SectionAlignment); - Image->ImageContext.ImageAddress =3D DstBuffer; + if (EFI_ERROR (Status)) { + return Status; } =20 Image->ImageBasePage =3D Image->ImageContext.ImageAddress; @@ -875,12 +841,9 @@ CoreLoadPeImage ( // // Free memory. // - - if (DstBufAlocated) { - CoreFreePages (Image->ImageContext.ImageAddress, Image->NumberOfPages); - Image->ImageContext.ImageAddress =3D 0; - Image->ImageBasePage =3D 0; - } + CoreFreePages (Image->ImageContext.ImageAddress, Image->NumberOfPages); + Image->ImageContext.ImageAddress =3D 0; + Image->ImageBasePage =3D 0; =20 if (Image->ImageContext.FixupData !=3D NULL) { CoreFreePool (Image->ImageContext.FixupData); @@ -1094,12 +1057,6 @@ CoreUnloadAndCloseImage ( @param SourceBuffer If not NULL, a pointer to the memory loc= ation containing a copy of the image to be loa= ded. @param SourceSize The size in bytes of SourceBuffer. - @param DstBuffer The buffer to store the image - @param NumberOfPages If not NULL, it inputs a pointer to the = page - number of DstBuffer and outputs a pointe= r to - the page number of the image. If this nu= mber is - not enough, return EFI_BUFFER_TOO_SMALL= and - this parameter contains the required num= ber. @param ImageHandle Pointer to the returned image handle tha= t is created when the image is successfully l= oaded. @param Attribute The bit mask of attributes to set for th= e load @@ -1132,8 +1089,6 @@ CoreLoadImageCommon ( IN EFI_DEVICE_PATH_PROTOCOL *FilePath, IN VOID *SourceBuffer OPTIONAL, IN UINTN SourceSize, - IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL, - IN OUT UINTN *NumberOfPages OPTIONAL, OUT EFI_HANDLE *ImageHandle, IN UINT32 Attribute ) @@ -1342,12 +1297,7 @@ CoreLoadImageCommon ( Image->Info.Revision =3D EFI_LOADED_IMAGE_PROTOCOL_REVISION; Image->Info.FilePath =3D DuplicateDevicePath (FilePath); Image->Info.ParentHandle =3D ParentImageHandle; - - if (NumberOfPages !=3D NULL) { - Image->NumberOfPages =3D *NumberOfPages; - } else { - Image->NumberOfPages =3D 0; - } + Image->NumberOfPages =3D 0; =20 // // Install the protocol interfaces for this image @@ -1367,21 +1317,11 @@ CoreLoadImageCommon ( // // Load the image. // - Status =3D CoreLoadPeImage (BootPolicy, &FHand, Image, DstBuffer, Attrib= ute); + Status =3D CoreLoadPeImage (BootPolicy, &FHand, Image, Attribute); if (EFI_ERROR (Status)) { - if ((Status =3D=3D EFI_BUFFER_TOO_SMALL) || (Status =3D=3D EFI_OUT_OF_= RESOURCES)) { - if (NumberOfPages !=3D NULL) { - *NumberOfPages =3D Image->NumberOfPages; - } - } - goto Done; } =20 - if (NumberOfPages !=3D NULL) { - *NumberOfPages =3D Image->NumberOfPages; - } - // // Register the image in the Debug Image Info Table if the attribute is = set // @@ -1473,7 +1413,7 @@ CoreLoadImageCommon ( // if (EFI_ERROR (Status)) { if (Image !=3D NULL) { - CoreUnloadAndCloseImage (Image, (BOOLEAN)(DstBuffer =3D=3D 0)); + CoreUnloadAndCloseImage (Image, TRUE); Image =3D NULL; } } else if (EFI_ERROR (SecurityStatus)) { @@ -1546,8 +1486,6 @@ CoreLoadImage ( FilePath, SourceBuffer, SourceSize, - (EFI_PHYSICAL_ADDRESS)(UINTN)NULL, - NULL, ImageHandle, EFI_LOAD_PE_IMAGE_ATTRIBUTE_RUNTIME_REGISTRATION | EFI_LOAD_P= E_IMAGE_ATTRIBUTE_DEBUG_IMAGE_INFO_TABLE_REGISTRATION ); --=20 2.39.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 (#105364): https://edk2.groups.io/g/devel/message/105364 Mute This Topic: https://groups.io/mt/99197134/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- From nobody Sat May 18 20:15:36 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+105365+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+105365+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1685355449; cv=none; d=zohomail.com; s=zohoarc; b=YFxTSQBwPYoAapyMfeGTqrBTgb8x6tfkqTJ15+A3o18uGhqMygFb9cMy+cA1L7f2U4LMv+Wz5OX5knV91nAykeWbiv5CFVwybSW2YxU08dlusG2dq0rMKe4lZ7Voy+GK42l9uujyD5+oAvOB17XlKCVzYdlNpM9SnHQYF1LwiKY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685355449; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=ojdyPSViGa9v22XPAg2fIT0QDHaqU5O4lk+UllHlMUc=; b=MH33uUcRllZb7ej78+SQgWkAx0/gJR2CvlAxK/SqvIAEq5CATt75pDX4zP4WcPGCiu+kjMRceOXm4vd0OynSKKe+1eFg0n2HwpZ1NVtYSzd8V5SLf6bPoES4jny/cFzJS0P4ClVOYf/bPk2yITO0ElPvFS2rpo9fq+pvBKQO5/8= 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+105365+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 1685355449477187.35370526993768; Mon, 29 May 2023 03:17:29 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id dntwYY1788612xcaEDfYRoTr; Mon, 29 May 2023 03:17:28 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web11.46672.1685355447197056921 for ; Mon, 29 May 2023 03:17:27 -0700 X-Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B68196101A; Mon, 29 May 2023 10:17:26 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB398C433A4; Mon, 29 May 2023 10:17:23 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Ray Ni , Jiewen Yao , Gerd Hoffmann , Taylor Beebe , Oliver Smith-Denny , Dandan Bi , Liming Gao , "Kinney, Michael D" , Leif Lindholm , Michael Kubacki Subject: [edk2-devel] [RFC PATCH 03/11] MdeModulePkg/DxeCore: Remove FreePage argument from CoreUnloadImage Date: Mon, 29 May 2023 12:16:57 +0200 Message-Id: <20230529101705.2476949-4-ardb@kernel.org> In-Reply-To: <20230529101705.2476949-1-ardb@kernel.org> References: <20230529101705.2476949-1-ardb@kernel.org> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ardb@kernel.org X-Gm-Message-State: Lyzm4ZM73jxFjkQkMsm0f5zyx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685355448; bh=Mt1rTRcPGTIDQPEngmX4wPnKIb0RdWdq2IrSS856OVg=; h=Cc:Date:From:Reply-To:Subject:To; b=CZWf0q2ALLoPOi4u1Y0+j21yEXh1lHFh9sJbsN4mRQvGMalbZ2kRCJjGsTzDPodH7Ur /ARgcEP0rvVnSNS8MGhEoSM5u2VfkQBKEuyn5J7Lkw4tzFcRnjVaC9lPBTGuBOz6gJmq4 aIXRgn2xlwmGPRJ7lwTyf8UJP7Pvos/Lxfg= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685355449827100004 Content-Type: text/plain; charset="utf-8" The FreePage argument to CoreUnloadAndCloseImage () is now always TRUE so drop it from the prototype. While at it, make the function static as it is never called from another translation unit. Signed-off-by: Ard Biesheuvel Reviewed-by: Ray Ni --- MdeModulePkg/Core/Dxe/Image/Image.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Im= age/Image.c index 6625d0cd0ff82107..f30e369370a09609 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -888,13 +888,12 @@ CoreLoadedImageInfo ( Unloads EFI image from memory. =20 @param Image EFI image - @param FreePage Free allocated pages =20 **/ +STATIC VOID CoreUnloadAndCloseImage ( - IN LOADED_IMAGE_PRIVATE_DATA *Image, - IN BOOLEAN FreePage + IN LOADED_IMAGE_PRIVATE_DATA *Image ) { EFI_STATUS Status; @@ -1022,7 +1021,7 @@ CoreUnloadAndCloseImage ( // // Free the Image from memory // - if ((Image->ImageBasePage !=3D 0) && FreePage) { + if (Image->ImageBasePage !=3D 0) { CoreFreePages (Image->ImageBasePage, Image->NumberOfPages); } =20 @@ -1413,7 +1412,7 @@ CoreLoadImageCommon ( // if (EFI_ERROR (Status)) { if (Image !=3D NULL) { - CoreUnloadAndCloseImage (Image, TRUE); + CoreUnloadAndCloseImage (Image); Image =3D NULL; } } else if (EFI_ERROR (SecurityStatus)) { @@ -1711,7 +1710,7 @@ CoreStartImage ( // unload it // if (EFI_ERROR (Image->Status) || (Image->Type =3D=3D EFI_IMAGE_SUBSYSTEM= _EFI_APPLICATION)) { - CoreUnloadAndCloseImage (Image, TRUE); + CoreUnloadAndCloseImage (Image); // // ImageHandle may be invalid after the image is unloaded, so use NULL= handle to record perf log. // @@ -1776,7 +1775,7 @@ CoreExit ( // // The image has not been started so just free its resources // - CoreUnloadAndCloseImage (Image, TRUE); + CoreUnloadAndCloseImage (Image); Status =3D EFI_SUCCESS; goto Done; } @@ -1874,7 +1873,7 @@ CoreUnloadImage ( // // if the Image was not started or Unloaded O.K. then clean up // - CoreUnloadAndCloseImage (Image, TRUE); + CoreUnloadAndCloseImage (Image); } =20 Done: --=20 2.39.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 (#105365): https://edk2.groups.io/g/devel/message/105365 Mute This Topic: https://groups.io/mt/99197135/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- From nobody Sat May 18 20:15:36 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+105366+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+105366+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1685355451; cv=none; d=zohomail.com; s=zohoarc; b=X2F6OMFOsnkeEP+i9PWFKbEJ3X5Zyoc2idjPDlf8TjhAqiaFSdkKGMqCmSIQWUrkIjHE4AuHyk+mykWROg8OZS1oWOPv7EVwexXqZ6dP25TXm/06VOWt7CK099MH5cLRqq9MOpq1/EuCTRxS+h90IULlxUR5EscaupqV0+/mLdg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685355451; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=ZVtP6E8cbXADhUUDc6Ep5INsIhxXWfVqTq5FISwsxlg=; b=gHYdVP76Tbw72Lv13zjIt6kMiMu0/li+R6aqg/504KSMJWuRCU1FimddFYwUKnwPpFpMXUpSIyarcUn+puf3Ppulk2RuK2SW5sln5iaH29FMU1v+f3zxFbaOa+qIFb41cBrJawkeVaGmKWiaLqoZL0Mn/4aEyqGggumfk2KZ0GU= 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+105366+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 168535545107754.67106556980889; Mon, 29 May 2023 03:17:31 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id Q1RtYY1788612xYbwk86fu5C; Mon, 29 May 2023 03:17:30 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web10.46505.1685355450083660571 for ; Mon, 29 May 2023 03:17:30 -0700 X-Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 900C661362; Mon, 29 May 2023 10:17:29 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94F91C4339E; Mon, 29 May 2023 10:17:26 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Ray Ni , Jiewen Yao , Gerd Hoffmann , Taylor Beebe , Oliver Smith-Denny , Dandan Bi , Liming Gao , "Kinney, Michael D" , Leif Lindholm , Michael Kubacki Subject: [edk2-devel] [RFC PATCH 04/11] MdeModulePkg/DxeCore: Avoid caching memory mapped FFS files Date: Mon, 29 May 2023 12:16:58 +0200 Message-Id: <20230529101705.2476949-5-ardb@kernel.org> In-Reply-To: <20230529101705.2476949-1-ardb@kernel.org> References: <20230529101705.2476949-1-ardb@kernel.org> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ardb@kernel.org X-Gm-Message-State: nG1lJM2ZVxpG0N2neyHZ4vwgx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685355450; bh=rsiFWIbLVVvMMNmbYfeLahouxJSNugnMy9ueafYcvRk=; h=Cc:Date:From:Reply-To:Subject:To; b=wDiz2zWwAeSobsRAbaNOvGM5MMPg+5/0nvWs2WSZzFHbNjLNcaWnr4YjjIuchk/ibRP b62Xwlsmhs+p3XlGHLdUIlWEzTEywI7S0GKd0BS/37StwTjIvHUZ6IQc7UAf8GRtVeV2d ffXpjOUZ7bhAwaKXtDXcJz6HC4s+vuE3/GM= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685355451841100013 Content-Type: text/plain; charset="utf-8" If a firmware volume is memory mapped, it means we can access it contents directly, and so caching serves little purpose beyond potentially a minor performance improvement. However, given that most files are read only a single time, and dispatched from a decompressed firmware volume in DRAM, we can just avoid the redundant caching here. Signed-off-by: Ard Biesheuvel --- MdeModulePkg/Core/Dxe/FwVol/FwVolRead.c | 22 -------------------- 1 file changed, 22 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/FwVol/FwVolRead.c b/MdeModulePkg/Core/Dx= e/FwVol/FwVolRead.c index 2ff22c93aad48d7e..69df96685d680868 100644 --- a/MdeModulePkg/Core/Dxe/FwVol/FwVolRead.c +++ b/MdeModulePkg/Core/Dxe/FwVol/FwVolRead.c @@ -284,7 +284,6 @@ FvReadFile ( UINT8 *SrcPtr; EFI_FFS_FILE_HEADER *FfsHeader; UINTN InputBufferSize; - UINTN WholeFileSize; =20 if (NameGuid =3D=3D NULL) { return EFI_INVALID_PARAMETER; @@ -316,27 +315,6 @@ FvReadFile ( // Get a pointer to the header // FfsHeader =3D FvDevice->LastKey->FfsHeader; - if (FvDevice->IsMemoryMapped) { - // - // Memory mapped FV has not been cached, so here is to cache by file. - // - if (!FvDevice->LastKey->FileCached) { - // - // Cache FFS file to memory buffer. - // - WholeFileSize =3D IS_FFS_FILE2 (FfsHeader) ? FFS_FILE2_SIZE (FfsHead= er) : FFS_FILE_SIZE (FfsHeader); - FfsHeader =3D AllocateCopyPool (WholeFileSize, FfsHeader); - if (FfsHeader =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - // - // Let FfsHeader in FfsFileEntry point to the cached file buffer. - // - FvDevice->LastKey->FfsHeader =3D FfsHeader; - FvDevice->LastKey->FileCached =3D TRUE; - } - } =20 // // Remember callers buffer size --=20 2.39.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 (#105366): https://edk2.groups.io/g/devel/message/105366 Mute This Topic: https://groups.io/mt/99197136/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- From nobody Sat May 18 20:15:36 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+105367+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+105367+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1685355454; cv=none; d=zohomail.com; s=zohoarc; b=RrsZp3zFurnjSCeYM/m4ZZzpqEmGdlw4MChNAqGSHCsGKtQ7lMXUbTfdESf70TzgNqnR21SQkY+Ova5OZE6Y1gW0bLVOTuWpXS9JWtyHds+zhXtiU4inROmCPyPHc9svNtk5UY0gK4PXcd/wWaWNcoA136DAheDXrYz/99DKPls= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685355454; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=13XHVrIB79xrk43NEuj4JuBZz8C1he7lXlI/6ziDwKo=; b=B3ls0Do+NHByOpDe2xWYY11gQX3CBjmL140GFYbQ1DgZ5mVBhaNBrFwGfLNkfQvhPBC6BKNvFKviXswzZfK7N1Tj2H21r/9qYay3+M1+Q6XYjihsB+Iz/uV2xiPQRnVnCNlTKw/eT+GbgkLE+1+LiX0yMeTg4Si2lWmof+a6F+8= 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+105367+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 1685355454020604.2908460087955; Mon, 29 May 2023 03:17:34 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id fLxIYY1788612xKkjhOZGq7I; Mon, 29 May 2023 03:17:33 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web11.46679.1685355452933148710 for ; Mon, 29 May 2023 03:17:33 -0700 X-Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6BB5560AF5; Mon, 29 May 2023 10:17:32 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71213C433EF; Mon, 29 May 2023 10:17:29 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Ray Ni , Jiewen Yao , Gerd Hoffmann , Taylor Beebe , Oliver Smith-Denny , Dandan Bi , Liming Gao , "Kinney, Michael D" , Leif Lindholm , Michael Kubacki Subject: [edk2-devel] [RFC PATCH 05/11] MdeModulePkg/DxeCore: Use memory mapped FV protocol to avoid image copy Date: Mon, 29 May 2023 12:16:59 +0200 Message-Id: <20230529101705.2476949-6-ardb@kernel.org> In-Reply-To: <20230529101705.2476949-1-ardb@kernel.org> References: <20230529101705.2476949-1-ardb@kernel.org> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ardb@kernel.org X-Gm-Message-State: qFLDIRBkQvBvAX7Q3bfeXkYBx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685355453; bh=TP2WDpS5ZZ0YNiccb3Zh1RbucK/UlcJT0ns9lgQCqgQ=; h=Cc:Date:From:Reply-To:Subject:To; b=JqWTGtXxBHnNOgHuvyXcgwS25+ciqNSP7tH7yFT07EIRmYJFZD3ikCpnBeVHL6LK3T4 AXNhSpmK+5HnkeNr8mD+qbs+6NCI1GRknXAoAuuc5+X9jd61FhwlcKlAS4NvYjDGqolCW cP/c/TBJZKVbwu7kqXKa6wjHRiaeQaQJeaQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685355455893100003 Content-Type: text/plain; charset="utf-8" Use the memory mapped FV protocol to obtain the existing location in memory and the size of an image being loaded from a firmware volume. This removes the need to do a memcopy of the file data. Signed-off-by: Ard Biesheuvel --- MdeModulePkg/Core/Dxe/DxeMain.h | 1 + MdeModulePkg/Core/Dxe/DxeMain.inf | 3 + MdeModulePkg/Core/Dxe/Image/Image.c | 111 +++++++++++++++++--- MdeModulePkg/Include/Protocol/MemoryMappedFv.h | 59 +++++++++++ MdeModulePkg/MdeModulePkg.dec | 3 + 5 files changed, 163 insertions(+), 14 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/DxeMain.h b/MdeModulePkg/Core/Dxe/DxeMai= n.h index 43daa037be441150..a695b457c79b65bb 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.h +++ b/MdeModulePkg/Core/Dxe/DxeMain.h @@ -45,6 +45,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include #include #include #include diff --git a/MdeModulePkg/Core/Dxe/DxeMain.inf b/MdeModulePkg/Core/Dxe/DxeM= ain.inf index 35d5bf0dee6f7f3f..a7175cb364b9b5de 100644 --- a/MdeModulePkg/Core/Dxe/DxeMain.inf +++ b/MdeModulePkg/Core/Dxe/DxeMain.inf @@ -153,6 +153,9 @@ [Protocols] gEfiLoadedImageDevicePathProtocolGuid ## PRODUCES gEfiHiiPackageListProtocolGuid ## SOMETIMES_PRODUCES gEfiSmmBase2ProtocolGuid ## SOMETIMES_CONSUMES + ## PRODUCES + ## CONSUMES + gEdkiiMemoryMappedFvProtocolGuid gEdkiiPeCoffImageEmulatorProtocolGuid ## SOMETIMES_CONSUMES =20 # Arch Protocols diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Im= age/Image.c index f30e369370a09609..3dfab4829b3ca17f 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -1043,6 +1043,76 @@ CoreUnloadAndCloseImage ( CoreFreePool (Image); } =20 +/** + Get the image file data and size directly from a memory mapped FV + + If FilePath is NULL, then NULL is returned. + If FileSize is NULL, then NULL is returned. + If AuthenticationStatus is NULL, then NULL is returned. + + @param[in] FvHandle The firmware volume handle + @param[in] FilePath The pointer to the device path of = the file + that is abstracted to the file buf= fer. + @param[out] FileSize The pointer to the size of the abs= tracted + file buffer. + @param[out] AuthenticationStatus Pointer to the authentication stat= us. + + @retval NULL FilePath is NULL, or FileSize is NULL, or AuthenticationS= tatus + is NULL, or the file is not memory mapped + @retval other The abstracted file buffer. +**/ +STATIC +VOID * +GetFileFromMemoryMappedFv ( + IN EFI_HANDLE FvHandle, + IN CONST EFI_DEVICE_PATH_PROTOCOL *FilePath, + OUT UINTN *FileSize, + OUT UINT32 *AuthenticationStatus + ) +{ + EDKII_MEMORY_MAPPED_FV_PROTOCOL *MemMappedFv; + CONST EFI_GUID *NameGuid; + EFI_PHYSICAL_ADDRESS Address; + EFI_STATUS Status; + + if ((FilePath =3D=3D NULL) || + (FileSize =3D=3D NULL) || + (AuthenticationStatus =3D=3D NULL)) + { + return NULL; + } + + NameGuid =3D EfiGetNameGuidFromFwVolDevicePathNode ( + (CONST MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)FilePath); + if (NameGuid =3D=3D NULL) { + return NULL; + } + + Status =3D gBS->HandleProtocol ( + FvHandle, + &gEdkiiMemoryMappedFvProtocolGuid, + (VOID **)&MemMappedFv + ); + if (EFI_ERROR (Status)) { + ASSERT (Status =3D=3D EFI_UNSUPPORTED); + return NULL; + } + + Status =3D MemMappedFv->GetLocationAndSize ( + MemMappedFv, + NameGuid, + EFI_SECTION_PE32, + &Address, + FileSize, + AuthenticationStatus + ); + if (EFI_ERROR (Status) || (Address > (MAX_ADDRESS - *FileSize))) { + return NULL; + } + + return (VOID *)(UINTN)Address; +} + /** Loads an EFI image into memory and returns a handle to the image. =20 @@ -1164,6 +1234,16 @@ CoreLoadImageCommon ( Status =3D CoreLocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid, &Ha= ndleFilePath, &DeviceHandle); if (!EFI_ERROR (Status)) { ImageIsFromFv =3D TRUE; + + // + // If possible, use the memory mapped file image directly, rather th= an copying it into a buffer + // + FHand.Source =3D GetFileFromMemoryMappedFv ( + DeviceHandle, + HandleFilePath, + &FHand.SourceSize, + &AuthenticationStatus + ); } else { HandleFilePath =3D FilePath; Status =3D CoreLocateDevicePath (&gEfiSimpleFileSystemProtoc= olGuid, &HandleFilePath, &DeviceHandle); @@ -1187,21 +1267,24 @@ CoreLoadImageCommon ( // // Get the source file buffer by its device path. // - FHand.Source =3D GetFileBufferByFilePath ( - BootPolicy, - FilePath, - &FHand.SourceSize, - &AuthenticationStatus - ); if (FHand.Source =3D=3D NULL) { - Status =3D EFI_NOT_FOUND; - } else { - FHand.FreeBuffer =3D TRUE; - if (ImageIsFromLoadFile) { - // - // LoadFile () may cause the device path of the Handle be updated. - // - OriginalFilePath =3D AppendDevicePath (DevicePathFromHandle (Devic= eHandle), Node); + FHand.Source =3D GetFileBufferByFilePath ( + BootPolicy, + FilePath, + &FHand.SourceSize, + &AuthenticationStatus + ); + + if (FHand.Source =3D=3D NULL) { + Status =3D EFI_NOT_FOUND; + } else { + FHand.FreeBuffer =3D TRUE; + if (ImageIsFromLoadFile) { + // + // LoadFile () may cause the device path of the Handle be update= d. + // + OriginalFilePath =3D AppendDevicePath (DevicePathFromHandle (Dev= iceHandle), Node); + } } } } diff --git a/MdeModulePkg/Include/Protocol/MemoryMappedFv.h b/MdeModulePkg/= Include/Protocol/MemoryMappedFv.h new file mode 100644 index 0000000000000000..821009122113a658 --- /dev/null +++ b/MdeModulePkg/Include/Protocol/MemoryMappedFv.h @@ -0,0 +1,59 @@ +/** @file + Protocol to obtain information about files in memory mapped firmware vol= umes + + Copyright (c) 2023, Google LLC. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef EDKII_MEMORY_MAPPED_FV_H_ +#define EDKII_MEMORY_MAPPED_FV_H_ + +#define EDKII_MEMORY_MAPPED_FV_PROTOCOL_GUID \ + { 0xb9bfa973, 0x5384, 0x441e, { 0xa4, 0xe7, 0x20, 0xe6, 0x5d, 0xaf, 0x2e= , 0x0f } } + +typedef struct _EDKII_MEMORY_MAPPED_FV_PROTOCOL EDKII_MEMORY_MAPPED_FV_PRO= TOCOL; + +// +// Function Prototypes +// + +/** + Get the physical address and size of a file's section in a memory mapped= FV + + @param[in] This The protocol pointer + @param[in] NameGuid The name GUID of the file + @param[in] SectionType The file section from which to retrieve addres= s and size + @param[out] FileAddress The physical address of the file + @param[out] FileSize The size of the file + @param[out] AuthStatus The authentication status associated with the = file + + @retval EFI_SUCCESS Information about the file was retrieved = successfully. + @retval EFI_INVALID_PARAMETER FileAddress was NULL, FileSize was NULL, = AuthStatus + was NULL. + @retval EFI_NOT_FOUND No section of the specified type could be= located in + the specified file. + +**/ +typedef +EFI_STATUS +(EFIAPI *GET_LOCATION_AND_SIZE)( + IN EDKII_MEMORY_MAPPED_FV_PROTOCOL *This, + IN CONST EFI_GUID *NameGuid, + IN EFI_SECTION_TYPE SectionType, + OUT EFI_PHYSICAL_ADDRESS *FileAddress, + OUT UINTN *FileSize, + OUT UINT32 *AuthStatus + ); + +// +// Protocol interface structure +// +struct _EDKII_MEMORY_MAPPED_FV_PROTOCOL { + GET_LOCATION_AND_SIZE GetLocationAndSize; +}; + +extern EFI_GUID gEdkiiMemoryMappedFvProtocolGuid; + +#endif diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index d65dae18aa81e569..2d72ac733d82195e 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -679,6 +679,9 @@ [Protocols] ## Include/Protocol/PlatformBootManager.h gEdkiiPlatformBootManagerProtocolGuid =3D { 0xaa17add4, 0x756c, 0x460d, = { 0x94, 0xb8, 0x43, 0x88, 0xd7, 0xfb, 0x3e, 0x59 } } =20 + ## Include/Protocol/MemoryMappedFv.h + gEdkiiMemoryMappedFvProtocolGuid =3D { 0xb9bfa973, 0x5384, 0x441e, { 0xa= 4, 0xe7, 0x20, 0xe6, 0x5d, 0xaf, 0x2e, 0x0f } } + # # [Error.gEfiMdeModulePkgTokenSpaceGuid] # 0x80000001 | Invalid value provided. --=20 2.39.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 (#105367): https://edk2.groups.io/g/devel/message/105367 Mute This Topic: https://groups.io/mt/99197138/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- From nobody Sat May 18 20:15:36 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+105368+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+105368+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1685355456; cv=none; d=zohomail.com; s=zohoarc; b=m3TeE2GSWXsKcz1VhPYdhHBPQsO324qzugcIMduTLZxKiTCd4eTdLcbSYkUCLAUIrbBQ1a8q9dWijvGs3DxCP5v8DaukTPSfEQqXS7+i4SCi07HGXjpo0lCCAz2Z6VlNur2TO0f3xl08qON9qZvzYEAgdb1KtG6bncrCisMg2oY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685355456; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=zAVpjjEdbBQGvM0mPqIVz9LJZCtcDEjmCV5CMk1uL0A=; b=gvMmi484AqQ2SncTxY2NcmS7J/WTljvLRGYxAJ0N20LJuGRhv0kdtQTHStbC467ZmPGgXQQP0fuhRbQBL8d3uIquwQNEBzIxmMG9xXrsYYWllqO+LkQmbttqRjV628f+5AmKoimQ56JirM/46LwybZl0yZkUuyiqtZRQObaux7g= 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+105368+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 1685355456825573.3971952793556; Mon, 29 May 2023 03:17:36 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id q58pYY1788612xcT4VYMLdxy; Mon, 29 May 2023 03:17:36 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web10.46507.1685355455795454568 for ; Mon, 29 May 2023 03:17:35 -0700 X-Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 505DE61405; Mon, 29 May 2023 10:17:35 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4942EC4339E; Mon, 29 May 2023 10:17:32 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Ray Ni , Jiewen Yao , Gerd Hoffmann , Taylor Beebe , Oliver Smith-Denny , Dandan Bi , Liming Gao , "Kinney, Michael D" , Leif Lindholm , Michael Kubacki Subject: [edk2-devel] [RFC PATCH 06/11] MdeModulePkg/DxeCore: Expose memory mapped FV protocol when possible Date: Mon, 29 May 2023 12:17:00 +0200 Message-Id: <20230529101705.2476949-7-ardb@kernel.org> In-Reply-To: <20230529101705.2476949-1-ardb@kernel.org> References: <20230529101705.2476949-1-ardb@kernel.org> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ardb@kernel.org X-Gm-Message-State: jesvQgRc2E5yF2ivcH7CxeX0x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685355456; bh=iw8XLoPBUOnbLNE0XvlvJzUbCAALvlsg9xieYXBpodY=; h=Cc:Date:From:Reply-To:Subject:To; b=LzBeQirLr0P7Af0alu1Nq4eYF+/QLiAWtciPsl6AjRcEcPov83rC0VgpqxtuAPhvwVl wcZsnQfUpoVgkxIF23fdI7duaOg2sKV7ySQFb+su7u6pFybQfsbU88SirCoGvaO68kmJT KxKIqQIobefSJtIRBFCJVtP3q90ZefLP4Pc= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685355457884100007 Content-Type: text/plain; charset="utf-8" Expose the EDK2 specific memory mapped FV protocol in addition to the firmware volume protocol defined by PI when the underlying firmware volume block protocol informs us that the firmware volume is memory mapped. This permits the image loader to access any FFS files in the image directly, rather than requiring it to load a cached copy into memory via the ReadFile() API. This avoids a redundant memcpy(). Signed-off-by: Ard Biesheuvel --- MdeModulePkg/Core/Dxe/FwVol/FwVol.c | 113 +++++++++++++++++++- MdeModulePkg/Core/Dxe/FwVol/FwVolDriver.h | 31 ++++++ 2 files changed, 140 insertions(+), 4 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/FwVol/FwVol.c b/MdeModulePkg/Core/Dxe/Fw= Vol/FwVol.c index 153bfecafa7772ea..f7f236496686bc36 100644 --- a/MdeModulePkg/Core/Dxe/FwVol/FwVol.c +++ b/MdeModulePkg/Core/Dxe/FwVol/FwVol.c @@ -41,7 +41,8 @@ FV_DEVICE mFvDevice =3D { 0, 0, FALSE, - FALSE + FALSE, + { MemoryMappedFvGetLocationAndSize }, }; =20 // @@ -676,11 +677,13 @@ NotifyFwVolBlock ( // // Install an New FV protocol on the existing handle // - Status =3D CoreInstallProtocolInterface ( + Status =3D CoreInstallMultipleProtocolInterfaces ( &Handle, &gEfiFirmwareVolume2ProtocolGuid, - EFI_NATIVE_INTERFACE, - &FvDevice->Fv + &FvDevice->Fv, + (FvDevice->IsMemoryMapped ? &gEdkiiMemoryMappedFvProtoc= olGuid : NULL), + &FvDevice->MemoryMappedFv, + NULL ); ASSERT_EFI_ERROR (Status); } else { @@ -722,3 +725,105 @@ FwVolDriverInit ( ); return EFI_SUCCESS; } + +/** + Get the physical address and size of a file's section in a memory mapped= FV + + @param[in] This The protocol pointer + @param[in] NameGuid The name GUID of the file + @param[in] SectionType The file section from which to retrieve addres= s and size + @param[out] FileAddress The physical address of the file + @param[out] FileSize The size of the file + @param[out] AuthStatus The authentication status associated with the = file + + @retval EFI_SUCCESS Information about the file was retrieved = successfully. + @retval EFI_INVALID_PARAMETER FileAddress was NULL, FileSize was NULL, = AuthStatus + was NULL. + @retval EFI_NOT_FOUND No section of the specified type could be= located in + the specified file. + +**/ +EFI_STATUS +EFIAPI +MemoryMappedFvGetLocationAndSize ( + IN EDKII_MEMORY_MAPPED_FV_PROTOCOL *This, + IN CONST EFI_GUID *NameGuid, + IN EFI_SECTION_TYPE SectionType, + OUT EFI_PHYSICAL_ADDRESS *FileAddress, + OUT UINTN *FileSize, + OUT UINT32 *AuthStatus + ) +{ + FV_DEVICE *FvDevice; + EFI_STATUS Status; + EFI_FV_FILETYPE FileType; + EFI_FV_FILE_ATTRIBUTES FileAttributes; + EFI_GUID FileNameGuid; + FFS_FILE_LIST_ENTRY *FfsFileEntry; + EFI_COMMON_SECTION_HEADER *Section; + UINTN FvFileSize; + UINTN SectionLength; + UINTN HeaderLength; + + FvDevice =3D FV_DEVICE_FROM_MMFV (This); + FfsFileEntry =3D NULL; + + do { + FileType =3D 0; + Status =3D FvGetNextFile ( + &FvDevice->Fv, + &FfsFileEntry, + &FileType, + &FileNameGuid, + &FileAttributes, + &FvFileSize + ); + if (EFI_ERROR (Status)) { + return EFI_NOT_FOUND; + } + } while (!CompareGuid (&FileNameGuid, NameGuid)); + + // + // Skip over file header + // + if (IS_FFS_FILE2 (FfsFileEntry->FfsHeader)) { + Section =3D (VOID *)((UINT8 *)FfsFileEntry->FfsHeader + + sizeof (EFI_FFS_FILE_HEADER2)); + } else { + Section =3D (VOID *)((UINT8 *)FfsFileEntry->FfsHeader + + sizeof (EFI_FFS_FILE_HEADER)); + } + + do { + if (IS_SECTION2 (Section)) { + SectionLength =3D SECTION2_SIZE (Section); + HeaderLength =3D sizeof (EFI_COMMON_SECTION_HEADER2); + } else { + SectionLength =3D SECTION_SIZE (Section); + HeaderLength =3D sizeof (EFI_COMMON_SECTION_HEADER); + } + + if (SectionLength > FvFileSize) { + DEBUG ((DEBUG_WARN, "%a: %x > %x\n", __func__, SectionLength, FvFile= Size)); + break; + } + + if (Section->Type =3D=3D SectionType) { + *FileAddress =3D (UINTN)Section + HeaderLength; + *FileSize =3D SectionLength - HeaderLength; + *AuthStatus =3D FvDevice->AuthenticationStatus; + + return EFI_SUCCESS; + } + + // + // SectionLength is adjusted it is 4 byte aligned. + // Go to the next section + // + SectionLength =3D ALIGN_VALUE (SectionLength, 4); + Section =3D (EFI_COMMON_SECTION_HEADER *)((UINT8 *)Section + Sec= tionLength); + FvFileSize -=3D SectionLength; + } while (TRUE); + + return EFI_NOT_FOUND; +} diff --git a/MdeModulePkg/Core/Dxe/FwVol/FwVolDriver.h b/MdeModulePkg/Core/= Dxe/FwVol/FwVolDriver.h index 3403c812b2ebcb45..eb1b702c1ee0bd4f 100644 --- a/MdeModulePkg/Core/Dxe/FwVol/FwVolDriver.h +++ b/MdeModulePkg/Core/Dxe/FwVol/FwVolDriver.h @@ -40,10 +40,13 @@ typedef struct { UINT8 ErasePolarity; BOOLEAN IsFfs3Fv; BOOLEAN IsMemoryMapped; + EDKII_MEMORY_MAPPED_FV_PROTOCOL MemoryMappedFv; } FV_DEVICE; =20 #define FV_DEVICE_FROM_THIS(a) CR(a, FV_DEVICE, Fv, FV2_DEVICE_SIGNATURE) =20 +#define FV_DEVICE_FROM_MMFV(a) CR(a, FV_DEVICE, MemoryMappedFv, FV2_DEVIC= E_SIGNATURE) + /** Retrieves attributes, insures positive polarity of attribute bits, retur= ns resulting attributes in output parameter. @@ -384,4 +387,32 @@ IsValidFfsFile ( IN EFI_FFS_FILE_HEADER *FfsHeader ); =20 +/** + Get the physical address and size of a file's section in a memory mapped= FV + + @param[in] This The protocol pointer + @param[in] NameGuid The name GUID of the file + @param[in] SectionType The file section from which to retrieve addres= s and size + @param[out] FileAddress The physical address of the file + @param[out] FileSize The size of the file + @param[out] AuthStatus The authentication status associated with the = file + + @retval EFI_SUCCESS Information about the file was retrieved = successfully. + @retval EFI_INVALID_PARAMETER FileAddress was NULL, FileSize was NULL, = AuthStatus + was NULL. + @retval EFI_NOT_FOUND No section of the specified type could be= located in + the specified file. + +**/ +EFI_STATUS +EFIAPI +MemoryMappedFvGetLocationAndSize ( + IN EDKII_MEMORY_MAPPED_FV_PROTOCOL *This, + IN CONST EFI_GUID *NameGuid, + IN EFI_SECTION_TYPE SectionType, + OUT EFI_PHYSICAL_ADDRESS *FileAddress, + OUT UINTN *FileSize, + OUT UINT32 *AuthStatus + ); + #endif --=20 2.39.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 (#105368): https://edk2.groups.io/g/devel/message/105368 Mute This Topic: https://groups.io/mt/99197139/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- From nobody Sat May 18 20:15:36 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+105369+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+105369+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1685355459; cv=none; d=zohomail.com; s=zohoarc; b=dyC7JW5h5GYHLovS3N1jDHVeIryEF4kCRX4BIpIaZfUVUZ3DRqVGzIdE9uEaPviZaoGx5eC4oC0jTYH1Tn0744mu8DGLbOywPmJrL2cODYr0qzb8HFM7GzCHSe26r30i0qEbpW+sxpK8YHQ8OfL6v/XbAdjoUPQG1qCKCSx3uQ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685355459; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=XbylUMOtGZgsv/J5fn/HMHFhuwAY1Sq75iG9KL0QySs=; b=nKSjQGPixy5ylMivX0RZJ2vmtw51uG+VHqAnF9ES+HOvykCEXJRLGbj/iQXi3Ebf4Zx864JNmQeJJOTWqWI1tenA9YAXfuAI8ekcwvxGjLIBfzFaY/mUNasINCyyOMe5z+bSNw77gpdVkjUxGHudIRGXpkQNHvXsOVI94QL2PEk= 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+105369+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 1685355459621676.5713750384731; Mon, 29 May 2023 03:17:39 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id JBbmYY1788612xnzU2T8p2fr; Mon, 29 May 2023 03:17:39 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web10.46509.1685355458568862230 for ; Mon, 29 May 2023 03:17:38 -0700 X-Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 205DC60AF5; Mon, 29 May 2023 10:17:38 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 24E3EC433EF; Mon, 29 May 2023 10:17:34 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Ray Ni , Jiewen Yao , Gerd Hoffmann , Taylor Beebe , Oliver Smith-Denny , Dandan Bi , Liming Gao , "Kinney, Michael D" , Leif Lindholm , Michael Kubacki Subject: [edk2-devel] [RFC PATCH 07/11] MdeModulePkg/DxeCore: Execute loaded images in place if possible Date: Mon, 29 May 2023 12:17:01 +0200 Message-Id: <20230529101705.2476949-8-ardb@kernel.org> In-Reply-To: <20230529101705.2476949-1-ardb@kernel.org> References: <20230529101705.2476949-1-ardb@kernel.org> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ardb@kernel.org X-Gm-Message-State: zsQ3MemXwckiEfV7bxsqosIGx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685355459; bh=bvjD74IdNE34/Qe07wpkVHJl9DwYHqa4dkUv1gGyuX4=; h=Cc:Date:From:Reply-To:Subject:To; b=VyivE3amKpEhxkKZI4vTHYjX4DSLcXKrz9g0rHoHRGMjuwfBBtSTlkz4p6v2AgRZRkv Lhm0IFOvch4GhfABexjeI0GZyUKmwq9VCC+86mEg2u110KWWQKIy4XZMnVu3HBokDM7UY J4/fw2jsaITxyZgZ8EfEpA6c0asPmlYtV78= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685355459921100009 Content-Type: text/plain; charset="utf-8" In the image loader, check whether an image has already been relocated to the address from which it is being loaded. This is not something that can happen by accident, and so we can assume that this means that the image was intended to be executed in place. This removes a redundant copy of the image contents, and also permits the image to be mapped with restricted permissions even before the CPU arch protocol has been dispatched. Signed-off-by: Ard Biesheuvel --- MdeModulePkg/Core/Dxe/Image/Image.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Im= age/Image.c index 3dfab4829b3ca17f..621637e869daf62d 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -573,7 +573,7 @@ STATIC EFI_STATUS CoreLoadPeImage ( IN BOOLEAN BootPolicy, - IN VOID *Pe32Handle, + IN IMAGE_FILE_HANDLE *Pe32Handle, IN LOADED_IMAGE_PRIVATE_DATA *Image, IN UINT32 Attribute ) @@ -630,10 +630,16 @@ CoreLoadPeImage ( return EFI_UNSUPPORTED; } =20 + // + // Check whether the loaded image can be executed in place + // + if (Image->ImageContext.ImageAddress =3D=3D (PHYSICAL_ADDRESS)(UINTN)Pe3= 2Handle->Source) { + goto ExecuteInPlace; + } + // // Allocate Destination Buffer as caller did not pass it in // - if (Image->ImageContext.SectionAlignment > EFI_PAGE_SIZE) { Size =3D (UINTN)Image->ImageContext.ImageSize + Image->ImageContext.Se= ctionAlignment; } else { @@ -704,6 +710,7 @@ CoreLoadPeImage ( // // Load the image from the file into the allocated memory // +ExecuteInPlace: Status =3D PeCoffLoaderLoadImage (&Image->ImageContext); if (EFI_ERROR (Status)) { goto Done; --=20 2.39.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 (#105369): https://edk2.groups.io/g/devel/message/105369 Mute This Topic: https://groups.io/mt/99197140/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- From nobody Sat May 18 20:15:36 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+105370+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+105370+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1685355463; cv=none; d=zohomail.com; s=zohoarc; b=PU8yB8u2ewHHp11ZI5WP0fXOsCBDCZi3iiSAMV6DW0qcCFgYPvMyjViw04ncwRLiZgpTRfiwk+evTAwbtkJmGaI0xAazvdAhlXtaDtTy0bQGvOIs6VAIyta6+iKymPgfTRwC6uudmVqtRCeiFwjFtnRWlxL0zFNl0xiQVFYZDL8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685355463; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=AWBg6q7uwLq5yhcch+sbehwBookYGjC9o6Nx4KYhEag=; b=nGZBAM5Xg9781nriXGhlvMQRrxeibFv5i1RUIg6HLrSTFXJrzaLfcKmlnkLEO/zyTOAHppdQdocFjRhuJoij3MHVOKLMKufqk35is0uYBu4UJgA5mFl33K42HDgCilaY2YM9GBBixhVcg9wJmT+ypgkj7mvAO0nZGD3oPzhArc4= 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+105370+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 1685355463300368.3962502082304; Mon, 29 May 2023 03:17:43 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 2KUDYY1788612x84RI1HSAZt; Mon, 29 May 2023 03:17:42 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web10.46512.1685355461422191016 for ; Mon, 29 May 2023 03:17:41 -0700 X-Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EA72561362; Mon, 29 May 2023 10:17:40 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1FE6C433D2; Mon, 29 May 2023 10:17:37 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Ray Ni , Jiewen Yao , Gerd Hoffmann , Taylor Beebe , Oliver Smith-Denny , Dandan Bi , Liming Gao , "Kinney, Michael D" , Leif Lindholm , Michael Kubacki Subject: [edk2-devel] [RFC PATCH 08/11] MdeModulePkg/DxeIpl: Relocate and remap XIP capable DXE drivers Date: Mon, 29 May 2023 12:17:02 +0200 Message-Id: <20230529101705.2476949-9-ardb@kernel.org> In-Reply-To: <20230529101705.2476949-1-ardb@kernel.org> References: <20230529101705.2476949-1-ardb@kernel.org> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ardb@kernel.org X-Gm-Message-State: oFL1oPMHU8rtQ9eBHOGPt17cx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685355462; bh=kOFMUKMhKISEB80t6YzTzVvir+SClZRFyDyYHGp+V1c=; h=Cc:Date:From:Reply-To:Subject:To; b=X0tdRczr8T091McgFbf3uR1m+wAvEi93k6xnUJIb/aLHEwetPb/HdQLlU1CW+V974wA d4JoamcexCAqVgYeS/iCdgWhYLjCVR9YqbTA2otROQQVwYPQsiTkPVSK/4G0ka7uWdLBH CnHz/vZBcpgwV8zO0vRcentV972e7v6HQtw= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685355463911100001 Content-Type: text/plain; charset="utf-8" Before handing over to the DXE core, iterate over all known FFS files and find the ones that can execute in place. These files are then relocated in place and mapped with restricted permissions, allowing the DXE core to dispatch them without the need to perform any manipulation of the file contents or the page table permissions. Signed-off-by: Ard Biesheuvel --- MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf | 1 + MdeModulePkg/Core/DxeIplPeim/DxeLoad.c | 196 ++++++++++++++++++++ 2 files changed, 197 insertions(+) diff --git a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf b/MdeModulePkg/Core/Dx= eIplPeim/DxeIpl.inf index f1990eac77607854..60112100df78b396 100644 --- a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf +++ b/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf @@ -65,6 +65,7 @@ [LibraryClasses] PeimEntryPoint DebugLib DebugAgentLib + PeCoffLib PeiServicesTablePointerLib PerformanceLib =20 diff --git a/MdeModulePkg/Core/DxeIplPeim/DxeLoad.c b/MdeModulePkg/Core/Dxe= IplPeim/DxeLoad.c index 2c19f1a507baf34a..1f20db1faffbd1d2 100644 --- a/MdeModulePkg/Core/DxeIplPeim/DxeLoad.c +++ b/MdeModulePkg/Core/DxeIplPeim/DxeLoad.c @@ -10,6 +10,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include "DxeIpl.h" =20 +#include +#include + // // Module Globals used in the DXE to PEI hand off // These must be module globals, so the stack can be switched @@ -228,6 +231,197 @@ ValidateMemoryTypeInfoVariable ( return TRUE; } =20 +/** + Support routine for the PE/COFF Loader that reads a buffer from a PE/COF= F file. + The function is used for XIP code to have optimized memory copy. + + @param FileHandle The handle to the PE/COFF file + @param FileOffset The offset, in bytes, into the file to read + @param ReadSize The number of bytes to read from the file startin= g at FileOffset + @param Buffer A pointer to the buffer to read the data into. + + @return EFI_SUCCESS ReadSize bytes of data were read into Buffer from= the + PE/COFF file starting at FileOffset + +**/ +STATIC +EFI_STATUS +EFIAPI +PeiImageRead ( + IN VOID *FileHandle, + IN UINTN FileOffset, + IN UINTN *ReadSize, + OUT VOID *Buffer + ) +{ + CHAR8 *Destination8; + CHAR8 *Source8; + + Destination8 =3D Buffer; + Source8 =3D (CHAR8 *)((UINTN)FileHandle + FileOffset); + if (Destination8 !=3D Source8) { + CopyMem (Destination8, Source8, *ReadSize); + } + + return EFI_SUCCESS; +} + +STATIC +VOID +RemapImage ( + IN EDKII_MEMORY_ATTRIBUTE_PPI *MemoryPpi, + IN CONST PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext + ) +{ + EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr; + EFI_IMAGE_SECTION_HEADER *Section; + PHYSICAL_ADDRESS SectionAddress; + EFI_STATUS Status; + UINT64 Permissions; + UINTN Index; + + if (MemoryPpi =3D=3D NULL) { + return; + } + + Hdr.Union =3D (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((UINT8 *)ImageContext-= >Handle + + ImageContext->PeCoffHead= erOffset); + ASSERT (Hdr.Pe32->Signature =3D=3D EFI_IMAGE_NT_SIGNATURE); + + Section =3D (EFI_IMAGE_SECTION_HEADER *)((UINT8 *)Hdr.Union + sizeof (UI= NT32) + + sizeof (EFI_IMAGE_FILE_HEADER) + + Hdr.Pe32->FileHeader.SizeOfOption= alHeader + ); + + for (Index =3D 0; Index < Hdr.Pe32->FileHeader.NumberOfSections; Index++= ) { + SectionAddress =3D ImageContext->ImageAddress + Section[Index].Virtual= Address; + Permissions =3D 0; + + if ((Section[Index].Characteristics & EFI_IMAGE_SCN_MEM_WRITE) =3D=3D = 0) { + Permissions |=3D EFI_MEMORY_RO; + } + + if ((Section[Index].Characteristics & EFI_IMAGE_SCN_MEM_EXECUTE) =3D= =3D 0) { + Permissions |=3D EFI_MEMORY_XP; + } + + Status =3D MemoryPpi->SetPermissions ( + MemoryPpi, + SectionAddress, + Section[Index].Misc.VirtualSize, + Permissions, + Permissions ^ EFI_MEMORY_RO ^ EFI_MEMORY_XP + ); + ASSERT_EFI_ERROR (Status); + } +} + +STATIC +VOID +RelocateAndRemapDriversInPlace ( + VOID + ) +{ + EFI_STATUS Status; + UINTN Instance; + EFI_PEI_FV_HANDLE VolumeHandle; + EFI_PEI_FILE_HANDLE FileHandle; + PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; + UINT32 AuthenticationState; + EDKII_MEMORY_ATTRIBUTE_PPI *MemoryPpi; + + MemoryPpi =3D NULL; + PeiServicesLocatePpi (&gEdkiiMemoryAttributePpiGuid, 0, NULL, (VOID **)&= MemoryPpi); + + Instance =3D 0; + do { + // + // Traverse all firmware volume instances + // + Status =3D PeiServicesFfsFindNextVolume (Instance, &VolumeHandle); + if (Status =3D=3D EFI_NOT_FOUND) { + return; + } + + ASSERT_EFI_ERROR (Status); + + FileHandle =3D NULL; + do { + Status =3D PeiServicesFfsFindNextFile ( + EFI_FV_FILETYPE_DRIVER, + VolumeHandle, + &FileHandle); + if (Status =3D=3D EFI_NOT_FOUND) { + break; + } + + ASSERT_EFI_ERROR (Status); + + ZeroMem (&ImageContext, sizeof (ImageContext)); + + Status =3D PeiServicesFfsFindSectionData3 ( + EFI_SECTION_PE32, + 0, + FileHandle, + &ImageContext.Handle, + &AuthenticationState + ); + if (Status =3D=3D EFI_NOT_FOUND) { + continue; + } + + ASSERT_EFI_ERROR (Status); + + ImageContext.ImageRead =3D PeiImageRead; + Status =3D PeCoffLoaderGetImageInfo (&ImageContext); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + continue; + } + + ImageContext.ImageAddress =3D (PHYSICAL_ADDRESS)(UINTN)ImageContext.= Handle; + if ((ImageContext.ImageAddress & (ImageContext.SectionAlignment - 1)= ) !=3D 0) { + DEBUG ((DEBUG_VERBOSE, "%a: skip PE image at %p\n", __func__, Imag= eContext.Handle)); + continue; + } + + DEBUG (( + DEBUG_INFO, + "%a: relocate PE image at %p for execution in place\n", + __func__, + ImageContext.Handle + )); + + // + // 'Load' the image in-place - this just performs a sanity check on + // the PE metadata but does not actually move any data + // + Status =3D PeCoffLoaderLoadImage (&ImageContext); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + continue; + } + + // + // Relocate this driver in place + // + Status =3D PeCoffLoaderRelocateImage (&ImageContext); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + continue; + } + + // + // Apply section permissions to the page tables + // + RemapImage (MemoryPpi, &ImageContext); + + } while (TRUE); + + Instance++; + } while (TRUE); +} + /** Main entry point to last PEIM. =20 @@ -436,6 +630,8 @@ DxeLoadCore ( DxeCoreEntryPoint ); =20 + RelocateAndRemapDriversInPlace (); + // // Report Status Code EFI_SW_PEI_PC_HANDOFF_TO_NEXT // --=20 2.39.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 (#105370): https://edk2.groups.io/g/devel/message/105370 Mute This Topic: https://groups.io/mt/99197142/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- From nobody Sat May 18 20:15:36 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+105371+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+105371+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1685355465; cv=none; d=zohomail.com; s=zohoarc; b=Isnp6PMd/CVI2s5+J5ITlYS5V+SV9vJcgmr6fqcEDdA3Kd17vlehm39p4ki2BnQuathGVVr7LQ9l3tV4NAKdQITftlWecqYBPvv3iQXJdwnXED2LwRoQRyJoQg9t4EQI2TY5iGrFQ0SIqiEzbGdZZhgGgW5VVI9PK2VxLLOppGU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685355465; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=7spuucBi5iS4AvrTae7OMV0+uwtFGZ0WSDSiKszP5pI=; b=XmGeY6AoukPcAh20/laf1GTdUpvBmyE6Sv5RFqw0zvN/2a1O/AGHA/Zzw1Ir366cFjrSD1Vz8ggWaBk46llvkYP+xAAia54UzINr4bsJjyZ8mr9e6OVZvSnPLmqSNWO7JW5bBkXJQtIzISIYuY/O02C7Xrg5LJduFQEopL/8//w= 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+105371+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 1685355465237565.178539819862; Mon, 29 May 2023 03:17:45 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id YQnDYY1788612x8ShlXi70iD; Mon, 29 May 2023 03:17:44 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web10.46513.1685355464268754848 for ; Mon, 29 May 2023 03:17:44 -0700 X-Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C5FD160AF5; Mon, 29 May 2023 10:17:43 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB55AC433EF; Mon, 29 May 2023 10:17:40 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Ray Ni , Jiewen Yao , Gerd Hoffmann , Taylor Beebe , Oliver Smith-Denny , Dandan Bi , Liming Gao , "Kinney, Michael D" , Leif Lindholm , Michael Kubacki Subject: [edk2-devel] [RFC PATCH 09/11] MdeModulePkg/DxeCore: Add PCD NX policy bit for default NX state Date: Mon, 29 May 2023 12:17:03 +0200 Message-Id: <20230529101705.2476949-10-ardb@kernel.org> In-Reply-To: <20230529101705.2476949-1-ardb@kernel.org> References: <20230529101705.2476949-1-ardb@kernel.org> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ardb@kernel.org X-Gm-Message-State: fCcP8dbLtthCvhjiZcyyPsh0x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685355464; bh=ejuU0qrFUmjECraugV5MWud8KMK5IjwNEMcGE1q865s=; h=Cc:Date:From:Reply-To:Subject:To; b=CwwXY1yBYsm2swDJ6KS+f9y1lDkzKraJDUUXMgfjq7/cURRLaEcvMCz/3ccqF1MfSio HxE3saybc7VLtkvLP4v2UqWmtycbiUJKnB77Q3bZrCMzt/Y2w2//6zUj3YHTItlULyL8W BOD2g+739otLcoOOD6SWNekoyZJrPwWzt28= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685355465928100005 Content-Type: text/plain; charset="utf-8" Introduce a new bit in the NX memory protection policy PCD mask that specifies that the platform enters DXE with all unused and all non-code regions mapped with non-execute permissions. This removes the need to do a pass over all memory regions to update their NX memory attributes. Signed-off-by: Ard Biesheuvel --- MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c | 7 +++++++ MdeModulePkg/MdeModulePkg.dec | 3 +++ 2 files changed, 10 insertions(+) diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c b/MdeModulePkg/C= ore/Dxe/Misc/MemoryProtection.c index 7cc829b17402c2bc..983ed450f143d62d 100644 --- a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c @@ -861,6 +861,13 @@ InitializeDxeNxMemoryProtectionPolicy ( ASSERT (StackBase !=3D 0); } =20 + // + // If the platform maps all DRAM non-execute by default, we are done her= e. + // + if ((PcdGet64 (PcdDxeNxMemoryProtectionPolicy) & BIT61) !=3D 0) { + return; + } + DEBUG (( DEBUG_INFO, "%a: applying strict permissions to active memory regions\n", diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 2d72ac733d82195e..d2bd0cbb40300889 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -1416,12 +1416,15 @@ [PcdsFixedAtBuild, PcdsPatchableInModule] # EfiMemoryMappedIOPortSpace 0x1000
# EfiPalCode 0x2000
# EfiPersistentMemory 0x4000
+ # Default state 0x2000000000000000
# OEM Reserved 0x4000000000000000
# OS Reserved 0x8000000000000000
# # NOTE: User must NOT set NX protection for EfiLoaderCode / EfiBootServi= cesCode / EfiRuntimeServicesCode.
# User MUST set the same NX protection for EfiBootServicesData and= EfiConventionalMemory.
# + # If the platform enters DXE with all unused and non-code regions mapped= NX, bit 61 should be set.
+ # # e.g. 0x7FD5 can be used for all memory except Code.
# e.g. 0x7BD4 can be used for all memory except Code and ACPINVS/Reserve= d.
# --=20 2.39.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 (#105371): https://edk2.groups.io/g/devel/message/105371 Mute This Topic: https://groups.io/mt/99197143/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- From nobody Sat May 18 20:15:36 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+105372+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+105372+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1685355468; cv=none; d=zohomail.com; s=zohoarc; b=f75uQ/Yy1QZgY8xZrTLWwxZDIGn1fKP9B7JEn3KG9q6NScrNs/wVxeVBTMAz0r0p+FC4x8KDcfKY3jnzU13DNxACa+fIOuV+PgcF1zCbBplK/cnWvej2JuQq0o6Q3uHvKuBfme5En0IYIImF9aTxYhj2/BJiFCrJw25cX3mGPuQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685355468; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=FlmGb+sufqcoJvY/3R+O3S8fl3dezZF21rWSTn/9uv0=; b=R6AzW8nUAWTRWPTej+51SurBuqcDZIZlitJejzG0sbSRn8vUry5AO24zE6MrdYh+wtjhdIzRb37SIGGUrCRdQ8DbxYyU48/PG1DTvMngT+lZN01hXjo95px/auWypE04P64ZRIbN4YmXUOBpx0OXz7PrHUX+f7B0uhDRSqEU0ao= 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+105372+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 1685355468280454.8760562298396; Mon, 29 May 2023 03:17:48 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id eGTrYY1788612xdORSfOyGk1; Mon, 29 May 2023 03:17:47 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web11.46681.1685355467141721609 for ; Mon, 29 May 2023 03:17:47 -0700 X-Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9EEAD6101A; Mon, 29 May 2023 10:17:46 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id A7362C433A0; Mon, 29 May 2023 10:17:43 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Ray Ni , Jiewen Yao , Gerd Hoffmann , Taylor Beebe , Oliver Smith-Denny , Dandan Bi , Liming Gao , "Kinney, Michael D" , Leif Lindholm , Michael Kubacki Subject: [edk2-devel] [RFC PATCH 10/11] ArmVirtPkg/ArmVirtQemu: Allow CPU arch protocol DXE to execute in place Date: Mon, 29 May 2023 12:17:04 +0200 Message-Id: <20230529101705.2476949-11-ardb@kernel.org> In-Reply-To: <20230529101705.2476949-1-ardb@kernel.org> References: <20230529101705.2476949-1-ardb@kernel.org> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ardb@kernel.org X-Gm-Message-State: hGborufYikoT1Gb1RKvNF0Cqx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685355467; bh=twzqzDUailjfXLo5cRK5THUo4G4dtpcVnVC8ViOv8fo=; h=Cc:Date:From:Reply-To:Subject:To; b=ltybl69bh0j6jvfiYR6NORmKiO9PmuUpymHNwhI9Vkr7p3gWMMjHBPm3wMAulgKOuBT zsHjaDLH4BSE3zFDfmRVMBt6K7COoDOaFjHRe7C1ZEE7uEEjgjXEiPmo+bdf7hUGGxy84 nx08KuTo71ydVI6mkRGGO2oEzG3b5mua2hk= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685355469797100003 Content-Type: text/plain; charset="utf-8" Add ArmCpuDxe and its dependencies to the APRIORI DXE section, and use a rule override to emit the executable images in a way that permits them to execute in place from the firmware volume. This allows them to be mapped with the appropriate permissions before dispatching the DXE core. Signed-off-by: Ard Biesheuvel --- ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc | 17 ++++++++++++----- ArmVirtPkg/ArmVirtRules.fdf.inc | 9 +++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc b/ArmVirtPkg/ArmVirtQemuF= vMain.fdf.inc index 8a063bac04ac287c..24d5c8dd1dc99ca6 100644 --- a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc +++ b/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc @@ -38,16 +38,23 @@ [FV.FvMain] READ_LOCK_CAP =3D TRUE READ_LOCK_STATUS =3D TRUE =20 + APRIORI DXE { + INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf + INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf + INF EmbeddedPkg/Drivers/FdtClientDxe/FdtClientDxe.inf + INF ArmPkg/Drivers/ArmGic/ArmGicDxe.inf + INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf + } INF MdeModulePkg/Core/Dxe/DxeMain.inf - INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf + INF RuleOverride=3DDXE_XIP MdeModulePkg/Universal/PCD/Dxe/Pcd.inf INF OvmfPkg/Fdt/VirtioFdtDxe/VirtioFdtDxe.inf - INF EmbeddedPkg/Drivers/FdtClientDxe/FdtClientDxe.inf + INF RuleOverride=3DDXE_XIP EmbeddedPkg/Drivers/FdtClientDxe/FdtClientDxe= .inf INF OvmfPkg/Fdt/HighMemDxe/HighMemDxe.inf =20 # # PI DXE Drivers producing Architectural Protocols (EFI Services) # - INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf + INF RuleOverride=3DDXE_XIP ArmPkg/Drivers/CpuDxe/CpuDxe.inf INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf @@ -71,7 +78,7 @@ [FV.FvMain] INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf INF MdeModulePkg/Universal/SerialDxe/SerialDxe.inf =20 - INF ArmPkg/Drivers/ArmGic/ArmGicDxe.inf + INF RuleOverride=3DDXE_XIP ArmPkg/Drivers/ArmGic/ArmGicDxe.inf INF ArmPkg/Drivers/TimerDxe/TimerDxe.inf INF OvmfPkg/VirtNorFlashDxe/VirtNorFlashDxe.inf INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf @@ -107,7 +114,7 @@ [FV.FvMain] # # Bds # - INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf + INF RuleOverride=3DDXE_XIP MdeModulePkg/Universal/DevicePathDxe/DevicePa= thDxe.inf INF MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf INF MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf INF MdeModulePkg/Universal/DriverHealthManagerDxe/DriverHealthManagerDxe= .inf diff --git a/ArmVirtPkg/ArmVirtRules.fdf.inc b/ArmVirtPkg/ArmVirtRules.fdf.= inc index b8ec040d2330deb3..0b9acc6d9031d9cf 100644 --- a/ArmVirtPkg/ArmVirtRules.fdf.inc +++ b/ArmVirtPkg/ArmVirtRules.fdf.inc @@ -79,6 +79,15 @@ [Rule.Common.DXE_DRIVER] RAW ASL Optional |.aml } =20 +[Rule.Common.DXE_DRIVER.DXE_XIP] + FILE DRIVER =3D $(NAMED_GUID) { + DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NA= ME).depex + PE32 PE32 Align =3D Auto $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING=3D"$(MODULE_NAME)" Optional + RAW ACPI Optional |.acpi + RAW ASL Optional |.aml + } + [Rule.Common.DXE_RUNTIME_DRIVER] FILE DRIVER =3D $(NAMED_GUID) { DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NA= ME).depex --=20 2.39.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 (#105372): https://edk2.groups.io/g/devel/message/105372 Mute This Topic: https://groups.io/mt/99197144/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- From nobody Sat May 18 20:15:36 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+105373+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+105373+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1685355470; cv=none; d=zohomail.com; s=zohoarc; b=Go6rOTg2ITDXAC09gyfKsh9BMfoFv40tvex6Wiru4YT0FAA0Uhdy3r6dt4ubW2sMAEjcKpxvWyxlpy5v0izDrG8zkBlyHNzQxJtrY2dlHjz9mCXxds5asFDqVRhkPTcGrwZVEbC5MM23wRKEOVDQbXH82Od/uxNc9wHWY4hIp1I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685355470; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=TxNlSL3IauNWwOA6iO3iYqc9V6EqduFQwh+Cx04aKY8=; b=Iub0tlN3IXLKS6X/BVQxM/dCb0//oPz2XXEtiA4GNhG9vvE0oZWATUdKs2vntONb8p7O2uBUHhyfABZAWO7kysLQU1YaYqijBxXjinX2g07XbWS/Iu1RAW8nImMAxz/4SpiZcEYhUpLlx16EIsx4aoHd4UaOSc9NqsYpnIgrOoU= 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+105373+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 1685355470956791.5711636562747; Mon, 29 May 2023 03:17:50 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id qMGJYY1788612xbVo1TVQdVR; Mon, 29 May 2023 03:17:50 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web10.46517.1685355469926700772 for ; Mon, 29 May 2023 03:17:50 -0700 X-Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 777F061405; Mon, 29 May 2023 10:17:49 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FB4AC4339E; Mon, 29 May 2023 10:17:46 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Ray Ni , Jiewen Yao , Gerd Hoffmann , Taylor Beebe , Oliver Smith-Denny , Dandan Bi , Liming Gao , "Kinney, Michael D" , Leif Lindholm , Michael Kubacki Subject: [edk2-devel] [RFC PATCH 11/11] ArmVirtPkg/ArmVirtQemu: Map all DRAM non-execute by default Date: Mon, 29 May 2023 12:17:05 +0200 Message-Id: <20230529101705.2476949-12-ardb@kernel.org> In-Reply-To: <20230529101705.2476949-1-ardb@kernel.org> References: <20230529101705.2476949-1-ardb@kernel.org> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ardb@kernel.org X-Gm-Message-State: C1RGPVkHi72pMdLmnzPczXqQx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685355470; bh=XhM/Clxmgq81k35lJLIAdeJ4/wCpBX6+hK5OCwZugsw=; h=Cc:Date:From:Reply-To:Subject:To; b=L6Ueqks/54mcp/y/h5S/sTrQVBbGMwdAUVOGOSQing4qWjqmyNOo8GLQlZ/V+D8qtSY Hq7j+svESlME/W656ntUyf24JNFzE8n51XXKnpWcw+kHFJg0MlcYqGAQIbrwrGRtqIAei 6kDnDxxbzts7HBmpJl7pduer/pHiVSBQAOo= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685355471503100005 Content-Type: text/plain; charset="utf-8" Now that both PEI and DXE can deal with memory being mapped non-execute by default, update the early mapping code to create non-execute mappings for all of DRAM. While at it, map the NOR flash read-only as well. Signed-off-by: Ard Biesheuvel --- ArmVirtPkg/ArmVirtQemu.dsc | 1 + ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c | 4 ++-- ArmVirtPkg/MemoryInitPei/MemoryInitPeim.inf | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc index 449e73b9e1329111..7d159f27cfea8790 100644 --- a/ArmVirtPkg/ArmVirtQemu.dsc +++ b/ArmVirtPkg/ArmVirtQemu.dsc @@ -151,6 +151,7 @@ [PcdsFeatureFlag.common] [PcdsFixedAtBuild.common] !if $(ARCH) =3D=3D AARCH64 gArmTokenSpaceGuid.PcdVFPEnabled|1 + gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy|0xE0000000= 00007FD5 !endif =20 gArmPlatformTokenSpaceGuid.PcdCPUCoresStackBase|0x4007c000 diff --git a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c b/A= rmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c index 23bd0fe68ef79d98..1ed5815989594ebd 100644 --- a/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c +++ b/ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c @@ -91,7 +91,7 @@ ArmVirtGetMemoryMap ( VirtualMemoryTable[0].PhysicalBase =3D PcdGet64 (PcdSystemMemoryBase); VirtualMemoryTable[0].VirtualBase =3D VirtualMemoryTable[0].PhysicalBas= e; VirtualMemoryTable[0].Length =3D *(UINT64 *)GET_GUID_HOB_DATA (Mem= orySizeHob); - VirtualMemoryTable[0].Attributes =3D ARM_MEMORY_REGION_ATTRIBUTE_WRITE= _BACK; + VirtualMemoryTable[0].Attributes =3D ARM_MEMORY_REGION_ATTRIBUTE_WRITE= _BACK_XP; =20 DEBUG (( DEBUG_INFO, @@ -115,7 +115,7 @@ ArmVirtGetMemoryMap ( VirtualMemoryTable[2].PhysicalBase =3D PcdGet64 (PcdFvBaseAddress); VirtualMemoryTable[2].VirtualBase =3D VirtualMemoryTable[2].PhysicalBas= e; VirtualMemoryTable[2].Length =3D FixedPcdGet32 (PcdFvSize); - VirtualMemoryTable[2].Attributes =3D ARM_MEMORY_REGION_ATTRIBUTE_WRITE= _BACK; + VirtualMemoryTable[2].Attributes =3D ARM_MEMORY_REGION_ATTRIBUTE_WRITE= _BACK_RO; =20 // End of Table ZeroMem (&VirtualMemoryTable[3], sizeof (ARM_MEMORY_REGION_DESCRIPTOR)); diff --git a/ArmVirtPkg/MemoryInitPei/MemoryInitPeim.inf b/ArmVirtPkg/Memor= yInitPei/MemoryInitPeim.inf index 2039f71a0ebecd5d..6e70bf6eaa245b7a 100644 --- a/ArmVirtPkg/MemoryInitPei/MemoryInitPeim.inf +++ b/ArmVirtPkg/MemoryInitPei/MemoryInitPeim.inf @@ -56,4 +56,4 @@ [FixedPcd] gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData =20 [Depex] - TRUE + gEdkiiMemoryAttributePpiGuid --=20 2.39.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 (#105373): https://edk2.groups.io/g/devel/message/105373 Mute This Topic: https://groups.io/mt/99197146/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-