Skip to content

Commit 3d82c59

Browse files
rostedtKAGA-KOKO
authored andcommitted
x86/ftrace: Move the ftrace specific code out of entry_32.S
The function tracing hook code for ftrace is not an entry point from userspace and does not belong in the entry_*.S files. It has already been moved out of entry_64.S. Move it out of entry_32.S into its own ftrace_32.S file. Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Reviewed-by: Ingo Molnar <mingo@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Link: http://lkml.kernel.org/r/20170323143445.645218946@goodmis.org Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent db65d7b commit 3d82c59

File tree

3 files changed

+176
-169
lines changed

3 files changed

+176
-169
lines changed

arch/x86/entry/entry_32.S

Lines changed: 0 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,13 @@
3535
#include <asm/errno.h>
3636
#include <asm/segment.h>
3737
#include <asm/smp.h>
38-
#include <asm/page_types.h>
3938
#include <asm/percpu.h>
4039
#include <asm/processor-flags.h>
41-
#include <asm/ftrace.h>
4240
#include <asm/irq_vectors.h>
4341
#include <asm/cpufeatures.h>
4442
#include <asm/alternative-asm.h>
4543
#include <asm/asm.h>
4644
#include <asm/smap.h>
47-
#include <asm/export.h>
4845
#include <asm/frame.h>
4946

5047
.section .entry.text, "ax"
@@ -886,172 +883,6 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
886883

887884
#endif /* CONFIG_HYPERV */
888885

889-
#ifdef CONFIG_FUNCTION_TRACER
890-
#ifdef CONFIG_DYNAMIC_FTRACE
891-
892-
ENTRY(mcount)
893-
ret
894-
END(mcount)
895-
896-
ENTRY(ftrace_caller)
897-
pushl %eax
898-
pushl %ecx
899-
pushl %edx
900-
pushl $0 /* Pass NULL as regs pointer */
901-
movl 4*4(%esp), %eax
902-
movl 0x4(%ebp), %edx
903-
movl function_trace_op, %ecx
904-
subl $MCOUNT_INSN_SIZE, %eax
905-
906-
.globl ftrace_call
907-
ftrace_call:
908-
call ftrace_stub
909-
910-
addl $4, %esp /* skip NULL pointer */
911-
popl %edx
912-
popl %ecx
913-
popl %eax
914-
.Lftrace_ret:
915-
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
916-
.globl ftrace_graph_call
917-
ftrace_graph_call:
918-
jmp ftrace_stub
919-
#endif
920-
921-
/* This is weak to keep gas from relaxing the jumps */
922-
WEAK(ftrace_stub)
923-
ret
924-
END(ftrace_caller)
925-
926-
ENTRY(ftrace_regs_caller)
927-
pushf /* push flags before compare (in cs location) */
928-
929-
/*
930-
* i386 does not save SS and ESP when coming from kernel.
931-
* Instead, to get sp, &regs->sp is used (see ptrace.h).
932-
* Unfortunately, that means eflags must be at the same location
933-
* as the current return ip is. We move the return ip into the
934-
* ip location, and move flags into the return ip location.
935-
*/
936-
pushl 4(%esp) /* save return ip into ip slot */
937-
938-
pushl $0 /* Load 0 into orig_ax */
939-
pushl %gs
940-
pushl %fs
941-
pushl %es
942-
pushl %ds
943-
pushl %eax
944-
pushl %ebp
945-
pushl %edi
946-
pushl %esi
947-
pushl %edx
948-
pushl %ecx
949-
pushl %ebx
950-
951-
movl 13*4(%esp), %eax /* Get the saved flags */
952-
movl %eax, 14*4(%esp) /* Move saved flags into regs->flags location */
953-
/* clobbering return ip */
954-
movl $__KERNEL_CS, 13*4(%esp)
955-
956-
movl 12*4(%esp), %eax /* Load ip (1st parameter) */
957-
subl $MCOUNT_INSN_SIZE, %eax /* Adjust ip */
958-
movl 0x4(%ebp), %edx /* Load parent ip (2nd parameter) */
959-
movl function_trace_op, %ecx /* Save ftrace_pos in 3rd parameter */
960-
pushl %esp /* Save pt_regs as 4th parameter */
961-
962-
GLOBAL(ftrace_regs_call)
963-
call ftrace_stub
964-
965-
addl $4, %esp /* Skip pt_regs */
966-
movl 14*4(%esp), %eax /* Move flags back into cs */
967-
movl %eax, 13*4(%esp) /* Needed to keep addl from modifying flags */
968-
movl 12*4(%esp), %eax /* Get return ip from regs->ip */
969-
movl %eax, 14*4(%esp) /* Put return ip back for ret */
970-
971-
popl %ebx
972-
popl %ecx
973-
popl %edx
974-
popl %esi
975-
popl %edi
976-
popl %ebp
977-
popl %eax
978-
popl %ds
979-
popl %es
980-
popl %fs
981-
popl %gs
982-
addl $8, %esp /* Skip orig_ax and ip */
983-
popf /* Pop flags at end (no addl to corrupt flags) */
984-
jmp .Lftrace_ret
985-
986-
popf
987-
jmp ftrace_stub
988-
#else /* ! CONFIG_DYNAMIC_FTRACE */
989-
990-
ENTRY(mcount)
991-
cmpl $__PAGE_OFFSET, %esp
992-
jb ftrace_stub /* Paging not enabled yet? */
993-
994-
cmpl $ftrace_stub, ftrace_trace_function
995-
jnz .Ltrace
996-
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
997-
cmpl $ftrace_stub, ftrace_graph_return
998-
jnz ftrace_graph_caller
999-
1000-
cmpl $ftrace_graph_entry_stub, ftrace_graph_entry
1001-
jnz ftrace_graph_caller
1002-
#endif
1003-
.globl ftrace_stub
1004-
ftrace_stub:
1005-
ret
1006-
1007-
/* taken from glibc */
1008-
.Ltrace:
1009-
pushl %eax
1010-
pushl %ecx
1011-
pushl %edx
1012-
movl 0xc(%esp), %eax
1013-
movl 0x4(%ebp), %edx
1014-
subl $MCOUNT_INSN_SIZE, %eax
1015-
1016-
call *ftrace_trace_function
1017-
1018-
popl %edx
1019-
popl %ecx
1020-
popl %eax
1021-
jmp ftrace_stub
1022-
END(mcount)
1023-
#endif /* CONFIG_DYNAMIC_FTRACE */
1024-
EXPORT_SYMBOL(mcount)
1025-
#endif /* CONFIG_FUNCTION_TRACER */
1026-
1027-
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
1028-
ENTRY(ftrace_graph_caller)
1029-
pushl %eax
1030-
pushl %ecx
1031-
pushl %edx
1032-
movl 0xc(%esp), %eax
1033-
lea 0x4(%ebp), %edx
1034-
movl (%ebp), %ecx
1035-
subl $MCOUNT_INSN_SIZE, %eax
1036-
call prepare_ftrace_return
1037-
popl %edx
1038-
popl %ecx
1039-
popl %eax
1040-
ret
1041-
END(ftrace_graph_caller)
1042-
1043-
.globl return_to_handler
1044-
return_to_handler:
1045-
pushl %eax
1046-
pushl %edx
1047-
movl %ebp, %eax
1048-
call ftrace_return_to_handler
1049-
movl %eax, %ecx
1050-
popl %edx
1051-
popl %eax
1052-
jmp *%ecx
1053-
#endif
1054-
1055886
#ifdef CONFIG_TRACING
1056887
ENTRY(trace_page_fault)
1057888
ASM_CLAC

