Linux Perf Users
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>, linux-trace-kernel@vger.kernel.org
Cc: jpoimboe@kernel.org, rostedt@goodmis.org, peterz@infradead.org,
	mingo@redhat.com, tglx@kernel.org, bp@alien8.de,
	dave.hansen@linux.intel.com, x86@kernel.org,
	catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com,
	pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu,
	alex@ghiti.fr, acme@kernel.org, namhyung@kernel.org,
	linux-perf-users@vger.kernel.org, mhiramat@kernel.org,
	ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	bpf@vger.kernel.org, nathan@kernel.org, nsc@kernel.org,
	linux-kbuild@vger.kernel.org, ojeda@kernel.org, ardb@kernel.org,
	linux-efi@vger.kernel.org, "Marc Zyngier" <maz@kernel.org>,
	"Oliver Upton" <oupton@kernel.org>,
	kvmarm@lists.linux.dev, shuah@kernel.org, indu.bhagat@oracle.com,
	jremus@linux.ibm.com, wnliu@google.com, dylanbhatch@google.com,
	gary@garyguo.net
Subject: Re: [RFC PATCH v1 07/11] arm64/unwind: Add Minimal DWARF CFI kernel unwinder
Date: Mon, 23 Nov 2026 00:24:31 +0000	[thread overview]
Message-ID: <sashiko-outbox-228470@kernel.org> (raw)
In-Reply-To: <20261122235757.3456048-8-irogers@google.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] arm64: perf: eager CFI walk and off-by-4 PC in
  perf_arch_fetch_caller_regs()
- [Medium] arm64: vdso: -fomit-frame-pointer breaks vDSO unwinding with
  DWARF CFI
- [Low] arm64: Kconfig disables LATENCYTOP and fault-injection filter
  with DWARF CFI
- [Low] arm64: stacktrace: unused frame_key in
  kunwind_recover_return_address()
--

commit 2d8be9c8d60de13378d6fcee8e46e78f6a7a8167
Author: Ian Rogers <irogers@google.com>

arm64/unwind: Add Minimal DWARF CFI kernel unwinder

This commit adds CONFIG_UNWINDER_DWARF_CFI as a kernel unwinder choice
alongside CONFIG_UNWINDER_FRAME_POINTER on arm64, building the kernel
with -fomit-frame-pointer and unwinding kernel frames via Minimal DWARF
CFI tables.

> diff --git a/arch/arm64/Kconfig.debug b/arch/arm64/Kconfig.debug
> index 265c4461031f4..4f5c99a2fa967 100644
> --- a/arch/arm64/Kconfig.debug
> +++ b/arch/arm64/Kconfig.debug
> @@ -1,5 +1,37 @@
>  # SPDX-License-Identifier: GPL-2.0-only
>  
> +choice
> +	prompt "Choose kernel unwinder"
> +	default UNWINDER_FRAME_POINTER
> +	help
> +	  This determines which method will be used for unwinding kernel stack
> +	  traces for panics, oopses, bugs, warnings, perf, /proc/<pid>/stack,
> +	  livepatch, lockdep, and more.  If unsure, keep the default frame
> +	  pointer unwinder.
> +
> +config UNWINDER_FRAME_POINTER
> +	bool "Frame pointer unwinder"
> +	select ARCH_WANT_FRAME_POINTERS
> +	select FRAME_POINTER
> +	help
> +	  This option enables the standard frame pointer (x29) unwinder for
> +	  unwinding kernel stack traces on arm64.  Kernel code is compiled
> +	  with frame records stored on the stack at a small runtime register
> +	  and code-size cost.
> +
> +config UNWINDER_DWARF_CFI
> +	bool "Minimal DWARF CFI unwinder"
> +	depends on (!FUNCTION_TRACER || DYNAMIC_FTRACE_WITH_ARGS) && (!SHADOW_CALL_STACK || DYNAMIC_SCS)
> +	select UNWIND_DWARF_CFI
> +	select UNWIND_TABLES

[Severity: Low]
Moving select FRAME_POINTER out of config ARM64 and under
CONFIG_UNWINDER_FRAME_POINTER leaves CONFIG_FRAME_POINTER disabled when
CONFIG_UNWINDER_DWARF_CFI=y.  Because LATENCYTOP and
FAULT_INJECTION_STACKTRACE_FILTER in lib/Kconfig.debug still depend on:

	depends on FRAME_POINTER || MIPS || PPC || S390 || MICROBLAZE || ARM || ARC || X86

should ARM64 (or UNWINDER_DWARF_CFI) be added to those dependency lists
so both features remain selectable with the DWARF CFI unwinder?

> diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
> index ed28f94be428e..7ec8e96b20329 100644
> --- a/arch/arm64/Makefile
> +++ b/arch/arm64/Makefile
> @@ -23,6 +23,11 @@ ifeq ($(CONFIG_ARM64_ERRATUM_843419),y)
>  LDFLAGS_vmlinux	+= --fix-cortex-a53-843419
>  endif
>  
> +ifeq ($(CONFIG_UNWINDER_DWARF_CFI),y)
> +KBUILD_CFLAGS	+= -fomit-frame-pointer
> +LDFLAGS_vmlinux	+= --eh-frame-hdr
> +endif

[Severity: Medium]
Does adding -fomit-frame-pointer globally to KBUILD_CFLAGS break user
stack unwinding through the arm64 vDSO?

Unlike arch/arm64/kvm/hyp/nvhe/Makefile, arch/arm64/kernel/vdso/Makefile
does not filter out -fomit-frame-pointer or pass -fno-omit-frame-pointer,
and arch/arm64/kernel/vdso/vdso.lds.S discards *(.eh_frame .eh_frame_hdr).
Non-leaf vDSO C functions (such as __kernel_getrandom and
clock_gettime_fallback) are therefore built without frame records and
linked without .eh_frame tables, breaking both arch_stack_walk_user() and
user-space frame-pointer unwinders when a thread is inside the vDSO.

> diff --git a/arch/arm64/include/asm/perf_event.h b/arch/arm64/include/asm/perf_event.h
> index ee45b4e773470..4a7dbb7ce41c9 100644
> --- a/arch/arm64/include/asm/perf_event.h
> +++ b/arch/arm64/include/asm/perf_event.h
> @@ -13,11 +13,26 @@
>  #define perf_arch_bpf_user_pt_regs(regs) &regs->user_regs
>  #endif
>  
> +#ifdef CONFIG_UNWINDER_DWARF_CFI
> +void arm64_unwind_perf_caller_regs(struct pt_regs *regs, unsigned long pc,
> +				   unsigned long caller_ip, unsigned long sp,
> +				   unsigned long fp);
> +
> +#define perf_arch_fetch_caller_regs(regs, __ip) do {			\
> +	unsigned long __here_pc, __here_fp;				\
> +	asm volatile("1: adr %0, 1b\n\t"				\
> +		     "mov %1, x29"					\
> +		     : "=r" (__here_pc), "=r" (__here_fp));		\
> +	arm64_unwind_perf_caller_regs((regs), __here_pc, (__ip),	\
> +				      current_stack_pointer, __here_fp);\
> +} while (0)

[Severity: High]
Does perf_arch_fetch_caller_regs() need to perform a full DWARF CFI
lookup and bytecode evaluation eagerly on every call, and does storing
__ip in regs->pc cause kunwind_next_cfi() to look up the caller FDE at
an off-by-4 address?

perf_fetch_caller_regs() runs unconditionally on every tracepoint hit in
do_perf_trace_##call() and on every context switch with active software
events in __perf_sw_event_sched(), even when no callchain is requested.
Replacing the four inline register stores with
arm64_unwind_perf_caller_regs() constructs stack_info descriptors, binary
searches .eh_frame_hdr (and module FDE tables), and evaluates DWARF CFI
bytecode on every event.

In addition, perf_fetch_caller_regs() passes CALLER_ADDR0 (call_insn + 4)
as __ip.  arm64_unwind_perf_caller_regs() steps regs->sp and
regs->regs[29] to the caller frame and sets regs->pc = caller_ip, but
when perf_callchain_kernel() later unwinds those regs,
kunwind_init_from_regs() sets state->source = KUNWIND_SOURCE_REGS_PC.
kunwind_next_cfi() then skips the - 4 adjustment:

	lookup_pc = (state->source == KUNWIND_SOURCE_REGS_PC) ?
		    state->common.pc : state->common.pc - 4;

and evaluates the caller's CFI at call_insn + 4 instead of call_insn,
which can mis-unwind if call_insn sits immediately before an epilogue or
FDE boundary.

> diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c
> index 3ebcf8c53fb04..9ce0e3f6cabe6 100644
> --- a/arch/arm64/kernel/stacktrace.c
> +++ b/arch/arm64/kernel/stacktrace.c

[ ... ]

