Re: [RFC PATCH v1 07/11] arm64/unwind: Add Minimal DWARF CFI kernel unwinder
From: bot+bpf-ci
Date: Sun Nov 22 2026 - 19:57:01 EST
> arm64/unwind: Add Minimal DWARF CFI kernel unwinder
TL;DR:
- DWARF CFI unwinder may WARN or truncate traces when IRQ hits the
ftrace_caller epilogue under function_graph
- CFI lookups called from noinstr walks are kprobe-able
- Build may fail without PERF_EVENTS; unconditional notrace/KCOV exclusion
> diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
> --- a/arch/arm64/kernel/Makefile
> +++ b/arch/arm64/kernel/Makefile
> @@ -8,6 +8,7 @@ CFLAGS_armv8_deprecated.o := -I$(src)
> CFLAGS_REMOVE_ftrace.o = $(CC_FLAGS_FTRACE)
> CFLAGS_REMOVE_insn.o = $(CC_FLAGS_FTRACE)
> CFLAGS_REMOVE_return_address.o = $(CC_FLAGS_FTRACE)
> +CFLAGS_REMOVE_stacktrace.o = $(CC_FLAGS_FTRACE)
[ ... ]
> @@ -24,6 +25,7 @@ KASAN_SANITIZE_stacktrace.o := n
> KCOV_INSTRUMENT_entry-common.o := n
> KCOV_INSTRUMENT_idle.o := n
> +KCOV_INSTRUMENT_stacktrace.o := n
Both of these are unconditional, so they also apply to the default
CONFIG_UNWINDER_FRAME_POINTER build, where the unwinder is unchanged.
Do dump_backtrace(), show_stack(), arch_stack_walk_user() and the other
non-noinstr functions in stacktrace.c now lose function tracer, fentry/fexit
BPF attachment and KCOV coverage for frame pointer kernels? The commit
message does not mention this.
The noinstr walkers were already excluded, and the only new function that
plausibly needs notrace is arm64_unwind_perf_caller_regs(), which exists
only with CONFIG_UNWINDER_DWARF_CFI. Could these switches be made
conditional on CONFIG_UNWINDER_DWARF_CFI, or could that one function be
marked notrace instead?
> diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c
> --- a/arch/arm64/kernel/stacktrace.c
> +++ b/arch/arm64/kernel/stacktrace.c
[ ... ]
> + * Uses rcu_read_lock_sched_notrace() and rcu_dereference_raw() so lookups are
> + * safe inside noinstr stack walks and NMI contexts.
[ ... ]
> +static __always_inline int
> +arm64_dwarf_cfi_find(unsigned long pc, struct dwarf_cfi_row *row)
> +{
> + size_t hdr_size = __stop_eh_frame_hdr - __start_eh_frame_hdr;
> + int err;
> +
> + err = dwarf_cfi_unwind_eh_frame_hdr(__start_eh_frame_hdr, hdr_size,
> + __start_eh_frame, __stop_eh_frame,
> + pc, &arm64_cfi_arch, row);
> + if (!err)
> + return 0;
> +
> + return arm64_dwarf_cfi_module_find(pc, row);
> +}
arch_stack_walk(), arch_stack_walk_reliable() and arch_bpf_stack_walk() are
noinline noinstr, with every helper __always_inline, so that the walk cannot
be kprobed (see commit 0fbcd8abf337, "arm64: Prohibit instrumentation on
arch_stack_walk()"). Lockdep and irq tracing reach the walk through
return_address(), e.g. trace_hardirqs_off_finish() in arm64_enter_el1_dbg().
Doesn't this inlined helper make ordinary out-of-line calls into .text for
every frame?
dwarf_cfi_unwind_eh_frame_hdr() (kernel/unwind/dwarf_cfi.c, no
NOKPROBE_SYMBOL)
__module_address() (kernel/module/main.c, for PCs outside
vmlinux)
dwarf_cfi_mod_eval() (dwarf_cfi.c, for module PCs)
None of these are in __noinstr_text or __kprobes_text, so the kprobe
blacklist does not cover them. A probe on dwarf_cfi_unwind_eh_frame_hdr()
can then be hit from inside the debug exception stack walk, which is the
path the noinstr marking was meant to close. I could not show a nested
KPROBE_REENTER BUG in this tree because reenter_kprobe() now recovers from
KPROBE_HIT_SS reentry (23f851ac0078), but such probes would still be
reentered and counted as missed.
Is the kernel-doc claim that these lookups are "safe inside noinstr stack
walks and NMI contexts" accurate as written? Should the interpreter and
module lookup entry points be noinstr or NOKPROBE_SYMBOL(), or the comment
be corrected?
[ ... ]
> +void arm64_unwind_perf_caller_regs(struct pt_regs *regs, unsigned long pc,
> + unsigned long caller_ip, unsigned long sp,
> + unsigned long fp)
arm64_unwind_perf_caller_regs() is a global function whose only prototype is
in arch/arm64/include/asm/perf_event.h. stacktrace.c only gets that header
through <linux/perf_event.h>, which includes <asm/perf_event.h> under
CONFIG_PERF_EVENTS. CONFIG_PERF_EVENTS is user selectable on arm64 and
UNWINDER_DWARF_CFI does not depend on it.
With CONFIG_PERF_EVENTS=n and CONFIG_UNWINDER_DWARF_CFI=y, doesn't this
definition get compiled with no previous prototype, so that
-Wmissing-prototypes (always enabled by scripts/Makefile.warn) fails the
build under CONFIG_WERROR=y? The function and its EXPORT_SYMBOL_GPL() are
also dead code in that configuration, since perf_fetch_caller_regs() has no
callers without perf.
Should the definition and export be under CONFIG_PERF_EVENTS, or the
prototype moved to a header that is always included?
[ ... ]
> @@ -159,6 +414,22 @@ kunwind_recover_return_address(struct kunwind_state *state)
[ ... ]
> +#ifdef CONFIG_FUNCTION_GRAPH_TRACER
> + if (state->task->ret_stack &&
> + (state->common.pc == (unsigned long)return_to_handler)) {
> + unsigned long orig_pc;
> +
> + orig_pc = ftrace_graph_ret_addr(state->task, &state->graph_idx,
> + state->common.pc, frame_key);
> + if (state->common.pc == orig_pc) {
> + WARN_ON_ONCE(state->task == current);
> + return -EINVAL;
> + }
> + state->common.pc = orig_pc;
> + state->flags.fgraph = 1;
> + }
> +#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
Under CONFIG_UNWINDER_DWARF_CFI, frame_key is state->sp, which matches the
retp recorded by ftrace_graph_func() only if the previous step computed a
CFA. The link register fallback in kunwind_next_cfi() does not compute one:
if (state->lr_valid && !is_bpf_text_address(lookup_pc)) {
state->common.pc = state->lr;
state->lr_valid = false;
state->source = KUNWIND_SOURCE_FRAME;
state->unreliable = true;
return 0;
}
state->sp is left at the interrupted SP, and kunwind_init_from_regs() and
kunwind_next_regs_pc() now set lr_valid = !!regs->regs[30]. The
ftrace_caller epilogue can reach this fallback:
ldr x29, [sp, #FREGS_FP] // x29 = callsite FP
ldr x30, [sp, #FREGS_LR] // x30 = return_to_handler if hooked
ldr x9, [sp, #FREGS_PC] // <- IRQ here
add sp, sp, #FREGS_SIZE + 32 // <- or here
ret x9
If an IRQ or pseudo-NMI lands on the ldr x9 or add sp instruction for a
function F hooked by ftrace_graph_func():
- regs->pc is in ftrace_caller, so arm64_dwarf_cfi_find() fails.
- x29 is already restored, so the old_fp == state->sp + sizeof(struct
__arch_ftrace_regs) check is false and the ftrace_caller special case is
skipped.
- The fallback sets pc = regs->regs[30] = return_to_handler, and state->sp
stays at the interrupted SP, which is below F's CFA.
- kunwind_next()->kunwind_recover_return_address() then finds no ret_stack
entry whose retp equals that SP, so ftrace_graph_ret_addr() returns
return_to_handler unchanged.
At that point state->common.pc == orig_pc, so WARN_ON_ONCE(state->task ==
current) fires and the walk returns -EINVAL, cutting the trace off. Current
task walks that can reach this include perf_callchain_kernel(),
show_regs()->dump_backtrace(regs), and any stack_trace_save() from IRQ
context (lockdep, KASAN, kmemleak, page_owner). With function_graph tracing
and perf -g sampling the two instruction window can be hit regularly, and
with panic_on_warn it panics.
The frame pointer unwinder follows regs->regs[29] here and does not hit
this. Can the ftrace_caller epilogue be recognised without relying on x29
(fregs->sp == state->sp + fsize is still valid until the add sp), or should
the walk stop without a WARN when return_to_handler is recovered from an LR
fallback whose SP was never advanced to a CFA?
[ ... ]
> @@ -251,6 +531,212 @@ kunwind_next_frame_record(struct kunwind_state *state)
> * records (e.g. a cycle), determined based on the location and fp value of A
> * and the location (but not the fp value) of B.
> */
> +#ifdef CONFIG_UNWINDER_DWARF_CFI
> +/**
> + * kunwind_next_cfi() - Step one ARM64 kernel frame using Minimal DWARF CFI
Doesn't inserting kunwind_next_cfi() here leave the existing block comment
("Unwind from one frame record (A) to the next frame record (B). We
terminate early if ...") sitting above the new #ifdef and kernel-doc, about
200 lines away from kunwind_next(), which it was documenting?
The orphaned text describes frame record chaining, whereas
kunwind_next_cfi() steps by DWARF CFI and only uses frame records as a
fallback, so it is misleading for both functions. Could the
CONFIG_UNWINDER_DWARF_CFI block be placed before that comment, directly
after kunwind_next_frame_record()?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/45087188604