Skip to content

Commit 745cfea

Browse files
committed
x86/ftrace: Fix warning and considate ftrace_jmp_replace() and ftrace_call_replace()
Arnd reported the following compiler warning: arch/x86/kernel/ftrace.c:669:23: error: 'ftrace_jmp_replace' defined but not used [-Werror=unused-function] The ftrace_jmp_replace() function now only has a single user and should be simply moved by that user. But looking at the code, it shows that ftrace_jmp_replace() is similar to ftrace_call_replace() except that instead of using the opcode of 0xe8 it uses 0xe9. It makes more sense to consolidate that function into one implementation that both ftrace_jmp_replace() and ftrace_call_replace() use by passing in the op code separate. The structure in ftrace_code_union is also modified to replace the "e8" field with the more appropriate name "op". Cc: stable@vger.kernel.org Reported-by: Arnd Bergmann <arnd@arndb.de> Acked-by: Arnd Bergmann <arnd@arndb.de> Link: http://lkml.kernel.org/r/20190304200748.1418790-1-arnd@arndb.de Fixes: d2a68c4 ("x86/ftrace: Do not call function graph from dynamic trampolines") Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent 83540fb commit 745cfea

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

arch/x86/kernel/ftrace.c

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ int ftrace_arch_code_modify_post_process(void)
4949
union ftrace_code_union {
5050
char code[MCOUNT_INSN_SIZE];
5151
struct {
52-
unsigned char e8;
52+
unsigned char op;
5353
int offset;
5454
} __attribute__((packed));
5555
};
@@ -59,20 +59,23 @@ static int ftrace_calc_offset(long ip, long addr)
5959
return (int)(addr - ip);
6060
}
6161

62-
static unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr)
62+
static unsigned char *
63+
ftrace_text_replace(unsigned char op, unsigned long ip, unsigned long addr)
6364
{
6465
static union ftrace_code_union calc;
6566

66-
calc.e8 = 0xe8;
67+
calc.op = op;
6768
calc.offset = ftrace_calc_offset(ip + MCOUNT_INSN_SIZE, addr);
6869

69-
/*
70-
* No locking needed, this must be called via kstop_machine
71-
* which in essence is like running on a uniprocessor machine.
72-
*/
7370
return calc.code;
7471
}
7572

73+
static unsigned char *
74+
ftrace_call_replace(unsigned long ip, unsigned long addr)
75+
{
76+
return ftrace_text_replace(0xe8, ip, addr);
77+
}
78+
7679
static inline int
7780
within(unsigned long addr, unsigned long start, unsigned long end)
7881
{
@@ -664,22 +667,6 @@ int __init ftrace_dyn_arch_init(void)
664667
return 0;
665668
}
666669

667-
#if defined(CONFIG_X86_64) || defined(CONFIG_FUNCTION_GRAPH_TRACER)
668-
static unsigned char *ftrace_jmp_replace(unsigned long ip, unsigned long addr)
669-
{
670-
static union ftrace_code_union calc;
671-
672-
/* Jmp not a call (ignore the .e8) */
673-
calc.e8 = 0xe9;
674-
calc.offset = ftrace_calc_offset(ip + MCOUNT_INSN_SIZE, addr);
675-
676-
/*
677-
* ftrace external locks synchronize the access to the static variable.
678-
*/
679-
return calc.code;
680-
}
681-
#endif
682-
683670
/* Currently only x86_64 supports dynamic trampolines */
684671
#ifdef CONFIG_X86_64
685672

@@ -891,8 +878,8 @@ static void *addr_from_call(void *ptr)
891878
return NULL;
892879

893880
/* Make sure this is a call */
894-
if (WARN_ON_ONCE(calc.e8 != 0xe8)) {
895-
pr_warn("Expected e8, got %x\n", calc.e8);
881+
if (WARN_ON_ONCE(calc.op != 0xe8)) {
882+
pr_warn("Expected e8, got %x\n", calc.op);
896883
return NULL;
897884
}
898885

@@ -963,6 +950,11 @@ void arch_ftrace_trampoline_free(struct ftrace_ops *ops)
963950
#ifdef CONFIG_DYNAMIC_FTRACE
964951
extern void ftrace_graph_call(void);
965952

953+
static unsigned char *ftrace_jmp_replace(unsigned long ip, unsigned long addr)
954+
{
955+
return ftrace_text_replace(0xe9, ip, addr);
956+
}
957+
966958
static int ftrace_mod_jmp(unsigned long ip, void *func)
967959
{
968960
unsigned char *new;

0 commit comments

Comments
 (0)