Commit b0337678 authored by Christophe Leroy's avatar Christophe Leroy Committed by Michael Ellerman

powerpc/code-patching: Use jump_label for testing freed initmem

Once init is done, initmem is freed forever so no need to
test system_state at every call to patch_instruction().

Use jump_label.

This reduces by 2% the time needed to activate ftrace on an 8xx.
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/0aee964721cab7316cffde21a2ca223cee14d373.1647962456.git.christophe.leroy@csgroup.eu
parent cb3ac452
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
#define BRANCH_SET_LINK 0x1 #define BRANCH_SET_LINK 0x1
#define BRANCH_ABSOLUTE 0x2 #define BRANCH_ABSOLUTE 0x2
DECLARE_STATIC_KEY_FALSE(init_mem_is_free);
bool is_offset_in_branch_range(long offset); bool is_offset_in_branch_range(long offset);
bool is_offset_in_cond_branch_range(long offset); bool is_offset_in_cond_branch_range(long offset);
int create_branch(ppc_inst_t *instr, const u32 *addr, int create_branch(ppc_inst_t *instr, const u32 *addr,
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/cpuhotplug.h> #include <linux/cpuhotplug.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <linux/jump_label.h>
#include <asm/tlbflush.h> #include <asm/tlbflush.h>
#include <asm/page.h> #include <asm/page.h>
...@@ -188,10 +189,12 @@ static int do_patch_instruction(u32 *addr, ppc_inst_t instr) ...@@ -188,10 +189,12 @@ static int do_patch_instruction(u32 *addr, ppc_inst_t instr)
#endif /* CONFIG_STRICT_KERNEL_RWX */ #endif /* CONFIG_STRICT_KERNEL_RWX */
__ro_after_init DEFINE_STATIC_KEY_FALSE(init_mem_is_free);
int patch_instruction(u32 *addr, ppc_inst_t instr) int patch_instruction(u32 *addr, ppc_inst_t instr)
{ {
/* Make sure we aren't patching a freed init section */ /* Make sure we aren't patching a freed init section */
if (system_state >= SYSTEM_FREEING_INITMEM && init_section_contains(addr, 4)) if (static_branch_likely(&init_mem_is_free) && init_section_contains(addr, 4))
return 0; return 0;
return do_patch_instruction(addr, instr); return do_patch_instruction(addr, instr);
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <asm/kasan.h> #include <asm/kasan.h>
#include <asm/svm.h> #include <asm/svm.h>
#include <asm/mmzone.h> #include <asm/mmzone.h>
#include <asm/code-patching.h>
#include <mm/mmu_decl.h> #include <mm/mmu_decl.h>
...@@ -311,6 +312,7 @@ void free_initmem(void) ...@@ -311,6 +312,7 @@ void free_initmem(void)
{ {
ppc_md.progress = ppc_printk_progress; ppc_md.progress = ppc_printk_progress;
mark_initmem_nx(); mark_initmem_nx();
static_branch_enable(&init_mem_is_free);
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