arch/x86/kernel/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
4747
obj-$(CONFIG_IRQ_WORK) += irq_work.o
4848
obj-y += probe_roms.o
4949
obj-$(CONFIG_X86_64) += sys_x86_64.o ftrace_64.o
50+
obj-$(CONFIG_X86_32) += ftrace_32.o
5051
obj-$(CONFIG_X86_ESPFIX64) += espfix_64.o
5152
obj-$(CONFIG_SYSFS) += ksysfs.o
5253
obj-y += bootflag.o e820.o

arch/x86/kernel/ftrace_32.S

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
/*
2+
* Copyright (C) 2017 Steven Rostedt, VMware Inc.
3+
*/
4+
5+
#include <linux/linkage.h>
6+
#include <asm/page_types.h>
7+
#include <asm/segment.h>
8+
#include <asm/export.h>
9+
#include <asm/ftrace.h>
10+
11+
#ifdef CONFIG_FUNCTION_TRACER
12+
#ifdef CONFIG_DYNAMIC_FTRACE
13+
14+
ENTRY(mcount)
15+
ret
16+
END(mcount)
17+
18+
ENTRY(ftrace_caller)
19+
pushl %eax
20+
pushl %ecx
21+
pushl %edx
22+
pushl $0 /* Pass NULL as regs pointer */
23+
movl 4*4(%esp), %eax
24+
movl 0x4(%ebp), %edx
25+
movl function_trace_op, %ecx
26+
subl $MCOUNT_INSN_SIZE, %eax
27+
28+
.globl ftrace_call
29+
ftrace_call:
30+
call ftrace_stub
31+
32+
addl $4, %esp /* skip NULL pointer */
33+
popl %edx
34+
popl %ecx
35+
popl %eax
36+
.Lftrace_ret:
37+
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
38+
.globl ftrace_graph_call
39+
ftrace_graph_call:
40+
jmp ftrace_stub
41+
#endif
42+
43+
/* This is weak to keep gas from relaxing the jumps */
44+
WEAK(ftrace_stub)
45+
ret
46+
END(ftrace_caller)
47+
48+
ENTRY(ftrace_regs_caller)
49+
pushf /* push flags before compare (in cs location) */
50+
51+
/*
52+
* i386 does not save SS and ESP when coming from kernel.
53+
* Instead, to get sp, &regs->sp is used (see ptrace.h).
54+
* Unfortunately, that means eflags must be at the same location
55+
* as the current return ip is. We move the return ip into the
56+
* ip location, and move flags into the return ip location.
57+
*/
58+
pushl 4(%esp) /* save return ip into ip slot */
59+
60+
pushl $0 /* Load 0 into orig_ax */
61+
pushl %gs
62+
pushl %fs
63+
pushl %es
64+
pushl %ds
65+
pushl %eax
66+
pushl %ebp
67+
pushl %edi
68+
pushl %esi
69+
pushl %edx
70+
pushl %ecx
71+
pushl %ebx
72+
73+
movl 13*4(%esp), %eax /* Get the saved flags */
74+
movl %eax, 14*4(%esp) /* Move saved flags into regs->flags location */
75+
/* clobbering return ip */
76+
movl $__KERNEL_CS, 13*4(%esp)
77+
78+
movl 12*4(%esp), %eax /* Load ip (1st parameter) */
79+
subl $MCOUNT_INSN_SIZE, %eax /* Adjust ip */
80+
movl 0x4(%ebp), %edx /* Load parent ip (2nd parameter) */
81+
movl function_trace_op, %ecx /* Save ftrace_pos in 3rd parameter */
82+
pushl %esp /* Save pt_regs as 4th parameter */
83+
84+
GLOBAL(ftrace_regs_call)
85+
call ftrace_stub
86+
87+
addl $4, %esp /* Skip pt_regs */
88+
movl 14*4(%esp), %eax /* Move flags back into cs */
89+
movl %eax, 13*4(%esp) /* Needed to keep addl from modifying flags */
90+
movl 12*4(%esp), %eax /* Get return ip from regs->ip */
91+
movl %eax, 14*4(%esp) /* Put return ip back for ret */
92+
93+
popl %ebx
94+
popl %ecx
95+
popl %edx
96+
popl %esi
97+
popl %edi
98+
popl %ebp
99+
popl %eax
100+
popl %ds
101+
popl %es
102+
popl %fs
103+
popl %gs
104+
addl $8, %esp /* Skip orig_ax and ip */
105+
popf /* Pop flags at end (no addl to corrupt flags) */
106+
jmp .Lftrace_ret
107+
108+
popf
109+
jmp ftrace_stub
110+
#else /* ! CONFIG_DYNAMIC_FTRACE */
111+
112+
ENTRY(mcount)
113+
cmpl $__PAGE_OFFSET, %esp
114+
jb ftrace_stub /* Paging not enabled yet? */
115+
116+
cmpl $ftrace_stub, ftrace_trace_function
117+
jnz .Ltrace
118+
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
119+
cmpl $ftrace_stub, ftrace_graph_return
120+
jnz ftrace_graph_caller
121+
122+
cmpl $ftrace_graph_entry_stub, ftrace_graph_entry
123+
jnz ftrace_graph_caller
124+
#endif
125+
.globl ftrace_stub
126+
ftrace_stub:
127+
ret
128+
129+
/* taken from glibc */
130+
.Ltrace:
131+
pushl %eax
132+
pushl %ecx
133+
pushl %edx
134+
movl 0xc(%esp), %eax
135+
movl 0x4(%ebp), %edx
136+
subl $MCOUNT_INSN_SIZE, %eax
137+
138+
call *ftrace_trace_function
139+
140+
popl %edx
141+
popl %ecx
142+
popl %eax
143+
jmp ftrace_stub
144+
END(mcount)
145+
#endif /* CONFIG_DYNAMIC_FTRACE */
146+
EXPORT_SYMBOL(mcount)
147+
#endif /* CONFIG_FUNCTION_TRACER */
148+
149+
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
150+
ENTRY(ftrace_graph_caller)
151+
pushl %eax
152+
pushl %ecx
153+
pushl %edx
154+
movl 0xc(%esp), %eax
155+
lea 0x4(%ebp), %edx
156+
movl (%ebp), %ecx
157+
subl $MCOUNT_INSN_SIZE, %eax
158+
call prepare_ftrace_return
159+
popl %edx
160+
popl %ecx
161+
popl %eax
162+
ret
163+
END(ftrace_graph_caller)
164+
165+
.globl return_to_handler
166+
return_to_handler:
167+
pushl %eax
168+
pushl %edx
169+
movl %ebp, %eax
170+
call ftrace_return_to_handler
171+
movl %eax, %ecx
172+
popl %edx
173+
popl %eax
174+
jmp *%ecx
175+
#endif

0 commit comments

Comments
 (0)