Skip to content

Commit 73effcc

Browse files
Ard Biesheuvelwildea01
Ard Biesheuvel
authored andcommitted
arm64/efi: do not assume DRAM base is aligned to 2 MB
The current arm64 Image relocation code in the UEFI stub assumes that the dram_base argument it receives is always a multiple of 2 MB. In reality, it is simply the lowest start address of all RAM entries in the UEFI memory map, which means it could be any multiple of 4 KB. Since the arm64 kernel Image needs to reside TEXT_OFFSET bytes beyond a 2 MB aligned base, or it will fail to boot, make sure we round dram_base to 2 MB before using it to calculate the relocation address. Fixes: e38457c ("arm64: efi: prefer AllocatePages() over efi_low_alloc() for vmlinux") Reported-by: Timur Tabi <timur@codeaurora.org> Tested-by: Timur Tabi <timur@codeaurora.org> Acked-by: Mark Rutland <mark.rutland@arm.com> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent 9702970 commit 73effcc

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

arch/arm64/kernel/efi-stub.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,20 @@ efi_status_t __init handle_kernel_image(efi_system_table_t *sys_table_arg,
2525
unsigned long kernel_size, kernel_memsize = 0;
2626
unsigned long nr_pages;
2727
void *old_image_addr = (void *)*image_addr;
28+
unsigned long preferred_offset;
29+
30+
/*
31+
* The preferred offset of the kernel Image is TEXT_OFFSET bytes beyond
32+
* a 2 MB aligned base, which itself may be lower than dram_base, as
33+
* long as the resulting offset equals or exceeds it.
34+
*/
35+
preferred_offset = round_down(dram_base, SZ_2M) + TEXT_OFFSET;
36+
if (preferred_offset < dram_base)
37+
preferred_offset += SZ_2M;
2838

2939
/* Relocate the image, if required. */
3040
kernel_size = _edata - _text;
31-
if (*image_addr != (dram_base + TEXT_OFFSET)) {
41+
if (*image_addr != preferred_offset) {
3242
kernel_memsize = kernel_size + (_end - _edata);
3343

3444
/*
@@ -42,7 +52,7 @@ efi_status_t __init handle_kernel_image(efi_system_table_t *sys_table_arg,
4252
* Mustang), we can still place the kernel at the address
4353
* 'dram_base + TEXT_OFFSET'.
4454
*/
45-
*image_addr = *reserve_addr = dram_base + TEXT_OFFSET;
55+
*image_addr = *reserve_addr = preferred_offset;
4656
nr_pages = round_up(kernel_memsize, EFI_ALLOC_ALIGN) /
4757
EFI_PAGE_SIZE;
4858
status = efi_call_early(allocate_pages, EFI_ALLOCATE_ADDRESS,

0 commit comments

Comments
 (0)