Commit 97740051 authored by Ard Biesheuvel's avatar Ard Biesheuvel Committed by Will Deacon

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: default avatarArd Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
parent 7eb90f2f
...@@ -59,7 +59,7 @@ config DEBUG_RODATA ...@@ -59,7 +59,7 @@ config DEBUG_RODATA
If in doubt, say Y If in doubt, say Y
config DEBUG_ALIGN_RODATA config DEBUG_ALIGN_RODATA
depends on DEBUG_RODATA && ARM64_4K_PAGES depends on DEBUG_RODATA
bool "Align linker sections up to SECTION_SIZE" bool "Align linker sections up to SECTION_SIZE"
help help
If this option is enabled, sections that may potentially be marked as If this option is enabled, sections that may potentially be marked as
......
...@@ -63,14 +63,19 @@ PECOFF_FILE_ALIGNMENT = 0x200; ...@@ -63,14 +63,19 @@ PECOFF_FILE_ALIGNMENT = 0x200;
#endif #endif
#if defined(CONFIG_DEBUG_ALIGN_RODATA) #if defined(CONFIG_DEBUG_ALIGN_RODATA)
#define ALIGN_DEBUG_RO . = ALIGN(1<<SECTION_SHIFT); /*
#define ALIGN_DEBUG_RO_MIN(min) ALIGN_DEBUG_RO * 4 KB granule: 1 level 2 entry
#elif defined(CONFIG_DEBUG_RODATA) * 16 KB granule: 128 level 3 entries, with contiguous bit
#define ALIGN_DEBUG_RO . = ALIGN(1<<PAGE_SHIFT); * 64 KB granule: 32 level 3 entries, with contiguous bit
#define ALIGN_DEBUG_RO_MIN(min) ALIGN_DEBUG_RO */
#define SEGMENT_ALIGN SZ_2M
#else #else
#define ALIGN_DEBUG_RO /*
#define ALIGN_DEBUG_RO_MIN(min) . = ALIGN(min); * 4 KB granule: 16 level 3 entries, with contiguous bit
* 16 KB granule: 4 level 3 entries, without contiguous bit
* 64 KB granule: 1 level 3 entry
*/
#define SEGMENT_ALIGN SZ_64K
#endif #endif
SECTIONS SECTIONS
...@@ -114,12 +119,12 @@ SECTIONS ...@@ -114,12 +119,12 @@ SECTIONS
*(.got) /* Global offset table */ *(.got) /* Global offset table */
} }
ALIGN_DEBUG_RO_MIN(PAGE_SIZE) . = ALIGN(SEGMENT_ALIGN);
RO_DATA(PAGE_SIZE) /* everything from this point to */ RO_DATA(PAGE_SIZE) /* everything from this point to */
EXCEPTION_TABLE(8) /* _etext will be marked RO NX */ EXCEPTION_TABLE(8) /* _etext will be marked RO NX */
NOTES NOTES
ALIGN_DEBUG_RO_MIN(PAGE_SIZE) . = ALIGN(SEGMENT_ALIGN);
_etext = .; /* End of text and rodata section */ _etext = .; /* End of text and rodata section */
__init_begin = .; __init_begin = .;
...@@ -168,7 +173,7 @@ SECTIONS ...@@ -168,7 +173,7 @@ SECTIONS
*(.hash) *(.hash)
} }
. = ALIGN(PAGE_SIZE); . = ALIGN(SEGMENT_ALIGN);
__init_end = .; __init_end = .;
_data = .; _data = .;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment