From: Andrii Nakryiko <andrii@kernel.org>
To: bpf@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Cc: catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com,
linux-perf-users@vger.kernel.org, peterz@infradead.org,
jolsa@kernel.org, rostedt@goodmis.org,
Andrii Nakryiko <andrii@kernel.org>
Subject: [PATCH bpf-next 2/3] selftests/bpf: Add stacktrace_ips test for tracepoint
Date: Fri, 13 Nov 2026 16:18:45 -0800 [thread overview]
Message-ID: <20261114001846.873499-3-andrii@kernel.org> (raw)
In-Reply-To: <20261114001846.873499-1-andrii@kernel.org>
Add a tp subtest that checks the stack captured by bpf_get_stack()
from a tracepoint program, recorded only for the test's own process.
Depending on static calls and inlining, the stack may or may not have
__traceiter_bpf_testmod_test_read in front of bpf_testmod_test_read,
so accept both. Also check that the entry after it differs: kernels
without commit 6d08340d1e35 ("Revert "perf/x86: Always store regs->ip
in perf_callchain_kernel()"") report the tracepoint's caller twice.
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
.../selftests/bpf/prog_tests/stacktrace_ips.c | 54 +++++++++++++++++++
.../selftests/bpf/progs/stacktrace_ips.c | 13 +++++
2 files changed, 67 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/stacktrace_ips.c b/tools/testing/selftests/bpf/prog_tests/stacktrace_ips.c
index da42b00e3d1f..a03d4c10c469 100644
--- a/tools/testing/selftests/bpf/prog_tests/stacktrace_ips.c
+++ b/tools/testing/selftests/bpf/prog_tests/stacktrace_ips.c
@@ -137,6 +137,58 @@ static void test_stacktrace_ips_raw_tp(void)
stacktrace_ips__destroy(skel);
}
+static void test_stacktrace_ips_tp(void)
+{
+ __u64 traceiter_addr, read_addr, *ips;
+ struct stacktrace_ips *skel;
+ struct ksyms *ksyms = NULL;
+ struct ksym *ksym;
+ int i;
+
+ skel = stacktrace_ips__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "stacktrace_ips__open_and_load"))
+ return;
+
+ if (!skel->kconfig->CONFIG_UNWINDER_ORC) {
+ test__skip();
+ goto cleanup;
+ }
+
+ skel->bss->my_pid = getpid();
+
+ skel->links.tp_test = bpf_program__attach(skel->progs.tp_test);
+ if (!ASSERT_OK_PTR(skel->links.tp_test, "bpf_program__attach"))
+ goto cleanup;
+
+ trigger_module_test_read(1);
+
+ ksyms = load_kallsyms_local();
+ if (!ASSERT_OK_PTR(ksyms, "load_kallsyms_local"))
+ goto cleanup;
+ traceiter_addr = ksym_get_addr_local(ksyms, "__traceiter_bpf_testmod_test_read");
+ read_addr = ksym_get_addr_local(ksyms, "bpf_testmod_test_read");
+
+ /*
+ * Depending on static calls and inlining, __traceiter_bpf_testmod_test_read
+ * may or may not be in front of bpf_testmod_test_read.
+ */
+ ips = skel->bss->tp_ips;
+ ksym = ksym_search_local(ksyms, ips[0]);
+ if (!ASSERT_OK_PTR(ksym, "ksym_search_local"))
+ goto cleanup;
+ i = ksym->addr == traceiter_addr ? 1 : 0;
+
+ ksym = ksym_search_local(ksyms, ips[i]);
+ if (!ASSERT_OK_PTR(ksym, "ksym_search_local"))
+ goto cleanup;
+ ASSERT_EQ(ksym->addr, read_addr, "stack_cmp");
+ ASSERT_NEQ(ips[i], ips[i + 1], "stack_dup");
+
+cleanup:
+ free_kallsyms_local(ksyms);
+ stacktrace_ips__destroy(skel);
+}
+
static void test_stacktrace_ips_kprobe(bool retprobe)
{
LIBBPF_OPTS(bpf_kprobe_opts, opts,
@@ -238,6 +290,8 @@ static void __test_stacktrace_ips(void)
test_stacktrace_ips_kprobe_multi(true);
if (test__start_subtest("raw_tp"))
test_stacktrace_ips_raw_tp();
+ if (test__start_subtest("tp"))
+ test_stacktrace_ips_tp();
if (test__start_subtest("kprobe"))
test_stacktrace_ips_kprobe(false);
if (test__start_subtest("kretprobe"))
diff --git a/tools/testing/selftests/bpf/progs/stacktrace_ips.c b/tools/testing/selftests/bpf/progs/stacktrace_ips.c
index 6830f2978613..df10ef3cb14d 100644
--- a/tools/testing/selftests/bpf/progs/stacktrace_ips.c
+++ b/tools/testing/selftests/bpf/progs/stacktrace_ips.c
@@ -53,6 +53,19 @@ int rawtp_test(void *ctx)
return 0;
}
+__u64 tp_ips[128];
+int my_pid;
+
+SEC("tp/bpf_testmod/bpf_testmod_test_read")
+int tp_test(void *ctx)
+{
+ if (bpf_get_current_pid_tgid() >> 32 != my_pid)
+ return 0;
+
+ bpf_get_stack(ctx, tp_ips, sizeof(tp_ips), 0);
+ return 0;
+}
+
SEC("fentry/bpf_testmod_stacktrace_test")
int fentry_test(struct pt_regs *ctx)
{
--
2.53.1-Meta
next prev parent reply other threads:[~2026-11-14 0:18 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-14 0:18 [PATCH bpf-next 0/3] Fix duplicate caller frame in arm64 stack traces Andrii Nakryiko
2026-11-14 0:18 ` [PATCH bpf-next 1/3] arm64: perf: Don't report the caller twice in caller-regs callchains Andrii Nakryiko
2026-11-14 0:26 ` sashiko-bot
2026-11-14 0:18 ` Andrii Nakryiko [this message]
2026-11-14 0:26 ` [PATCH bpf-next 2/3] selftests/bpf: Add stacktrace_ips test for tracepoint sashiko-bot
2026-11-14 0:18 ` [PATCH bpf-next 3/3] selftests/bpf: Run stacktrace_ips raw_tp, tp and fentry tests on arm64 Andrii Nakryiko
2026-11-14 0:30 ` sashiko-bot
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=20261114001846.873499-3-andrii@kernel.org \
--to=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=catalin.marinas@arm.com \
--cc=jolsa@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=will@kernel.org \
/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