Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <alexei.starovoitov@gmail.com>
Cc: Martin KaFai Lau <martin.lau@linux.dev>
Cc: bpf <bpf@vger.kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Alan Maguire <alan.maguire@oracle.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Link: https://lore.kernel.org/173519000417.391279.14011193569589886419.stgit@devnote2
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Acked-by: Florent Revest <revest@chromium.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

authored by

Masami Hiramatsu (Google) and committed by
Steven Rostedt (Google)
8e2759da 0566cefe

+14 -13
+14 -13
kernel/trace/bpf_trace.c
··· 2561 2561 void *data; 2562 2562 }; 2563 2563 2564 - #if defined(CONFIG_FPROBE) && defined(CONFIG_DYNAMIC_FTRACE_WITH_REGS) 2564 + #ifdef CONFIG_FPROBE 2565 2565 struct bpf_kprobe_multi_link { 2566 2566 struct bpf_link link; 2567 2567 struct fprobe fp; ··· 2583 2583 const char **syms; 2584 2584 char *buf; 2585 2585 }; 2586 + 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 2586 2593 2587 2594 static int copy_user_syms(struct user_syms *us, unsigned long __user *usyms, u32 cnt) 2588 2595 { ··· 2785 2778 2786 2779 static int 2787 2780 kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link, 2788 - unsigned long entry_ip, struct pt_regs *regs, 2781 + unsigned long entry_ip, struct ftrace_regs *fregs, 2789 2782 bool is_return, void *data) 2790 2783 { 2791 2784 struct bpf_kprobe_multi_run_ctx run_ctx = { ··· 2797 2790 .entry_ip = entry_ip, 2798 2791 }; 2799 2792 struct bpf_run_ctx *old_run_ctx; 2793 + struct pt_regs *regs; 2800 2794 int err; 2801 2795 2802 2796 if (unlikely(__this_cpu_inc_return(bpf_prog_active) != 1)) { ··· 2808 2800 2809 2801 migrate_disable(); 2810 2802 rcu_read_lock(); 2803 + regs = ftrace_partial_regs(fregs, bpf_kprobe_multi_pt_regs_ptr()); 2811 2804 old_run_ctx = bpf_set_run_ctx(&run_ctx.session_ctx.run_ctx); 2812 2805 err = bpf_prog_run(link->link.prog, regs); 2813 2806 bpf_reset_run_ctx(old_run_ctx); ··· 2825 2816 unsigned long ret_ip, struct ftrace_regs *fregs, 2826 2817 void *data) 2827 2818 { 2828 - struct pt_regs *regs = ftrace_get_regs(fregs); 2829 2819 struct bpf_kprobe_multi_link *link; 2830 2820 int err; 2831 2821 2832 - if (!regs) 2833 - return 0; 2834 - 2835 2822 link = container_of(fp, struct bpf_kprobe_multi_link, fp); 2836 - err = kprobe_multi_link_prog_run(link, get_entry_ip(fentry_ip), regs, false, data); 2823 + err = kprobe_multi_link_prog_run(link, get_entry_ip(fentry_ip), fregs, false, data); 2837 2824 return is_kprobe_session(link->link.prog) ? err : 0; 2838 2825 } 2839 2826 ··· 2839 2834 void *data) 2840 2835 { 2841 2836 struct bpf_kprobe_multi_link *link; 2842 - struct pt_regs *regs = ftrace_get_regs(fregs); 2843 - 2844 - if (!regs) 2845 - return; 2846 2837 2847 2838 link = container_of(fp, struct bpf_kprobe_multi_link, fp); 2848 - kprobe_multi_link_prog_run(link, get_entry_ip(fentry_ip), regs, true, data); 2839 + kprobe_multi_link_prog_run(link, get_entry_ip(fentry_ip), fregs, true, data); 2849 2840 } 2850 2841 2851 2842 static int symbols_cmp_r(const void *a, const void *b, const void *priv) ··· 3102 3101 kvfree(cookies); 3103 3102 return err; 3104 3103 } 3105 - #else /* !CONFIG_FPROBE || !CONFIG_DYNAMIC_FTRACE_WITH_REGS */ 3104 + #else /* !CONFIG_FPROBE */ 3106 3105 int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) 3107 3106 { 3108 3107 return -EOPNOTSUPP;