From nobody Thu Mar 28 19:16:06 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1514908247134300.6237196764861; Tue, 2 Jan 2018 07:50:47 -0800 (PST) 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) 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) 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) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.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 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-Google-Smtp-Source: ACJfBovg+yNMRS4XsjTFg9qjiNDEMJKki09NF69Sq+KWWBeEFogi1NnTHKVKTpGES2bk/szMJkFG/w== X-Received: by 10.28.27.206 with SMTP id b197mr38597294wmb.96.1514908241709; Tue, 02 Jan 2018 07:50:41 -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 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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(+) diff --git a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c b/ArmPlatformP= kg/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; =20 // Get Virtual Memory Map from the Platform Library @@ -117,6 +121,76 @@ MemoryPeim ( ); } =20 + // + // Reserve the memory space occupied by the firmware volume + // + + SystemMemoryTop =3D (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdSystemMemoryBase)= + (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdSystemMemorySize); + FdTop =3D (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFdBaseAddress) + (EFI_PHYSI= CAL_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 fo= r the region, + // but this only works if we split off the underlying resource descripto= r as well. + if ((PcdGet64 (PcdFdBaseAddress) >=3D PcdGet64 (PcdSystemMemoryBase)) &&= (FdTop <=3D SystemMemoryTop)) { + Found =3D FALSE; + + // Search for System Memory Hob that contains the firmware + NextHob.Raw =3D GetHobList (); + while ((NextHob.Raw =3D GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, = NextHob.Raw)) !=3D NULL) { + if ((NextHob.ResourceDescriptor->ResourceType =3D=3D EFI_RESOURCE_SY= STEM_MEMORY) && + (PcdGet64 (PcdFdBaseAddress) >=3D NextHob.ResourceDescriptor->Ph= ysicalStart) && + (FdTop <=3D NextHob.ResourceDescriptor->PhysicalStart + NextHob.= ResourceDescriptor->ResourceLength)) + { + ResourceAttributes =3D NextHob.ResourceDescriptor->ResourceAttribu= te; + ResourceLength =3D NextHob.ResourceDescriptor->ResourceLength; + ResourceTop =3D NextHob.ResourceDescriptor->PhysicalStart + Resour= ceLength; + + if (PcdGet64 (PcdFdBaseAddress) =3D=3D NextHob.ResourceDescriptor-= >PhysicalStart) { + if (SystemMemoryTop !=3D 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 +=3D PcdGet32(PcdFdS= ize); + NextHob.ResourceDescriptor->ResourceLength -=3D PcdGet32(PcdFd= Size); + } + } 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 =3D PcdGet64 (PcdFdBa= seAddress) - NextHob.ResourceDescriptor->PhysicalStart; + + // If there is some memory available on the top of the FD then c= reate a HOB + if (FdTop < NextHob.ResourceDescriptor->PhysicalStart + Resource= Length) { + // 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 d= ata + BuildMemoryAllocationHob (PcdGet64 (PcdFdBaseAddress), + PcdGet32 (PcdFdSize), + EfiBootServicesData); + + Found =3D TRUE; + break; + } + NextHob.Raw =3D GET_NEXT_HOB (NextHob); + } + + ASSERT(Found); + } + // Build Memory Allocation Hob InitMmu (MemoryTable); =20 --=20 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel