Skip to content

Commit a3ed415

Browse files
mhiramatrostedt
authored andcommitted
fgraph: Replace fgraph_ret_regs with ftrace_regs
Use ftrace_regs instead of fgraph_ret_regs for tracing return value on function_graph tracer because of simplifying the callback interface. The CONFIG_HAVE_FUNCTION_GRAPH_RETVAL is also replaced by CONFIG_HAVE_FUNCTION_GRAPH_FREGS. Signed-off-by: Masami Hiramatsu (Google) <[email protected]> Acked-by: Heiko Carstens <[email protected]> Acked-by: Will Deacon <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Florent Revest <[email protected]> Cc: Martin KaFai Lau <[email protected]> Cc: bpf <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Alan Maguire <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Huacai Chen <[email protected]> Cc: WANG Xuerui <[email protected]> Cc: Paul Walmsley <[email protected]> Cc: Palmer Dabbelt <[email protected]> Cc: Albert Ou <[email protected]> Cc: Vasily Gorbik <[email protected]> Cc: Alexander Gordeev <[email protected]> Cc: Heiko Carstens <[email protected]> Cc: Christian Borntraeger <[email protected]> Cc: Sven Schnelle <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Dave Hansen <[email protected]> Cc: [email protected] Cc: "H. Peter Anvin" <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Link: https://lore.kernel.org/173518991508.391279.16635322774382197642.stgit@devnote2 Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 41705c4 commit a3ed415

File tree

24 files changed

+119
-207
lines changed

24 files changed

+119
-207
lines changed

arch/arm64/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ config ARM64
219219
select HAVE_FTRACE_MCOUNT_RECORD
220220
select HAVE_FUNCTION_TRACER
221221
select HAVE_FUNCTION_ERROR_INJECTION
222+
select HAVE_FUNCTION_GRAPH_FREGS
222223
select HAVE_FUNCTION_GRAPH_TRACER
223224
select HAVE_FUNCTION_GRAPH_RETVAL
224225
select HAVE_GCC_PLUGINS

arch/arm64/include/asm/ftrace.h

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ ftrace_override_function_with_return(struct ftrace_regs *fregs)
129129
arch_ftrace_regs(fregs)->pc = arch_ftrace_regs(fregs)->lr;
130130
}
131131

132+
static __always_inline unsigned long
133+
ftrace_regs_get_frame_pointer(const struct ftrace_regs *fregs)
134+
{
135+
return arch_ftrace_regs(fregs)->fp;
136+
}
137+
132138
int ftrace_regs_query_register_offset(const char *name);
133139

