Skip to content

Commit d19ad07

Browse files
committed
ftrace: Have the callbacks receive a struct ftrace_regs instead of pt_regs
In preparation to have arguments of a function passed to callbacks attached to functions as default, change the default callback prototype to receive a struct ftrace_regs as the forth parameter instead of a pt_regs. For callbacks that set the FL_SAVE_REGS flag in their ftrace_ops flags, they will now need to get the pt_regs via a ftrace_get_regs() helper call. If this is called by a callback that their ftrace_ops did not have a FL_SAVE_REGS flag set, it that helper function will return NULL. This will allow the ftrace_regs to hold enough just to get the parameters and stack pointer, but without the worry that callbacks may have a pt_regs that is not completely filled. Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Masami Hiramatsu <mhiramat@kernel.org> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent 58954b3 commit d19ad07

18 files changed

Lines changed: 71 additions & 45 deletions

File tree

‎arch/csky/kernel/probes/ftrace.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,19 @@ int arch_check_ftrace_location(struct kprobe *p)
1111

1212
/* Ftrace callback handler for kprobes -- called under preepmt disabed */
1313
void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,
14-
struct ftrace_ops *ops, struct pt_regs *regs)
14+
struct ftrace_ops *ops, struct ftrace_regs *fregs)
1515
{
1616
int bit;
1717
bool lr_saver = false;
1818
struct kprobe *p;
1919
struct kprobe_ctlblk *kcb;
20+
struct pt_regs *regs;
2021

2122
bit = ftrace_test_recursion_trylock(ip, parent_ip);
2223
if (bit < 0)
2324
return;
2425

26+
regs = ftrace_get_regs(fregs);
2527
preempt_disable_notrace();
2628
p = get_kprobe((kprobe_opcode_t *)ip);
2729
if (!p) {

‎arch/nds32/kernel/ftrace.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ extern void (*ftrace_trace_function)(unsigned long, unsigned long,
1010
extern void ftrace_graph_caller(void);
1111

1212
noinline void __naked ftrace_stub(unsigned long ip, unsigned long parent_ip,
13-
struct ftrace_ops *op, struct pt_regs *regs)
13+
struct ftrace_ops *op, struct ftrace_regs *fregs)
1414
{
1515
__asm__ (""); /* avoid to optimize as pure function */
1616
}
@@ -38,7 +38,7 @@ EXPORT_SYMBOL(_mcount);
3838
#else /* CONFIG_DYNAMIC_FTRACE */
3939

4040
noinline void __naked ftrace_stub(unsigned long ip, unsigned long parent_ip,
41-
struct ftrace_ops *op, struct pt_regs *regs)
41+
struct ftrace_ops *op, struct ftrace_regs *fregs)
4242
{
4343
__asm__ (""); /* avoid to optimize as pure function */
4444
}

‎arch/parisc/kernel/ftrace.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static void __hot prepare_ftrace_return(unsigned long *parent,
5151
void notrace __hot ftrace_function_trampoline(unsigned long parent,
5252
unsigned long self_addr,
5353
unsigned long org_sp_gr3,
54-
struct pt_regs *regs)
54+
struct ftrace_regs *fregs)
5555
{
5656
#ifndef CONFIG_DYNAMIC_FTRACE
5757
extern ftrace_func_t ftrace_trace_function;
@@ -61,7 +61,7 @@ void notrace __hot ftrace_function_trampoline(unsigned long parent,
6161
if (function_trace_op->flags & FTRACE_OPS_FL_ENABLED &&
6262
ftrace_trace_function != ftrace_stub)
6363
ftrace_trace_function(self_addr, parent,
64-
function_trace_op, regs);
64+
function_trace_op, fregs);
6565

6666
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
6767
if (dereference_function_descriptor(ftrace_graph_return) !=
@@ -204,16 +204,18 @@ int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec,
204204

205205
#ifdef CONFIG_KPROBES_ON_FTRACE
206206
void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,
207-
struct ftrace_ops *ops, struct pt_regs *regs)
207+
struct ftrace_ops *ops, struct ftrace_regs *fregs)
208208
{
209209
struct kprobe_ctlblk *kcb;
210+
struct pt_regs *regs;
210211
struct kprobe *p;
211212
int bit;
212213

213214
bit = ftrace_test_recursion_trylock(ip, parent_ip);
214215
if (bit < 0)
215216
return;
216217

218+
regs = ftrace_get_regs(fregs);
217219
preempt_disable_notrace();
218220
p = get_kprobe((kprobe_opcode_t *)ip);
219221
if (unlikely(!p) || kprobe_disabled(p))

‎arch/powerpc/kernel/kprobes-ftrace.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@
1414

1515
/* Ftrace callback handler for kprobes */
1616
void kprobe_ftrace_handler(unsigned long nip, unsigned long parent_nip,
17-
struct ftrace_ops *ops, struct pt_regs *regs)
17+
struct ftrace_ops *ops, struct ftrace_regs *fregs)
1818
{
1919
struct kprobe *p;
2020
struct kprobe_ctlblk *kcb;
21+
struct pt_regs *regs;
2122
int bit;
2223

2324
bit = ftrace_test_recursion_trylock(nip, parent_nip);
2425
if (bit < 0)
2526
return;
2627

28+
regs = ftrace_get_regs(fregs);
2729
preempt_disable_notrace();
2830
p = get_kprobe((kprobe_opcode_t *)nip);
2931
if (unlikely(!p) || kprobe_disabled(p))

‎arch/s390/kernel/ftrace.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,18 @@ int ftrace_disable_ftrace_graph_caller(void)
198198

199199
#ifdef CONFIG_KPROBES_ON_FTRACE
200200
void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,
201-
struct ftrace_ops *ops, struct pt_regs *regs)
201+
struct ftrace_ops *ops, struct ftrace_regs *fregs)
202202
{
203203
struct kprobe_ctlblk *kcb;
204+
struct pt_regs *regs;
204205
struct kprobe *p;
205206
int bit;
206207

207208
bit = ftrace_test_recursion_trylock(ip, parent_ip);
208209
if (bit < 0)
209210
return;
210211

212+
regs = ftrace_get_regs(fregs);
211213
preempt_disable_notrace();
212214
p = get_kprobe((kprobe_opcode_t *)ip);
213215
if (unlikely(!p) || kprobe_disabled(p))

‎arch/x86/kernel/kprobes/ftrace.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414

1515
/* Ftrace callback handler for kprobes -- called under preepmt disabed */
1616
void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,
17-
struct ftrace_ops *ops, struct pt_regs *regs)
17+
struct ftrace_ops *ops, struct ftrace_regs *fregs)
1818
{
19+
struct pt_regs *regs = ftrace_get_regs(fregs);
1920
struct kprobe *p;
2021
struct kprobe_ctlblk *kcb;
2122
int bit;

‎fs/pstore/ftrace.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static u64 pstore_ftrace_stamp;
2626
static void notrace pstore_ftrace_call(unsigned long ip,
2727
unsigned long parent_ip,
2828
struct ftrace_ops *op,
29-
struct pt_regs *regs)
29+
struct ftrace_regs *fregs)
3030
{
3131
int bit;
3232
unsigned long flags;

‎include/linux/ftrace.h‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,20 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
9090

9191
struct ftrace_ops;
9292

93+
struct ftrace_regs {
94+
struct pt_regs regs;
95+
};
96+
97+
static __always_inline struct pt_regs *ftrace_get_regs(struct ftrace_regs *fregs)
98+
{
99+
if (!fregs)
100+
return NULL;
101+
102+
return &fregs->regs;
103+
}
104+
93105
typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip,
94-
struct ftrace_ops *op, struct pt_regs *regs);
106+
struct ftrace_ops *op, struct ftrace_regs *fregs);
95107

