From: liujing40 <liujing.root@gmail.com>
To: menglong.dong@linux.dev
Cc: andrii@kernel.org, ast@kernel.org, bpf@vger.kernel.org,
daniel@iogearbox.net, eddyz87@gmail.com, haoluo@google.com,
john.fastabend@gmail.com, jolsa@kernel.org, kpsingh@kernel.org,
linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
liujing.root@gmail.com, liujing40@xiaomi.com,
martin.lau@linux.dev, mhiramat@kernel.org, sdf@fomichev.me,
song@kernel.org, yonghong.song@linux.dev
Subject: Re: [PATCH 2/2] bpf: Implement kretprobe fallback for kprobe multi link
Date: Mon, 22 Dec 2025 16:02:53 +0800 [thread overview]
Message-ID: <20251222080253.2314895-1-liujing40@xiaomi.com> (raw)
In-Reply-To: <24197762.6Emhk5qWAg@7940hx>
On Fri, 19 Dec 2025 09:57:37 +0800
Menglong Dong <menglong.dong@linux.dev> wrote:
> On 2025/12/18 21:06 liujing40 <liujing.root@gmail.com> 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 <liujing40@xiaomi.com>
> > ---
> > 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.
next prev parent reply other threads:[~2025-12-22 8:03 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-18 13:06 [PATCH 0/2] bpf: Add kretprobe fallback for kprobe multi link liujing40
2025-12-18 13:06 ` [PATCH 1/2] bpf: Prepare for kprobe multi link fallback patch liujing40
2025-12-18 13:06 ` [PATCH 2/2] bpf: Implement kretprobe fallback for kprobe multi link liujing40
2025-12-18 13:33 ` bot+bpf-ci
2026-01-29 0:13 ` Masami Hiramatsu
2025-12-18 17:53 ` Alexei Starovoitov
2025-12-18 21:09 ` Steven Rostedt
2025-12-22 8:00 ` liujing40
2025-12-19 1:57 ` Menglong Dong
2025-12-22 8:02 ` liujing40 [this message]
2025-12-22 17:15 ` Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251222080253.2314895-1-liujing40@xiaomi.com \
--to=liujing.root@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=liujing40@xiaomi.com \
--cc=martin.lau@linux.dev \
--cc=menglong.dong@linux.dev \
--cc=mhiramat@kernel.org \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox