[PATCH bpf-next v3 1/3] arm64: perf: Don't report the caller twice in caller-regs callchains

Leo Yan leo.yan at arm.com
Thu Dec 3 06:13:43 PST 2026


On Tue, Dec 01, 2026 at 03:02:45PM -0800, Andrii Nakryiko wrote:
> 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.

> Mark these regs on arm64 by setting pstate to PSR_MODE_EL1t, which
> exceptions taken from the kernel never have (the kernel runs in EL1h,
> or EL2h with VHE). For regs with that mode, kunwind_stack_walk() steps
> to the frame record at x29 before reporting anything, so the unwind
> starts from the LR saved there and regs->pc is not reported.

I tested this patch and confirmed it fixes the issue.

...

> +/* 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;	\
>  }

It seems to me that the issue comes from a mismatch between the IP and
the frame pointer. Could we update the interface to pass them as a pair?

  perf_arch_fetch_caller_regs(regs, caller_ip, caller_fp)

I've read Will's comment on v1, so I'll wait to hear which approach he
prefers. If go with this version, please feel free to add my test tag:

Tested-by: Leo Yan <leo.yan at arm.com>

Thanks,
Leo



More information about the linux-arm-kernel mailing list