* [PATCH bpf-next v2 0/3] Fix duplicate caller frame in arm64 stack traces
@ 2026-11-19 0:01 Andrii Nakryiko
2026-11-19 0:01 ` [PATCH bpf-next v2 1/3] arm64: perf: Don't report the caller twice in caller-regs callchains Andrii Nakryiko
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Andrii Nakryiko @ 2026-11-19 0:01 UTC (permalink / raw)
To: bpf, linux-arm-kernel
Cc: catalin.marinas, will, mark.rutland, linux-perf-users, peterz,
jolsa, rostedt, Andrii Nakryiko
On arm64 the caller is reported twice when the kernel builds a callchain for
the current task from regs filled by perf_fetch_caller_regs(), instead of regs
saved by a real exception. There was a similar problem on x86-64, but it was
since fixed. Now it's time for arm64.
Patch 1 has the fix, patches 2-3 add BPF selftests for this.
I'm targeting bpf-next because of BPF selftests and to have BPF CI test
everything. Patch 1 doesn't have to go through bpf-next, but it's simple enough,
so if arm64 folks are ok with that, please ack and then we'll land everything
in one go into bpf-next.
v1->v2:
- keep __builtin_frame_address(0) in perf_arch_fetch_caller_regs(), mark
these regs with PSR_MODE_EL1t instead, and have perf_callchain_kernel()
skip the duplicate leaf regs->pc for them, like x86 does with
perf_hw_regs() (Will);
v1: https://lore.kernel.org/bpf/20261114001846.873499-1-andrii@kernel.org/
Andrii Nakryiko (3):
arm64: perf: Don't report the caller twice in caller-regs callchains
selftests/bpf: Add stacktrace_ips test for tracepoint
selftests/bpf: Run stacktrace_ips raw_tp, tp and fentry tests on arm64
arch/arm64/include/asm/perf_event.h | 2 +-
arch/arm64/kernel/perf_callchain.c | 33 ++++++++-
.../selftests/bpf/prog_tests/stacktrace_ips.c | 67 ++++++++++++++++++-
.../selftests/bpf/progs/stacktrace_ips.c | 18 ++++-
4 files changed, 113 insertions(+), 7 deletions(-)
--
2.53.1-Meta
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH bpf-next v2 1/3] arm64: perf: Don't report the caller twice in caller-regs callchains
2026-11-19 0:01 [PATCH bpf-next v2 0/3] Fix duplicate caller frame in arm64 stack traces Andrii Nakryiko
@ 2026-11-19 0:01 ` Andrii Nakryiko
2026-11-19 0:22 ` sashiko-bot
2026-11-19 1:38 ` Alexei Starovoitov
2026-11-19 0:01 ` [PATCH bpf-next v2 2/3] selftests/bpf: Add stacktrace_ips test for tracepoint Andrii Nakryiko
2026-11-19 0:01 ` [PATCH bpf-next v2 3/3] selftests/bpf: Run stacktrace_ips raw_tp, tp and fentry tests on arm64 Andrii Nakryiko
2 siblings, 2 replies; 8+ messages in thread
From: Andrii Nakryiko @ 2026-11-19 0:01 UTC (permalink / raw)
To: bpf, linux-arm-kernel
Cc: catalin.marinas, will, mark.rutland, linux-perf-users, peterz,
jolsa, rostedt, Andrii Nakryiko
perf_arch_fetch_caller_regs() sets regs->pc to the return address of
the function it is used in (CALLER_ADDR0) and points regs->regs[29] at
that function's own frame record, whose saved LR is that same return
address. perf_callchain_kernel() reports regs->pc and then unwinds from
the frame record at x29, so the caller shows up twice at the top of
every kernel callchain built from perf_fetch_caller_regs(): tracepoint
events, software events emitted by __perf_sw_event_sched()
(context-switches, cgroup-switches, cpu-migrations), and
bpf_get_stack() and bpf_get_stackid() in tracepoint, raw tracepoint,
tp_btf and fentry/fexit programs. E.g., for a tracepoint program
attached to sched_process_fork:
__traceiter_sched_process_fork+0x44
__traceiter_sched_process_fork+0x44
kernel_clone+0x250
...
x86 tells such regs apart in perf_callchain_kernel() with
perf_hw_regs(): perf_arch_fetch_caller_regs() sets regs->flags to 0,
while hardware-saved RFLAGS always has X86_EFLAGS_FIXED set, and
regs->ip is not reported for regs that fail the check.
Do the same on arm64. Set pstate to PSR_MODE_EL1t, which exceptions
taken from the kernel never have (the kernel runs in EL1h, or EL2h
with VHE), and skip the leaf regs->pc in perf_callchain_kernel() for
regs with that mode. The unwind still starts from regs, with the frame
record at x29 walked by the unwinder.
regs->pstate of software events emitted by __perf_sw_event_sched(),
which BPF perf_event programs see in bpf_perf_event_data::regs, changes
from PSR_MODE_EL1h to PSR_MODE_EL1t.
x86 had the same duplicate entry, fixed by commit 6d08340d1e35
("Revert "perf/x86: Always store regs->ip in perf_callchain_kernel()"").
Fixes: 5b09a094f2fb ("arm64: perf: Fix callchain parse error with kernel tracepoint events")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
arch/arm64/include/asm/perf_event.h | 2 +-
arch/arm64/kernel/perf_callchain.c | 33 ++++++++++++++++++++++++++++-
2 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/include/asm/perf_event.h b/arch/arm64/include/asm/perf_event.h
index ee45b4e77347..b3e7c24a5aab 100644
--- a/arch/arm64/include/asm/perf_event.h
+++ b/arch/arm64/include/asm/perf_event.h
@@ -17,7 +17,7 @@
(regs)->pc = (__ip); \
(regs)->regs[29] = (unsigned long) __builtin_frame_address(0); \
(regs)->sp = current_stack_pointer; \
- (regs)->pstate = PSR_MODE_EL1h; \
+ (regs)->pstate = PSR_MODE_EL1t; \
}
#endif
diff --git a/arch/arm64/kernel/perf_callchain.c b/arch/arm64/kernel/perf_callchain.c
index 9b7f26b128b5..3e956c4b0798 100644
--- a/arch/arm64/kernel/perf_callchain.c
+++ b/arch/arm64/kernel/perf_callchain.c
@@ -28,6 +28,31 @@ void perf_callchain_user(struct perf_callchain_entry_ctx *entry,
arch_stack_walk_user(callchain_trace, entry, regs);
}
+/*
+ * Determine whether the regs were taken from an exception handler rather than
+ * from perf_arch_fetch_caller_regs().
+ */
+static bool perf_hw_regs(struct pt_regs *regs)
+{
+ return (regs->pstate & PSR_MODE_MASK) != PSR_MODE_EL1t;
+}
+
+struct caller_regs_callchain {
+ struct perf_callchain_entry_ctx *entry;
+ bool skip_leaf;
+};
+
+static bool caller_regs_callchain_trace(void *data, unsigned long pc)
+{
+ struct caller_regs_callchain *cc = data;
+
+ if (cc->skip_leaf) {
+ cc->skip_leaf = false;
+ return true;
+ }
+ return callchain_trace(cc->entry, pc);
+}
+
void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry,
struct pt_regs *regs)
{
@@ -36,5 +61,11 @@ void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry,
return;
}
- arch_stack_walk(callchain_trace, entry, current, regs);
+ if (perf_hw_regs(regs)) {
+ arch_stack_walk(callchain_trace, entry, current, regs);
+ } else {
+ struct caller_regs_callchain cc = { .entry = entry, .skip_leaf = true };
+
+ arch_stack_walk(caller_regs_callchain_trace, &cc, current, regs);
+ }
}
--
2.53.1-Meta
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH bpf-next v2 2/3] selftests/bpf: Add stacktrace_ips test for tracepoint
2026-11-19 0:01 [PATCH bpf-next v2 0/3] Fix duplicate caller frame in arm64 stack traces Andrii Nakryiko
2026-11-19 0:01 ` [PATCH bpf-next v2 1/3] arm64: perf: Don't report the caller twice in caller-regs callchains Andrii Nakryiko
@ 2026-11-19 0:01 ` Andrii Nakryiko
2026-11-19 0:07 ` sashiko-bot
2026-11-19 0:01 ` [PATCH bpf-next v2 3/3] selftests/bpf: Run stacktrace_ips raw_tp, tp and fentry tests on arm64 Andrii Nakryiko
2 siblings, 1 reply; 8+ messages in thread
From: Andrii Nakryiko @ 2026-11-19 0:01 UTC (permalink / raw)
To: bpf, linux-arm-kernel
Cc: catalin.marinas, will, mark.rutland, linux-perf-users, peterz,
jolsa, rostedt, Andrii Nakryiko
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: x86
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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH bpf-next v2 3/3] selftests/bpf: Run stacktrace_ips raw_tp, tp and fentry tests on arm64
2026-11-19 0:01 [PATCH bpf-next v2 0/3] Fix duplicate caller frame in arm64 stack traces Andrii Nakryiko
2026-11-19 0:01 ` [PATCH bpf-next v2 1/3] arm64: perf: Don't report the caller twice in caller-regs callchains Andrii Nakryiko
2026-11-19 0:01 ` [PATCH bpf-next v2 2/3] selftests/bpf: Add stacktrace_ips test for tracepoint Andrii Nakryiko
@ 2026-11-19 0:01 ` Andrii Nakryiko
2026-11-19 0:05 ` sashiko-bot
2 siblings, 1 reply; 8+ messages in thread
From: Andrii Nakryiko @ 2026-11-19 0:01 UTC (permalink / raw)
To: bpf, linux-arm-kernel
Cc: catalin.marinas, will, mark.rutland, linux-perf-users, peterz,
jolsa, rostedt, Andrii Nakryiko
The raw_tp, tp and fentry subtests check stacks unwound from
perf_fetch_caller_regs() regs. Now that arm64 perf_callchain_kernel()
skips regs->pc of such regs and no longer reports the caller twice,
run these subtests on arm64 as well, where kernel stacks are always
unwound through frame records.
Leave the kprobe, kretprobe, kprobe_multi, kretprobe_multi and fexit
subtests x86-only: on arm64, kprobes at function entry miss the probed
function's caller, and fexit stacks have an extra entry for the traced
function. The kretprobe subtests pass on arm64, but don't use
perf_fetch_caller_regs() regs.
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
.../selftests/bpf/prog_tests/stacktrace_ips.c | 15 +++++++++++----
.../testing/selftests/bpf/progs/stacktrace_ips.c | 5 +++--
2 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/stacktrace_ips.c b/tools/testing/selftests/bpf/prog_tests/stacktrace_ips.c
index a03d4c10c469..aee46543f390 100644
--- a/tools/testing/selftests/bpf/prog_tests/stacktrace_ips.c
+++ b/tools/testing/selftests/bpf/prog_tests/stacktrace_ips.c
@@ -2,7 +2,7 @@
#include <test_progs.h>
#include "stacktrace_ips.skel.h"
-#ifdef __x86_64__
+#if defined(__x86_64__) || defined(__aarch64__)
static int check_stacktrace_ips(int fd, __u32 key, int cnt, ...)
{
__u64 ips[PERF_MAX_STACK_DEPTH];
@@ -47,6 +47,12 @@ static int check_stacktrace_ips(int fd, __u32 key, int cnt, ...)
return err;
}
+/* arm64 always unwinds kernel stacks through frame records */
+static bool unwinder_ok(struct stacktrace_ips *skel)
+{
+ return skel->kconfig->CONFIG_UNWINDER_ORC || skel->kconfig->CONFIG_ARM64;
+}
+
static void test_stacktrace_ips_kprobe_multi(bool retprobe)
{
LIBBPF_OPTS(bpf_kprobe_multi_opts, opts,
@@ -106,7 +112,7 @@ static void test_stacktrace_ips_raw_tp(void)
if (!ASSERT_OK_PTR(skel, "stacktrace_ips__open_and_load"))
return;
- if (!skel->kconfig->CONFIG_UNWINDER_ORC) {
+ if (!unwinder_ok(skel)) {
test__skip();
goto cleanup;
}
@@ -149,7 +155,7 @@ static void test_stacktrace_ips_tp(void)
if (!ASSERT_OK_PTR(skel, "stacktrace_ips__open_and_load"))
return;
- if (!skel->kconfig->CONFIG_UNWINDER_ORC) {
+ if (!unwinder_ok(skel)) {
test__skip();
goto cleanup;
}
@@ -244,7 +250,8 @@ static void test_stacktrace_ips_trampoline(bool retprobe)
if (!ASSERT_OK_PTR(skel, "stacktrace_ips__open_and_load"))
return;
- if (!skel->kconfig->CONFIG_UNWINDER_ORC) {
+ /* on arm64, fexit stacks also have a frame for the traced function */
+ if ((retprobe && !skel->kconfig->CONFIG_UNWINDER_ORC) || !unwinder_ok(skel)) {
test__skip();
goto cleanup;
}
diff --git a/tools/testing/selftests/bpf/progs/stacktrace_ips.c b/tools/testing/selftests/bpf/progs/stacktrace_ips.c
index df10ef3cb14d..11dfebd4ddb2 100644
--- a/tools/testing/selftests/bpf/progs/stacktrace_ips.c
+++ b/tools/testing/selftests/bpf/progs/stacktrace_ips.c
@@ -19,14 +19,15 @@ struct {
} stackmap SEC(".maps");
extern bool CONFIG_UNWINDER_ORC __kconfig __weak;
+extern bool CONFIG_ARM64 __kconfig __weak;
/*
- * This function is here to have CONFIG_UNWINDER_ORC
+ * This function is here to have CONFIG_UNWINDER_ORC and CONFIG_ARM64
* used and added to object BTF.
*/
int unused(void)
{
- return CONFIG_UNWINDER_ORC ? 0 : 1;
+ return CONFIG_UNWINDER_ORC || CONFIG_ARM64 ? 0 : 1;
}
__u32 stack_key;
--
2.53.1-Meta
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH bpf-next v2 3/3] selftests/bpf: Run stacktrace_ips raw_tp, tp and fentry tests on arm64
2026-11-19 0:01 ` [PATCH bpf-next v2 3/3] selftests/bpf: Run stacktrace_ips raw_tp, tp and fentry tests on arm64 Andrii Nakryiko
@ 2026-11-19 0:05 ` sashiko-bot
0 siblings, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-11-19 0:05 UTC (permalink / raw)
To: Andrii Nakryiko; +Cc: linux-perf-users
> The raw_tp, tp and fentry subtests check stacks unwound from
> perf_fetch_caller_regs() regs. Now that arm64 perf_callchain_kernel()
> skips regs->pc of such regs and no longer reports the caller twice,
> run these subtests on arm64 as well, where kernel stacks are always
> unwound through frame records.
>
> Leave the kprobe, kretprobe, kprobe_multi, kretprobe_multi and fexit
> subtests x86-only: on arm64, kprobes at function entry miss the probed
> function's caller, and fexit stacks have an extra entry for the traced
> function. The kretprobe subtests pass on arm64, but don't use
> perf_fetch_caller_regs() regs.
>
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119000112.2377949-1-andrii@kernel.org?part=3
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH bpf-next v2 2/3] selftests/bpf: Add stacktrace_ips test for tracepoint
2026-11-19 0:01 ` [PATCH bpf-next v2 2/3] selftests/bpf: Add stacktrace_ips test for tracepoint Andrii Nakryiko
@ 2026-11-19 0:07 ` sashiko-bot
0 siblings, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-11-19 0:07 UTC (permalink / raw)
To: Andrii Nakryiko; +Cc: linux-perf-users
> 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: x86
> 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>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119000112.2377949-1-andrii@kernel.org?part=2
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH bpf-next v2 1/3] arm64: perf: Don't report the caller twice in caller-regs callchains
2026-11-19 0:01 ` [PATCH bpf-next v2 1/3] arm64: perf: Don't report the caller twice in caller-regs callchains Andrii Nakryiko
@ 2026-11-19 0:22 ` sashiko-bot
2026-11-19 1:38 ` Alexei Starovoitov
1 sibling, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-11-19 0:22 UTC (permalink / raw)
To: Andrii Nakryiko; +Cc: linux-perf-users
> perf_arch_fetch_caller_regs() sets regs->pc to the return address of
> the function it is used in (CALLER_ADDR0) and points regs->regs[29] at
> that function's own frame record, whose saved LR is that same return
> address. perf_callchain_kernel() reports regs->pc and then unwinds from
> the frame record at x29, so the caller shows up twice at the top of
> every kernel callchain built from perf_fetch_caller_regs(): tracepoint
> events, software events emitted by __perf_sw_event_sched()
> (context-switches, cgroup-switches, cpu-migrations), and
> bpf_get_stack() and bpf_get_stackid() in tracepoint, raw tracepoint,
> tp_btf and fentry/fexit programs. E.g., for a tracepoint program
> attached to sched_process_fork:
>
> __traceiter_sched_process_fork+0x44
> __traceiter_sched_process_fork+0x44
> kernel_clone+0x250
> [ ... ]
> x86 had the same duplicate entry, fixed by commit 6d08340d1e35
> ("Revert "perf/x86: Always store regs->ip in perf_callchain_kernel()"").
>
> Fixes: 5b09a094f2fb ("arm64: perf: Fix callchain parse error with kernel tracepoint events")
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119000112.2377949-1-andrii@kernel.org?part=1
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH bpf-next v2 1/3] arm64: perf: Don't report the caller twice in caller-regs callchains
2026-11-19 0:01 ` [PATCH bpf-next v2 1/3] arm64: perf: Don't report the caller twice in caller-regs callchains Andrii Nakryiko
2026-11-19 0:22 ` sashiko-bot
@ 2026-11-19 1:38 ` Alexei Starovoitov
1 sibling, 0 replies; 8+ messages in thread
From: Alexei Starovoitov @ 2026-11-19 1:38 UTC (permalink / raw)
To: Andrii Nakryiko, bpf, linux-arm-kernel
Cc: catalin.marinas, will, mark.rutland, linux-perf-users, peterz,
jolsa, rostedt
On Wed, Nov 18, 2026 at 04:01 PM Andrii Nakryiko <andrii@kernel.org> wrote:
> Do the same on arm64. Set pstate to PSR_MODE_EL1t, which exceptions
> taken from the kernel never have (the kernel runs in EL1h, or EL2h
> with VHE), and skip the leaf regs->pc in perf_callchain_kernel() for
> regs with that mode. The unwind still starts from regs, with the frame
> record at x29 walked by the unwinder.
my bot thinks the following will be a more accurate fix...
diff --git a/arch/arm64/include/asm/perf_event.h b/arch/arm64/include/asm/perf_event.h
index ee45b4e..7c5ab65 100644
--- a/arch/arm64/include/asm/perf_event.h
+++ b/arch/arm64/include/asm/perf_event.h
@@ -13,11 +13,12 @@
#define perf_arch_bpf_user_pt_regs(regs) ®s->user_regs
#endif
+/* PSR_MODE_EL1t marks these regs for kunwind_stack_walk() */
#define perf_arch_fetch_caller_regs(regs, __ip) { \
(regs)->pc = (__ip); \
(regs)->regs[29] = (unsigned long) __builtin_frame_address(0); \
(regs)->sp = current_stack_pointer; \
- (regs)->pstate = PSR_MODE_EL1h; \
+ (regs)->pstate = PSR_MODE_EL1t; \
}
#endif
diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c
index 3ebcf8c..de394ff 100644
--- a/arch/arm64/kernel/stacktrace.c
+++ b/arch/arm64/kernel/stacktrace.c
@@ -357,6 +357,13 @@ kunwind_stack_walk(kunwind_consume_fn consume_state,
if (task != current)
return -EINVAL;
kunwind_init_from_regs(&state, regs);
+ /*
+ * With perf_arch_fetch_caller_regs() the PC is a copy of the
+ * LR in the frame record at FP. Start from that record.
+ */
+ if (processor_mode(regs) == PSR_MODE_EL1t &&
+ kunwind_next(&state))
+ return -EINVAL;
} else if (task == current) {
kunwind_init_from_caller(&state);
} else {
^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-11-19 1:38 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 0:01 [PATCH bpf-next v2 0/3] Fix duplicate caller frame in arm64 stack traces Andrii Nakryiko
2026-11-19 0:01 ` [PATCH bpf-next v2 1/3] arm64: perf: Don't report the caller twice in caller-regs callchains Andrii Nakryiko
2026-11-19 0:22 ` sashiko-bot
2026-11-19 1:38 ` Alexei Starovoitov
2026-11-19 0:01 ` [PATCH bpf-next v2 2/3] selftests/bpf: Add stacktrace_ips test for tracepoint Andrii Nakryiko
2026-11-19 0:07 ` sashiko-bot
2026-11-19 0:01 ` [PATCH bpf-next v2 3/3] selftests/bpf: Run stacktrace_ips raw_tp, tp and fentry tests on arm64 Andrii Nakryiko
2026-11-19 0:05 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox