Skip to content

Commit 46bc082

Browse files
mhiramatrostedt
authored andcommitted
fprobe: Use ftrace_regs in fprobe entry handler
This allows fprobes to be available with CONFIG_DYNAMIC_FTRACE_WITH_ARGS instead of CONFIG_DYNAMIC_FTRACE_WITH_REGS, then we can enable fprobe on arm64. Cc: Alexei Starovoitov <[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]> Link: https://lore.kernel.org/173518994037.391279.2786805566359674586.stgit@devnote2 Signed-off-by: Masami Hiramatsu (Google) <[email protected]> Acked-by: Florent Revest <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 2ca8c11 commit 46bc082

File tree

7 files changed

+23
-12
lines changed

7 files changed

+23
-12
lines changed

include/linux/fprobe.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
struct fprobe;
1111

1212
typedef int (*fprobe_entry_cb)(struct fprobe *fp, unsigned long entry_ip,
13-
unsigned long ret_ip, struct pt_regs *regs,
13+
unsigned long ret_ip, struct ftrace_regs *regs,
1414
void *entry_data);
1515

1616
typedef void (*fprobe_exit_cb)(struct fprobe *fp, unsigned long entry_ip,

kernel/trace/Kconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ config DYNAMIC_FTRACE_WITH_ARGS
297297
config FPROBE
298298
bool "Kernel Function Probe (fprobe)"
299299
depends on FUNCTION_TRACER
300-
depends on DYNAMIC_FTRACE_WITH_REGS
300+
depends on DYNAMIC_FTRACE_WITH_REGS || DYNAMIC_FTRACE_WITH_ARGS
301301
depends on HAVE_RETHOOK
302302
select RETHOOK
303303
default n
@@ -682,6 +682,7 @@ config FPROBE_EVENTS
682682
select TRACING
683683
select PROBE_EVENTS
684684
select DYNAMIC_EVENTS
685+
depends on DYNAMIC_FTRACE_WITH_REGS
685686
default y
686687
help
687688
This allows user to add tracing events on the function entry and

kernel/trace/bpf_trace.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2561,7 +2561,7 @@ struct bpf_session_run_ctx {
25612561
void *data;
25622562
};
25632563

2564-
#ifdef CONFIG_FPROBE
2564+
#if defined(CONFIG_FPROBE) && defined(CONFIG_DYNAMIC_FTRACE_WITH_REGS)
25652565
struct bpf_kprobe_multi_link {
25662566
struct bpf_link link;
25672567
struct fprobe fp;
@@ -2813,12 +2813,16 @@ kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link,
28132813

28142814
static int
28152815
kprobe_multi_link_handler(struct fprobe *fp, unsigned long fentry_ip,
2816-
unsigned long ret_ip, struct pt_regs *regs,
2816+
unsigned long ret_ip, struct ftrace_regs *fregs,
28172817
void *data)
28182818
{
2819+
struct pt_regs *regs = ftrace_get_regs(fregs);
28192820
struct bpf_kprobe_multi_link *link;
28202821
int err;
28212822

2823+
if (!regs)
2824+
return 0;
2825+
28222826
link = container_of(fp, struct bpf_kprobe_multi_link, fp);
28232827
err = kprobe_multi_link_prog_run(link, get_entry_ip(fentry_ip), regs, false, data);
28242828
return is_kprobe_session(link->link.prog) ? err : 0;
@@ -3093,7 +3097,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
30933097
kvfree(cookies);
30943098
return err;
30953099
}
3096-
#else /* !CONFIG_FPROBE */
3100+
#else /* !CONFIG_FPROBE || !CONFIG_DYNAMIC_FTRACE_WITH_REGS */
30973101
int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
30983102
{
30993103
return -EOPNOTSUPP;

kernel/trace/fprobe.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static inline void __fprobe_handler(unsigned long ip, unsigned long parent_ip,
4646
}
4747

4848
if (fp->entry_handler)
49-
ret = fp->entry_handler(fp, ip, parent_ip, ftrace_get_regs(fregs), entry_data);
49+
ret = fp->entry_handler(fp, ip, parent_ip, fregs, entry_data);
5050

5151
/* If entry_handler returns !0, nmissed is not counted. */
5252
if (rh) {
@@ -182,6 +182,7 @@ static void fprobe_init(struct fprobe *fp)
182182
fp->ops.func = fprobe_kprobe_handler;
183183
else
184184
fp->ops.func = fprobe_handler;
185+
185186
fp->ops.flags |= FTRACE_OPS_FL_SAVE_REGS;
186187
}
187188

kernel/trace/trace_fprobe.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,13 @@ NOKPROBE_SYMBOL(fentry_trace_func);
217217

218218
/* function exit handler */
219219
static int trace_fprobe_entry_handler(struct fprobe *fp, unsigned long entry_ip,
220-
unsigned long ret_ip, struct pt_regs *regs,
220+
unsigned long ret_ip, struct ftrace_regs *fregs,
221221
void *entry_data)
222222
{
223223
struct trace_fprobe *tf = container_of(fp, struct trace_fprobe, fp);
224+
struct pt_regs *regs = ftrace_get_regs(fregs);
224225

225-
if (tf->tp.entry_arg)
226+
if (regs && tf->tp.entry_arg)
226227
store_trace_entry_data(entry_data, &tf->tp, regs);
227228

228229
return 0;
@@ -339,12 +340,16 @@ NOKPROBE_SYMBOL(fexit_perf_func);
339340
#endif /* CONFIG_PERF_EVENTS */
340341

341342
static int fentry_dispatcher(struct fprobe *fp, unsigned long entry_ip,
342-
unsigned long ret_ip, struct pt_regs *regs,
343+
unsigned long ret_ip, struct ftrace_regs *fregs,
343344
void *entry_data)
344345
{
345346
struct trace_fprobe *tf = container_of(fp, struct trace_fprobe, fp);
347+
struct pt_regs *regs = ftrace_get_regs(fregs);
346348
int ret = 0;
347349

350+
if (!regs)
351+
return 0;
352+
348353
if (trace_probe_test_flag(&tf->tp, TP_FLAG_TRACE))
349354
fentry_trace_func(tf, entry_ip, regs);
350355
#ifdef CONFIG_PERF_EVENTS

lib/test_fprobe.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static noinline u32 fprobe_selftest_nest_target(u32 value, u32 (*nest)(u32))
4040

4141
static notrace int fp_entry_handler(struct fprobe *fp, unsigned long ip,
4242
unsigned long ret_ip,
43-
struct pt_regs *regs, void *data)
43+
struct ftrace_regs *fregs, void *data)
4444
{
4545
KUNIT_EXPECT_FALSE(current_test, preemptible());
4646
/* This can be called on the fprobe_selftest_target and the fprobe_selftest_target2 */
@@ -81,7 +81,7 @@ static notrace void fp_exit_handler(struct fprobe *fp, unsigned long ip,
8181

8282
static notrace int nest_entry_handler(struct fprobe *fp, unsigned long ip,
8383
unsigned long ret_ip,
84-
struct pt_regs *regs, void *data)
84+
struct ftrace_regs *fregs, void *data)
8585
{
8686
KUNIT_EXPECT_FALSE(current_test, preemptible());
8787
return 0;

samples/fprobe/fprobe_example.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static void show_backtrace(void)
5050

5151
static int sample_entry_handler(struct fprobe *fp, unsigned long ip,
5252
unsigned long ret_ip,
53-
struct pt_regs *regs, void *data)
53+
struct ftrace_regs *fregs, void *data)
5454
{
5555
if (use_trace)
5656
/*

0 commit comments

Comments
 (0)