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

powerpc/ftrace: Minimise number of #ifdefs

A lot of #ifdefs can be replaced by IS_ENABLED()

Do so.
Signed-off-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
[mpe: Fold in changes suggested by Naveen and Christophe on list]
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/18ce6708d6f8c71d87436f9c6019f04df4125128.1652074503.git.christophe.leroy@csgroup.eu
parent b97d0e3d
...@@ -219,7 +219,6 @@ static inline unsigned long ppc_kallsyms_lookup_name(const char *name) ...@@ -219,7 +219,6 @@ static inline unsigned long ppc_kallsyms_lookup_name(const char *name)
return addr; return addr;
} }
#ifdef CONFIG_PPC64
/* /*
* Some instruction encodings commonly used in dynamic ftracing * Some instruction encodings commonly used in dynamic ftracing
* and function live patching. * and function live patching.
...@@ -236,6 +235,5 @@ static inline unsigned long ppc_kallsyms_lookup_name(const char *name) ...@@ -236,6 +235,5 @@ static inline unsigned long ppc_kallsyms_lookup_name(const char *name)
/* usually preceded by a mflr r0 */ /* usually preceded by a mflr r0 */
#define PPC_INST_STD_LR PPC_RAW_STD(_R0, _R1, PPC_LR_STKOFF) #define PPC_INST_STD_LR PPC_RAW_STD(_R0, _R1, PPC_LR_STKOFF)
#endif /* CONFIG_PPC64 */
#endif /* _ASM_POWERPC_CODE_PATCHING_H */ #endif /* _ASM_POWERPC_CODE_PATCHING_H */
...@@ -41,9 +41,7 @@ struct mod_arch_specific { ...@@ -41,9 +41,7 @@ struct mod_arch_specific {
#ifdef CONFIG_DYNAMIC_FTRACE #ifdef CONFIG_DYNAMIC_FTRACE
unsigned long tramp; unsigned long tramp;
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
unsigned long tramp_regs; unsigned long tramp_regs;
#endif
#endif #endif
/* List of BUG addresses, source line numbers and filenames */ /* List of BUG addresses, source line numbers and filenames */
......
...@@ -150,26 +150,39 @@ __ftrace_make_nop(struct module *mod, ...@@ -150,26 +150,39 @@ __ftrace_make_nop(struct module *mod,
return -EINVAL; return -EINVAL;
} }
/* When using -mprofile-kernel or PPC32 there is no load to jump over */ if (IS_ENABLED(CONFIG_MPROFILE_KERNEL)) {
pop = ppc_inst(PPC_RAW_NOP()); if (copy_inst_from_kernel_nofault(&op, (void *)(ip - 4))) {
pr_err("Fetching instruction at %lx failed.\n", ip - 4);
return -EFAULT;
}
#ifdef CONFIG_PPC64 /* We expect either a mflr r0, or a std r0, LRSAVE(r1) */
#ifdef CONFIG_MPROFILE_KERNEL if (!ppc_inst_equal(op, ppc_inst(PPC_RAW_MFLR(_R0))) &&
if (copy_inst_from_kernel_nofault(&op, (void *)(ip - 4))) { !ppc_inst_equal(op, ppc_inst(PPC_INST_STD_LR))) {
pr_err("Fetching instruction at %lx failed.\n", ip - 4); pr_err("Unexpected instruction %s around bl _mcount\n",
return -EFAULT; ppc_inst_as_str(op));
} return -EINVAL;
}
} else if (IS_ENABLED(CONFIG_PPC64)) {
/*
* Check what is in the next instruction. We can see ld r2,40(r1), but
* on first pass after boot we will see mflr r0.
*/
if (copy_inst_from_kernel_nofault(&op, (void *)(ip + 4))) {
pr_err("Fetching op failed.\n");
return -EFAULT;
}
/* We expect either a mflr r0, or a std r0, LRSAVE(r1) */ if (!ppc_inst_equal(op, ppc_inst(PPC_INST_LD_TOC))) {
if (!ppc_inst_equal(op, ppc_inst(PPC_RAW_MFLR(_R0))) && pr_err("Expected %08lx found %s\n", PPC_INST_LD_TOC, ppc_inst_as_str(op));
!ppc_inst_equal(op, ppc_inst(PPC_INST_STD_LR))) { return -EINVAL;
pr_err("Unexpected instruction %s around bl _mcount\n", }
ppc_inst_as_str(op));
return -EINVAL;
} }
#else
/* /*
* Our original call site looks like: * When using -mprofile-kernel or PPC32 there is no load to jump over.
*
* Otherwise our original call site looks like:
* *
* bl <tramp> * bl <tramp>
* ld r2,XX(r1) * ld r2,XX(r1)
...@@ -181,24 +194,10 @@ __ftrace_make_nop(struct module *mod, ...@@ -181,24 +194,10 @@ __ftrace_make_nop(struct module *mod,
* *
* Use a b +8 to jump over the load. * Use a b +8 to jump over the load.
*/ */
if (IS_ENABLED(CONFIG_MPROFILE_KERNEL) || IS_ENABLED(CONFIG_PPC32))
pop = ppc_inst(PPC_RAW_BRANCH(8)); /* b +8 */ pop = ppc_inst(PPC_RAW_NOP());
else
/* pop = ppc_inst(PPC_RAW_BRANCH(8)); /* b +8 */
* Check what is in the next instruction. We can see ld r2,40(r1), but
* on first pass after boot we will see mflr r0.
*/
if (copy_inst_from_kernel_nofault(&op, (void *)(ip + 4))) {
pr_err("Fetching op failed.\n");
return -EFAULT;
}
if (!ppc_inst_equal(op, ppc_inst(PPC_INST_LD_TOC))) {
pr_err("Expected %08lx found %s\n", PPC_INST_LD_TOC, ppc_inst_as_str(op));
return -EINVAL;
}
#endif /* CONFIG_MPROFILE_KERNEL */
#endif /* PPC64 */
if (patch_instruction((u32 *)ip, pop)) { if (patch_instruction((u32 *)ip, pop)) {
pr_err("Patching NOP failed.\n"); pr_err("Patching NOP failed.\n");
...@@ -207,6 +206,11 @@ __ftrace_make_nop(struct module *mod, ...@@ -207,6 +206,11 @@ __ftrace_make_nop(struct module *mod,
return 0; return 0;
} }
#else
static int __ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec, unsigned long addr)
{
return 0;
}
#endif /* CONFIG_MODULES */ #endif /* CONFIG_MODULES */
static unsigned long find_ftrace_tramp(unsigned long ip) static unsigned long find_ftrace_tramp(unsigned long ip)
...@@ -279,11 +283,11 @@ static int setup_mcount_compiler_tramp(unsigned long tramp) ...@@ -279,11 +283,11 @@ static int setup_mcount_compiler_tramp(unsigned long tramp)
} }
/* Let's re-write the tramp to go to ftrace_[regs_]caller */ /* Let's re-write the tramp to go to ftrace_[regs_]caller */
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_REGS))
ptr = ppc_global_function_entry((void *)ftrace_regs_caller); ptr = ppc_global_function_entry((void *)ftrace_regs_caller);
#else else
ptr = ppc_global_function_entry((void *)ftrace_caller); ptr = ppc_global_function_entry((void *)ftrace_caller);
#endif
if (patch_branch((u32 *)tramp, ptr, 0)) { if (patch_branch((u32 *)tramp, ptr, 0)) {
pr_debug("REL24 out of range!\n"); pr_debug("REL24 out of range!\n");
return -1; return -1;
...@@ -352,10 +356,12 @@ int ftrace_make_nop(struct module *mod, ...@@ -352,10 +356,12 @@ int ftrace_make_nop(struct module *mod,
old = ftrace_call_replace(ip, addr, 1); old = ftrace_call_replace(ip, addr, 1);
new = ppc_inst(PPC_RAW_NOP()); new = ppc_inst(PPC_RAW_NOP());
return ftrace_modify_code(ip, old, new); return ftrace_modify_code(ip, old, new);
} else if (core_kernel_text(ip)) } else if (core_kernel_text(ip)) {
return __ftrace_make_nop_kernel(rec, addr); return __ftrace_make_nop_kernel(rec, addr);
} else if (!IS_ENABLED(CONFIG_MODULES)) {
return -EINVAL;
}
#ifdef CONFIG_MODULES
/* /*
* Out of range jumps are called from modules. * Out of range jumps are called from modules.
* We should either already have a pointer to the module * We should either already have a pointer to the module
...@@ -378,10 +384,6 @@ int ftrace_make_nop(struct module *mod, ...@@ -378,10 +384,6 @@ int ftrace_make_nop(struct module *mod,
mod = rec->arch.mod; mod = rec->arch.mod;
return __ftrace_make_nop(mod, rec, addr); return __ftrace_make_nop(mod, rec, addr);
#else
/* We should not get here without modules */
return -EINVAL;
#endif /* CONFIG_MODULES */
} }
#ifdef CONFIG_MODULES #ifdef CONFIG_MODULES
...@@ -411,10 +413,9 @@ __ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr) ...@@ -411,10 +413,9 @@ __ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
if (copy_inst_from_kernel_nofault(op, ip)) if (copy_inst_from_kernel_nofault(op, ip))
return -EFAULT; return -EFAULT;
#ifdef CONFIG_PPC64_ELF_ABI_V1 if (IS_ENABLED(CONFIG_PPC64_ELF_ABI_V1) &&
if (copy_inst_from_kernel_nofault(op + 1, ip + 4)) copy_inst_from_kernel_nofault(op + 1, ip + 4))
return -EFAULT; return -EFAULT;
#endif
if (!expected_nop_sequence(ip, op[0], op[1])) { if (!expected_nop_sequence(ip, op[0], op[1])) {
pr_err("Unexpected call sequence at %p: %s %s\n", pr_err("Unexpected call sequence at %p: %s %s\n",
...@@ -423,20 +424,15 @@ __ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr) ...@@ -423,20 +424,15 @@ __ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
} }
/* If we never set up ftrace trampoline(s), then bail */ /* If we never set up ftrace trampoline(s), then bail */
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS if (!mod->arch.tramp ||
if (!mod->arch.tramp || !mod->arch.tramp_regs) { (IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_REGS) && !mod->arch.tramp_regs)) {
#else
if (!mod->arch.tramp) {
#endif
pr_err("No ftrace trampoline\n"); pr_err("No ftrace trampoline\n");
return -EINVAL; return -EINVAL;
} }
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_REGS) && rec->flags & FTRACE_FL_REGS)
if (rec->flags & FTRACE_FL_REGS)
tramp = mod->arch.tramp_regs; tramp = mod->arch.tramp_regs;
else else
#endif
tramp = mod->arch.tramp; tramp = mod->arch.tramp;
if (module_trampoline_target(mod, tramp, &ptr)) { if (module_trampoline_target(mod, tramp, &ptr)) {
...@@ -460,6 +456,11 @@ __ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr) ...@@ -460,6 +456,11 @@ __ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
return 0; return 0;
} }
#else
static int __ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
{
return 0;
}
#endif /* CONFIG_MODULES */ #endif /* CONFIG_MODULES */
static int __ftrace_make_call_kernel(struct dyn_ftrace *rec, unsigned long addr) static int __ftrace_make_call_kernel(struct dyn_ftrace *rec, unsigned long addr)
...@@ -472,16 +473,12 @@ static int __ftrace_make_call_kernel(struct dyn_ftrace *rec, unsigned long addr) ...@@ -472,16 +473,12 @@ static int __ftrace_make_call_kernel(struct dyn_ftrace *rec, unsigned long addr)
entry = ppc_global_function_entry((void *)ftrace_caller); entry = ppc_global_function_entry((void *)ftrace_caller);
ptr = ppc_global_function_entry((void *)addr); ptr = ppc_global_function_entry((void *)addr);
if (ptr != entry) { if (ptr != entry && IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_REGS))
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
entry = ppc_global_function_entry((void *)ftrace_regs_caller); entry = ppc_global_function_entry((void *)ftrace_regs_caller);
if (ptr != entry) {
#endif if (ptr != entry) {
pr_err("Unknown ftrace addr to patch: %ps\n", (void *)ptr); pr_err("Unknown ftrace addr to patch: %ps\n", (void *)ptr);
return -EINVAL; return -EINVAL;
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
}
#endif
} }
/* Make sure we have a nop */ /* Make sure we have a nop */
...@@ -524,10 +521,13 @@ int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr) ...@@ -524,10 +521,13 @@ int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
old = ppc_inst(PPC_RAW_NOP()); old = ppc_inst(PPC_RAW_NOP());
new = ftrace_call_replace(ip, addr, 1); new = ftrace_call_replace(ip, addr, 1);
return ftrace_modify_code(ip, old, new); return ftrace_modify_code(ip, old, new);
} else if (core_kernel_text(ip)) } else if (core_kernel_text(ip)) {
return __ftrace_make_call_kernel(rec, addr); return __ftrace_make_call_kernel(rec, addr);
} else if (!IS_ENABLED(CONFIG_MODULES)) {
/* We should not get here without modules */
return -EINVAL;
}
#ifdef CONFIG_MODULES
/* /*
* Out of range jumps are called from modules. * Out of range jumps are called from modules.
* Being that we are converting from nop, it had better * Being that we are converting from nop, it had better
...@@ -539,10 +539,6 @@ int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr) ...@@ -539,10 +539,6 @@ int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
} }
return __ftrace_make_call(rec, addr); return __ftrace_make_call(rec, addr);
#else
/* We should not get here without modules */
return -EINVAL;
#endif /* CONFIG_MODULES */
} }
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
...@@ -633,6 +629,11 @@ __ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr, ...@@ -633,6 +629,11 @@ __ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
return 0; return 0;
} }
#else
static int __ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr, unsigned long addr)
{
return 0;
}
#endif #endif
int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr, int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
...@@ -657,9 +658,11 @@ int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr, ...@@ -657,9 +658,11 @@ int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
* variant, so there is nothing to do here * variant, so there is nothing to do here
*/ */
return 0; return 0;
} else if (!IS_ENABLED(CONFIG_MODULES)) {
/* We should not get here without modules */
return -EINVAL;
} }
#ifdef CONFIG_MODULES
/* /*
* Out of range jumps are called from modules. * Out of range jumps are called from modules.
*/ */
...@@ -669,10 +672,6 @@ int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr, ...@@ -669,10 +672,6 @@ int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
} }
return __ftrace_modify_call(rec, old_addr, addr); return __ftrace_modify_call(rec, old_addr, addr);
#else
/* We should not get here without modules */
return -EINVAL;
#endif /* CONFIG_MODULES */
} }
#endif #endif
...@@ -686,15 +685,13 @@ int ftrace_update_ftrace_func(ftrace_func_t func) ...@@ -686,15 +685,13 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
new = ftrace_call_replace(ip, (unsigned long)func, 1); new = ftrace_call_replace(ip, (unsigned long)func, 1);
ret = ftrace_modify_code(ip, old, new); ret = ftrace_modify_code(ip, old, new);
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
/* Also update the regs callback function */ /* Also update the regs callback function */
if (!ret) { if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_REGS) && !ret) {
ip = (unsigned long)(&ftrace_regs_call); ip = (unsigned long)(&ftrace_regs_call);
old = ppc_inst_read((u32 *)&ftrace_regs_call); old = ppc_inst_read((u32 *)&ftrace_regs_call);
new = ftrace_call_replace(ip, (unsigned long)func, 1); new = ftrace_call_replace(ip, (unsigned long)func, 1);
ret = ftrace_modify_code(ip, old, new); ret = ftrace_modify_code(ip, old, new);
} }
#endif
return ret; return ret;
} }
...@@ -724,12 +721,15 @@ int __init ftrace_dyn_arch_init(void) ...@@ -724,12 +721,15 @@ int __init ftrace_dyn_arch_init(void)
PPC_RAW_MTCTR(_R12), PPC_RAW_MTCTR(_R12),
PPC_RAW_BCTR() PPC_RAW_BCTR()
}; };
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS unsigned long addr;
unsigned long addr = ppc_global_function_entry((void *)ftrace_regs_caller); long reladdr;
#else
unsigned long addr = ppc_global_function_entry((void *)ftrace_caller); if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_REGS))
#endif addr = ppc_global_function_entry((void *)ftrace_regs_caller);
long reladdr = addr - kernel_toc_addr(); else
addr = ppc_global_function_entry((void *)ftrace_caller);
reladdr = addr - kernel_toc_addr();
if (reladdr >= SZ_2G || reladdr < -(long)SZ_2G) { if (reladdr >= SZ_2G || reladdr < -(long)SZ_2G) {
pr_err("Address of %ps out of range of kernel_toc.\n", pr_err("Address of %ps out of range of kernel_toc.\n",
...@@ -746,11 +746,6 @@ int __init ftrace_dyn_arch_init(void) ...@@ -746,11 +746,6 @@ int __init ftrace_dyn_arch_init(void)
return 0; return 0;
} }
#else
int __init ftrace_dyn_arch_init(void)
{
return 0;
}
#endif #endif
#ifdef CONFIG_FUNCTION_GRAPH_TRACER #ifdef CONFIG_FUNCTION_GRAPH_TRACER
......
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