134140
int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec);
@@ -186,23 +192,6 @@ static inline bool arch_syscall_match_sym_name(const char *sym,
186192

187193
#ifndef __ASSEMBLY__
188194
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
189-
struct fgraph_ret_regs {
190-
/* x0 - x7 */
191-
unsigned long regs[8];
192-
193-
unsigned long fp;
194-
unsigned long __unused;
195-
};
196-
197-
static inline unsigned long fgraph_ret_regs_return_value(struct fgraph_ret_regs *ret_regs)
198-
{
199-
return ret_regs->regs[0];
200-
}
201-
202-
static inline unsigned long fgraph_ret_regs_frame_pointer(struct fgraph_ret_regs *ret_regs)
203-
{
204-
return ret_regs->fp;
205-
}
206195

207196
void prepare_ftrace_return(unsigned long self_addr, unsigned long *parent,
208197
unsigned long frame_pointer);

arch/arm64/kernel/asm-offsets.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,18 +179,6 @@ int main(void)
179179
DEFINE(FTRACE_OPS_FUNC, offsetof(struct ftrace_ops, func));
180180
#endif
181181
BLANK();
182-
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
183-
DEFINE(FGRET_REGS_X0, offsetof(struct fgraph_ret_regs, regs[0]));
184-
DEFINE(FGRET_REGS_X1, offsetof(struct fgraph_ret_regs, regs[1]));
185-
DEFINE(FGRET_REGS_X2, offsetof(struct fgraph_ret_regs, regs[2]));
186-
DEFINE(FGRET_REGS_X3, offsetof(struct fgraph_ret_regs, regs[3]));
187-
DEFINE(FGRET_REGS_X4, offsetof(struct fgraph_ret_regs, regs[4]));
188-
DEFINE(FGRET_REGS_X5, offsetof(struct fgraph_ret_regs, regs[5]));
189-
DEFINE(FGRET_REGS_X6, offsetof(struct fgraph_ret_regs, regs[6]));
190-
DEFINE(FGRET_REGS_X7, offsetof(struct fgraph_ret_regs, regs[7]));
191-
DEFINE(FGRET_REGS_FP, offsetof(struct fgraph_ret_regs, fp));
192-
DEFINE(FGRET_REGS_SIZE, sizeof(struct fgraph_ret_regs));
193-
#endif
194182
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
195183
DEFINE(FTRACE_OPS_DIRECT_CALL, offsetof(struct ftrace_ops, direct_call));
196184
#endif

arch/arm64/kernel/entry-ftrace.S

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -329,24 +329,28 @@ SYM_FUNC_END(ftrace_stub_graph)
329329
* @fp is checked against the value passed by ftrace_graph_caller().
330330
*/
331331
SYM_CODE_START(return_to_handler)
332-
/* save return value regs */
333-
sub sp, sp, #FGRET_REGS_SIZE
334-
stp x0, x1, [sp, #FGRET_REGS_X0]
335-
stp x2, x3, [sp, #FGRET_REGS_X2]
336-
stp x4, x5, [sp, #FGRET_REGS_X4]
337-
stp x6, x7, [sp, #FGRET_REGS_X6]
338-
str x29, [sp, #FGRET_REGS_FP] // parent's fp
332+
/* Make room for ftrace_regs */
333+
sub sp, sp, #FREGS_SIZE
334+
335+
/* Save return value regs */
336+
stp x0, x1, [sp, #FREGS_X0]
337+
stp x2, x3, [sp, #FREGS_X2]
338+
stp x4, x5, [sp, #FREGS_X4]
339+
stp x6, x7, [sp, #FREGS_X6]
340+
341+
/* Save the callsite's FP */
342+
str x29, [sp, #FREGS_FP]
339343

340344
mov x0, sp
341-
bl ftrace_return_to_handler // addr = ftrace_return_to_hander(regs);
345+
bl ftrace_return_to_handler // addr = ftrace_return_to_hander(fregs);
342346
mov x30, x0 // restore the original return address
343347

344-
/* restore return value regs */
345-
ldp x0, x1, [sp, #FGRET_REGS_X0]
346-
ldp x2, x3, [sp, #FGRET_REGS_X2]
347-
ldp x4, x5, [sp, #FGRET_REGS_X4]
348-
ldp x6, x7, [sp, #FGRET_REGS_X6]
349-
add sp, sp, #FGRET_REGS_SIZE
348+
/* Restore return value regs */
349+
ldp x0, x1, [sp, #FREGS_X0]
350+
ldp x2, x3, [sp, #FREGS_X2]
351+
ldp x4, x5, [sp, #FREGS_X4]
352+
ldp x6, x7, [sp, #FREGS_X6]
353+
add sp, sp, #FREGS_SIZE
350354

351355
ret
352356
SYM_CODE_END(return_to_handler)

arch/loongarch/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ config LOONGARCH
137137
select HAVE_FTRACE_MCOUNT_RECORD
138138
select HAVE_FUNCTION_ARG_ACCESS_API
139139
select HAVE_FUNCTION_ERROR_INJECTION
140-
select HAVE_FUNCTION_GRAPH_RETVAL if HAVE_FUNCTION_GRAPH_TRACER
140+
select HAVE_FUNCTION_GRAPH_FREGS
141141
select HAVE_FUNCTION_GRAPH_TRACER
142142
select HAVE_FUNCTION_TRACER
143143
select HAVE_GCC_PLUGINS

arch/loongarch/include/asm/ftrace.h

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ ftrace_regs_set_instruction_pointer(struct ftrace_regs *fregs, unsigned long ip)
5757
instruction_pointer_set(&arch_ftrace_regs(fregs)->regs, ip);
5858
}
5959

60+
#undef ftrace_regs_get_frame_pointer
61+
#define ftrace_regs_get_frame_pointer(fregs) \
62+
(arch_ftrace_regs(fregs)->regs.regs[22])
63+
6064
#define ftrace_graph_func ftrace_graph_func
6165
void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
6266
struct ftrace_ops *op, struct ftrace_regs *fregs);
@@ -78,26 +82,4 @@ __arch_ftrace_set_direct_caller(struct pt_regs *regs, unsigned long addr)
7882

7983
#endif /* CONFIG_FUNCTION_TRACER */
8084

81-
#ifndef __ASSEMBLY__
82-
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
83-
struct fgraph_ret_regs {
84-
/* a0 - a1 */
85-
unsigned long regs[2];
86-
87-
unsigned long fp;
88-
unsigned long __unused;
89-
};
90-
91-
static inline unsigned long fgraph_ret_regs_return_value(struct fgraph_ret_regs *ret_regs)
92-
{
93-
return ret_regs->regs[0];
94-
}
95-
96-
static inline unsigned long fgraph_ret_regs_frame_pointer(struct fgraph_ret_regs *ret_regs)
97-
{
98-
return ret_regs->fp;
99-
}
100-
#endif /* ifdef CONFIG_FUNCTION_GRAPH_TRACER */
101-
#endif
102-
10385
#endif /* _ASM_LOONGARCH_FTRACE_H */

arch/loongarch/kernel/asm-offsets.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -280,18 +280,6 @@ static void __used output_pbe_defines(void)
280280
}
281281
#endif
282282

283-
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
284-
static void __used output_fgraph_ret_regs_defines(void)
285-
{
286-
COMMENT("LoongArch fgraph_ret_regs offsets.");
287-
OFFSET(FGRET_REGS_A0, fgraph_ret_regs, regs[0]);
288-
OFFSET(FGRET_REGS_A1, fgraph_ret_regs, regs[1]);
289-
OFFSET(FGRET_REGS_FP, fgraph_ret_regs, fp);
290-
DEFINE(FGRET_REGS_SIZE, sizeof(struct fgraph_ret_regs));
291-
BLANK();
292-
}
293-
#endif
294-
295283
static void __used output_kvm_defines(void)
296284
{
297285
COMMENT("KVM/LoongArch Specific offsets.");

arch/loongarch/kernel/mcount.S

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,23 @@ SYM_FUNC_START(ftrace_graph_caller)
7979
SYM_FUNC_END(ftrace_graph_caller)
8080

8181
SYM_FUNC_START(return_to_handler)
82-
PTR_ADDI sp, sp, -FGRET_REGS_SIZE
83-
PTR_S a0, sp, FGRET_REGS_A0
84-
PTR_S a1, sp, FGRET_REGS_A1
85-
PTR_S zero, sp, FGRET_REGS_FP
82+
/* Save return value regs */
83+
PTR_ADDI sp, sp, -PT_SIZE
84+
PTR_S a0, sp, PT_R4
85+
PTR_S a1, sp, PT_R5
86+
PTR_S zero, sp, PT_R22
8687

8788
move a0, sp
8889
bl ftrace_return_to_handler
8990

9091
/* Restore the real parent address: a0 -> ra */
9192
move ra, a0
9293

93-
PTR_L a0, sp, FGRET_REGS_A0
94-
PTR_L a1, sp, FGRET_REGS_A1
95-
PTR_ADDI sp, sp, FGRET_REGS_SIZE
94+
/* Restore return value regs */
95+
PTR_L a0, sp, PT_R4
96+
PTR_L a1, sp, PT_R5
97+
PTR_ADDI sp, sp, PT_SIZE
98+
9699
jr ra
97100
SYM_FUNC_END(return_to_handler)
98101
#endif /* CONFIG_FUNCTION_GRAPH_TRACER */

arch/loongarch/kernel/mcount_dyn.S

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,19 +140,19 @@ SYM_CODE_END(ftrace_graph_caller)
140140
SYM_CODE_START(return_to_handler)
141141
UNWIND_HINT_UNDEFINED
142142
/* Save return value regs */
143-
PTR_ADDI sp, sp, -FGRET_REGS_SIZE
144-
PTR_S a0, sp, FGRET_REGS_A0
145-
PTR_S a1, sp, FGRET_REGS_A1
146-
PTR_S zero, sp, FGRET_REGS_FP
143+
PTR_ADDI sp, sp, -PT_SIZE
144+
PTR_S a0, sp, PT_R4
145+
PTR_S a1, sp, PT_R5
146+
PTR_S zero, sp, PT_R22
147147

148148
move a0, sp
149149
bl ftrace_return_to_handler
150150
move ra, a0
151151

152152
/* Restore return value regs */
153-
PTR_L a0, sp, FGRET_REGS_A0
154-
PTR_L a1, sp, FGRET_REGS_A1
155-
PTR_ADDI sp, sp, FGRET_REGS_SIZE
153+
PTR_L a0, sp, PT_R4
154+
PTR_L a1, sp, PT_R5
155+
PTR_ADDI sp, sp, PT_SIZE
156156

157157
jr ra
158158
SYM_CODE_END(return_to_handler)

arch/riscv/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ config RISCV
148148
select HAVE_DYNAMIC_FTRACE_WITH_ARGS if HAVE_DYNAMIC_FTRACE
149149
select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL
150150
select HAVE_FUNCTION_GRAPH_TRACER
151-
select HAVE_FUNCTION_GRAPH_RETVAL if HAVE_FUNCTION_GRAPH_TRACER
151+
select HAVE_FUNCTION_GRAPH_FREGS
152152
select HAVE_FUNCTION_TRACER if !XIP_KERNEL && !PREEMPTION
153153
select HAVE_EBPF_JIT if MMU
154154
select HAVE_GUP_FAST if MMU

arch/riscv/include/asm/ftrace.h

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ static __always_inline unsigned long ftrace_regs_get_stack_pointer(const struct
168168
return arch_ftrace_regs(fregs)->sp;
169169
}
170170

171+
static __always_inline unsigned long ftrace_regs_get_frame_pointer(const struct ftrace_regs *fregs)
172+
{
173+
return arch_ftrace_regs(fregs)->s0;
174+
}
175+
171176
static __always_inline unsigned long ftrace_regs_get_argument(struct ftrace_regs *fregs,
172177
unsigned int n)
173178
{
@@ -208,25 +213,4 @@ static inline void arch_ftrace_set_direct_caller(struct ftrace_regs *fregs, unsi
208213

209214
#endif /* CONFIG_DYNAMIC_FTRACE */
210215

211-
#ifndef __ASSEMBLY__
212-
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
213-
struct fgraph_ret_regs {
214-
unsigned long a1;
215-
unsigned long a0;
216-
unsigned long s0;
217-
unsigned long ra;
218-
};
219-
220-
static inline unsigned long fgraph_ret_regs_return_value(struct fgraph_ret_regs *ret_regs)
221-
{
222-
return ret_regs->a0;
223-
}
224-
225-
static inline unsigned long fgraph_ret_regs_frame_pointer(struct fgraph_ret_regs *ret_regs)
226-
{
227-
return ret_regs->s0;
228-
}
229-
#endif /* ifdef CONFIG_FUNCTION_GRAPH_TRACER */
230-
#endif
231-
232216
#endif /* _ASM_RISCV_FTRACE_H */

arch/riscv/kernel/mcount.S

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include <asm/asm-offsets.h>
1313
#include <asm/ftrace.h>
1414

15+
#define ABI_SIZE_ON_STACK 80
16+
1517
.text
1618

1719
.macro SAVE_ABI_STATE
@@ -26,12 +28,12 @@
2628
* register if a0 was not saved.
2729
*/
2830
.macro SAVE_RET_ABI_STATE
29-
addi sp, sp, -4*SZREG
30-
REG_S s0, 2*SZREG(sp)
31-
REG_S ra, 3*SZREG(sp)
32-
REG_S a0, 1*SZREG(sp)
33-
REG_S a1, 0*SZREG(sp)
34-
addi s0, sp, 4*SZREG
31+
addi sp, sp, -ABI_SIZE_ON_STACK
32+
REG_S ra, 1*SZREG(sp)
33+
REG_S s0, 8*SZREG(sp)
34+
REG_S a0, 10*SZREG(sp)
35+
REG_S a1, 11*SZREG(sp)
36+
addi s0, sp, ABI_SIZE_ON_STACK
3537
.endm
3638

3739
.macro RESTORE_ABI_STATE
@@ -41,11 +43,11 @@
4143
.endm
4244

4345
.macro RESTORE_RET_ABI_STATE
44-
REG_L ra, 3*SZREG(sp)
45-
REG_L s0, 2*SZREG(sp)
46-
REG_L a0, 1*SZREG(sp)
47-
REG_L a1, 0*SZREG(sp)
48-
addi sp, sp, 4*SZREG
46+
REG_L ra, 1*SZREG(sp)
47+
REG_L s0, 8*SZREG(sp)
48+
REG_L a0, 10*SZREG(sp)
49+
REG_L a1, 11*SZREG(sp)
50+
addi sp, sp, ABI_SIZE_ON_STACK
4951
.endm
5052

5153
SYM_TYPED_FUNC_START(ftrace_stub)

arch/s390/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ config S390
192192
select HAVE_FTRACE_MCOUNT_RECORD
193193
select HAVE_FUNCTION_ARG_ACCESS_API
194194
select HAVE_FUNCTION_ERROR_INJECTION
195-
select HAVE_FUNCTION_GRAPH_RETVAL
195+
select HAVE_FUNCTION_GRAPH_FREGS
196196
select HAVE_FUNCTION_GRAPH_TRACER
197197
select HAVE_FUNCTION_TRACER
198198
select HAVE_GCC_PLUGINS

arch/s390/include/asm/ftrace.h

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,30 +62,20 @@ static __always_inline struct pt_regs *arch_ftrace_get_regs(struct ftrace_regs *
6262
return NULL;
6363
}
6464

65-
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
66-
struct fgraph_ret_regs {
67-
unsigned long gpr2;
68-
unsigned long fp;
69-
};
70-
71-
static __always_inline unsigned long fgraph_ret_regs_return_value(struct fgraph_ret_regs *ret_regs)
72-
{
73-
return ret_regs->gpr2;
74-
}
75-
76-
static __always_inline unsigned long fgraph_ret_regs_frame_pointer(struct fgraph_ret_regs *ret_regs)
77-
{
78-
return ret_regs->fp;
79-
}
80-
#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
81-
8265
static __always_inline void
8366
ftrace_regs_set_instruction_pointer(struct ftrace_regs *fregs,
8467
unsigned long ip)
8568
{
8669
arch_ftrace_regs(fregs)->regs.psw.addr = ip;
8770
}
8871

72+
#undef ftrace_regs_get_frame_pointer
73+
static __always_inline unsigned long
74+
ftrace_regs_get_frame_pointer(struct ftrace_regs *fregs)
75+
{
76+
return ftrace_regs_get_stack_pointer(fregs);
77+
}
78+
8979
#ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
9080
/*
9181
* When an ftrace registered caller is tracing a function that is

arch/s390/kernel/asm-offsets.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,6 @@ int main(void)
175175
DEFINE(OLDMEM_SIZE, PARMAREA + offsetof(struct parmarea, oldmem_size));
176176
DEFINE(COMMAND_LINE, PARMAREA + offsetof(struct parmarea, command_line));
177177
DEFINE(MAX_COMMAND_LINE_SIZE, PARMAREA + offsetof(struct parmarea, max_command_line_size));
178-
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
179-
/* function graph return value tracing */
180-
OFFSET(__FGRAPH_RET_GPR2, fgraph_ret_regs, gpr2);
181-
OFFSET(__FGRAPH_RET_FP, fgraph_ret_regs, fp);
182-
DEFINE(__FGRAPH_RET_SIZE, sizeof(struct fgraph_ret_regs));
183-
#endif
184178
OFFSET(__FTRACE_REGS_PT_REGS, __arch_ftrace_regs, regs);
185179
DEFINE(__FTRACE_REGS_SIZE, sizeof(struct __arch_ftrace_regs));
186180

0 commit comments

Comments
 (0)