Skip to content

Commit bad90aa

Browse files
rnavmpe
authored andcommitted
powerpc/ftrace: Consolidate ftrace support into fewer files
ftrace_low.S has just the _mcount stub and return_to_handler(). Merge this back into ftrace_mprofile.S and ftrace_64_pg.S to keep all ftrace code together, and to allow those to evolve independently. ftrace_mprofile.S is also not an entirely accurate name since this also holds ppc32 code. This will be all the more incorrect once support for -fpatchable-function-entry is added. Rename files here to more accurately describe the code: - ftrace_mprofile.S is renamed to ftrace_entry.S - ftrace_pg.c is renamed to ftrace_64_pg.c - ftrace_64_pg.S is rename to ftrace_64_pg_entry.S Signed-off-by: Naveen N Rao <naveen@kernel.org> Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://msgid.link/b900c9a8bba9d6c3c295e0f99886acf3e5bf6f7b.1687166935.git.naveen@kernel.org
1 parent f3993a0 commit bad90aa

5 files changed

Lines changed: 131 additions & 76 deletions

File tree

arch/powerpc/kernel/trace/Makefile

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66
ifdef CONFIG_FUNCTION_TRACER
77
# do not trace tracer code
88
CFLAGS_REMOVE_ftrace.o = $(CC_FLAGS_FTRACE)
9-
CFLAGS_REMOVE_ftrace_pg.o = $(CC_FLAGS_FTRACE)
9+
CFLAGS_REMOVE_ftrace_64_pg.o = $(CC_FLAGS_FTRACE)
1010
endif
1111

12-
obj32-$(CONFIG_FUNCTION_TRACER) += ftrace_mprofile.o ftrace.o
12+
obj32-$(CONFIG_FUNCTION_TRACER) += ftrace.o ftrace_entry.o
1313
ifdef CONFIG_MPROFILE_KERNEL
14-
obj64-$(CONFIG_FUNCTION_TRACER) += ftrace_mprofile.o ftrace.o
14+
obj64-$(CONFIG_FUNCTION_TRACER) += ftrace.o ftrace_entry.o
1515
else
16-
obj64-$(CONFIG_FUNCTION_TRACER) += ftrace_64_pg.o ftrace_pg.o
16+
obj64-$(CONFIG_FUNCTION_TRACER) += ftrace_64_pg.o ftrace_64_pg_entry.o
1717
endif
18-
obj-$(CONFIG_FUNCTION_TRACER) += ftrace_low.o
1918
obj-$(CONFIG_TRACING) += trace_clock.o
2019

2120
obj-$(CONFIG_PPC64) += $(obj64-y)
@@ -26,7 +25,7 @@ GCOV_PROFILE_ftrace.o := n
2625
KCOV_INSTRUMENT_ftrace.o := n
2726
KCSAN_SANITIZE_ftrace.o := n
2827
UBSAN_SANITIZE_ftrace.o := n
29-
GCOV_PROFILE_ftrace_pg.o := n
30-
KCOV_INSTRUMENT_ftrace_pg.o := n
31-
KCSAN_SANITIZE_ftrace_pg.o := n
32-
UBSAN_SANITIZE_ftrace_pg.o := n
28+
GCOV_PROFILE_ftrace_64_pg.o := n
29+
KCOV_INSTRUMENT_ftrace_64_pg.o := n
30+
KCSAN_SANITIZE_ftrace_64_pg.o := n
31+
UBSAN_SANITIZE_ftrace_64_pg.o := n

arch/powerpc/kernel/trace/ftrace_64_pg.S

Lines changed: 0 additions & 66 deletions
This file was deleted.

arch/powerpc/kernel/trace/ftrace_low.S renamed to arch/powerpc/kernel/trace/ftrace_64_pg_entry.S

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* SPDX-License-Identifier: GPL-2.0-or-later */
22
/*
3-
* Split from entry_64.S
3+
* Split from ftrace_64.S
44
*/
55

66
#include <linux/export.h>
@@ -10,6 +10,62 @@
1010
#include <asm/ftrace.h>
1111
#include <asm/ppc-opcode.h>
1212

