From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-x233.google.com (mail-wm0-x233.google.com [IPv6:2a00:1450:400c:c09::233]) (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 345D680292 for ; Tue, 14 Mar 2017 02:01:01 -0700 (PDT) Received: by mail-wm0-x233.google.com with SMTP id n11so58206908wma.0 for ; Tue, 14 Mar 2017 02:01:01 -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=J7033POjM9SWyZwxC2MwH0iWCtRuku8u0mknsqG6zAg=; b=NluA+cIKuB9tJ6b+DBakwhZ+xaa7CqSERqxvJA0JCPF78+7vuLru9Gu0T1qTGW5/uX naDYP77Lezm+HhIBGr+4SsrV/mnaSH67pRtDFJQqIKJPsYbVZ3gSlKMiThG3Fs91hx70 J7vzrLaZCTQAMVGU/FrlhvJFnSZVcEEtIklfs= 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=J7033POjM9SWyZwxC2MwH0iWCtRuku8u0mknsqG6zAg=; b=mY2GrLf1bSUiTf0HYJMCAHeU+/aF5j4iIRhAj/91Y7CoZCgQIc8AjRR/v+qBSiP8r8 O03tkcwBM/OHRuENjYvd52Clhsl9dqnRabAQbH0m1Lg6VrdMOwjpK9GCDRAY5gf2dVFt G1ey4geV7kWvgH/s3CwmbqFqif22fbYh+GdDyZFmVi/gmfKsh2Tj8DId8jgd7RyymIkB y62su9rE16dkayoGZ7Ql77H7dSTLvXKc13RBCuOvZUjsDzwuagJsJv9Q9UqYhSaB/whb aTFT13uFM7XVpuTP3RMKxNJXZauuD/EgQkUSfX571OJgdom48vhpcUI4hm54BCADo7RV H0tQ== X-Gm-Message-State: AFeK/H2pKkw65BA7go2Ol6jq0h/Bi+X0yYCDCWkLh0VgCad1t1YriCipKkkUShOG0ENxRonq X-Received: by 10.28.158.87 with SMTP id h84mr13921971wme.4.1489482059531; Tue, 14 Mar 2017 02:00:59 -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 v14sm12483438wmv.24.2017.03.14.02.00.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Mar 2017 02:00:58 -0700 (PDT) Date: Tue, 14 Mar 2017 09:00:57 +0000 From: Leif Lindholm To: Ard Biesheuvel Cc: edk2-devel@lists.01.org, ryan.harkin@linaro.org, sigmaepsilon92@gmail.com, lersek@redhat.com Message-ID: <20170314090057.GP16034@bivouac.eciton.net> References: <1489478464-5737-1-git-send-email-ard.biesheuvel@linaro.org> MIME-Version: 1.0 In-Reply-To: <1489478464-5737-1-git-send-email-ard.biesheuvel@linaro.org> 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 09:01:01 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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. > > #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. > + } > + > + 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