Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/0aee964721cab7316cffde21a2ca223cee14d373.1647962456.git.christophe.leroy@csgroup.eu

authored by

Christophe Leroy and committed by
Michael Ellerman
b0337678 cb3ac452

+8 -1
+2
arch/powerpc/include/asm/code-patching.h
··· 22 22 #define BRANCH_SET_LINK 0x1 23 23 #define BRANCH_ABSOLUTE 0x2 24 24 25 + DECLARE_STATIC_KEY_FALSE(init_mem_is_free); 26 + 25 27 bool is_offset_in_branch_range(long offset); 26 28 bool is_offset_in_cond_branch_range(long offset); 27 29 int create_branch(ppc_inst_t *instr, const u32 *addr,
+4 -1
arch/powerpc/lib/code-patching.c
··· 8 8 #include <linux/init.h> 9 9 #include <linux/cpuhotplug.h> 10 10 #include <linux/uaccess.h> 11 + #include <linux/jump_label.h> 11 12 12 13 #include <asm/tlbflush.h> 13 14 #include <asm/page.h> ··· 189 188 190 189 #endif /* CONFIG_STRICT_KERNEL_RWX */ 191 190 191 + __ro_after_init DEFINE_STATIC_KEY_FALSE(init_mem_is_free); 192 + 192 193 int patch_instruction(u32 *addr, ppc_inst_t instr) 193 194 { 194 195 /* Make sure we aren't patching a freed init section */ 195 - if (system_state >= SYSTEM_FREEING_INITMEM && init_section_contains(addr, 4)) 196 + if (static_branch_likely(&init_mem_is_free) && init_section_contains(addr, 4)) 196 197 return 0; 197 198 198 199 return do_patch_instruction(addr, instr);
+2
arch/powerpc/mm/mem.c
··· 22 22 #include <asm/kasan.h> 23 23 #include <asm/svm.h> 24 24 #include <asm/mmzone.h> 25 + #include <asm/code-patching.h> 25 26 26 27 #include <mm/mmu_decl.h> 27 28 ··· 312 311 { 313 312 ppc_md.progress = ppc_printk_progress; 314 313 mark_initmem_nx(); 314 + static_branch_enable(&init_mem_is_free); 315 315 free_initmem_default(POISON_FREE_INITMEM); 316 316 } 317 317