[PATCH RFC bpf-next 28/31] selftests/bpf: Add kprobe multi inline strict test

From: Jiri Olsa

Date: Wed Dec 02 2026 - 07:35:30 EST


Add inline_strict test for kprobe multi link with
BPF_F_KPROBE_MULTI_INLINE_STRICT flag:

- the attach fails when the flag is used without
BPF_F_KPROBE_MULTI_INLINE flag
- the attach fails for function with inlined instance that can't
be attached, and the log names the function and the instance
- the attach succeeds for function with all the inlined instances
attached and link's fdinfo shows no skipped instance

Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
---
.../bpf/prog_tests/kprobe_multi_test.c | 82 +++++++++++++++++++
1 file changed, 82 insertions(+)

diff --git a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
index 761cd7fe63ac..f3eb95261c7a 100644
--- a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
+++ b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
@@ -1326,6 +1326,86 @@ static void test_inline_fails(void)
kprobe_multi_inline__destroy(skel);
}

+/* With strict flag all the inlined instances need to be attached. */
+static void test_inline_strict(void)
+{
+ LIBBPF_OPTS(bpf_kprobe_multi_opts, opts);
+ LIBBPF_OPTS(bpf_link_create_opts, lopts);
+ const char *partial[1] = { "bpf_kprobe_multi_inline_partial" };
+ const char *syms[1] = { "bpf_kprobe_multi_inline_inner" };
+ struct kprobe_multi_inline *skel = NULL;
+ unsigned long sites[INLINE_MAX];
+ int cnt, saved_error, prog_fd, link_fd;
+
+ cnt = get_inline_sites(syms[0], sites, INLINE_MAX);
+ if (cnt == -ENOENT) {
+ test__skip();
+ return;
+ }
+ if (!ASSERT_EQ(cnt, 2, "inline_sites_cnt"))
+ return;
+
+ skel = kprobe_multi_inline__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "kprobe_multi_inline__open_and_load"))
+ return;
+
+ prog_fd = bpf_program__fd(skel->progs.test_kprobe_inline);
+
+ /* strict without inlined */
+ opts.syms = syms;
+ opts.cnt = 1;
+ opts.inlined_strict = true;
+
+ skel->links.test_kprobe_inline =
+ bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_inline, NULL, &opts);
+ saved_error = -errno;
+ if (!ASSERT_ERR_PTR(skel->links.test_kprobe_inline, "strict_no_inlined"))
+ goto cleanup;
+ ASSERT_EQ(saved_error, -EINVAL, "strict_no_inlined_error");
+
+ lopts.kprobe_multi.syms = syms;
+ lopts.kprobe_multi.cnt = 1;
+ lopts.kprobe_multi.flags = BPF_F_KPROBE_MULTI_INLINE_STRICT;
+
+ if (!inline_link_fails(prog_fd, BPF_TRACE_KPROBE_MULTI, &lopts, -EINVAL,
+ "Strict flag needs to be used with inline flag."))
+ goto cleanup;
+
+ /* function with inlined instance that can't be attached */
+ opts.syms = partial;
+ opts.inlined = true;
+
+ skel->links.test_kprobe_inline =
+ bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_inline, NULL, &opts);
+ saved_error = -errno;
+ if (!ASSERT_ERR_PTR(skel->links.test_kprobe_inline, "strict_partial"))
+ goto cleanup;
+ ASSERT_EQ(saved_error, -EINVAL, "strict_partial_error");
+
+ lopts.kprobe_multi.syms = partial;
+ lopts.kprobe_multi.flags = BPF_F_KPROBE_MULTI_INLINE | BPF_F_KPROBE_MULTI_INLINE_STRICT;
+
+ if (!inline_link_fails(prog_fd, BPF_TRACE_KPROBE_MULTI, &lopts, -EINVAL,
+ "Function bpf_kprobe_multi_inline_partial has inlined instance "
+ "that can't be attached, bpf_kprobe_multi_inline_test4+"))
+ goto cleanup;
+
+ /* function with all the inlined instances attached */
+ opts.syms = syms;
+
+ skel->links.test_kprobe_inline =
+ bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_inline, NULL, &opts);
+ if (!ASSERT_OK_PTR(skel->links.test_kprobe_inline, "strict_attach"))
+ goto cleanup;
+
+ link_fd = bpf_link__fd(skel->links.test_kprobe_inline);
+ ASSERT_EQ(get_fdinfo_cnt(link_fd, "kprobe_inline_cnt"), cnt, "kprobe_inline_cnt");
+ ASSERT_EQ(get_fdinfo_cnt(link_fd, "kprobe_inline_skipped"), 0, "kprobe_inline_skipped");
+
+cleanup:
+ kprobe_multi_inline__destroy(skel);
+}
+
/* Run all the tests for attaching to inlined functions. */
static void test_inline_subtests(void)
{
@@ -1344,6 +1424,8 @@ static void test_inline_subtests(void)
test_inline_fails();
if (test__start_subtest("inline_module"))
test_inline_module();
+ if (test__start_subtest("inline_strict"))
+ test_inline_strict();

free_inline_btf();
}
--
2.56.1