mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-03 02:56:38 +07:00
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>
This commit is contained in:
parent
b134bd9028
commit
fa7f9189e0
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user