From: Jiri Olsa <olsajiri@gmail.com>
To: Varun R Mallya <varunrmallya@gmail.com>
Cc: andrii@kernel.org, alan.maguire@oracle.com,
yonghong.song@linux.dev, song@kernel.org, bpf@vger.kernel.org,
ast@kernel.org, daniel@iogearbox.net, memxor@gmail.com,
eddyz87@gmail.com, martin.lau@linux.dev,
menglong8.dong@gmail.com, puranjay@kernel.org, bjorn@kernel.org,
leon.hwang@linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH bpf-next v2 2/3] libbpf: Add FEAT_KPROBE_MULTI_LINK feature probe.
Date: Mon, 30 Mar 2026 16:52:46 +0200 [thread overview]
Message-ID: <acqOPsDCKHIrH1HT@krava> (raw)
In-Reply-To: <20260330110019.549079-3-varunrmallya@gmail.com>
On Mon, Mar 30, 2026 at 04:30:18PM +0530, Varun R Mallya wrote:
> Add FEAT_KPROBE_MULTI_LINK, similar to UPROBE_MULTI_LINK
> by loading and creating a link for a small BPF program with
> BPF_TRACE_KPROBE_MULTI as the expected attach type, and
> then checking the success of the operation.
>
> Signed-off-by: Varun R Mallya <varunrmallya@gmail.com>
> ---
> tools/lib/bpf/features.c | 37 +++++++++++++++++++++++++++++++++
> tools/lib/bpf/libbpf_internal.h | 2 ++
> 2 files changed, 39 insertions(+)
>
> diff --git a/tools/lib/bpf/features.c b/tools/lib/bpf/features.c
> index adcad221c601..13227c9ea69d 100644
> --- a/tools/lib/bpf/features.c
> +++ b/tools/lib/bpf/features.c
> @@ -424,6 +424,40 @@ static int probe_uprobe_multi_link(int token_fd)
> return link_fd < 0 && err == -EINVAL;
> }
>
> +static int probe_kprobe_multi_link(int token_fd)
> +{
> + LIBBPF_OPTS(bpf_prog_load_opts, load_opts,
> + .expected_attach_type = BPF_TRACE_KPROBE_MULTI,
> + .token_fd = token_fd,
> + .prog_flags = token_fd ? BPF_F_TOKEN_FD : 0,
> + );
> + LIBBPF_OPTS(bpf_link_create_opts, link_opts);
> + struct bpf_insn insns[] = {
> + BPF_MOV64_IMM(BPF_REG_0, 0),
> + BPF_EXIT_INSN(),
> + };
> + int prog_fd, link_fd, err;
> + const char *sym = "bpf_map_lookup_elem"; /* stable, always present */
> +
> + prog_fd = bpf_prog_load(BPF_PROG_TYPE_KPROBE, NULL, "GPL",
> + insns, ARRAY_SIZE(insns), &load_opts);
> + if (prog_fd < 0)
> + return -errno;
> +
> + /* attaching to a valid symbol should succeed */
> + link_opts.kprobe_multi.syms = &sym;
> + link_opts.kprobe_multi.cnt = 1;
maybe we could set cnt > MAX_KPROBE_MULTI_CNT and check if the fail
is E2BIG ? this could save some cycles, but haven't tried that
jirka
> + link_fd = bpf_link_create(prog_fd, -1, BPF_TRACE_KPROBE_MULTI, &link_opts);
> + err = -errno;
> + if (link_fd >= 0)
> + close(link_fd);
> + close(prog_fd);
> + /* if kprobe_multi is supported, link creation either succeeds or
> + * fails with something other than -EINVAL due to permissions,
> + */
> + return link_fd >= 0 || (err != -EINVAL);
> +}
> +
SNIP
next prev parent reply other threads:[~2026-03-30 14:52 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-30 11:00 [RFC PATCH bpf-next v2 0/3] Upgrading uprobe and kprobe to their `multi` counterparts Varun R Mallya
2026-03-30 11:00 ` [RFC PATCH bpf-next v2 1/3] libbpf: Auto-upgrade uprobes to multi-uprobes when supported Varun R Mallya
2026-03-30 11:47 ` bot+bpf-ci
2026-03-30 14:52 ` Jiri Olsa
2026-04-01 9:56 ` Varun R Mallya
2026-03-30 11:00 ` [RFC PATCH bpf-next v2 2/3] libbpf: Add FEAT_KPROBE_MULTI_LINK feature probe Varun R Mallya
2026-03-30 14:42 ` Leon Hwang
2026-04-01 9:57 ` Varun R Mallya
2026-03-30 14:52 ` Jiri Olsa [this message]
2026-04-01 9:49 ` Varun R Mallya
2026-03-30 11:00 ` [RFC PATCH bpf-next v2 3/3] libbpf: Auto-upgrade kprobes to multi-kprobes when supported Varun R Mallya
2026-03-30 11:47 ` bot+bpf-ci
2026-04-01 9:59 ` Varun R Mallya
2026-03-30 14:53 ` Jiri Olsa
2026-04-01 10:53 ` Varun R Mallya
2026-04-01 11:11 ` Varun R Mallya
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=acqOPsDCKHIrH1HT@krava \
--to=olsajiri@gmail.com \
--cc=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bjorn@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=leon.hwang@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=menglong8.dong@gmail.com \
--cc=puranjay@kernel.org \
--cc=song@kernel.org \
--cc=varunrmallya@gmail.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.