From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c09::241; helo=mail-wm0-x241.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wm0-x241.google.com (mail-wm0-x241.google.com [IPv6:2a00:1450:400c:c09::241]) (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 6BEE922402DE5 for ; Wed, 28 Feb 2018 07:38:44 -0800 (PST) Received: by mail-wm0-x241.google.com with SMTP id q83so5869475wme.5 for ; Wed, 28 Feb 2018 07:44:51 -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:in-reply-to:references; bh=UtqSIJ+XlQXbPzh6pxENtO9wuQtaGP2vhbm6DNRM+4E=; b=aMjCalXdHep0RrW5Ovb3CuZ7CnLRbD0DHEVPOj/zRv0KQ5SQHkNcR2MV4b7Gty8Bql dCZgIYBSE4QND7y3vgKfpXaNa8sZmP5D2bAi1SY3efmTWWWHUTymSdmrJTJ0GXj9/bhi RTec4uXEQNb/OnaWMV2Ye2A5sPgqK4E0EYLJk= 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:in-reply-to :references; bh=UtqSIJ+XlQXbPzh6pxENtO9wuQtaGP2vhbm6DNRM+4E=; b=iXwEtTrBnb8oOxRXyt+iNPdqmMDfXIyz5tOJ42pP9EI3qUD5ttdsDFq+AsbPA2SrFM EdlzQmRySW63RnYYsDf5Noat1+hiPhSGgfVdIkr5XlbgegkAn0LZYylREjOyn5zQfBV+ 0sGXY5DY433wp7rwqG29GFXNXztr/9rJETESPOebYQyANpw9T+s5xnUVDZ55RdeF6hAp gUlz59zGokaW8ylAVcDTe/gg0WUrTv69XxVNB9LubQJTWeexeZwQdAOYYqQR2PlWVYCU WTup6i2esXLPKz6i5nQo0cqIO4+kC4frVZFBLFiq67nBcrLQ0P02mqcvUI+GF3qO8fKh PM+g== X-Gm-Message-State: APf1xPAgn+P31DEBYnmxJjLjWHPTzF0SvGw5ZkrjByb1sPCEjVkD/iNJ khSacpc9a3cPn/faFiQP8MngII6Cr20= X-Google-Smtp-Source: AG47ELv+QQgTc7ExT5igprp15htGYOoBtROzt/AE8ruE7XJrwgaIgEfxZjMB27YPth5WecT8/xY1xg== X-Received: by 10.28.167.208 with SMTP id q199mr14416041wme.29.1519832690037; Wed, 28 Feb 2018 07:44:50 -0800 (PST) Received: from localhost.localdomain ([160.163.57.8]) by smtp.gmail.com with ESMTPSA id k18sm3326204wmd.4.2018.02.28.07.44.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Feb 2018 07:44:49 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Cc: leif.lindholm@linaro.org, Ard Biesheuvel Date: Wed, 28 Feb 2018 15:44:41 +0000 Message-Id: <20180228154441.10554-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180228154441.10554-1-ard.biesheuvel@linaro.org> References: <20180228154441.10554-1-ard.biesheuvel@linaro.org> Subject: [PATCH 2/2] ArmPlatformPkg/MemoryInitPeiLib: reserve rather than remove FV memory 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: , X-List-Received-Date: Wed, 28 Feb 2018 15:38:45 -0000 Instead of completely removing the memory occupied by the primary PrePi FV from the memory map, thereby making it inaccessible to the OS, mark it as boot services data. This will ensure that the memory is left untouched by the firmware, but will release it to the OS when it calls ExitBootServices(). Note that for reasons that are not entirely clear, this only works as desired if the memory allocation HOB and the resource descriptor HOB that describe the region are identical in offset and size, and so we still need to iterate over the descriptors and split them up. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c | 21 ++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c index 2feb11f21d5d..01fd028dbd55 100644 --- a/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c +++ b/ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c @@ -129,7 +129,8 @@ MemoryPeim ( 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 mark the region with the attribute non-present + // 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; @@ -145,12 +146,10 @@ MemoryPeim ( ResourceTop = NextHob.ResourceDescriptor->PhysicalStart + ResourceLength; if (PcdGet64 (PcdFdBaseAddress) == NextHob.ResourceDescriptor->PhysicalStart) { - if (SystemMemoryTop == FdTop) { - NextHob.ResourceDescriptor->ResourceAttribute = ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT; - } else { - // Create the System Memory HOB for the firmware with the non-present attribute + if (SystemMemoryTop != FdTop) { + // Create the System Memory HOB for the firmware BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, - ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT, + ResourceAttributes, PcdGet64 (PcdFdBaseAddress), PcdGet32 (PcdFdSize)); @@ -159,9 +158,9 @@ MemoryPeim ( NextHob.ResourceDescriptor->ResourceLength -= PcdGet32(PcdFdSize); } } else { - // Create the System Memory HOB for the firmware with the non-present attribute + // Create the System Memory HOB for the firmware BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, - ResourceAttributes & ~EFI_RESOURCE_ATTRIBUTE_PRESENT, + ResourceAttributes, PcdGet64 (PcdFdBaseAddress), PcdGet32 (PcdFdSize)); @@ -177,6 +176,12 @@ MemoryPeim ( ResourceTop - FdTop); } } + + // Mark the memory covering the Firmware Device as boot services data + BuildMemoryAllocationHob (PcdGet64 (PcdFdBaseAddress), + PcdGet32 (PcdFdSize), + EfiBootServicesData); + Found = TRUE; break; } -- 2.11.0