13+
_GLOBAL_TOC(ftrace_caller)
14+
lbz r3, PACA_FTRACE_ENABLED(r13)
15+
cmpdi r3, 0
16+
beqlr
17+
18+
/* Taken from output of objdump from lib64/glibc */
19+
mflr r3
20+
ld r11, 0(r1)
21+
stdu r1, -112(r1)
22+
std r3, 128(r1)
23+
ld r4, 16(r11)
24+
subi r3, r3, MCOUNT_INSN_SIZE
25+
.globl ftrace_call
26+
ftrace_call:
27+
bl ftrace_stub
28+
nop
29+
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
30+
.globl ftrace_graph_call
31+
ftrace_graph_call:
32+
b ftrace_graph_stub
33+
_GLOBAL(ftrace_graph_stub)
34+
#endif
35+
ld r0, 128(r1)
36+
mtlr r0
37+
addi r1, r1, 112
38+
39+
_GLOBAL(ftrace_stub)
40+
blr
41+
42+
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
43+
_GLOBAL(ftrace_graph_caller)
44+
addi r5, r1, 112
45+
/* load r4 with local address */
46+
ld r4, 128(r1)
47+
subi r4, r4, MCOUNT_INSN_SIZE
48+
49+
/* Grab the LR out of the caller stack frame */
50+
ld r11, 112(r1)
51+
ld r3, 16(r11)
52+
53+
bl prepare_ftrace_return
54+
nop
55+
56+
/*
57+
* prepare_ftrace_return gives us the address we divert to.
58+
* Change the LR in the callers stack frame to this.
59+
*/
60+
ld r11, 112(r1)
61+
std r3, 16(r11)
62+
63+
ld r0, 128(r1)
64+
mtlr r0
65+
addi r1, r1, 112
66+
blr
67+
#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
68+
1369
.pushsection ".tramp.ftrace.text","aw",@progbits;
1470
.globl ftrace_tramp_text
1571
ftrace_tramp_text:

arch/powerpc/kernel/trace/ftrace_mprofile.S renamed to arch/powerpc/kernel/trace/ftrace_entry.S

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Split from ftrace_64.S
44
*/
55

6+
#include <linux/export.h>
67
#include <linux/magic.h>
78
#include <asm/ppc_asm.h>
89
#include <asm/asm-offsets.h>
@@ -248,3 +249,68 @@ livepatch_handler:
248249
/* Return to original caller of live patched function */
249250
blr
250251
#endif /* CONFIG_LIVEPATCH */
252+
253+
_GLOBAL(mcount)
254+
_GLOBAL(_mcount)
255+
EXPORT_SYMBOL(_mcount)
256+
mflr r12
257+
mtctr r12
258+
mtlr r0
259+
bctr
260+
261+
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
262+
_GLOBAL(return_to_handler)
263+
/* need to save return values */
264+
#ifdef CONFIG_PPC64
265+
std r4, -32(r1)
266+
std r3, -24(r1)
267+
/* save TOC */
268+
std r2, -16(r1)
269+
std r31, -8(r1)
270+
mr r31, r1
271+
stdu r1, -112(r1)
272+
273+
/*
274+
* We might be called from a module.
275+
* Switch to our TOC to run inside the core kernel.
276+
*/
277+
LOAD_PACA_TOC()
278+
#else
279+
stwu r1, -16(r1)
280+
stw r3, 8(r1)
281+
stw r4, 12(r1)
282+
#endif
283+
284+
bl ftrace_return_to_handler
285+
nop
286+
287+
/* return value has real return address */
288+
mtlr r3
289+
290+
#ifdef CONFIG_PPC64
291+
ld r1, 0(r1)
292+
ld r4, -32(r1)
293+
ld r3, -24(r1)
294+
ld r2, -16(r1)
295+
ld r31, -8(r1)
296+
#else
297+
lwz r3, 8(r1)
298+
lwz r4, 12(r1)
299+
addi r1, r1, 16
300+
#endif
301+
302+
/* Jump back to real return address */
303+
blr
304+
#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
305+
306+
.pushsection ".tramp.ftrace.text","aw",@progbits;
307+
.globl ftrace_tramp_text
308+
ftrace_tramp_text:
309+
.space 32
310+
.popsection
311+
312+
.pushsection ".tramp.ftrace.init","aw",@progbits;
313+
.globl ftrace_tramp_init
314+
ftrace_tramp_init:
315+
.space 32
316+
.popsection

0 commit comments

Comments
 (0)