From patchwork Tue Jan 2 15:50:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 123151 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp9112017qgn; Tue, 2 Jan 2018 07:50:46 -0800 (PST) X-Google-Smtp-Source: ACJfBovH7HlDj5zhxAC1YD6elwgN9N5PEkGYgF3Zy7AC56IlP5bhBM7kEQk+53S3ubKPH9BsirdY X-Received: by 10.101.91.195 with SMTP id o3mr28030440pgr.215.1514908246291; Tue, 02 Jan 2018 07:50:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514908246; cv=none; d=google.com; s=arc-20160816; b=NIyC6DZiM7umPghwyRqgpXY7jYKBO9NGfGyL+zKxBtlKTfhOyK/HS3CvjUaD2qXC+M 10aRPjO8mdYDrD/37PH+Q3IjW1uabhl5s1JwiKg+OHzPoGmSYX2k8+A6OX4FuJkPEOgC fxq35NsB6P99czRSRzX5nAjWF2CQWZHCl4bU3paOCkHKHoeMRxI4dwrKFmKTLPs411ik q6xnauGriYM/CKBsvrIpIiHlIgNC+oaT58WPfzxDEk4tOb2gYbWTgRF0108EUOmeG8qq uNUEmMKWAM8N5ghBCKRXTnqyuDT1fXAxztZoNi7gPIzrmt2eqBhzBIUntJrp1Q3cqWOI 5srA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=6vyZ+mGfij/ExW/0XYMZrquq+W72NlODuTOBbfThufc=; b=KnIVBLdAUhVl8EQsqYHhWO1kvpTen1sBVk44mTZEwTuMJfKOVYwG32NgZW87AhKuQk v9BBQeP5ODRiChIMA9hkpWYOxf6ID9ShC2Y1m/xrQZ1S24w1PszJu2o/KCTnxtMZAFpR TqUG297syXIGyfqnylUadwQfNyIiaBjZktf40/vArTCZqhiQKIdJCzdPgoC7qR2VFrY3 Gktk8BggoBJ1NC1CT/r1mLoS7Jfn6pW/br4bm+weMX4vJppBKg4DR1t2rjvXTY2I83CE hPlYD1qWPuY6L8+Ek8cI3aa/9gOYsZKfjIKoUYqGn0p6STcEcQ9/nBqL9TvCxxFgdZbt KUtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=O3fPvRgo; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id i1si34091525pld.759.2018.01.02.07.50.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jan 2018 07:50:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=O3fPvRgo; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 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 04FCB221DB2AA; Tue, 2 Jan 2018 07:45:43 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c09::242; helo=mail-wm0-x242.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wm0-x242.google.com (mail-wm0-x242.google.com [IPv6:2a00:1450:400c:c09::242]) (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 A08102205BEB5 for ; Tue, 2 Jan 2018 07:45:41 -0800 (PST) Received: by mail-wm0-x242.google.com with SMTP id y82so16769578wmg.1 for ; Tue, 02 Jan 2018 07:50:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=tzEyFL0tHmQ+Q5/HyCYn5M89TWrHVjWN5631nFjvUdQ=; b=O3fPvRgo+4zeqYiXgHdO25zkUF2j4TkLhvDgQTyYsWrpj3GaKvVnhZgWbGv0zO35cz 858DHCP+YuJ7HMvO7ZA7JZXgCiGhEu7fUKzaxRBDiJhIFKSsG/ajBm61jyZHuAEDtBYd fU0k/8WWbNfLox8MIz3BdYC93qz36UPuUZ3XI= 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=tzEyFL0tHmQ+Q5/HyCYn5M89TWrHVjWN5631nFjvUdQ=; b=UoMv8YNDuB+WUh8CCQBLy43mj0Egb7If4yM554jPULHWxEPARH4qGotWG4Ph1M3nJ2 Esy8m/w9BR5J9Al1hnRBP4xZxGMV8Z7T++eDZq4ZV7a+A9uND3EDLRAR3IYn/MrH3xda MguZPi57lU0KQblfjqP9j/jyGBZ+5j5qcPgz0l2viJVDcoLrY8vCh6audBvK6PmJBuA3 u9Ue/Zir0vwSe6nQH3Yb3C66PUL4Tg1bA2kLOySB5yooZFEjE3Uf7CTRN2NIVH+M1bo0 aBP6pFplfH/hf0hCbvdOSfw3xb6jjga7Ux7JycJmRMaYb0KPdDRgdA2yx0vUSMca5zc3 0+xA== X-Gm-Message-State: AKGB3mKVikpW9llDcUjWbuuLxDcRrLUjRdHLLKZwyM8uJyeM1R8vZofM skVPXOXHB5dl5YR2/qD5Qyg+WcW9/KA= X-Received: by 10.28.27.206 with SMTP id b197mr38597294wmb.96.1514908241709; Tue, 02 Jan 2018 07:50:41 -0800 (PST) Received: from localhost.localdomain ([160.89.138.198]) by smtp.gmail.com with ESMTPSA id c53sm63772360wrg.10.2018.01.02.07.50.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jan 2018 07:50:40 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Tue, 2 Jan 2018 15:50:34 +0000 Message-Id: <20180102155034.13688-1-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 Subject: [edk2] [PATCH] ArmPlatformPkg/MemoryInitPeiLib: mark primary FV region as boot services data X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel , vladimir.olovyannikov@broadcom.com, leif.lindholm@linaro.org MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" Commit 8ae5fc182941 ("ArmPlatformPkg/MemoryInitPeiLib: don't reserve primary FV in memory") deleted the code that removes the memory covering the primary firmware volume from the memory map. The assumption was that this is no longer necessary now that we no longer expose compression and PE/COFF loader library code from the PrePi module to DXE core. However, the FV is still declared, and so code may attempt to access it anyway, which may cause unexpected results depending on whether the memory has been reused for other purposes in the mean time. So reinstate the code that splits off the resource descriptor HOB that describes the firmware device, but this time, don't mark the memory as unusable, but create a memory allocation HOB that marks the region as boot services data. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- Vladimir, Udit, Meenakshi: please confirm whether this code works for you. ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c | 74 ++++++++++++++++++++ 1 file changed, 74 insertions(+) -- 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c index d03214b5df66..d1b5c0be9497 100644 --- a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c +++ b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c @@ -70,7 +70,11 @@ MemoryPeim ( { ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable; EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes; + UINT64 ResourceLength; EFI_PEI_HOB_POINTERS NextHob; + EFI_PHYSICAL_ADDRESS FdTop; + EFI_PHYSICAL_ADDRESS SystemMemoryTop; + EFI_PHYSICAL_ADDRESS ResourceTop; BOOLEAN Found; // Get Virtual Memory Map from the Platform Library @@ -117,6 +121,76 @@ MemoryPeim ( ); } + // + // Reserve the memory space occupied by the firmware volume + // + + SystemMemoryTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdSystemMemoryBase) + (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdSystemMemorySize); + FdTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFdBaseAddress) + (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFdSize); + + // EDK2 does not have the concept of boot firmware copied into DRAM. To avoid the DXE + // core to overwrite this area we must create a memory allocation HOB for the region, + // but this only works if we split off the underlying resource descriptor as well. + if ((PcdGet64 (PcdFdBaseAddress) >= PcdGet64 (PcdSystemMemoryBase)) && (FdTop <= SystemMemoryTop)) { + Found = FALSE; + + // Search for System Memory Hob that contains the firmware + NextHob.Raw = GetHobList (); + while ((NextHob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, NextHob.Raw)) != NULL) { + if ((NextHob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) && + (PcdGet64 (PcdFdBaseAddress) >= NextHob.ResourceDescriptor->PhysicalStart) && + (FdTop <= NextHob.ResourceDescriptor->PhysicalStart + NextHob.ResourceDescriptor->ResourceLength)) + { + ResourceAttributes = NextHob.ResourceDescriptor->ResourceAttribute; + ResourceLength = NextHob.ResourceDescriptor->ResourceLength; + ResourceTop = NextHob.ResourceDescriptor->PhysicalStart + ResourceLength; + + if (PcdGet64 (PcdFdBaseAddress) == NextHob.ResourceDescriptor->PhysicalStart) { + if (SystemMemoryTop != FdTop) { + // Create the System Memory HOB for the firmware with the non-present attribute + BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, + ResourceAttributes, + PcdGet64 (PcdFdBaseAddress), + PcdGet32 (PcdFdSize)); + + // Top of the FD is system memory available for UEFI + NextHob.ResourceDescriptor->PhysicalStart += PcdGet32(PcdFdSize); + NextHob.ResourceDescriptor->ResourceLength -= PcdGet32(PcdFdSize); + } + } else { + // Create the System Memory HOB for the firmware + BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, + ResourceAttributes, + PcdGet64 (PcdFdBaseAddress), + PcdGet32 (PcdFdSize)); + + // Update the HOB + NextHob.ResourceDescriptor->ResourceLength = PcdGet64 (PcdFdBaseAddress) - NextHob.ResourceDescriptor->PhysicalStart; + + // If there is some memory available on the top of the FD then create a HOB + if (FdTop < NextHob.ResourceDescriptor->PhysicalStart + ResourceLength) { + // Create the System Memory HOB for the remaining region (top of the FD) + BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, + ResourceAttributes, + FdTop, + ResourceTop - FdTop); + } + } + + // Mark the memory covering the Firmware Device as boot services data + BuildMemoryAllocationHob (PcdGet64 (PcdFdBaseAddress), + PcdGet32 (PcdFdSize), + EfiBootServicesData); + + Found = TRUE; + break; + } + NextHob.Raw = GET_NEXT_HOB (NextHob); + } + + ASSERT(Found); + } + // Build Memory Allocation Hob InitMmu (MemoryTable);