Skip to content

Commit 41cd96f

Browse files
Ard Biesheuvelingomolnar
authored andcommitted
efi: libstub/arm: Account for firmware reserved memory at the base of RAM
The EFI stubloader for ARM starts out by allocating a 32 MB window at the base of RAM, in order to ensure that the decompressor (which blindly copies the uncompressed kernel into that window) does not overwrite other allocations that are made while running in the context of the EFI firmware. In some cases, (e.g., U-Boot running on the Raspberry Pi 2), this is causing boot failures because this initial allocation conflicts with a page of reserved memory at the base of RAM that contains the SMP spin tables and other pieces of firmware data and which was put there by the bootloader under the assumption that the TEXT_OFFSET window right below the kernel is only used partially during early boot, and will be left alone once the memory reservations are processed and taken into account. So let's permit reserved memory regions to exist in the region starting at the base of RAM, and ending at TEXT_OFFSET - 5 * PAGE_SIZE, which is the window below the kernel that is not touched by the early boot code. Tested-by: Guillaume Gardet <Guillaume.Gardet@arm.com> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Acked-by: Chester Lin <clin@suse.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-efi@vger.kernel.org Link: https://lkml.kernel.org/r/20191029173755.27149-5-ardb@kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 18b915a commit 41cd96f

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

‎drivers/firmware/efi/libstub/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ lib-$(CONFIG_EFI_ARMSTUB) += arm-stub.o fdt.o string.o random.o \
5252

5353
lib-$(CONFIG_ARM) += arm32-stub.o
5454
lib-$(CONFIG_ARM64) += arm64-stub.o
55+
CFLAGS_arm32-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET)
5556
CFLAGS_arm64-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET)
5657

5758
#

‎drivers/firmware/efi/libstub/arm32-stub.c‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
195195
unsigned long dram_base,
196196
efi_loaded_image_t *image)
197197
{
198+
unsigned long kernel_base;
198199
efi_status_t status;
199200

200201
/*
@@ -204,9 +205,18 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
204205
* loaded. These assumptions are made by the decompressor,
205206
* before any memory map is available.
206207
*/
207-
dram_base = round_up(dram_base, SZ_128M);
208+
kernel_base = round_up(dram_base, SZ_128M);
208209

209-
status = reserve_kernel_base(sys_table, dram_base, reserve_addr,
210+
/*
211+
* Note that some platforms (notably, the Raspberry Pi 2) put
212+
* spin-tables and other pieces of firmware at the base of RAM,
213+
* abusing the fact that the window of TEXT_OFFSET bytes at the
214+
* base of the kernel image is only partially used at the moment.
215+
* (Up to 5 pages are used for the swapper page tables)
216+
*/
217+
kernel_base += TEXT_OFFSET - 5 * PAGE_SIZE;
218+
219+
status = reserve_kernel_base(sys_table, kernel_base, reserve_addr,
210220
reserve_size);
211221
if (status != EFI_SUCCESS) {
212222
pr_efi_err(sys_table, "Unable to allocate memory for uncompressed kernel.\n");
@@ -220,7 +230,7 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table,
220230
*image_size = image->image_size;
221231
status = efi_relocate_kernel(sys_table, image_addr, *image_size,
222232
*image_size,
223-
dram_base + MAX_UNCOMP_KERNEL_SIZE, 0);
233+
kernel_base + MAX_UNCOMP_KERNEL_SIZE, 0);
224234
if (status != EFI_SUCCESS) {
225235
pr_efi_err(sys_table, "Failed to relocate kernel.\n");
226236
efi_free(sys_table, *reserve_size, *reserve_addr);

0 commit comments

Comments
 (0)