[PATCH bpf-next v2 1/3] arm64: perf: Don't report the caller twice in caller-regs callchains
Alexei Starovoitov
alexei.starovoitov at gmail.com
Wed Nov 18 17:38:22 PST 2026
On Wed, Nov 18, 2026 at 04:01 PM Andrii Nakryiko <andrii at 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 {
More information about the linux-arm-kernel
mailing list