Commit 8b8a8f0a authored by Christophe Leroy's avatar Christophe Leroy Committed by Michael Ellerman

powerpc/code-patching: Improve verification of patchability

Today, patch_instruction() assumes that it is called exclusively on
valid addresses, and only checks that it is not called on an init
address after init section has been freed.

Improve verification by calling kernel_text_address() instead.

kernel_text_address() already includes a verification of
initmem release.
Signed-off-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/bc683d499a411730504b132a924de0ccc2ef1f79.1636971137.git.christophe.leroy@csgroup.eu
parent a3bcfc18
...@@ -9,7 +9,6 @@ extern void ppc_printk_progress(char *s, unsigned short hex); ...@@ -9,7 +9,6 @@ extern void ppc_printk_progress(char *s, unsigned short hex);
extern unsigned int rtas_data; extern unsigned int rtas_data;
extern unsigned long long memory_limit; extern unsigned long long memory_limit;
extern bool init_mem_is_free;
extern void *zalloc_maybe_bootmem(size_t size, gfp_t mask); extern void *zalloc_maybe_bootmem(size_t size, gfp_t mask);
struct device_node; struct device_node;
......
...@@ -190,10 +190,9 @@ static int do_patch_instruction(u32 *addr, struct ppc_inst instr) ...@@ -190,10 +190,9 @@ static int do_patch_instruction(u32 *addr, struct ppc_inst instr)
int patch_instruction(u32 *addr, struct ppc_inst instr) int patch_instruction(u32 *addr, struct ppc_inst instr)
{ {
/* Make sure we aren't patching a freed init section */ /* Make sure we aren't patching a freed init section */
if (init_mem_is_free && init_section_contains(addr, 4)) { if (!kernel_text_address((unsigned long)addr))
pr_debug("Skipping init section patching addr: 0x%px\n", addr);
return 0; return 0;
}
return do_patch_instruction(addr, instr); return do_patch_instruction(addr, instr);
} }
NOKPROBE_SYMBOL(patch_instruction); NOKPROBE_SYMBOL(patch_instruction);
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include <mm/mmu_decl.h> #include <mm/mmu_decl.h>
unsigned long long memory_limit; unsigned long long memory_limit;
bool init_mem_is_free;
unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)] __page_aligned_bss; unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)] __page_aligned_bss;
EXPORT_SYMBOL(empty_zero_page); EXPORT_SYMBOL(empty_zero_page);
...@@ -312,7 +311,6 @@ void free_initmem(void) ...@@ -312,7 +311,6 @@ void free_initmem(void)
{ {
ppc_md.progress = ppc_printk_progress; ppc_md.progress = ppc_printk_progress;
mark_initmem_nx(); mark_initmem_nx();
init_mem_is_free = true;
free_initmem_default(POISON_FREE_INITMEM); free_initmem_default(POISON_FREE_INITMEM);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment