aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt (VMware) <rostedt@goodmis.org>2019-05-09 15:32:05 -0400
committerSteven Rostedt (VMware) <rostedt@goodmis.org>2019-05-10 12:33:09 -0400
commit562e14f72292249e52e6346a9e3a30be652b0cf6 (patch)
tree25e276f9e975255e922f28d659aebe6de67d8497
parent518049d9d3e25dcd7be6e3d728e86f292ad0c922 (diff)
ftrace/x86: Remove mcount support
There's two methods of enabling function tracing in Linux on x86. One is with just "gcc -pg" and the other is "gcc -pg -mfentry". The former will use calls to a special function "mcount" after the frame is set up in all C functions. The latter will add calls to a special function called "fentry" as the very first instruction of all C functions. At compile time, there is a check to see if gcc supports, -mfentry, and if it does, it will use that, because it is more versatile and less error prone for function tracing. Starting with v4.19, the minimum gcc supported to build the Linux kernel, was raised to version 4.6. That also happens to be the first gcc version to support -mfentry. Since on x86, using gcc versions from 4.6 and beyond will unconditionally enable the -mfentry, it will no longer use mcount as the method for inserting calls into the C functions of the kernel. This means that there is no point in continuing to maintain mcount in x86. Remove support for using mcount. This makes the code less complex, and will also allow it to be simplified in the future. Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Jiri Kosina <jkosina@suse.cz> Acked-by: Josh Poimboeuf <jpoimboe@redhat.com> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
-rw-r--r--arch/x86/include/asm/ftrace.h8
-rw-r--r--arch/x86/include/asm/livepatch.h3
-rw-r--r--arch/x86/kernel/ftrace_32.S36
-rw-r--r--arch/x86/kernel/ftrace_64.S28
4 files changed, 9 insertions, 66 deletions
diff --git a/arch/x86/include/asm/ftrace.h b/arch/x86/include/asm/ftrace.h
index cf350639e76d..287f1f7b2e52 100644
--- a/arch/x86/include/asm/ftrace.h
+++ b/arch/x86/include/asm/ftrace.h
@@ -3,12 +3,10 @@
3#define _ASM_X86_FTRACE_H 3#define _ASM_X86_FTRACE_H
4 4
5#ifdef CONFIG_FUNCTION_TRACER 5#ifdef CONFIG_FUNCTION_TRACER
6#ifdef CC_USING_FENTRY 6#ifndef CC_USING_FENTRY
7# define MCOUNT_ADDR ((unsigned long)(__fentry__)) 7# error Compiler does not support fentry?
8#else
9# define MCOUNT_ADDR ((unsigned long)(mcount))
10# define HAVE_FUNCTION_GRAPH_FP_TEST
11#endif 8#endif
9# define MCOUNT_ADDR ((unsigned long)(__fentry__))
12#define MCOUNT_INSN_SIZE 5 /* sizeof mcount call */ 10#define MCOUNT_INSN_SIZE 5 /* sizeof mcount call */
13 11
14#ifdef CONFIG_DYNAMIC_FTRACE 12#ifdef CONFIG_DYNAMIC_FTRACE
diff --git a/arch/x86/include/asm/livepatch.h b/arch/x86/include/asm/livepatch.h
index ed80003ce3e2..2f2bdf0662f8 100644
--- a/arch/x86/include/asm/livepatch.h
+++ b/arch/x86/include/asm/livepatch.h
@@ -26,9 +26,6 @@
26 26
27static inline int klp_check_compiler_support(void) 27static inline int klp_check_compiler_support(void)
28{ 28{
29#ifndef CC_USING_FENTRY
30 return 1;
31#endif
32 return 0; 29 return 0;
33} 30}
34 31
diff --git a/arch/x86/kernel/ftrace_32.S b/arch/x86/kernel/ftrace_32.S
index 459e6b4a19bc..2ba914a34b06 100644
--- a/arch/x86/kernel/ftrace_32.S
+++ b/arch/x86/kernel/ftrace_32.S
@@ -10,20 +10,10 @@
10#include <asm/ftrace.h> 10#include <asm/ftrace.h>
11#include <asm/nospec-branch.h> 11#include <asm/nospec-branch.h>
12 12
13#ifdef CC_USING_FENTRY
14# define function_hook __fentry__ 13# define function_hook __fentry__
15EXPORT_SYMBOL(__fentry__) 14EXPORT_SYMBOL(__fentry__)
16#else
17# define function_hook mcount
18EXPORT_SYMBOL(mcount)
19#endif
20
21/* mcount uses a frame pointer even if CONFIG_FRAME_POINTER is not set */
22#if !defined(CC_USING_FENTRY) || defined(CONFIG_FRAME_POINTER)
23# define USING_FRAME_POINTER
24#endif
25 15
26#ifdef USING_FRAME_POINTER 16#ifdef CONFIG_FRAME_POINTER
27# define MCOUNT_FRAME 1 /* using frame = true */ 17# define MCOUNT_FRAME 1 /* using frame = true */
28#else 18#else
29# define MCOUNT_FRAME 0 /* using frame = false */ 19# define MCOUNT_FRAME 0 /* using frame = false */
@@ -35,8 +25,7 @@ END(function_hook)
35 25
36ENTRY(ftrace_caller) 26ENTRY(ftrace_caller)
37 27
38#ifdef USING_FRAME_POINTER 28#ifdef CONFIG_FRAME_POINTER
39# ifdef CC_USING_FENTRY
40 /* 29 /*
41 * Frame pointers are of ip followed by bp. 30 * Frame pointers are of ip followed by bp.
42 * Since fentry is an immediate jump, we are left with 31 * Since fentry is an immediate jump, we are left with
@@ -47,7 +36,7 @@ ENTRY(ftrace_caller)
47 pushl %ebp 36 pushl %ebp
48 movl %esp, %ebp 37 movl %esp, %ebp
49 pushl 2*4(%esp) /* function ip */ 38 pushl 2*4(%esp) /* function ip */
50# endif 39
51 /* For mcount, the function ip is directly above */ 40 /* For mcount, the function ip is directly above */
52 pushl %ebp 41 pushl %ebp
53 movl %esp, %ebp 42 movl %esp, %ebp
@@ -57,7 +46,7 @@ ENTRY(ftrace_caller)
57 pushl %edx 46 pushl %edx
58 pushl $0 /* Pass NULL as regs pointer */ 47 pushl $0 /* Pass NULL as regs pointer */
59 48
60#ifdef USING_FRAME_POINTER 49#ifdef CONFIG_FRAME_POINTER
61 /* Load parent ebp into edx */ 50 /* Load parent ebp into edx */
62 movl 4*4(%esp), %edx 51 movl 4*4(%esp), %edx
63#else 52#else
@@ -80,13 +69,11 @@ ftrace_call:
80 popl %edx 69 popl %edx
81 popl %ecx 70 popl %ecx
82 popl %eax 71 popl %eax
83#ifdef USING_FRAME_POINTER 72#ifdef CONFIG_FRAME_POINTER
84 popl %ebp 73 popl %ebp
85# ifdef CC_USING_FENTRY
86 addl $4,%esp /* skip function ip */ 74 addl $4,%esp /* skip function ip */
87 popl %ebp /* this is the orig bp */ 75 popl %ebp /* this is the orig bp */
88 addl $4, %esp /* skip parent ip */ 76 addl $4, %esp /* skip parent ip */
89# endif
90#endif 77#endif
91.Lftrace_ret: 78.Lftrace_ret:
92#ifdef CONFIG_FUNCTION_GRAPH_TRACER 79#ifdef CONFIG_FUNCTION_GRAPH_TRACER
@@ -131,11 +118,7 @@ ENTRY(ftrace_regs_caller)
131 118
132 movl 12*4(%esp), %eax /* Load ip (1st parameter) */ 119 movl 12*4(%esp), %eax /* Load ip (1st parameter) */
133 subl $MCOUNT_INSN_SIZE, %eax /* Adjust ip */ 120 subl $MCOUNT_INSN_SIZE, %eax /* Adjust ip */
134#ifdef CC_USING_FENTRY
135 movl 15*4(%esp), %edx /* Load parent ip (2nd parameter) */ 121 movl 15*4(%esp), %edx /* Load parent ip (2nd parameter) */
136#else
137 movl 0x4(%ebp), %edx /* Load parent ip (2nd parameter) */
138#endif
139 movl function_trace_op, %ecx /* Save ftrace_pos in 3rd parameter */ 122 movl function_trace_op, %ecx /* Save ftrace_pos in 3rd parameter */
140 pushl %esp /* Save pt_regs as 4th parameter */ 123 pushl %esp /* Save pt_regs as 4th parameter */
141 124
@@ -176,13 +159,8 @@ ENTRY(ftrace_graph_caller)
176 pushl %edx 159 pushl %edx
177 movl 3*4(%esp), %eax 160 movl 3*4(%esp), %eax
178 /* Even with frame pointers, fentry doesn't have one here */ 161 /* Even with frame pointers, fentry doesn't have one here */
179#ifdef CC_USING_FENTRY
180 lea 4*4(%esp), %edx 162 lea 4*4(%esp), %edx
181 movl $0, %ecx 163 movl $0, %ecx
182#else
183 lea 0x4(%ebp), %edx
184 movl (%ebp), %ecx
185#endif
186 subl $MCOUNT_INSN_SIZE, %eax 164 subl $MCOUNT_INSN_SIZE, %eax
187 call prepare_ftrace_return 165 call prepare_ftrace_return
188 popl %edx 166 popl %edx
@@ -195,11 +173,7 @@ END(ftrace_graph_caller)
195return_to_handler: 173return_to_handler:
196 pushl %eax 174 pushl %eax
197 pushl %edx 175 pushl %edx
198#ifdef CC_USING_FENTRY
199 movl $0, %eax 176 movl $0, %eax
200#else
201 movl %ebp, %eax
202#endif
203 call ftrace_return_to_handler 177 call ftrace_return_to_handler
204 movl %eax, %ecx 178 movl %eax, %ecx
205 popl %edx 179 popl %edx
diff --git a/arch/x86/kernel/ftrace_64.S b/arch/x86/kernel/ftrace_64.S
index 75f2b36b41a6..10eb2760ef2c 100644
--- a/arch/x86/kernel/ftrace_64.S
+++ b/arch/x86/kernel/ftrace_64.S
@@ -13,22 +13,12 @@
13 .code64 13 .code64
14 .section .entry.text, "ax" 14 .section .entry.text, "ax"
15 15
16#ifdef CC_USING_FENTRY
17# define function_hook __fentry__ 16# define function_hook __fentry__
18EXPORT_SYMBOL(__fentry__) 17EXPORT_SYMBOL(__fentry__)
19#else
20# define function_hook mcount
21EXPORT_SYMBOL(mcount)
22#endif
23 18
24#ifdef CONFIG_FRAME_POINTER 19#ifdef CONFIG_FRAME_POINTER
25# ifdef CC_USING_FENTRY
26/* Save parent and function stack frames (rip and rbp) */ 20/* Save parent and function stack frames (rip and rbp) */
27# define MCOUNT_FRAME_SIZE (8+16*2) 21# define MCOUNT_FRAME_SIZE (8+16*2)
28# else
29/* Save just function stack frame (rip and rbp) */
30# define MCOUNT_FRAME_SIZE (8+16)
31# endif
32#else 22#else
33/* No need to save a stack frame */ 23/* No need to save a stack frame */
34# define MCOUNT_FRAME_SIZE 0 24# define MCOUNT_FRAME_SIZE 0
@@ -75,17 +65,13 @@ EXPORT_SYMBOL(mcount)
75 * fentry is called before the stack frame is set up, where as mcount 65 * fentry is called before the stack frame is set up, where as mcount
76 * is called afterward. 66 * is called afterward.
77 */ 67 */
78#ifdef CC_USING_FENTRY 68
79 /* Save the parent pointer (skip orig rbp and our return address) */ 69 /* Save the parent pointer (skip orig rbp and our return address) */
80 pushq \added+8*2(%rsp) 70 pushq \added+8*2(%rsp)
81 pushq %rbp 71 pushq %rbp
82 movq %rsp, %rbp 72 movq %rsp, %rbp
83 /* Save the return address (now skip orig rbp, rbp and parent) */ 73 /* Save the return address (now skip orig rbp, rbp and parent) */
84 pushq \added+8*3(%rsp) 74 pushq \added+8*3(%rsp)
85#else
86 /* Can't assume that rip is before this (unless added was zero) */
87 pushq \added+8(%rsp)
88#endif
89 pushq %rbp 75 pushq %rbp
90 movq %rsp, %rbp 76 movq %rsp, %rbp
91#endif /* CONFIG_FRAME_POINTER */ 77#endif /* CONFIG_FRAME_POINTER */
@@ -113,12 +99,7 @@ EXPORT_SYMBOL(mcount)
113 movq %rdx, RBP(%rsp) 99 movq %rdx, RBP(%rsp)
114 100
115 /* Copy the parent address into %rsi (second parameter) */ 101 /* Copy the parent address into %rsi (second parameter) */
116#ifdef CC_USING_FENTRY
117 movq MCOUNT_REG_SIZE+8+\added(%rsp), %rsi 102 movq MCOUNT_REG_SIZE+8+\added(%rsp), %rsi
118#else
119 /* %rdx contains original %rbp */
120 movq 8(%rdx), %rsi
121#endif
122 103
123 /* Move RIP to its proper location */ 104 /* Move RIP to its proper location */
124 movq MCOUNT_REG_SIZE+\added(%rsp), %rdi 105 movq MCOUNT_REG_SIZE+\added(%rsp), %rdi
@@ -303,15 +284,8 @@ ENTRY(ftrace_graph_caller)
303 /* Saves rbp into %rdx and fills first parameter */ 284 /* Saves rbp into %rdx and fills first parameter */
304 save_mcount_regs 285 save_mcount_regs
305 286
306#ifdef CC_USING_FENTRY
307 leaq MCOUNT_REG_SIZE+8(%rsp), %rsi 287 leaq MCOUNT_REG_SIZE+8(%rsp), %rsi
308 movq $0, %rdx /* No framepointers needed */ 288 movq $0, %rdx /* No framepointers needed */
309#else
310 /* Save address of the return address of traced function */
311 leaq 8(%rdx), %rsi
312 /* ftrace does sanity checks against frame pointers */
313 movq (%rdx), %rdx
314#endif
315 call prepare_ftrace_return 289 call prepare_ftrace_return
316 290
317 restore_mcount_regs 291 restore_mcount_regs