Skip to content

Commit ac7127e

Browse files
zhangqingmychenhuacai
authored andcommitted
LoongArch/ftrace: Add HAVE_DYNAMIC_FTRACE_WITH_ARGS support
Allow for arguments to be passed in to ftrace_regs by default. If this is set, then arguments and stack can be found from the pt_regs. 1. HAVE_DYNAMIC_FTRACE_WITH_ARGS don't need special hook for graph tracer entry point, but instead we can use graph_ops::func function to install the return_hooker. 2. Livepatch requires this option in the future. Signed-off-by: Qing Zhang <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent 8778ba2 commit ac7127e

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

arch/loongarch/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ config LOONGARCH
8989
select HAVE_DEBUG_STACKOVERFLOW
9090
select HAVE_DMA_CONTIGUOUS
9191
select HAVE_DYNAMIC_FTRACE
92+
select HAVE_DYNAMIC_FTRACE_WITH_ARGS
9293
select HAVE_DYNAMIC_FTRACE_WITH_REGS
9394
select HAVE_EBPF_JIT
9495
select HAVE_EXIT_THREAD

arch/loongarch/include/asm/ftrace.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,23 @@ void prepare_ftrace_return(unsigned long self_addr, unsigned long *parent);
3737

3838
#endif /* CONFIG_DYNAMIC_FTRACE */
3939

40+
#ifdef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS
41+
struct ftrace_ops;
42+
43+
struct ftrace_regs {
44+
struct pt_regs regs;
45+
};
46+
47+
static __always_inline struct pt_regs *arch_ftrace_get_regs(struct ftrace_regs *fregs)
48+
{
49+
return &fregs->regs;
50+
}
51+
52+
#define ftrace_graph_func ftrace_graph_func
53+
void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
54+
struct ftrace_ops *op, struct ftrace_regs *fregs);
55+
#endif
56+
4057
#endif /* __ASSEMBLY__ */
4158

4259
#endif /* CONFIG_FUNCTION_TRACER */

arch/loongarch/kernel/ftrace_dyn.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,16 @@ void prepare_ftrace_return(unsigned long self_addr, unsigned long *parent)
139139
*parent = return_hooker;
140140
}
141141

142+
#ifdef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS
143+
void ftrace_graph_func(unsigned long ip, unsigned long parent_ip,
144+
struct ftrace_ops *op, struct ftrace_regs *fregs)
145+
{
146+
struct pt_regs *regs = &fregs->regs;
147+
unsigned long *parent = (unsigned long *)&regs->regs[1];
148+
149+
prepare_ftrace_return(ip, (unsigned long *)parent);
150+
}
151+
#else
142152
static int ftrace_modify_graph_caller(bool enable)
143153
{
144154
u32 branch, nop;
@@ -166,4 +176,5 @@ int ftrace_disable_ftrace_graph_caller(void)
166176
{
167177
return ftrace_modify_graph_caller(false);
168178
}
179+
#endif /* CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS */
169180
#endif /* CONFIG_FUNCTION_GRAPH_TRACER */

0 commit comments

Comments
 (0)