From patchwork Tue Mar 14 08:01:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 95279 Delivered-To: patch@linaro.org Received: by 10.140.89.134 with SMTP id v6csp146259qgd; Tue, 14 Mar 2017 01:01:14 -0700 (PDT) X-Received: by 10.84.174.4 with SMTP id q4mr53700073plb.35.1489478474810; Tue, 14 Mar 2017 01:01:14 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id b1si14015948pfc.192.2017.03.14.01.01.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Mar 2017 01:01:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 4133F8033C; Tue, 14 Mar 2017 01:01:14 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-wr0-x22e.google.com (mail-wr0-x22e.google.com [IPv6:2a00:1450:400c:c0c::22e]) (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 CC8C5802A5 for ; Tue, 14 Mar 2017 01:01:12 -0700 (PDT) Received: by mail-wr0-x22e.google.com with SMTP id l37so118384909wrc.1 for ; Tue, 14 Mar 2017 01:01:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=BhtiWMd5S96t+Zpnd/sW28vNKUi0deuD2mEFljPpbPo=; b=OQlh7OQo+qCSgMoIqpFEUEX8kcp4DHcPfZb4350yFudvIPBz7ZnO1kzOhd7Wq8c0fJ 6X1/7uu+RF1krKb90myAEC+sT7sijRwGG3yY3p9Bp+b4HwLFFS3fRj+xHSqUV9Uwu2k6 eOXZ95ZkbvxCi23Iu2fukLCAjMyv+qCVRCN1Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=BhtiWMd5S96t+Zpnd/sW28vNKUi0deuD2mEFljPpbPo=; b=saSC+De1cmY7pR8He4Jxf8UaSVQvbVgh67GVkvmDzuxnpwWdWkXk5W6H8NYpQF6dXK sZPVILEmqqO4LxeosYPVXSetB7Akaya1siBrp82H/5ZdNSI4vzRmRdvtuiOgxBXjWOKA 32tbcx7dkbEM+wuQZRefzAoJffON2W+2/Mv0Tysej4lM0hPepRE4NS2+qTHgO/VuWexM Vy9w443FTuIQ3hV1tyNoQ+HqL1ckFmP71u4FRp7c3qxAJcnvXqWz9lY2ZK4XuBsn2cCt 9jX92hebO74ZK+EZIg3FQLNa1RfYpv/HLGOUyCdUVAW44Hw3C9rWEbKYfPMc0jEWj5i6 B95w== X-Gm-Message-State: AMke39n2HUJrD95y9mecU1yxmMBzzbwzATjODZGt9a5qqWoOUsTmwCNvbfdFRdHvw0jAWBN+ X-Received: by 10.223.155.135 with SMTP id d7mr29169323wrc.99.1489478470978; Tue, 14 Mar 2017 01:01:10 -0700 (PDT) Received: from localhost.localdomain ([197.130.229.126]) by smtp.gmail.com with ESMTPSA id p93sm27974450wrc.67.2017.03.14.01.01.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 14 Mar 2017 01:01:10 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, leif.lindholm@linaro.org Date: Tue, 14 Mar 2017 08:01:04 +0000 Message-Id: <1489478464-5737-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 Subject: [edk2] [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: , Cc: ryan.harkin@linaro.org, sigmaepsilon92@gmail.com, lersek@redhat.com, Ard Biesheuvel MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" 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(-) -- 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Reviewed-by: Leif Lindholm 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 #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); + } + + 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);