Release 4.11 arch/arm/kernel/ftrace.c
/*
* Dynamic function tracing support.
*
* Copyright (C) 2008 Abhishek Sagar <sagar.abhishek@gmail.com>
* Copyright (C) 2010 Rabin Vincent <rabin@rab.in>
*
* For licencing details, see COPYING.
*
* Defines low-level handling of mcount calls when the kernel
* is compiled with the -pg flag. When using dynamic ftrace, the
* mcount call-sites get patched with NOP till they are enabled.
* All code mutation routines here are called under stop_machine().
*/
#include <linux/ftrace.h>
#include <linux/uaccess.h>
#include <linux/module.h>
#include <linux/stop_machine.h>
#include <asm/cacheflush.h>
#include <asm/opcodes.h>
#include <asm/ftrace.h>
#include <asm/insn.h>
#ifdef CONFIG_THUMB2_KERNEL
#define NOP 0xf85deb04
/* pop.w {lr} */
#else
#define NOP 0xe8bd4000
/* pop {lr} */
#endif
#ifdef CONFIG_DYNAMIC_FTRACE
#ifdef CONFIG_OLD_MCOUNT
#define OLD_MCOUNT_ADDR ((unsigned long) mcount)
#define OLD_FTRACE_ADDR ((unsigned long) ftrace_caller_old)
#define OLD_NOP 0xe1a00000
/* mov r0, r0 */
static int __ftrace_modify_code(void *data)
{
int *command = data;
set_kernel_text_rw();
ftrace_modify_all_code(*command);
set_kernel_text_ro();
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Kees Cook | 31 | 100.00% | 1 | 100.00% |
Total | 31 | 100.00% | 1 | 100.00% |
void arch_ftrace_update_code(int command)
{
stop_machine(__ftrace_modify_code, &command, NULL);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Kees Cook | 18 | 100.00% | 1 | 100.00% |
Total | 18 | 100.00% | 1 | 100.00% |
static unsigned long ftrace_nop_replace(struct dyn_ftrace *rec)
{
return rec->arch.old_mcount ? OLD_NOP : NOP;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Rabin Vincent | 20 | 86.96% | 1 | 50.00% |
Abhishek Sagar | 3 | 13.04% | 1 | 50.00% |
Total | 23 | 100.00% | 2 | 100.00% |
static unsigned long adjust_address(struct dyn_ftrace *rec, unsigned long addr)
{
if (!rec->arch.old_mcount)
return addr;
if (addr == MCOUNT_ADDR)
addr = OLD_MCOUNT_ADDR;
else if (addr == FTRACE_ADDR)
addr = OLD_FTRACE_ADDR;
return addr;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Rabin Vincent | 49 | 94.23% | 1 | 50.00% |
Abhishek Sagar | 3 | 5.77% | 1 | 50.00% |
Total | 52 | 100.00% | 2 | 100.00% |
#else
static unsigned long ftrace_nop_replace(struct dyn_ftrace *rec)
{
return NOP;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Abhishek Sagar | 9 | 60.00% | 1 | 50.00% |
Rabin Vincent | 6 | 40.00% | 1 | 50.00% |
Total | 15 | 100.00% | 2 | 100.00% |
static unsigned long adjust_address(struct dyn_ftrace *rec, unsigned long addr)
{
return addr;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Rabin Vincent | 19 | 100.00% | 1 | 100.00% |
Total | 19 | 100.00% | 1 | 100.00% |
#endif
int ftrace_arch_code_modify_prepare(void)
{
set_all_modules_text_rw();
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Rabin Vincent | 13 | 100.00% | 1 | 100.00% |
Total | 13 | 100.00% | 1 | 100.00% |
int ftrace_arch_code_modify_post_process(void)
{
set_all_modules_text_ro();
/* Make sure any TLB misses during machine stop are cleared. */
flush_tlb_all();
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Rabin Vincent | 13 | 76.47% | 1 | 50.00% |
Kees Cook | 4 | 23.53% | 1 | 50.00% |
Total | 17 | 100.00% | 2 | 100.00% |
static unsigned long ftrace_call_replace(unsigned long pc, unsigned long addr)
{
return arm_gen_branch_link(pc, addr);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Rabin Vincent | 23 | 100.00% | 2 | 100.00% |
Total | 23 | 100.00% | 2 | 100.00% |
static int ftrace_modify_code(unsigned long pc, unsigned long old,
unsigned long new, bool validate)
{
unsigned long replaced;
if (IS_ENABLED(CONFIG_THUMB2_KERNEL)) {
old = __opcode_to_mem_thumb32(old);
new = __opcode_to_mem_thumb32(new);
} else {
old = __opcode_to_mem_arm(old);
new = __opcode_to_mem_arm(new);
}
if (validate) {
if (probe_kernel_read(&replaced, (void *)pc, MCOUNT_INSN_SIZE))
return -EFAULT;
if (replaced != old)
return -EINVAL;
}
if (probe_kernel_write((void *)pc, &new, MCOUNT_INSN_SIZE))
return -EPERM;
flush_icache_range(pc, pc + MCOUNT_INSN_SIZE);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Rabin Vincent | 96 | 72.18% | 3 | 60.00% |
Abhishek Sagar | 37 | 27.82% | 2 | 40.00% |
Total | 133 | 100.00% | 5 | 100.00% |
int ftrace_update_ftrace_func(ftrace_func_t func)
{
unsigned long pc;
unsigned long new;
int ret;
pc = (unsigned long)&ftrace_call;
new = ftrace_call_replace(pc, (unsigned long)func);
ret = ftrace_modify_code(pc, 0, new, false);
#ifdef CONFIG_OLD_MCOUNT
if (!ret) {
pc = (unsigned long)&ftrace_call_old;
new = ftrace_call_replace(pc, (unsigned long)func);
ret = ftrace_modify_code(pc, 0, new, false);
}
#endif
return ret;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Rabin Vincent | 55 | 52.88% | 2 | 66.67% |
Abhishek Sagar | 49 | 47.12% | 1 | 33.33% |
Total | 104 | 100.00% | 3 | 100.00% |
int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr)
{
unsigned long new, old;
unsigned long ip = rec->ip;
old = ftrace_nop_replace(rec);
new = ftrace_call_replace(ip, adjust_address(rec, addr));
return ftrace_modify_code(rec->ip, old, new, true);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Rabin Vincent | 63 | 100.00% | 2 | 100.00% |
Total | 63 | 100.00% | 2 | 100.00% |
int ftrace_make_nop(struct module *mod,
struct dyn_ftrace *rec, unsigned long addr)
{
unsigned long ip = rec->ip;
unsigned long old;
unsigned long new;
int ret;
old = ftrace_call_replace(ip, adjust_address(rec, addr));
new = ftrace_nop_replace(rec);
ret = ftrace_modify_code(ip, old, new, true);
#ifdef CONFIG_OLD_MCOUNT
if (ret == -EINVAL && addr == MCOUNT_ADDR) {
rec->arch.old_mcount = true;
old = ftrace_call_replace(ip, adjust_address(rec, addr));
new = ftrace_nop_replace(rec);
ret = ftrace_modify_code(ip, old, new, true);
}
#endif
return ret;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Rabin Vincent | 131 | 97.04% | 2 | 66.67% |
Abhishek Sagar | 4 | 2.96% | 1 | 33.33% |
Total | 135 | 100.00% | 3 | 100.00% |
int __init ftrace_dyn_arch_init(void)
{
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Abhishek Sagar | 11 | 100.00% | 1 | 100.00% |
Total | 11 | 100.00% | 1 | 100.00% |
#endif /* CONFIG_DYNAMIC_FTRACE */
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr,
unsigned long frame_pointer)
{
unsigned long return_hooker = (unsigned long) &return_to_handler;
struct ftrace_graph_ent trace;
unsigned long old;
int err;
if (unlikely(atomic_read(¤t->tracing_graph_pause)))
return;
old = *parent;
*parent = return_hooker;
trace.func = self_addr;
trace.depth = current->curr_ret_stack + 1;
/* Only trace if the calling function expects to */
if (!ftrace_graph_entry(&trace)) {
*parent = old;
return;
}
err = ftrace_push_return_trace(old, self_addr, &trace.depth,
frame_pointer, NULL);
if (err == -EBUSY) {
*parent = old;
return;
}
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Tim Bird | 95 | 72.52% | 1 | 33.33% |
Colin Cross | 34 | 25.95% | 1 | 33.33% |
Josh Poimboeuf | 2 | 1.53% | 1 | 33.33% |
Total | 131 | 100.00% | 3 | 100.00% |
#ifdef CONFIG_DYNAMIC_FTRACE
extern unsigned long ftrace_graph_call;
extern unsigned long ftrace_graph_call_old;
extern void ftrace_graph_caller_old(void);
static int __ftrace_modify_caller(unsigned long *callsite,
void (*func) (void), bool enable)
{
unsigned long caller_fn = (unsigned long) func;
unsigned long pc = (unsigned long) callsite;
unsigned long branch = arm_gen_branch(pc, caller_fn);
unsigned long nop = 0xe1a00000; /* mov r0, r0 */
unsigned long old = enable ? nop : branch;
unsigned long new = enable ? branch : nop;
return ftrace_modify_code(pc, old, new, true);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Rabin Vincent | 93 | 100.00% | 3 | 100.00% |
Total | 93 | 100.00% | 3 | 100.00% |
static int ftrace_modify_graph_caller(bool enable)
{
int ret;
ret = __ftrace_modify_caller(&ftrace_graph_call,
ftrace_graph_caller,
enable);
#ifdef CONFIG_OLD_MCOUNT
if (!ret)
ret = __ftrace_modify_caller(&ftrace_graph_call_old,
ftrace_graph_caller_old,
enable);
#endif
return ret;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Rabin Vincent | 49 | 100.00% | 1 | 100.00% |
Total | 49 | 100.00% | 1 | 100.00% |
int ftrace_enable_ftrace_graph_caller(void)
{
return ftrace_modify_graph_caller(true);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Rabin Vincent | 13 | 100.00% | 1 | 100.00% |
Total | 13 | 100.00% | 1 | 100.00% |
int ftrace_disable_ftrace_graph_caller(void)
{
return ftrace_modify_graph_caller(false);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Rabin Vincent | 13 | 100.00% | 1 | 100.00% |
Total | 13 | 100.00% | 1 | 100.00% |
#endif /* CONFIG_DYNAMIC_FTRACE */
#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Rabin Vincent | 722 | 68.57% | 7 | 50.00% |
Abhishek Sagar | 131 | 12.44% | 2 | 14.29% |
Tim Bird | 107 | 10.16% | 1 | 7.14% |
Kees Cook | 56 | 5.32% | 1 | 7.14% |
Colin Cross | 34 | 3.23% | 1 | 7.14% |
Josh Poimboeuf | 2 | 0.19% | 1 | 7.14% |
Wang Nan | 1 | 0.09% | 1 | 7.14% |
Total | 1053 | 100.00% | 14 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.