Skip to content

Commit 970d54f

Browse files
ruscurmpe
authored andcommitted
powerpc/book3s64/hash: Disable 16M linear mapping size if not aligned
With STRICT_KERNEL_RWX on in a relocatable kernel under the hash MMU, if the position the kernel is loaded at is not 16M aligned things go horribly wrong. Specifically hash__mark_initmem_nx() will call hash__change_memory_range() which then aligns down the start address, and due to the text not being 16M aligned causes some of the kernel text to be marked non-executable. We can avoid this when selecting the linear mapping size, so do so and print a warning. I tested this for various alignments and as long as the position is 64K aligned it's fine (the base requirement for powerpc). Signed-off-by: Russell Currey <[email protected]> [mpe: Add details of the failure mode] Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent fbee6ba commit 970d54f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

arch/powerpc/mm/book3s64/hash_utils.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,14 +652,23 @@ static void init_hpte_page_sizes(void)
652652

653653
static void __init htab_init_page_sizes(void)
654654
{
655+
bool aligned = true;
655656
init_hpte_page_sizes();
656657

657658
if (!debug_pagealloc_enabled()) {
658659
/*
659660
* Pick a size for the linear mapping. Currently, we only
660661
* support 16M, 1M and 4K which is the default
661662
*/
662-
if (mmu_psize_defs[MMU_PAGE_16M].shift)
663+
if (IS_ENABLED(STRICT_KERNEL_RWX) &&
664+
(unsigned long)_stext % 0x1000000) {
665+
if (mmu_psize_defs[MMU_PAGE_16M].shift)
666+
pr_warn("Kernel not 16M aligned, "
667+
"disabling 16M linear map alignment");
668+
aligned = false;
669+
}
670+
671+
if (mmu_psize_defs[MMU_PAGE_16M].shift && aligned)
663672
mmu_linear_psize = MMU_PAGE_16M;
664673
else if (mmu_psize_defs[MMU_PAGE_1M].shift)
665674
mmu_linear_psize = MMU_PAGE_1M;

0 commit comments

Comments
 (0)