Skip to content

Commit b134bd9

Browse files
committed
powerpc/mm/radix: Refactor radix__mark_rodata_ro()
Move the core logic into a helper, so we can use it for changing permissions other than _PAGE_WRITE. 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 76fc0cf commit b134bd9

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

arch/powerpc/mm/pgtable-radix.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,9 @@ int radix__map_kernel_page(unsigned long ea, unsigned long pa,
112112
}
113113

114114
#ifdef CONFIG_STRICT_KERNEL_RWX
115-
void radix__mark_rodata_ro(void)
115+
void radix__change_memory_range(unsigned long start, unsigned long end,
116+
unsigned long clear)
116117
{
117-
unsigned long start = (unsigned long)_stext;
118-
unsigned long end = (unsigned long)__init_begin;
119118
unsigned long idx;
120119
pgd_t *pgdp;
121120
pud_t *pudp;
@@ -125,7 +124,8 @@ void radix__mark_rodata_ro(void)
125124
start = ALIGN_DOWN(start, PAGE_SIZE);
126125
end = PAGE_ALIGN(end); // aligns up
127126

128-
pr_devel("marking ro start %lx, end %lx\n", start, end);
127+
pr_debug("Changing flags on range %lx-%lx removing 0x%lx\n",
128+
start, end, clear);
129129

130130
for (idx = start; idx < end; idx += PAGE_SIZE) {
131131
pgdp = pgd_offset_k(idx);
@@ -147,11 +147,21 @@ void radix__mark_rodata_ro(void)
147147
if (!ptep)
148148
continue;
149149
update_the_pte:
150-
radix__pte_update(&init_mm, idx, ptep, _PAGE_WRITE, 0, 0);
150+
radix__pte_update(&init_mm, idx, ptep, clear, 0, 0);
151151
}
152152

153153
radix__flush_tlb_kernel_range(start, end);
154154
}
155+
156+
void radix__mark_rodata_ro(void)
157+
{
158+
unsigned long start, end;
159+
160+
start = (unsigned long)_stext;
161+
end = (unsigned long)__init_begin;
162+
163+
radix__change_memory_range(start, end, _PAGE_WRITE);
164+
}
155165
#endif /* CONFIG_STRICT_KERNEL_RWX */
156166

157167
static inline void __meminit print_mapping(unsigned long start,

0 commit comments

Comments
 (0)