mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: bot+bpf-ci@kernel.org
To: irogers@google.com,linux-kernel@vger.kernel.org,linux-trace-kernel@vger.kernel.org,linux-arch@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,linux-arm-kernel@lists.infradead.org,pjw@kernel.org,palmer@dabbelt.com,aou@eecs.berkeley.edu,alex@ghiti.fr,linux-riscv@lists.infradead.org,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,rust-for-linux@vger.kernel.org,ardb@kernel.org,linux-efi@vger.kernel.org,maz@kernel.org,oupton@kernel.org,kvmarm@lists.linux.dev,shuah@kernel.org,linux-kselftest@vger.kernel.org,indu.bhagat@oracle.com,jremus@linux.ibm.com,wnliu@google.com,dylanbhatch@google.com,irogers@google.com,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mas
	on@kernel.org,ihor.solodrai@linux.dev
Subject: Re: [RFC PATCH v1 07/11] arm64/unwind: Add Minimal DWARF CFI kernel unwinder
Date: Mon, 23 Nov 2026 00:56:47 +0000 (UTC)	[thread overview]
Message-ID: <56e463aa6609799b8bd62ffd74e9791eb3f012b1e9f72a6460f7a978bf8b6162@mail.kernel.org> (raw)
In-Reply-To: <20261122235757.3456048-8-irogers@google.com>

[-- Attachment #1: Type: text/plain, Size: 8866 bytes --]

> 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

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

Thread overview: 21+ 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: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: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-22 23:57 ` [RFC PATCH v1 07/11] arm64/unwind: Add Minimal DWARF CFI kernel unwinder Ian Rogers
2026-11-23  0:56   ` bot+bpf-ci [this message]
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: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

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=56e463aa6609799b8bd62ffd74e9791eb3f012b1e9f72a6460f7a978bf8b6162@mail.kernel.org \
    --to=bot+bpf-ci@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=eddyz87@gmail.com \
    --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-arch@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=martin.lau@kernel.org \
    --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=rust-for-linux@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=tglx@kernel.org \
    --cc=will@kernel.org \
    --cc=wnliu@google.com \
    --cc=x86@kernel.org \
    --cc=yonghong.song@linux.dev \
    /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

all inboxes | Powered by JetHome®