From: Jiri Olsa <olsajiri@gmail.com>
To: Hoyeon Lee <hoyeon.lee@suse.com>
Cc: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Shuah Khan <shuah@kernel.org>, Feng Yang <yangfeng@kylinos.cn>,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH bpf-next v2 2/2] selftests/bpf: add test for address-based single kprobe attach
Date: Mon, 30 Mar 2026 12:08:20 +0200 [thread overview]
Message-ID: <acpLlFg_UUmzp80f@krava> (raw)
In-Reply-To: <20260329124429.689912-3-hoyeon.lee@suse.com>
On Sun, Mar 29, 2026 at 09:43:39PM +0900, Hoyeon Lee wrote:
> Currently, attach_probe covers manual single-kprobe attaches by
> func_name, but not by raw address. This commit adds address-based
> single-kprobe attach subtests for the two underlying attach paths,
> legacy tracefs/debugfs and PMU-based non-legacy. The new subtests
> resolve SYS_NANOSLEEP_KPROBE_NAME through kallsyms, pass the result
> through bpf_kprobe_opts.addr, and verify that kprobe and kretprobe are
> still triggered.
>
> Signed-off-by: Hoyeon Lee <hoyeon.lee@suse.com>
> ---
> .../selftests/bpf/prog_tests/attach_probe.c | 49 +++++++++++++++++++
> 1 file changed, 49 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/attach_probe.c b/tools/testing/selftests/bpf/prog_tests/attach_probe.c
> index 9e77e5da7097..64f2ed75779d 100644
> --- a/tools/testing/selftests/bpf/prog_tests/attach_probe.c
> +++ b/tools/testing/selftests/bpf/prog_tests/attach_probe.c
> @@ -123,6 +123,51 @@ static void test_attach_probe_manual(enum probe_attach_mode attach_mode)
> test_attach_probe_manual__destroy(skel);
> }
>
> +/* manual attach address-based kprobe/kretprobe testings */
> +static void test_attach_kprobe_by_addr(enum probe_attach_mode attach_mode)
> +{
> + DECLARE_LIBBPF_OPTS(bpf_kprobe_opts, kprobe_opts);
> + struct bpf_link *kprobe_link, *kretprobe_link;
> + struct test_attach_probe_manual *skel;
> + unsigned long func_addr;
> +
> + if (!ASSERT_OK(load_kallsyms(), "load_kallsyms"))
> + return;
> +
> + func_addr = ksym_get_addr(SYS_NANOSLEEP_KPROBE_NAME);
> + if (!ASSERT_NEQ(func_addr, 0UL, "func_addr"))
> + return;
> +
> + skel = test_attach_probe_manual__open_and_load();
> + if (!ASSERT_OK_PTR(skel, "skel_kprobe_manual_open_and_load"))
> + return;
> +
> + kprobe_opts.attach_mode = attach_mode;
> + kprobe_opts.retprobe = false;
> + kprobe_opts.addr = func_addr;
> + kprobe_link = bpf_program__attach_kprobe_opts(skel->progs.handle_kprobe,
> + NULL, &kprobe_opts);
> + if (!ASSERT_OK_PTR(kprobe_link, "attach_kprobe_by_addr"))
> + goto cleanup;
> + skel->links.handle_kprobe = kprobe_link;
we usually use skel->links.handle_kprobe directly, no need to use
kprobe_link or kretprobe_link
> +
> + kprobe_opts.retprobe = true;
> + kretprobe_link = bpf_program__attach_kprobe_opts(skel->progs.handle_kretprobe,
> + NULL, &kprobe_opts);
> + if (!ASSERT_OK_PTR(kretprobe_link, "attach_kretprobe_by_addr"))
> + goto cleanup;
> + skel->links.handle_kretprobe = kretprobe_link;
> +
> + /* trigger & validate kprobe && kretprobe */
> + usleep(1);
> +
> + ASSERT_EQ(skel->bss->kprobe_res, 1, "check_kprobe_res");
> + ASSERT_EQ(skel->bss->kretprobe_res, 2, "check_kretprobe_res");
> +
> +cleanup:
> + test_attach_probe_manual__destroy(skel);
> +}
> +
> /* attach uprobe/uretprobe long event name testings */
> static void test_attach_uprobe_long_event_name(void)
> {
> @@ -416,6 +461,10 @@ void test_attach_probe(void)
> test_attach_probe_manual(PROBE_ATTACH_MODE_PERF);
> if (test__start_subtest("manual-link"))
> test_attach_probe_manual(PROBE_ATTACH_MODE_LINK);
> + if (test__start_subtest("kprobe-legacy-by-addr"))
> + test_attach_kprobe_by_addr(PROBE_ATTACH_MODE_LEGACY);
> + if (test__start_subtest("kprobe-perf-by-addr"))
> + test_attach_kprobe_by_addr(PROBE_ATTACH_MODE_PERF);
should we test PROBE_ATTACH_MODE_LINK mode as well?
jirka
>
> if (test__start_subtest("auto"))
> test_attach_probe_auto(skel);
> --
> 2.52.0
>
next prev parent reply other threads:[~2026-03-30 10:08 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-29 12:43 [PATCH bpf-next v2 0/2] libbpf: allow address-based single kprobe attach Hoyeon Lee
2026-03-29 12:43 ` [PATCH bpf-next v2 1/2] " Hoyeon Lee
2026-03-30 10:08 ` Jiri Olsa
2026-03-31 1:47 ` Hoyeon Lee
2026-03-31 0:33 ` Andrii Nakryiko
2026-03-31 1:48 ` Hoyeon Lee
2026-03-31 2:15 ` Alexei Starovoitov
2026-03-31 5:55 ` Hoyeon Lee
2026-03-29 12:43 ` [PATCH bpf-next v2 2/2] selftests/bpf: add test for " Hoyeon Lee
2026-03-30 10:08 ` Jiri Olsa [this message]
2026-03-31 2:01 ` Hoyeon Lee
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=acpLlFg_UUmzp80f@krava \
--to=olsajiri@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=hoyeon.lee@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=yangfeng@kylinos.cn \
--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