Skip to content

Commit 8e2759d

Browse files
mhiramatrostedt
authored andcommitted
bpf: Enable kprobe_multi feature if CONFIG_FPROBE is enabled
Enable kprobe_multi feature if CONFIG_FPROBE is enabled. The pt_regs is converted from ftrace_regs by ftrace_partial_regs(), thus some registers may always returns 0. But it should be enough for function entry (access arguments) and exit (access return value). 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/173519000417.391279.14011193569589886419.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 0566cef commit 8e2759d

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

kernel/trace/bpf_trace.c

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

2564-
#if defined(CONFIG_FPROBE) && defined(CONFIG_DYNAMIC_FTRACE_WITH_REGS)
2564+
#ifdef CONFIG_FPROBE
25652565
struct bpf_kprobe_multi_link {
25662566
struct bpf_link link;
25672567
struct fprobe fp;
@@ -2584,6 +2584,13 @@ struct user_syms {
25842584
char *buf;
25852585
};
25862586

2587+
#ifndef CONFIG_HAVE_FTRACE_REGS_HAVING_PT_REGS
2588+
static DEFINE_PER_CPU(struct pt_regs, bpf_kprobe_multi_pt_regs);
2589+
#define bpf_kprobe_multi_pt_regs_ptr() this_cpu_ptr(&bpf_kprobe_multi_pt_regs)
2590+
#else
2591+
#define bpf_kprobe_multi_pt_regs_ptr() (NULL)
2592+
#endif
2593+
25872594
static int copy_user_syms(struct user_syms *us, unsigned long __user *usyms, u32 cnt)
25882595
{
25892596
unsigned long __user usymbol;
@@ -2778,7 +2785,7 @@ static u64 bpf_kprobe_multi_entry_ip(struct bpf_run_ctx *ctx)
27782785

27792786
static int
27802787
kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link,
2781-
unsigned long entry_ip, struct pt_regs *regs,
2788+
unsigned long entry_ip, struct ftrace_regs *fregs,
27822789
bool is_return, void *data)
27832790
{
27842791
struct bpf_kprobe_multi_run_ctx run_ctx = {
@@ -2790,6 +2797,7 @@ kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link,
27902797
.entry_ip = entry_ip,
27912798
};
27922799
struct bpf_run_ctx *old_run_ctx;
2800+
struct pt_regs *regs;
27932801
int err;
27942802

27952803
if (unlikely(__this_cpu_inc_return(bpf_prog_active) != 1)) {
@@ -2800,6 +2808,7 @@ kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link,
28002808

28012809
migrate_disable();
28022810
rcu_read_lock();
2811+
regs = ftrace_partial_regs(fregs, bpf_kprobe_multi_pt_regs_ptr());
28032812
old_run_ctx = bpf_set_run_ctx(&run_ctx.session_ctx.run_ctx);
28042813
err = bpf_prog_run(link->link.prog, regs);
28052814
bpf_reset_run_ctx(old_run_ctx);
@@ -2816,15 +2825,11 @@ kprobe_multi_link_handler(struct fprobe *fp, unsigned long fentry_ip,
28162825
unsigned long ret_ip, struct ftrace_regs *fregs,
28172826
void *data)
28182827
{
2819-
struct pt_regs *regs = ftrace_get_regs(fregs);
28202828
struct bpf_kprobe_multi_link *link;
28212829
int err;
28222830

2823-
if (!regs)
2824-
return 0;
2825-
28262831
link = container_of(fp, struct bpf_kprobe_multi_link, fp);
2827-
err = kprobe_multi_link_prog_run(link, get_entry_ip(fentry_ip), regs, false, data);
2832+
err = kprobe_multi_link_prog_run(link, get_entry_ip(fentry_ip), fregs, false, data);
28282833
return is_kprobe_session(link->link.prog) ? err : 0;
28292834
}
28302835

@@ -2834,13 +2839,9 @@ kprobe_multi_link_exit_handler(struct fprobe *fp, unsigned long fentry_ip,
28342839
void *data)
28352840
{
28362841
struct bpf_kprobe_multi_link *link;
2837-
struct pt_regs *regs = ftrace_get_regs(fregs);
2838-
2839-
if (!regs)
2840-
return;
28412842

28422843
link = container_of(fp, struct bpf_kprobe_multi_link, fp);
2843-
kprobe_multi_link_prog_run(link, get_entry_ip(fentry_ip), regs, true, data);
2844+
kprobe_multi_link_prog_run(link, get_entry_ip(fentry_ip), fregs, true, data);
28442845
}
28452846

28462847
static int symbols_cmp_r(const void *a, const void *b, const void *priv)
@@ -3101,7 +3102,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
31013102
kvfree(cookies);
31023103
return err;
31033104
}
3104-
#else /* !CONFIG_FPROBE || !CONFIG_DYNAMIC_FTRACE_WITH_REGS */
3105+
#else /* !CONFIG_FPROBE */
31053106
int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
31063107
{
31073108
return -EOPNOTSUPP;

0 commit comments

Comments
 (0)