From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1lKl4v-000261-UW for mharc-grub-devel@gnu.org; Fri, 12 Mar 2021 11:55:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48032) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lKl4j-00022L-Hd for grub-devel@gnu.org; Fri, 12 Mar 2021 11:55:45 -0500 Received: from smtp-outgoing-1601.laposte.net ([160.92.124.96]:35457) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lKl4g-0003DD-Hf for grub-devel@gnu.org; Fri, 12 Mar 2021 11:55:45 -0500 X-mail-filterd: {"version":"1.2.2", "queueID":"4DxsPr3L4LzKm49", "contextId":"a462f069-95bd-46ec-ab34-8f3d543b8341"} Received: from outgoing-mail.laposte.net (localhost.localdomain [127.0.0.1]) by mlpnf0115.laposte.net (SMTP Server) with ESMTP id 4DxsPr3L4LzKm49; Fri, 12 Mar 2021 17:55:28 +0100 (CET) X-mail-filterd: {"version":"1.2.2", "queueID":"4DxsPr0QDZzKm46", "contextId":"cf342a11-c9b4-402d-a600-7ea0ebb97039"} X-lpn-mailing: LEGIT X-lpn-spamrating: 36 X-lpn-spamlevel: not-spam X-lpn-spamcause: OK, (-100)(0000)gggruggvucftvghtrhhoucdtuddrgeduledruddvvddgleefucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecunfetrffquffvgfdpqfgfvfdpggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufffkffogggtgfesthekredtredtjeenucfhrhhomhepgghinhgtvghnthcuufhtvghhlhoruceovhhinhgtvghnthdrshhtvghhlhgvsehlrghpohhsthgvrdhnvghtqeenucggtffrrghtthgvrhhnpeegvdeulefhheektdeufeeludeuieevfefhkedtudduteevhfeujedtkeeijefgleenucffohhmrghinhepghhithhhuhgsrdgtohhmnecukfhppeekkedruddvuddrudegledrgeelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehhvghloheprhhomhhurghlugdrsggvrhhgvghrihgvpdhinhgvthepkeekrdduvddurddugeelrdegledpmhgrihhlfhhrohhmpehvihhntggvnhhtrdhsthgvhhhlvgeslhgrphhoshhtvgdrnhgvthdprhgtphhtthhopehgrhgrnhhtrdhlihhkvghlhiesrghrmhdrtghomhdprhgtphhtthhopehgrhhusgdquggvvhgvlhesghhnuhdrohhrghdprhgtphhtthhopehvihhntggvnhhtrdhsthgvhhhlvgeslhgrphhoshhtvgdrnhgvthdprhgtphhtthhopehlvghifhdrlhhinhguhhholhhmsehlihhnrghrohdrohhrghdprhgtp hhtthhopehpjhhonhgvshesrhgvughhrghtrdgtohhm Received: from romuald.bergerie (unknown [88.121.149.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mlpnf0115.laposte.net (SMTP Server) with ESMTPSA id 4DxsPr0QDZzKm46; Fri, 12 Mar 2021 17:55:28 +0100 (CET) Received: from radicelle.bergerie (radicelle.bergerie [192.168.124.12]) by romuald.bergerie (Postfix) with ESMTPS id 7E1593FC9214; Fri, 12 Mar 2021 17:55:27 +0100 (CET) Received: from vincent by radicelle.bergerie with local (Exim 4.94) (envelope-from ) id 1lKl4R-0005qz-6r; Fri, 12 Mar 2021 17:55:27 +0100 From: =?UTF-8?q?Vincent=20Stehl=C3=A9?= To: grub-devel@gnu.org Cc: =?UTF-8?q?Vincent=20Stehl=C3=A9?= , Grant Likely , Peter Jones , Leif Lindholm Subject: [PATCH] arm/efi: fix ram base detection Date: Fri, 12 Mar 2021 17:54:55 +0100 Message-Id: <20210312165455.22346-1-vincent.stehle@laposte.net> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=laposte.net; s=lpn-wlmd; t=1615568131; bh=wNwcp4R9XlQBLAGoD32zMZNTpNl7uMbZVy49HPd/xt4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type:Content-Transfer-Encoding; b=dowtgtnifAigpLHUYCp94A9vX+rLrC/jHHtvkZchrCs8jROI9gEMD1GrfjWhsWRzCTJMtilzJrJw+k9LUKlfd+QYi9pgCsoV9gy7Ccb6QcNpbzfZHAjFDDGqQfeOkTFZ5XCER99RkhheHICmW8o8trBFqVA+kPT93bQCI3l9dzxqSLgCJXNLyQYAAq9a14lDTm9owkTlwGWuZ9hSZfuparC0LcLqgWTAm92HPLvEFK4mUq343QDgywrf0PtKIVSyMfa0HcdEuoGaRnRpdyy/nm7J/rHavKzxQ9xpjutlwKu887j1W+a8dcFhe+LpJqWrsaNxCAbiBIITxdbwRaY4WQ==; Received-SPF: pass client-ip=160.92.124.96; envelope-from=vincent.stehle@laposte.net; helo=smtp-outgoing-1601.laposte.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Mar 2021 16:55:46 -0000 On 32b Arm platforms, grub allocates memory for the initrd in the first 512MB of DRAM. To do so, the grub_efi_get_ram_base() function will be called to compute the DRAM base. Currently this function returns the lowe= st start address of all memory regions with attribute write-back. However, if for example a small memory region with type reserved and attribute write-back is present at the bottom of the memory map, it will = be chosen as DRAM base and initrd memory allocation will fail with: error: out of memory. Press any key to continue... This is indeed the case with qemu arm machine virt when the secure world = is enabled and TF-A and OP-TEE are used. The secure world firmware will reserve secure memory, resulting in the following EFI memory map: Type Physical start - end #Pages Size Attribut= es reserved 000000000e100000-000000000effffff 00000f00 15MiB WB conv-mem 0000000040000000-0000000047ef9fff 00007efa 130024KiB WB ACPI-rec 0000000047efa000-0000000047f05fff 0000000c 48KiB WB conv-mem 0000000047f06000-000000006d4f9fff 000255f4 612304KiB WB ldr-data 000000006d4fa000-000000006d4fafff 00000001 4KiB WB ... In this case, the DRAM base is computed as 0xe100000, while it should be 0x40000000 instead. Fix this issue by considering only conventional memory with attribute write-back for DRAM base computation. This is similar to what is done by Peter Jones in commit 3c1a5d940be5 ("arm/arm64 loader: Better memory allocation and error messages.") in Fedora's grub[1]. This patch reduces the modifications to a minimum. [1]: https://github.com/rhboot/grub2.git Fixes: bad144c60f66 ("efi: Add grub_efi_get_ram_base() function for arm64= ") Suggested-by: Grant Likely Signed-off-by: Vincent Stehl=C3=A9 Cc: Peter Jones Cc: Leif Lindholm --- grub-core/kern/efi/mm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c index 0cdb063bb..abf8772bc 100644 --- a/grub-core/kern/efi/mm.c +++ b/grub-core/kern/efi/mm.c @@ -677,7 +677,8 @@ grub_efi_get_ram_base(grub_addr_t *base_addr) for (desc =3D memory_map, *base_addr =3D GRUB_EFI_MAX_USABLE_ADDRESS; (grub_addr_t) desc < ((grub_addr_t) memory_map + memory_map_size)= ; desc =3D NEXT_MEMORY_DESCRIPTOR (desc, desc_size)) - if (desc->attribute & GRUB_EFI_MEMORY_WB) + if (desc->type =3D=3D GRUB_EFI_CONVENTIONAL_MEMORY && + desc->attribute & GRUB_EFI_MEMORY_WB) *base_addr =3D grub_min (*base_addr, desc->physical_start); =20 grub_free(memory_map); --=20 2.30.0