Skip to content

Commit f7b2bdb

Browse files
author
Ard Biesheuvel
committed
arm64: don't map TEXT_OFFSET bytes below the kernel if we can avoid it
For historical reasons, the kernel Image must be loaded into physical memory at a 512 KB offset above a 2 MB aligned base address. The region between the base address and the start of the kernel Image has no significance to the kernel itself, but it is currently mapped explicitly into the early kernel VMA range for all translation granules. In some cases (i.e., 4 KB granule), this is unavoidable, due to the 2 MB granularity of the early kernel mappings. However, in other cases, e.g., when running with larger page sizes, or in the future, with more granular KASLR, there is no reason to map it explicitly like we do currently. So update the logic so that the region is mapped only if that happens as a side effect of rounding the start address of the kernel to swapper block size, and leave it unmapped otherwise. Since the symbol kernel_img_size now simply resolves to the memory footprint of the kernel Image, we can drop its definition from image.h and opencode its calculation. Acked-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Will Deacon <will.deacon@arm.com> (cherry picked from commit 18b9c0d641938242d8bcdba3c14a8f2beec2a97e) Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
1 parent 6a8cdd6 commit f7b2bdb

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

arch/arm64/kernel/head.S

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,13 @@ __create_page_tables:
391391
* Map the kernel image (starting with PHYS_OFFSET).
392392
*/
393393
mov x0, x26 // swapper_pg_dir
394-
mov_q x5, KIMAGE_VADDR
394+
mov_q x5, KIMAGE_VADDR + TEXT_OFFSET // compile time __va(_text)
395395
add x5, x5, x23 // add KASLR displacement
396396
create_pgd_entry x0, x5, x3, x6
397-
ldr w6, =kernel_img_size
398-
add x6, x6, x5
399-
mov x3, x24 // phys offset
397+
adrp x6, _end // runtime __pa(_end)
398+
adrp x3, _text // runtime __pa(_text)
399+
sub x6, x6, x3 // _end - _text
400+
add x6, x6, x5 // runtime __va(_end)
400401
create_block_map x0, x7, x3, x5, x6
401402

402403
/*

arch/arm64/kernel/image.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@
7171
DEFINE_IMAGE_LE64(_kernel_offset_le, TEXT_OFFSET); \
7272
DEFINE_IMAGE_LE64(_kernel_flags_le, __HEAD_FLAGS);
7373

74-
kernel_img_size = _end - (_text - TEXT_OFFSET);
75-
7674
#ifdef CONFIG_EFI
7775

7876
__efistub_stext_offset = stext - _text;

0 commit comments

Comments
 (0)