Skip to content

Commit 9d2d75e

Browse files
Gavin Shanwilldeacon
authored andcommitted
arm64/kernel: Fix range on invalidating dcache for boot page tables
Prior to commit 8eb7e28 ("arm64/mm: move runtime pgds to rodata"), idmap_pgd_dir, tramp_pg_dir, reserved_ttbr0, swapper_pg_dir, and init_pg_dir were contiguous at the end of the kernel image. The maintenance at the end of __create_page_tables assumed these were contiguous, and affected everything from the start of idmap_pg_dir to the end of init_pg_dir. That commit moved all but init_pg_dir into the .rodata section, with other data placed between idmap_pg_dir and init_pg_dir, but did not update the maintenance. Hence the maintenance is performed on much more data than necessary (but as the bootloader previously made this clean to the PoC there is no functional problem). As we only alter idmap_pg_dir, and init_pg_dir, we only need to perform maintenance for these. As the other dirs are in .rodata, the bootloader will have initialised them as expected and cleaned them to the PoC. The kernel will initialize them as necessary after enabling the MMU. This patch reworks the maintenance to only cover the idmap_pg_dir and init_pg_dir to avoid this unnecessary work. Signed-off-by: Gavin Shan <[email protected]> Reviewed-by: Mark Rutland <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent cfa7ede commit 9d2d75e

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

arch/arm64/include/asm/pgtable.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ extern pgd_t init_pg_dir[PTRS_PER_PGD];
457457
extern pgd_t init_pg_end[];
458458
extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
459459
extern pgd_t idmap_pg_dir[PTRS_PER_PGD];
460+
extern pgd_t idmap_pg_end[];
460461
extern pgd_t tramp_pg_dir[PTRS_PER_PGD];
461462

462463
extern void set_swapper_pgd(pgd_t *pgdp, pgd_t pgd);

arch/arm64/kernel/head.S

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,13 +393,19 @@ SYM_FUNC_START_LOCAL(__create_page_tables)
393393

394394
/*
395395
* Since the page tables have been populated with non-cacheable
396-
* accesses (MMU disabled), invalidate the idmap and swapper page
397-
* tables again to remove any speculatively loaded cache lines.
396+
* accesses (MMU disabled), invalidate those tables again to
397+
* remove any speculatively loaded cache lines.
398398
*/
399+
dmb sy
400+
399401
adrp x0, idmap_pg_dir
402+
adrp x1, idmap_pg_end
403+
sub x1, x1, x0
404+
bl __inval_dcache_area
405+
406+
adrp x0, init_pg_dir
400407
adrp x1, init_pg_end
401408
sub x1, x1, x0
402-
dmb sy
403409
bl __inval_dcache_area
404410

405411
ret x28

arch/arm64/kernel/vmlinux.lds.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ SECTIONS
133133

134134
idmap_pg_dir = .;
135135
. += IDMAP_DIR_SIZE;
136+
idmap_pg_end = .;
136137

137138
#ifdef CONFIG_UNMAP_KERNEL_AT_EL0
138139
tramp_pg_dir = .;

0 commit comments

Comments
 (0)