Skip to content

Commit 000ab69

Browse files
author
Steven Rostedt
committed
ftrace: allow archs to preform pre and post process for code modification
This patch creates the weak functions: ftrace_arch_code_modify_prepare and ftrace_arch_code_modify_post_process that are called before and after the stop machine is called to modify the kernel text. If the arch needs to do pre or post processing, it only needs to define these functions. [ Update: Ingo Molnar suggested using the name ftrace_arch_code_modify_* over using ftrace_arch_modify_* ] Signed-off-by: Steven Rostedt <srostedt@redhat.com>
1 parent 07a66d7 commit 000ab69

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

include/linux/ftrace.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ stack_trace_sysctl(struct ctl_table *table, int write,
9999
/* asm/ftrace.h must be defined for archs supporting dynamic ftrace */
100100
#include <asm/ftrace.h>
101101

102+
int ftrace_arch_code_modify_prepare(void);
103+
int ftrace_arch_code_modify_post_process(void);
104+
102105
enum {
103106
FTRACE_FL_FREE = (1 << 0),
104107
FTRACE_FL_FAILED = (1 << 1),

kernel/trace/ftrace.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,24 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
585585
return 1;
586586
}
587587

588+
/*
589+
* archs can override this function if they must do something
590+
* before the modifying code is performed.
591+
*/
592+
int __weak ftrace_arch_code_modify_prepare(void)
593+
{
594+
return 0;
595+
}
596+
597+
/*
598+
* archs can override this function if they must do something
599+
* after the modifying code is performed.
600+
*/
601+
int __weak ftrace_arch_code_modify_post_process(void)
602+
{
603+
return 0;
604+
}
605+
588606
static int __ftrace_modify_code(void *data)
589607
{
590608
int *command = data;
@@ -607,7 +625,17 @@ static int __ftrace_modify_code(void *data)
607625

608626
static void ftrace_run_update_code(int command)
609627
{
628+
int ret;
629+
630+
ret = ftrace_arch_code_modify_prepare();
631+
FTRACE_WARN_ON(ret);
632+
if (ret)
633+
return;
634+
610635
stop_machine(__ftrace_modify_code, &command, NULL);
636+
637+
ret = ftrace_arch_code_modify_post_process();
638+
FTRACE_WARN_ON(ret);
611639
}
612640

613641
static ftrace_func_t saved_ftrace_func;

0 commit comments

Comments
 (0)