> @@ -124,19 +363,35 @@ kunwind_init_from_task(struct kunwind_state *state,
>  
>  	state->common.fp = thread_saved_fp(task);
>  	state->common.pc = thread_saved_pc(task);
> +	state->sp = thread_saved_sp(task);
>  	state->source = KUNWIND_SOURCE_TASK;
>  }
>  
> +/**
> + * kunwind_recover_return_address() - Restore fgraph/kretprobe return addresses
> + * @state: Current ARM64 kernel unwind state.
> + *
> + * Replaces return_to_handler and __kretprobe_trampoline return addresses with
> + * the original caller PC from @state->task's shadow stacks in either hooking
> + * order. Under CONFIG_UNWINDER_DWARF_CFI (-fomit-frame-pointer), entries are
> + * keyed on the frame's entry SP (@state->sp, equal to the callee's CFA) rather
> + * than x29.
> + *
> + * Return: 0 on success, or -EINVAL if a shadow return address cannot be found.
> + */
>  static __always_inline int
>  kunwind_recover_return_address(struct kunwind_state *state)
>  {
> +	void *frame_key = IS_ENABLED(CONFIG_UNWINDER_DWARF_CFI) ?
> +			  (void *)state->sp : (void *)state->common.fp;

[Severity: Low]
When both CONFIG_FUNCTION_GRAPH_TRACER and CONFIG_KRETPROBES are
disabled, frame_key is unused in kunwind_recover_return_address(),
triggering a -Wunused-variable warning.  Should frame_key be marked
__maybe_unused?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261122235757.3456048-1-irogers@google.com?part=7

  reply	other threads:[~2026-11-23  0:24 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22 23:57 [RFC PATCH v1 00/11] unwind: Minimal DWARF CFI stack unwinding for x86, arm64, and riscv Ian Rogers
2026-11-22 23:57 ` [RFC PATCH v1 01/11] unwind: Add Minimal DWARF CFI bytecode interpreter and KUnit tests Ian Rogers
2026-11-23  0:11   ` sashiko-bot
2026-11-23  0:40   ` bot+bpf-ci
2026-11-22 23:57 ` [RFC PATCH v1 02/11] unwind_user: Support Minimal DWARF CFI user-space unwinding Ian Rogers
2026-11-23  0:11   ` sashiko-bot
2026-11-23  0:39   ` bot+bpf-ci
2026-11-22 23:57 ` [RFC PATCH v1 03/11] scripts, unwind: Add build-time .eh_frame minifier Ian Rogers
2026-11-23  0:40   ` bot+bpf-ci
2026-11-22 23:57 ` [RFC PATCH v1 04/11] objtool/ibt: Ignore .eh_frame relocations during ENDBR validation Ian Rogers
2026-11-22 23:57 ` [RFC PATCH v1 05/11] x86/unwind: Add Minimal DWARF CFI kernel unwinder Ian Rogers
2026-11-23  0:56   ` bot+bpf-ci
2026-11-22 23:57 ` [RFC PATCH v1 06/11] arm64: unwind_user: Support Minimal DWARF CFI and FP user unwinding Ian Rogers
2026-11-23  0:16   ` sashiko-bot
2026-11-22 23:57 ` [RFC PATCH v1 07/11] arm64/unwind: Add Minimal DWARF CFI kernel unwinder Ian Rogers
2026-11-23  0:24   ` sashiko-bot [this message]
2026-11-23  0:56   ` bot+bpf-ci
2026-11-22 23:57 ` [RFC PATCH v1 08/11] riscv: unwind_user: Support Minimal DWARF CFI and FP user unwinding Ian Rogers
2026-11-23  0:39   ` bot+bpf-ci
2026-11-22 23:57 ` [RFC PATCH v1 09/11] riscv/unwind: Add Minimal DWARF CFI kernel unwinder Ian Rogers
2026-11-23  0:24   ` sashiko-bot
2026-11-23  0:56   ` bot+bpf-ci
2026-11-22 23:57 ` [RFC PATCH v1 10/11] selftests/perf_events: Add Minimal DWARF CFI deferred user unwind test Ian Rogers
2026-11-23  0:40   ` bot+bpf-ci
2026-11-22 23:57 ` [RFC PATCH v1 11/11] scripts: Add eh_frame_min.py .eh_frame coverage and size analyzer Ian Rogers
2026-11-23  0:39   ` bot+bpf-ci
2026-11-23  0:24 ` [RFC PATCH v1 00/11] unwind: Minimal DWARF CFI stack unwinding for x86, arm64, and riscv 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=sashiko-outbox-228470@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=acme@kernel.org \
    --cc=alex@ghiti.fr \
    --cc=andrii@kernel.org \
    --cc=aou@eecs.berkeley.edu \
    --cc=ardb@kernel.org \
    --cc=ast@kernel.org \
    --cc=bp@alien8.de \
    --cc=bpf@vger.kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=daniel@iogearbox.net \
    --cc=dave.hansen@linux.intel.com \
    --cc=dylanbhatch@google.com \
    --cc=gary@garyguo.net \
    --cc=indu.bhagat@oracle.com \
    --cc=irogers@google.com \
    --cc=jpoimboe@kernel.org \
    --cc=jremus@linux.ibm.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=nathan@kernel.org \
    --cc=nsc@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=oupton@kernel.org \
    --cc=palmer@dabbelt.com \
    --cc=peterz@infradead.org \
    --cc=pjw@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shuah@kernel.org \
    --cc=tglx@kernel.org \
    --cc=will@kernel.org \
    --cc=wnliu@google.com \
    --cc=x86@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