From patchwork Mon Mar 13 09:28:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 95195 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp1016229obz; Mon, 13 Mar 2017 02:28:41 -0700 (PDT) X-Received: by 10.98.72.88 with SMTP id v85mr35824242pfa.99.1489397321078; Mon, 13 Mar 2017 02:28:41 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id n12si10955126pfb.207.2017.03.13.02.28.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Mar 2017 02:28:41 -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 8BFB6803B6; Mon, 13 Mar 2017 02:28:40 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-wr0-x22a.google.com (mail-wr0-x22a.google.com [IPv6:2a00:1450:400c:c0c::22a]) (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 EE8D1803A6 for ; Mon, 13 Mar 2017 02:28:39 -0700 (PDT) Received: by mail-wr0-x22a.google.com with SMTP id u48so99538943wrc.0 for ; Mon, 13 Mar 2017 02:28:39 -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=tEebw+oVPVtF4DEAzBKDSyPNMc0MSAFpebrph0iMNe8=; b=PtGeg6oSwbmqumVgzvMNxCefF9prsSTAYuyL8XtT1Ciu4y9uu7MV4aXjusJ3ED99MZ 0dDkANbLSkY6qxH8aebz2R/1K/SfvbZnllOXbw32FhpPXR0+T73TDcxlB46LqkOronl/ qDbG8pk3fXm+WjRvzBkn7Of5eG+rHB5U/B6q8= 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=tEebw+oVPVtF4DEAzBKDSyPNMc0MSAFpebrph0iMNe8=; b=Jydk8+nVg8C0Pqvb6Bi7u1LSApHy5HWbwBvwDvg95iPiI6vFt+msCbBtLKYGNzQYDA kNN4zwi2WPX+XVj2jV/hJx5RDCwnViMGypQXLJn+pzT9+btOZYHitnRUi4XT/6pr0+V8 LnU1Wcj0ikFeSoMJ9n+fGBnvxh6yLmdFllM0Wj356DZ3D/JoIjXJqB9AnbEUeceHLePa QgZTRLYeyguZG6W/NZZs0DnPB7vrZ+IMg0tE0BjfZd5VtzHmsYSYLZdJpw7ePEG0FOkc zEtr//czmxFJkTk+tPH42mubphAb/En2/swsKE++y3HjlPfPZACxTU0DnQ79jaqttCrf 6G3g== X-Gm-Message-State: AMke39mhlXFTs+DvE+EmGaB2pV4a23MwLgteNUdbDDfmcbiTqhuXkjYlfDfO2gAXgAwaDPX1 X-Received: by 10.223.170.200 with SMTP id i8mr30812768wrc.79.1489397318367; Mon, 13 Mar 2017 02:28:38 -0700 (PDT) Received: from localhost.localdomain ([160.169.103.157]) by smtp.gmail.com with ESMTPSA id q75sm10546830wmd.27.2017.03.13.02.28.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 13 Mar 2017 02:28:37 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, leif.lindholm@linaro.org Date: Mon, 13 Mar 2017 09:28:16 +0000 Message-Id: <1489397296-23566-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 Subject: [edk2] [PATCH] 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 --- EmbeddedPkg/Library/PrePiLib/PrePiLib.c | 34 +++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) -- 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel 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);