Skip to content

Commit fa7f918

Browse files
committed
powerpc/mm/hash: Refactor hash__mark_rodata_ro()
Move the core logic into a helper, so we can use it for changing other permissions. We also change the logic to align start down, and end up. This means calling the function with a range will expand that range to be at least 1 mmu_linear_psize page in size. We need that so we can use it on __init_begin ... __init_end which is not a full page in size. This should always work for _stext/__init_begin, because we align __init_begin to _stext + 16M in the linker script. Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Reviewed-by: Balbir Singh <bsingharora@gmail.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent b134bd9 commit fa7f918

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

arch/powerpc/mm/pgtable-hash64.c

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -425,33 +425,39 @@ int hash__has_transparent_hugepage(void)
425425
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
426426

427427
#ifdef CONFIG_STRICT_KERNEL_RWX
428-
void hash__mark_rodata_ro(void)
428+
static bool hash__change_memory_range(unsigned long start, unsigned long end,
429+
unsigned long newpp)
429430
{
430-
unsigned long start = (unsigned long)_stext;
431-
unsigned long end = (unsigned long)__init_begin;
432431
unsigned long idx;
433432
unsigned int step, shift;
434-
unsigned long newpp = PP_RXXX;
435433

436434
shift = mmu_psize_defs[mmu_linear_psize].shift;
437435
step = 1 << shift;
438436

439-
start = ((start + step - 1) >> shift) << shift;
440-
end = (end >> shift) << shift;
437+
start = ALIGN_DOWN(start, step);
438+
end = ALIGN(end, step); // aligns up
441439

442-
pr_devel("marking ro start %lx, end %lx, step %x\n",
443-
start, end, step);
440+
if (start >= end)
441+
return false;
444442

445-
if (start == end) {
446-
pr_warn("could not set rodata ro, relocate the start"
447-
" of the kernel to a 0x%x boundary\n", step);
448-
return;
449-
}
443+
pr_debug("Changing page protection on range 0x%lx-0x%lx, to 0x%lx, step 0x%x\n",
444+
start, end, newpp, step);
450445

451446
for (idx = start; idx < end; idx += step)
452447
/* Not sure if we can do much with the return value */
453448
mmu_hash_ops.hpte_updateboltedpp(newpp, idx, mmu_linear_psize,
454449
mmu_kernel_ssize);
455450

451+
return true;
452+
}
453+
454+
void hash__mark_rodata_ro(void)
455+
{
456+
unsigned long start, end;
457+
458+
start = (unsigned long)_stext;
459+
end = (unsigned long)__init_begin;
460+
461+
WARN_ON(!hash__change_memory_range(start, end, PP_RXXX));
456462
}
457463
#endif

0 commit comments

Comments
 (0)