Skip to content

Commit 1261c78

Browse files
author
Ard Biesheuvel
committed
arm64: simplify kernel segment mapping granularity
The mapping of the kernel consist of four segments, each of which is mapped with different permission attributes and/or lifetimes. To optimize the TLB and translation table footprint, we define various opaque constants in the linker script that resolve to different aligment values depending on the page size and whether CONFIG_DEBUG_ALIGN_RODATA is set. Considering that - a 4 KB granule kernel benefits from a 64 KB segment alignment (due to the fact that it allows the use of the contiguous bit), - the minimum alignment of the .data segment is THREAD_SIZE already, not PAGE_SIZE (i.e., we already have padding between _data and the start of the .data payload in many cases), - 2 MB is a suitable alignment value on all granule sizes, either for mapping directly (level 2 on 4 KB), or via the contiguous bit (level 3 on 16 KB and 64 KB), - anything beyond 2 MB exceeds the minimum alignment mandated by the boot protocol, and can only be mapped efficiently if the physical alignment happens to be the same, we can simplify this by standardizing on 64 KB (or 2 MB) explicitly, i.e., regardless of granule size, all segments are aligned either to 64 KB, or to 2 MB if CONFIG_DEBUG_ALIGN_RODATA=y. This also means we can drop the Kconfig dependency of CONFIG_DEBUG_ALIGN_RODATA on CONFIG_ARM64_4K_PAGES. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Will Deacon <will.deacon@arm.com> (cherry picked from commit 97740051dd31d200a0efaa84544fe5e4713aac40) Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
1 parent e916035 commit 1261c78

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

arch/arm64/Kconfig.debug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ config DEBUG_RODATA
7373
If in doubt, say Y
7474

7575
config DEBUG_ALIGN_RODATA
76-
depends on DEBUG_RODATA && ARM64_4K_PAGES
76+
depends on DEBUG_RODATA
7777
bool "Align linker sections up to SECTION_SIZE"
7878
help
7979
If this option is enabled, sections that may potentially be marked as

arch/arm64/kernel/vmlinux.lds.S

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,19 @@ PECOFF_FILE_ALIGNMENT = 0x200;
6363
#endif
6464

6565
#if defined(CONFIG_DEBUG_ALIGN_RODATA)
66-
#define ALIGN_DEBUG_RO . = ALIGN(1<<SECTION_SHIFT);
67-
#define ALIGN_DEBUG_RO_MIN(min) ALIGN_DEBUG_RO
68-
#elif defined(CONFIG_DEBUG_RODATA)
69-
#define ALIGN_DEBUG_RO . = ALIGN(1<<PAGE_SHIFT);
70-
#define ALIGN_DEBUG_RO_MIN(min) ALIGN_DEBUG_RO
66+
/*
67+
* 4 KB granule: 1 level 2 entry
68+
* 16 KB granule: 128 level 3 entries, with contiguous bit
69+
* 64 KB granule: 32 level 3 entries, with contiguous bit
70+
*/
71+
#define SEGMENT_ALIGN SZ_2M
7172
#else
72-
#define ALIGN_DEBUG_RO
73-
#define ALIGN_DEBUG_RO_MIN(min) . = ALIGN(min);
73+
/*
74+
* 4 KB granule: 16 level 3 entries, with contiguous bit
75+
* 16 KB granule: 4 level 3 entries, without contiguous bit
76+
* 64 KB granule: 1 level 3 entry
77+
*/
78+
#define SEGMENT_ALIGN SZ_64K
7479
#endif
7580

7681
SECTIONS
@@ -113,12 +118,12 @@ SECTIONS
113118
*(.got) /* Global offset table */
114119
}
115120

116-
ALIGN_DEBUG_RO_MIN(PAGE_SIZE)
121+
. = ALIGN(SEGMENT_ALIGN);
117122
RO_DATA(PAGE_SIZE) /* everything from this point to */
118123
EXCEPTION_TABLE(8) /* _etext will be marked RO NX */
119124
NOTES
120125

121-
ALIGN_DEBUG_RO_MIN(PAGE_SIZE)
126+
. = ALIGN(SEGMENT_ALIGN);
122127
_etext = .; /* End of text and rodata section */
123128
__init_begin = .;
124129

@@ -166,7 +171,7 @@ SECTIONS
166171
*(.hash)
167172
}
168173

169-
. = ALIGN(PAGE_SIZE);
174+
. = ALIGN(SEGMENT_ALIGN);
170175
__init_end = .;
171176

172177
_data = .;

0 commit comments

Comments
 (0)