BPF List
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@kernel.org>
To: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Masami Hiramatsu <mhiramat@kernel.org>
Cc: bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
	linux-kernel@vger.kernel.org, x86@kernel.org,
	Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	Quentin Monnet <qmo@kernel.org>,
	Alan Maguire <almagui@kernel.org>
Subject: [PATCH RFC bpf-next 29/31] selftests/bpf: Add kprobe multi inline args test
Date: Wed,  2 Dec 2026 13:30:33 +0100	[thread overview]
Message-ID: <20261202123035.10335-30-jolsa@kernel.org> (raw)
In-Reply-To: <20261202123035.10335-1-jolsa@kernel.org>

Add inline_args and inline_args_module tests for bpf_get_func_arg
and bpf_get_func_arg_cnt helpers used in kprobe multi program, for
inlined function in kernel and module and for function with entry
probe.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 .../bpf/prog_tests/kprobe_multi_test.c        | 185 ++++++++++++++++++
 .../selftests/bpf/progs/kprobe_multi_inline.c |  32 +++
 2 files changed, 217 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 f3eb95261c7a..6ae5bfaa81ba 100644
--- a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
+++ b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
@@ -1160,6 +1160,187 @@ static void test_inline_module(void)
 	kprobe_multi_inline__destroy(skel);
 }
 
