From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-x235.google.com (mail-wr0-x235.google.com [IPv6:2a00:1450:400c:c0c::235]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id A50FF803E0 for ; Tue, 14 Mar 2017 03:45:25 -0700 (PDT) Received: by mail-wr0-x235.google.com with SMTP id u108so120998601wrb.3 for ; Tue, 14 Mar 2017 03:45:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=NTfUgzkoPuY0GxwJ5hTl15TPk0NK2nwH+LufuDdSIhs=; b=U4P8ZYATGmGs0NUv9taFQ/snE8WQH0rrZdcMvEYXgmeceqQnzKCFVHIwCxSiaOWxgB Dstvoqs7CdmVS/BVCle+/pUcSfNA2qwcrirWF9ay7Nd5w59BHaqaVZlWYcHeH1Gl1ZBe /JvZdwFlHNcNSTZdu6B8cs+Qv0g9ciChWJbDM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=NTfUgzkoPuY0GxwJ5hTl15TPk0NK2nwH+LufuDdSIhs=; b=cQK5KmNEnv1XAgUDANrZeHzwRSXadtfpcCbMmT3KyExMRCuC+NJbkIzRCKYldK6Oth uB3wIUmBlFxagX0cZJShLsUjUFxdds/A9e+W9YFNUzjpLNp0nX4ZGtgL0Nmvhctp4iDF BhSSiaCP2lTnFyr2UEgizaPurF8R4n4ZgzY2ZzZeIksLNAw3CC+NcLYtQV93BuSlfpER EfqcPaovQDiKZY2bHN+vKt5NlZmc/dyhZ8BLjb3vxtFLWxLzgXcKZjlyQ9XInx4ErYR7 aslW4LWbc5ASaTDmunrLYMyn4H1GyjjCfzGwVgqM6cE/wbWx7rqLONuilB+bJgsioez1 7cmA== X-Gm-Message-State: AMke39nVWm129bbKJs/kKu3tlcwNSe0vMtOZU7UwIwTHyCyaONIABJrINYPuDihcJsryDENf X-Received: by 10.223.139.154 with SMTP id o26mr30758339wra.56.1489488324209; Tue, 14 Mar 2017 03:45:24 -0700 (PDT) Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id y1sm14875623wme.15.2017.03.14.03.45.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Mar 2017 03:45:23 -0700 (PDT) Date: Tue, 14 Mar 2017 10:45:21 +0000 From: Leif Lindholm To: Ard Biesheuvel Cc: "edk2-devel@lists.01.org" , Ryan Harkin , Michael Zimmermann , Laszlo Ersek Message-ID: <20170314104521.GQ16034@bivouac.eciton.net> References: <1489478464-5737-1-git-send-email-ard.biesheuvel@linaro.org> <20170314090057.GP16034@bivouac.eciton.net> MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Subject: Re: [PATCH v2] EmbeddedPkg/PrePiLib: allocate code pages for DxeCore 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, 14 Mar 2017 10:45:26 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Mar 14, 2017 at 09:03:43AM +0000, Ard Biesheuvel wrote: > On 14 March 2017 at 09:00, Leif Lindholm wrote: > > On Tue, Mar 14, 2017 at 08:01:04AM +0000, Ard Biesheuvel wrote: > >> The recently introduced memory protection features inadvertently broke > >> the boot on all PrePi platforms, because the changes to explicitly use > >> EfiBootServicesCode for loading the DxeCore PE/COFF image need to be > >> applied in a different way for PrePi. So add a simple helper function > >> that sets the type of an allocation to EfiBootServicesCode, and invoke > >> it to allocate the space for DxeCore. > >> > >> Contributed-under: TianoCore Contribution Agreement 1.0 > >> Signed-off-by: Ard Biesheuvel > >> Tested-by: Michael Zimmermann > >> --- > >> v2: add missing MemoryAllocationLib.h include > >> add Michael's T/b > >> > >> EmbeddedPkg/Library/PrePiLib/PrePi.h | 1 + > >> EmbeddedPkg/Library/PrePiLib/PrePiLib.c | 34 +++++++++++++++++++- > >> 2 files changed, 34 insertions(+), 1 deletion(-) > >> > >> diff --git a/EmbeddedPkg/Library/PrePiLib/PrePi.h b/EmbeddedPkg/Library/PrePiLib/PrePi.h > >> index 607561cd2496..84eca23ec8a6 100644 > >> --- a/EmbeddedPkg/Library/PrePiLib/PrePi.h > >> +++ b/EmbeddedPkg/Library/PrePiLib/PrePi.h > >> @@ -28,6 +28,7 @@ > >> #include > >> #include > >> #include > >> +#include > > > > Mandatory "don't need to fix sorting, but at least don't make it > > worse" comment. Can be folded in. > > Yeah, I pondered this for a while an gave up. I can just fix it > entirely if you prefer. Well, it's shuffled all over the place, so for now I'm just looking for a continuous improvement :) In this case, moving one or two lines up is equivalent. / Leif > >> > >> #include > >> > >> diff --git a/EmbeddedPkg/Library/PrePiLib/PrePiLib.c b/EmbeddedPkg/Library/PrePiLib/PrePiLib.c > >> index 9a1ef344df6e..bba8e7384edc 100644 > >> --- a/EmbeddedPkg/Library/PrePiLib/PrePiLib.c > >> +++ b/EmbeddedPkg/Library/PrePiLib/PrePiLib.c > >> @@ -28,6 +28,38 @@ SecWinNtPeiLoadFile ( > >> IN EFI_PHYSICAL_ADDRESS *EntryPoint > >> ); > >> > >> +STATIC > >> +VOID* > >> +EFIAPI > >> +AllocateCodePages ( > >> + IN UINTN Pages > >> + ) > >> +{ > >> + VOID *Alloc; > >> + EFI_PEI_HOB_POINTERS Hob; > >> + > >> + Alloc = AllocatePages (Pages); > >> + if (Alloc == NULL) { > >> + return NULL; > >> + } > >> + > >> + // find the HOB we just created, and change the type to EfiBootServicesCode > >> + Hob.Raw = GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION); > >> + while (Hob.Raw != NULL) { > >> + if (Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress == (UINTN)Alloc) { > >> + Hob.MemoryAllocation->AllocDescriptor.MemoryType = EfiBootServicesCode; > >> + return Alloc; > >> + } > >> + Hob.Raw = GET_NEXT_HOB (Hob); > >> + Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw); > > > > I've seen this written elsewhere as > > Hob.Raw = GetNextHob (EFI_HOB_TYPE_XXX, GET_NEXT_HOB (Hob)); > > > > Which looks like a nicer pattern to me. (And means I only need to read > > "hob" 5 times instead of 7.) > > > > Fold in if you agree. > > > > OK. I copied this from PrePiMemoryAllocationLib, but I agree that your > suggestion is better. > > >> + } > >> + > >> + ASSERT (FALSE); > >> + > >> + FreePages (Alloc, Pages); > >> + return NULL; > >> +} > >> + > >> > >> EFI_STATUS > >> EFIAPI > >> @@ -54,7 +86,7 @@ LoadPeCoffImage ( > >> // > >> // Allocate Memory for the image > >> // > >> - Buffer = AllocatePages (EFI_SIZE_TO_PAGES((UINT32)ImageContext.ImageSize)); > >> + Buffer = AllocateCodePages (EFI_SIZE_TO_PAGES((UINT32)ImageContext.ImageSize)); > >> ASSERT (Buffer != 0); > >> > >> > >> -- > >> 2.7.4 > > > > Reviewed-by: Leif Lindholm > >