On Fri, 19 Dec 2025 09:57:37 +0800 Menglong Dong <[email protected]> wrote: > On 2025/12/18 21:06 liujing40 <[email protected]> write: > > When fprobe is not available, provide a fallback implementation of > > kprobe_multi using the traditional kretprobe API. > > > > Uses kretprobe's entry_handler and handler callbacks to simulate fprobe's > > entry/exit functionality. > > > > Signed-off-by: Jing Liu <[email protected]> > > --- > > kernel/trace/bpf_trace.c | 307 +++++++++++++++++++++++++++++++++++++-- > > 1 file changed, 295 insertions(+), 12 deletions(-) > > > > diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c > > index 1fd07c10378f..426a1c627508 100644 > > --- a/kernel/trace/bpf_trace.c > > +++ b/kernel/trace/bpf_trace.c > > @@ -2274,12 +2274,44 @@ struct bpf_session_run_ctx { > > void *data; > > }; > > > > -#ifdef CONFIG_FPROBE > > +#if defined(CONFIG_FPROBE) || defined(CONFIG_KRETPROBES) > > +#ifndef CONFIG_FPROBE > > +struct bpf_kprobe { > > + struct bpf_kprobe_multi_link *link; > > + u64 cookie; > > + struct kretprobe rp; > > +}; > > + > > +static void bpf_kprobe_unregister(struct bpf_kprobe *kps, u32 cnt) > > +{ > > + for (int i = 0; i < cnt; i++) > > + unregister_kretprobe(&kps[i].rp); > > +} > > + > > +static int bpf_kprobe_register(struct bpf_kprobe *kps, u32 cnt) > > +{ > > + int ret = 0, i; > > + > > + for (i = 0; i < cnt; i++) { > > + ret = register_kretprobe(&kps[i].rp); > > + if (ret < 0) { > > + bpf_kprobe_unregister(kps, i); > > + break; > > + } > > + } > > + return ret; > > +} > > Hi, Jing. I don't see the point of the fallback logic. If we want to > use the kprobe-multi, we enable CONFIG_FPROBE. Is there any reason > that we can't enable CONFIG_FPROBE? As you said, for a "old kernel", > I think we don't introduce new feature for an old kernel. > > Besides, did you measure the performance of attaching bench? > You will register a kretprobe for each of the target. AFAIK, the > kprobe will use ftrace for optimization if we hook the entry of the > target function. So I suspect it will be quite slow here. > > Thanks! > Menglong Dong
The Dynamic ftrace feature is not enabled in Android for security reasons, forcing us to fall back on kretprobe. https://source.android.com/docs/core/tests/debug/ftrace#dftrace I will provide the benchmark test results as soon as possible.
