Skip to content

Commit 9316512

Browse files
chleroymaddy-kerneldev
authored andcommitted
powerpc/32: Remove PAGE_KERNEL_TEXT to fix startup failure
PAGE_KERNEL_TEXT is an old macro that is used to tell kernel whether kernel text has to be mapped read-only or read-write based on build time options. But nowadays, with functionnalities like jump_labels, static links, etc ... more only less all kernels need to be read-write at some point, and some combinations of configs failed to work due to innacurate setting of PAGE_KERNEL_TEXT. On the other hand, today we have CONFIG_STRICT_KERNEL_RWX which implements a more controlled access to kernel modifications. Instead of trying to keep PAGE_KERNEL_TEXT accurate with all possible options that may imply kernel text modification, always set kernel text read-write at startup and rely on CONFIG_STRICT_KERNEL_RWX to provide accurate protection. Do this by passing PAGE_KERNEL_X to map_kernel_page() in __maping_ram_chunk() instead of passing PAGE_KERNEL_TEXT. Once this is done, the only remaining user of PAGE_KERNEL_TEXT is mmu_mark_initmem_nx() which uses it in a call to setibat(). As setibat() ignores the RW/RO, we can seamlessly replace PAGE_KERNEL_TEXT by PAGE_KERNEL_X here as well and get rid of PAGE_KERNEL_TEXT completely. Reported-by: Erhard Furtner <erhard_f@mailbox.org> Closes: https://lore.kernel.org/all/342b4120-911c-4723-82ec-d8c9b03a8aef@mailbox.org/ Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> Tested-by: Andrew Donnellan <ajd@linux.ibm.com> Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com> Link: https://patch.msgid.link/8e2d793abf87ae3efb8f6dce10f974ac0eda61b8.1757412205.git.christophe.leroy@csgroup.eu
1 parent 7cec88b commit 9316512

3 files changed

Lines changed: 3 additions & 15 deletions

File tree

arch/powerpc/include/asm/pgtable.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,6 @@ struct mm_struct;
2020
#include <asm/nohash/pgtable.h>
2121
#endif /* !CONFIG_PPC_BOOK3S */
2222

23-
/*
24-
* Protection used for kernel text. We want the debuggers to be able to
25-
* set breakpoints anywhere, so don't write protect the kernel text
26-
* on platforms where such control is possible.
27-
*/
28-
#if defined(CONFIG_KGDB) || defined(CONFIG_XMON) || defined(CONFIG_BDI_SWITCH) || \
29-
defined(CONFIG_KPROBES) || defined(CONFIG_DYNAMIC_FTRACE)
30-
#define PAGE_KERNEL_TEXT PAGE_KERNEL_X
31-
#else
32-
#define PAGE_KERNEL_TEXT PAGE_KERNEL_ROX
33-
#endif
34-
3523
/* Make modules code happy. We don't set RO yet */
3624
#define PAGE_KERNEL_EXEC PAGE_KERNEL_X
3725

arch/powerpc/mm/book3s32/mmu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ int mmu_mark_initmem_nx(void)
204204

205205
for (i = 0; i < nb - 1 && base < top;) {
206206
size = bat_block_size(base, top);
207-
setibat(i++, PAGE_OFFSET + base, base, size, PAGE_KERNEL_TEXT);
207+
setibat(i++, PAGE_OFFSET + base, base, size, PAGE_KERNEL_X);
208208
base += size;
209209
}
210210
if (base < top) {
@@ -215,7 +215,7 @@ int mmu_mark_initmem_nx(void)
215215
pr_warn("Some RW data is getting mapped X. "
216216
"Adjust CONFIG_DATA_SHIFT to avoid that.\n");
217217
}
218-
setibat(i++, PAGE_OFFSET + base, base, size, PAGE_KERNEL_TEXT);
218+
setibat(i++, PAGE_OFFSET + base, base, size, PAGE_KERNEL_X);
219219
base += size;
220220
}
221221
for (; i < nb; i++)

arch/powerpc/mm/pgtable_32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static void __init __mapin_ram_chunk(unsigned long offset, unsigned long top)
104104
p = memstart_addr + s;
105105
for (; s < top; s += PAGE_SIZE) {
106106
ktext = core_kernel_text(v);
107-
map_kernel_page(v, p, ktext ? PAGE_KERNEL_TEXT : PAGE_KERNEL);
107+
map_kernel_page(v, p, ktext ? PAGE_KERNEL_X : PAGE_KERNEL);
108108
v += PAGE_SIZE;
109109
p += PAGE_SIZE;
110110
}

0 commit comments

Comments
 (0)