Skip to content

Commit 5779e3c

Browse files
Donglin Pengrostedt
authored andcommitted
LoongArch: ftrace: Enable HAVE_FUNCTION_GRAPH_RETVAL
The previous patch ("function_graph: Support recording and printing the return value of function") has laid the groundwork for the for the funcgraph-retval, and this modification makes it available on the LoongArch platform. We introduce a new structure called fgraph_ret_regs for the LoongArch platform to hold return registers and the frame pointer. We then fill its content in the return_to_handler and pass its address to the function ftrace_return_to_handler to record the return value. Link: https://lkml.kernel.org/r/c5462255e435fab363895c2d7433bc0f5a140411.1680954589.git.pengdonglin@sangfor.com.cn Reviewed-by: Huacai Chen <[email protected]> Signed-off-by: Donglin Peng <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent d938ba1 commit 5779e3c

File tree

5 files changed

+53
-14
lines changed

5 files changed

+53
-14
lines changed

arch/loongarch/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ config LOONGARCH
103103
select HAVE_FTRACE_MCOUNT_RECORD
104104
select HAVE_FUNCTION_ARG_ACCESS_API
105105
select HAVE_FUNCTION_ERROR_INJECTION
106+
select HAVE_FUNCTION_GRAPH_RETVAL if HAVE_FUNCTION_GRAPH_TRACER
106107
select HAVE_FUNCTION_GRAPH_TRACER
107108
select HAVE_FUNCTION_TRACER
108109
select HAVE_GENERIC_VDSO

arch/loongarch/include/asm/ftrace.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,26 @@ __arch_ftrace_set_direct_caller(struct pt_regs *regs, unsigned long addr)
100100

101101
#endif /* CONFIG_FUNCTION_TRACER */
102102

103+
#ifndef __ASSEMBLY__
104+
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
105+
struct fgraph_ret_regs {
106+
/* a0 - a1 */
107+
unsigned long regs[2];
108+
109+
unsigned long fp;
110+
unsigned long __unused;
111+
};
112+
113+
static inline unsigned long fgraph_ret_regs_return_value(struct fgraph_ret_regs *ret_regs)
114+
{
115+
return ret_regs->regs[0];
116+
}
117+
118+
static inline unsigned long fgraph_ret_regs_frame_pointer(struct fgraph_ret_regs *ret_regs)
119+
{
120+
return ret_regs->fp;
121+
}
122+
#endif /* ifdef CONFIG_FUNCTION_GRAPH_TRACER */
123+
#endif
124+
103125
#endif /* _ASM_LOONGARCH_FTRACE_H */

arch/loongarch/kernel/asm-offsets.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <asm/cpu-info.h>
1313
#include <asm/ptrace.h>
1414
#include <asm/processor.h>
15+
#include <asm/ftrace.h>
1516

1617
void output_ptreg_defines(void)
1718
{
@@ -264,11 +265,23 @@ void output_smpboot_defines(void)
264265
#ifdef CONFIG_HIBERNATION
265266
void output_pbe_defines(void)
266267
{
267-
COMMENT(" Linux struct pbe offsets. ");
268+
COMMENT("Linux struct pbe offsets.");
268269
OFFSET(PBE_ADDRESS, pbe, address);
269270
OFFSET(PBE_ORIG_ADDRESS, pbe, orig_address);
270271
OFFSET(PBE_NEXT, pbe, next);
271272
DEFINE(PBE_SIZE, sizeof(struct pbe));
272273
BLANK();
273274
}
274275
#endif
276+
277+
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
278+
void output_fgraph_ret_regs_defines(void)
279+
{
280+
COMMENT("LoongArch fgraph_ret_regs offsets.");
281+
OFFSET(FGRET_REGS_A0, fgraph_ret_regs, regs[0]);
282+
OFFSET(FGRET_REGS_A1, fgraph_ret_regs, regs[1]);
283+
OFFSET(FGRET_REGS_FP, fgraph_ret_regs, fp);
284+
DEFINE(FGRET_REGS_SIZE, sizeof(struct fgraph_ret_regs));
285+
BLANK();
286+
}
287+
#endif

arch/loongarch/kernel/mcount.S

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,20 @@ 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, -2 * SZREG
83-
PTR_S a0, sp, 0
84-
PTR_S a1, sp, SZREG
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
8586

87+
move a0, sp
8688
bl ftrace_return_to_handler
8789

8890
/* Restore the real parent address: a0 -> ra */
8991
move ra, a0
9092

91-
PTR_L a0, sp, 0
92-
PTR_L a1, sp, SZREG
93-
PTR_ADDI sp, sp, 2 * SZREG
93+
PTR_L a0, sp, FGRET_REGS_A0
94+
PTR_L a1, sp, FGRET_REGS_A1
95+
PTR_ADDI sp, sp, FGRET_REGS_SIZE
9496
jr ra
9597
SYM_FUNC_END(return_to_handler)
9698
#endif /* CONFIG_FUNCTION_GRAPH_TRACER */

arch/loongarch/kernel/mcount_dyn.S

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,19 @@ SYM_CODE_END(ftrace_graph_caller)
136136

137137
SYM_CODE_START(return_to_handler)
138138
/* Save return value regs */
139-
PTR_ADDI sp, sp, -2 * SZREG
140-
PTR_S a0, sp, 0
141-
PTR_S a1, sp, SZREG
139+
PTR_ADDI sp, sp, -FGRET_REGS_SIZE
140+
PTR_S a0, sp, FGRET_REGS_A0
141+
PTR_S a1, sp, FGRET_REGS_A1
142+
PTR_S zero, sp, FGRET_REGS_FP
142143

143-
move a0, zero
144+
move a0, sp
144145
bl ftrace_return_to_handler
145146
move ra, a0
146147

147148
/* Restore return value regs */
148-
PTR_L a0, sp, 0
149-
PTR_L a1, sp, SZREG
150-
PTR_ADDI sp, sp, 2 * SZREG
149+
PTR_L a0, sp, FGRET_REGS_A0
150+
PTR_L a1, sp, FGRET_REGS_A1
151+
PTR_ADDI sp, sp, FGRET_REGS_SIZE
151152

152153
jr ra
153154
SYM_CODE_END(return_to_handler)

0 commit comments

Comments
 (0)