Skip to content

Commit

Permalink
powerpc/mm/hash: Refactor hash__mark_rodata_ro()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Michael Ellerman committed Jul 18, 2017
1 parent b134bd9 commit fa7f918
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions arch/powerpc/mm/pgtable-hash64.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,33 +425,39 @@ int hash__has_transparent_hugepage(void)
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */

#ifdef CONFIG_STRICT_KERNEL_RWX
void hash__mark_rodata_ro(void)
static bool hash__change_memory_range(unsigned long start, unsigned long end,
unsigned long newpp)
{
unsigned long start = (unsigned long)_stext;
unsigned long end = (unsigned long)__init_begin;
unsigned long idx;
unsigned int step, shift;
unsigned long newpp = PP_RXXX;

shift = mmu_psize_defs[mmu_linear_psize].shift;
step = 1 << shift;

start = ((start + step - 1) >> shift) << shift;
end = (end >> shift) << shift;
start = ALIGN_DOWN(start, step);
end = ALIGN(end, step); // aligns up

pr_devel("marking ro start %lx, end %lx, step %x\n",
start, end, step);
if (start >= end)
return false;

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

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

return true;
}

void hash__mark_rodata_ro(void)
{
unsigned long start, end;

start = (unsigned long)_stext;
end = (unsigned long)__init_begin;

WARN_ON(!hash__change_memory_range(start, end, PP_RXXX));
}
#endif

0 comments on commit fa7f918

Please sign in to comment.