96108
ftrace_func_t ftrace_ops_get_func(struct ftrace_ops *ops);
97109

@@ -259,7 +271,7 @@ int register_ftrace_function(struct ftrace_ops *ops);
259271
int unregister_ftrace_function(struct ftrace_ops *ops);
260272

261273
extern void ftrace_stub(unsigned long a0, unsigned long a1,
262-
struct ftrace_ops *op, struct pt_regs *regs);
274+
struct ftrace_ops *op, struct ftrace_regs *fregs);
263275

264276
#else /* !CONFIG_FUNCTION_TRACER */
265277
/*

‎include/linux/kprobes.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ static inline void wait_for_kprobe_optimizer(void) { }
345345
#endif /* CONFIG_OPTPROBES */
346346
#ifdef CONFIG_KPROBES_ON_FTRACE
347347
extern void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,
348-
struct ftrace_ops *ops, struct pt_regs *regs);
348+
struct ftrace_ops *ops, struct ftrace_regs *fregs);
349349
extern int arch_prepare_kprobe_ftrace(struct kprobe *p);
350350
#endif
351351

‎kernel/livepatch/patch.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ struct klp_ops *klp_find_ops(void *old_func)
4040
static void notrace klp_ftrace_handler(unsigned long ip,
4141
unsigned long parent_ip,
4242
struct ftrace_ops *fops,
43-
struct pt_regs *regs)
43+
struct ftrace_regs *fregs)
4444
{
45+
struct pt_regs *regs = ftrace_get_regs(fregs);
4546
struct klp_ops *ops;
4647
struct klp_func *func;
4748
int patch_state;

0 commit comments

Comments
 (0)