+#define INLINE_ARGS_CNT		3
+
+/*
+ * The probe on @ip must be hit just once and see @exp arguments,
+ * anything above that needs to fail.
+ */
+static void inline_check_args(struct kprobe_multi_inline *skel, unsigned long ip,
+			      const __u64 *exp)
+{
+	int i, idx = -1;
+
+	if (!ASSERT_EQ(inline_hits(skel, ip, 0), 1, "args_hit"))
+		return;
+
+	for (i = 0; i < skel->bss->hits_cnt; i++) {
+		if (skel->bss->hits_ip[i] == ip)
+			idx = i;
+	}
+
+	ASSERT_EQ(skel->bss->args_cnt[idx], INLINE_ARGS_CNT, "args_cnt");
+
+	for (i = 0; i < INLINE_ARGS_CNT; i++) {
+		ASSERT_OK(skel->bss->args_err[idx][i], "args_err");
+		/* The arguments have different sizes, check the lower part. */
+		ASSERT_EQ((__u32)skel->bss->args_val[idx][i], (__u32)exp[i], "args_val");
+	}
+
+	ASSERT_EQ(skel->bss->args_err[idx][i], -EINVAL, "args_err_last");
+}
+
+/*
+ * Get arguments of inlined function and of function with entry probe
+ * in single link. The arguments of function with entry probe work also
+ * for link without inline flag, but not for return probe.
+ */
+static void test_inline_args(void)
+{
+	const char *syms[2] = { "bpf_kprobe_multi_inline_args", "bpf_fentry_test3" };
+	LIBBPF_OPTS(bpf_kprobe_multi_opts, opts);
+	struct kprobe_multi_inline *skel = NULL;
+	__u64 exp_entry[INLINE_ARGS_CNT] = { 4, 5, 6 };
+	__u64 exp[INLINE_ARGS_CNT] = { 1, 2, 3 };
+	unsigned long sites[INLINE_MAX], addr;
+	int cnt, i;
+
+	cnt = get_inline_sites(syms[0], sites, INLINE_MAX);
+	if (cnt == -ENOENT) {
+		test__skip();
+		return;
+	}
+	if (!ASSERT_EQ(cnt, 1, "sites_cnt"))
+		return;
+
+	addr = ksym_get_addr("bpf_fentry_test3");
+	if (!ASSERT_NEQ(addr, 0, "bpf_fentry_test3_addr"))
+		return;
+
+	skel = kprobe_multi_inline__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "kprobe_multi_inline__open_and_load"))
+		return;
+
+	skel->bss->pid = getpid();
+
+	opts.syms = syms;
+	opts.cnt = ARRAY_SIZE(syms);
+	opts.inlined = true;
+
+	skel->links.test_kprobe_inline_args =
+		bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_inline_args,
+						      NULL, &opts);
+	if (!ASSERT_OK_PTR(skel->links.test_kprobe_inline_args, "attach_kprobe_multi_opts"))
+		goto cleanup;
+
+	inline_trigger(skel);
+
+	ASSERT_EQ(skel->bss->hits_cnt, 2, "hits_cnt");
+	inline_check_args(skel, sites[0], exp);
+	inline_check_args(skel, addr, exp_entry);
+
+	kprobe_multi_inline__detach(skel);
+
+	/* Function with entry probe has arguments also without inline flag. */
+	opts.syms = &syms[1];
+	opts.cnt = 1;
+	opts.inlined = false;
+
+	skel->links.test_kprobe_inline_args =
+		bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_inline_args,
+						      NULL, &opts);
+	if (!ASSERT_OK_PTR(skel->links.test_kprobe_inline_args, "attach_kprobe_multi_opts"))
+		goto cleanup;
+
+	inline_trigger(skel);
+
+	ASSERT_EQ(skel->bss->hits_cnt, 1, "hits_cnt");
+	inline_check_args(skel, addr, exp_entry);
+
+	kprobe_multi_inline__detach(skel);
+
+	/* The same for function specified by address. */
+	opts.syms = NULL;
+	opts.addrs = &addr;
+
+	skel->links.test_kprobe_inline_args =
+		bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_inline_args,
+						      NULL, &opts);
+	if (!ASSERT_OK_PTR(skel->links.test_kprobe_inline_args, "attach_kprobe_multi_opts"))
+		goto cleanup;
+
+	inline_trigger(skel);
+
+	ASSERT_EQ(skel->bss->hits_cnt, 1, "hits_cnt");
+	inline_check_args(skel, addr, exp_entry);
+
+	kprobe_multi_inline__detach(skel);
+
+	/* There are no arguments in return probe. */
+	opts.retprobe = true;
+
+	skel->links.test_kprobe_inline_args =
+		bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_inline_args,
+						      NULL, &opts);
+	if (!ASSERT_OK_PTR(skel->links.test_kprobe_inline_args, "attach_kprobe_multi_opts"))
+		goto cleanup;
+
+	inline_trigger(skel);
+
+	if (!ASSERT_EQ(skel->bss->hits_cnt, 1, "hits_cnt"))
+		goto cleanup;
+	ASSERT_EQ(skel->bss->args_cnt[0], 0, "args_cnt");
+	for (i = 0; i < INLINE_ARGS_CNT; i++)
+		ASSERT_EQ(skel->bss->args_err[0][i], -EOPNOTSUPP, "args_err");
+
+cleanup:
+	kprobe_multi_inline__destroy(skel);
+}
+
+/* Get arguments of function inlined in module. */
+static void test_inline_args_module(void)
+{
+	LIBBPF_OPTS(bpf_kprobe_multi_opts, opts);
+	const char *syms[1] = { "bpf_testmod_kprobe_multi_inline_args" };
+	struct kprobe_multi_inline *skel = NULL;
+	__u64 exp[INLINE_ARGS_CNT] = { 1, 2, 3 };
+	unsigned long sites[INLINE_MAX];
+	int cnt;
+
+	cnt = get_testmod_inline_sites(syms[0], sites, INLINE_MAX);
+	if (cnt == -ENOENT) {
+		test__skip();
+		return;
+	}
+	if (!ASSERT_EQ(cnt, 1, "sites_cnt"))
+		return;
+
+	skel = kprobe_multi_inline__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "kprobe_multi_inline__open_and_load"))
+		return;
+
+	skel->bss->pid = getpid();
+
+	opts.syms = syms;
+	opts.cnt = ARRAY_SIZE(syms);
+	opts.inlined = true;
+
+	skel->links.test_kprobe_inline_args =
+		bpf_program__attach_kprobe_multi_opts(skel->progs.test_kprobe_inline_args,
+						      NULL, &opts);
+	if (!ASSERT_OK_PTR(skel->links.test_kprobe_inline_args, "attach_kprobe_multi_opts"))
+		goto cleanup;
+
+	skel->bss->hits_cnt = 0;
+	ASSERT_OK(trigger_module_test_read(1), "trigger_read");
+
+	ASSERT_EQ(skel->bss->hits_cnt, 1, "hits_cnt");
+	inline_check_args(skel, sites[0], exp);
+
+cleanup:
+	kprobe_multi_inline__destroy(skel);
+}
+
 /*
  * Make sure the link create fails with @error and kernel explains
  * the failure with @msg in the log.
@@ -1426,6 +1607,10 @@ static void test_inline_subtests(void)
 		test_inline_module();
 	if (test__start_subtest("inline_strict"))
 		test_inline_strict();
+	if (test__start_subtest("inline_args"))
+		test_inline_args();
+	if (test__start_subtest("inline_args_module"))
+		test_inline_args_module();
 
 	free_inline_btf();
 }
diff --git a/tools/testing/selftests/bpf/progs/kprobe_multi_inline.c b/tools/testing/selftests/bpf/progs/kprobe_multi_inline.c
index f2b428292544..a57e79f7c640 100644
--- a/tools/testing/selftests/bpf/progs/kprobe_multi_inline.c
+++ b/tools/testing/selftests/bpf/progs/kprobe_multi_inline.c
@@ -6,6 +6,7 @@
 char _license[] SEC("license") = "GPL";
 
 #define MAX_HITS 16
+#define MAX_ARGS 4
 
 int pid = 0;
 
@@ -13,6 +14,10 @@ __u64 hits_ip[MAX_HITS];
 __u64 hits_cookie[MAX_HITS];
 __u32 hits_cnt = 0;
 
+__u64 args_cnt[MAX_HITS];
+__u64 args_val[MAX_HITS][MAX_ARGS];
+long args_err[MAX_HITS][MAX_ARGS];
+
 /*
  * No tests in here, just to trigger 'bpf_kprobe_multi_inline_test*'
  * through tracing test_run
@@ -40,6 +45,33 @@ int test_kprobe_inline(struct pt_regs *ctx)
 	return 0;
 }
 
+SEC("kprobe.multi")
+int test_kprobe_inline_args(struct pt_regs *ctx)
+{
+	__u32 idx = hits_cnt;
+	__u64 val;
+	int i;
+
+	if (bpf_get_current_pid_tgid() >> 32 != pid)
+		return 0;
+
+	if (idx >= MAX_HITS)
+		return 0;
+
+	hits_ip[idx] = bpf_get_func_ip(ctx);
+	hits_cookie[idx] = bpf_get_attach_cookie(ctx);
+	args_cnt[idx] = bpf_get_func_arg_cnt(ctx);
+
+	for (i = 0; i < MAX_ARGS; i++) {
+		val = 0;
+		args_err[idx][i] = bpf_get_func_arg(ctx, i, &val);
+		args_val[idx][i] = val;
+	}
+
+	hits_cnt = idx + 1;
+	return 0;
+}
+
 SEC("kprobe.session")
 int test_session_inline(struct pt_regs *ctx)
 {
-- 
2.56.1


  parent reply	other threads:[~2026-12-02 12:35 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 12:30 [PATCH RFC bpf-next 00/31] bpf: Attach kprobe multi link to inlined functions Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 01/31] x86/ptrace: Add regs_get_dwarf_register function Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 02/31] kprobes: Make the kprobe hash table size configurable Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 03/31] kprobes: Add enable_kprobes to enable multiple kprobes at once Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 04/31] module: Add module_sect_addr function Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 05/31] bpf: Add bpf_get_btf_vmlinux_inline function Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 06/31] bpf: Use goto labels for error path in bpf_kprobe_multi_link_attach Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 07/31] bpf: Add support to attach inlined functions with kprobe multi link Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 08/31] bpf: Add cookie support for kprobe multi inlined functions Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 09/31] bpf: Add link info " Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 10/31] bpf: Add fdinfo " Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 11/31] bpf: Add btf_for_each_module_inline function Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 12/31] bpf: Change get_modules_for_addrs to use struct modules_array Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 13/31] tbpf: Add support to attach inlined functions in modules with kprobe multi link Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 14/31] bpf: Add BPF_F_KPROBE_MULTI_INLINE_STRICT flag for " Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 15/31] bpf: Add get_func_arg[_cnt] support for kprobe multi functions Jiri Olsa
2026-12-02 13:06   ` sashiko-bot
2026-12-02 12:30 ` [PATCH RFC bpf-next 16/31] bpf: Add get_func_arg[_cnt] support for kprobe multi inlined functions Jiri Olsa
2026-12-02 12:55   ` sashiko-bot
2026-12-02 12:30 ` [PATCH RFC bpf-next 17/31] bpf: Add log messages for kprobe multi inline attach Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 18/31] bpf: Add inlined functions for kprobe multi inline tests Jiri Olsa
2026-12-02 12:51   ` sashiko-bot
2026-12-02 12:30 ` [PATCH RFC bpf-next 19/31] libbpf: Add inline options to bpf_kprobe_multi_opts Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 20/31] libbpf: Print kernel log for failed kprobe multi attach Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 21/31] bpftool: Display inlined functions for kprobe multi link Jiri Olsa
2026-12-02 13:00   ` sashiko-bot
2026-12-02 12:30 ` [PATCH RFC bpf-next 22/31] selftests/bpf: Add inlined functions to bpf_testmod Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 23/31] selftests/bpf: Add kprobe multi inline attach test Jiri Olsa
2026-12-02 12:50   ` sashiko-bot
2026-12-02 12:30 ` [PATCH RFC bpf-next 24/31] selftests/bpf: Add kprobe multi inline mixed test Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 25/31] selftests/bpf: Add kprobe multi inline skip test Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 26/31] selftests/bpf: Add kprobe multi inline fails test Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 27/31] selftests/bpf: Add kprobe multi inline module test Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 28/31] selftests/bpf: Add kprobe multi inline strict test Jiri Olsa
2026-12-02 12:30 ` Jiri Olsa [this message]
2026-12-02 12:30 ` [PATCH RFC bpf-next 30/31] selftests/bpf: Add kprobe multi inline bench attach test Jiri Olsa
2026-12-02 12:30 ` [PATCH RFC bpf-next 31/31] selftests/bpf: Add kprobe multi inline link info test Jiri Olsa

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=20261202123035.10335-30-jolsa@kernel.org \
    --to=jolsa@kernel.org \
    --cc=almagui@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=qmo@kernel.org \
    --cc=song@kernel.org \
    --cc=x86@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