Skip to content

Commit 5fbc49c

Browse files
ardbiesheuvelwilldeacon
authored andcommitted
arm64: mm: Reserve enough pages for the initial ID map
The logic that conditionally allocates one additional page at each swapper page table level if KASLR is enabled is also applied to the initial ID map, now that we have started using the same set of macros to allocate the space for it. However, the placement of the kernel in physical memory might result in additional pages being needed at any level, even if KASLR is disabled in the build. So account for this in the computation. Fixes: c3cee92 ("arm64: head: cover entire kernel image in initial ID map") Signed-off-by: Ard Biesheuvel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 6bb0d64 commit 5fbc49c

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

arch/arm64/include/asm/kernel-pgtable.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,36 +64,36 @@
6464
#define EARLY_KASLR (0)
6565
#endif
6666

67-
#define EARLY_ENTRIES(vstart, vend, shift) \
68-
((((vend) - 1) >> (shift)) - ((vstart) >> (shift)) + 1 + EARLY_KASLR)
67+
#define EARLY_ENTRIES(vstart, vend, shift, add) \
68+
((((vend) - 1) >> (shift)) - ((vstart) >> (shift)) + 1 + add)
6969

70-
#define EARLY_PGDS(vstart, vend) (EARLY_ENTRIES(vstart, vend, PGDIR_SHIFT))
70+
#define EARLY_PGDS(vstart, vend, add) (EARLY_ENTRIES(vstart, vend, PGDIR_SHIFT, add))
7171

7272
#if SWAPPER_PGTABLE_LEVELS > 3
73-
#define EARLY_PUDS(vstart, vend) (EARLY_ENTRIES(vstart, vend, PUD_SHIFT))
73+
#define EARLY_PUDS(vstart, vend, add) (EARLY_ENTRIES(vstart, vend, PUD_SHIFT, add))
7474
#else
75-
#define EARLY_PUDS(vstart, vend) (0)
75+
#define EARLY_PUDS(vstart, vend, add) (0)
7676
#endif
7777

7878
#if SWAPPER_PGTABLE_LEVELS > 2
79-
#define EARLY_PMDS(vstart, vend) (EARLY_ENTRIES(vstart, vend, SWAPPER_TABLE_SHIFT))
79+
#define EARLY_PMDS(vstart, vend, add) (EARLY_ENTRIES(vstart, vend, SWAPPER_TABLE_SHIFT, add))
8080
#else
81-
#define EARLY_PMDS(vstart, vend) (0)
81+
#define EARLY_PMDS(vstart, vend, add) (0)
8282
#endif
8383

84-
#define EARLY_PAGES(vstart, vend) ( 1 /* PGDIR page */ \
85-
+ EARLY_PGDS((vstart), (vend)) /* each PGDIR needs a next level page table */ \
86-
+ EARLY_PUDS((vstart), (vend)) /* each PUD needs a next level page table */ \
87-
+ EARLY_PMDS((vstart), (vend))) /* each PMD needs a next level page table */
88-
#define INIT_DIR_SIZE (PAGE_SIZE * EARLY_PAGES(KIMAGE_VADDR, _end))
84+
#define EARLY_PAGES(vstart, vend, add) ( 1 /* PGDIR page */ \
85+
+ EARLY_PGDS((vstart), (vend), add) /* each PGDIR needs a next level page table */ \
86+
+ EARLY_PUDS((vstart), (vend), add) /* each PUD needs a next level page table */ \
87+
+ EARLY_PMDS((vstart), (vend), add)) /* each PMD needs a next level page table */
88+
#define INIT_DIR_SIZE (PAGE_SIZE * EARLY_PAGES(KIMAGE_VADDR, _end, EARLY_KASLR))
8989

9090
/* the initial ID map may need two extra pages if it needs to be extended */
9191
#if VA_BITS < 48
9292
#define INIT_IDMAP_DIR_SIZE ((INIT_IDMAP_DIR_PAGES + 2) * PAGE_SIZE)
9393
#else
9494
#define INIT_IDMAP_DIR_SIZE (INIT_IDMAP_DIR_PAGES * PAGE_SIZE)
9595
#endif
96-
#define INIT_IDMAP_DIR_PAGES EARLY_PAGES(KIMAGE_VADDR, _end + MAX_FDT_SIZE + SWAPPER_BLOCK_SIZE)
96+
#define INIT_IDMAP_DIR_PAGES EARLY_PAGES(KIMAGE_VADDR, _end + MAX_FDT_SIZE + SWAPPER_BLOCK_SIZE, 1)
9797

9898
/* Initial memory map size */
9999
#if ARM64_KERNEL_USES_PMD_MAPS

0 commit comments

Comments
 (0)