From: Jens Remus <jremus@linux.ibm.com>
To: Ian Rogers <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,
llvm@lists.linux.dev, 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,
wnliu@google.com, dylanbhatch@google.com
Subject: Re: [RFC PATCH v2 12/30] x86/unwind: Add Minimal DWARF CFI kernel unwinder
Date: Fri, 27 Nov 2026 16:43:34 +0100 [thread overview]
Message-ID: <a07554af-f6df-4a7f-a656-d01b8bc6ab6a@linux.ibm.com> (raw)
In-Reply-To: <20261125061523.1540234-13-irogers@google.com>
Hello Ian,
some early feedback.
On 11/25/2026 7:15 AM, Ian Rogers wrote:
> Add CONFIG_UNWINDER_DWARF_CFI as a selectable x86-64 kernel stack
> unwinder in arch/x86/kernel/unwind_dwarf.c, implementing the asm/unwind.h
> and HAVE_RELIABLE_STACKTRACE interfaces over compiler-generated
> .eh_frame and linker-generated --eh-frame-hdr tables:
> - Build kernel C and Rust objects with asynchronous unwind tables and
> -fomit-frame-pointer while suppressing unwind tables in boot/startup
> and purgatory objects.
> - Place .eh_frame_hdr and .eh_frame inside RO_DATA via
> ARCH_RODATA_SECTIONS, index loadable module .eh_frame sections via
> dwarf_cfi_mod_alloc()/dwarf_cfi_mod_free_rcu(), and enable BPF
> exception stack walks in arch/x86/net/bpf_jit_comp.c.
> - Unwind across task, IRQ, exception, ftrace, fgraph, rethook, BPF, and
> call_on_stack() frames, while rejecting in-kernel pt_regs exception
> boundaries in arch_stack_walk_reliable().
>
> Signed-off-by: Ian Rogers <irogers@google.com>
> diff --git a/arch/x86/kernel/unwind_dwarf.c b/arch/x86/kernel/unwind_dwarf.c
> +/**
> + * unwind_next_frame() - Advance @state to the next outer x86-64 kernel frame
> + * @state: Current x86 unwind state.
> + *
> + * Evaluates Minimal DWARF CFI for @state->ip, handles top-of-stack task
> + * pt_regs, arch_rethook_trampoline entry, %rsp-verified ENCODE_FRAME_POINTER
> + * entry/exception pt_regs transitions, and call_on_stack() IRQ stack pivots.
> + *
> + * Return: true if a valid outer frame was unwound, or false when the bottom of
> + * the stack is reached or an error terminates the walk.
> + */
> +bool unwind_next_frame(struct unwind_state *state)
> +{
...
> + /*
> + * Unencoded entry assembly (pre-ENCODE_FRAME_POINTER or
> + * post-POP_REGS) or an unaligned/encoded %rbp cannot be
> + * unwound via a frame-pointer guess.
> + */
> + if (in_entry_text(state->ip) || (state->bp & (sizeof(long) - 1)))
> + goto err;
> +
> + /* Fallback to frame-pointer guess and mark unreliable */
> + row = bpf_fp_row;
> + state->error = true;
> + }
> +
Maybe add a comment that the UNDEFINED rule indicates that the outermost
frame has been reached?
/* RA undefined indicates outermost frame reached */
> + if (row.ra_rule == DWARF_CFI_RULE_UNDEFINED)
> + goto the_end;
> +
> + if (row.ra_rule != DWARF_CFI_RULE_OFFSET)
> + goto err;
Good: For RA rule only OFFSET is supported. SP and FP rules may need
checking (see below).
> +
> + switch (row.cfa_base) {
> + case DWARF_CFI_BASE_SP: {
> + unsigned long sp_base = state->sp;
> +
> + /*
> + * call_on_stack() stores the pre-switch task-stack %rsp at the
> + * top slot of the per-CPU IRQ stack (info.end - 1) and pivots
> + * %rsp there before invoking the IRQ/softirq handler.
> + */
> + if (state->stack_info.type == STACK_TYPE_IRQ &&
> + state->sp == (unsigned long)(state->stack_info.end - 1)) {
> + if (!deref_stack_reg(state, state->sp, &sp_base))
> + goto err;
> + }
> + cfa = sp_base + row.cfa_off;
> + break;
> + }
> + case DWARF_CFI_BASE_FP:
> + cfa = state->bp + row.cfa_off;
> + break;
> + case DWARF_CFI_BASE_FP_INDIRECT:
> + if (!deref_stack_reg(state, state->bp + row.cfa_off, &cfa))
> + goto err;
> + break;
> + case DWARF_CFI_BASE_REG:
> + if (!get_scratch_reg(state, row.cfa_reg, &cfa))
> + goto err;
> + cfa += row.cfa_off;
> + break;
> + default:
> + goto err;
> + }
> +
> + ip_p = cfa + row.ra_off;
> + if (!deref_stack_reg(state, ip_p, &state->ip))
> + goto err;
> +
> + state->ip = dwarf_recover_ret_addr(state, state->ip,
> + (unsigned long *)ip_p);
> + if (!state->ip || dwarf_is_rethook_trampoline(state->ip))
> + goto err;
> +#ifdef CONFIG_FUNCTION_GRAPH_TRACER
> + if (state->ip == (unsigned long)return_to_handler)
> + goto err;
> +#endif
> +
> + if (row.fp_rule == DWARF_CFI_RULE_OFFSET) {
> + if (!deref_stack_reg(state, cfa + row.fp_off, &state->bp))
> + goto err;
> + } else if (row.fp_rule == DWARF_CFI_RULE_FP_OFFSET) {
> + if (!deref_stack_reg(state, state->bp + row.fp_off, &state->bp))
> + goto err;
> + }
IIUC any other FP rule falls through and is implicitly handled as SAME.
Furthermore row.sp_rule is not checked anywhere, so that any SP rule is
explicitly handled as SP = CFA. The implementations for the other archs
are similar. Maybe I am missing something.
> +
> + state->sp = cfa;
> + state->regs = NULL;
> + state->prev_regs = NULL;
> + state->full_regs = false;
> + state->signal = row.signal;
> +
Regards,
Jens
--
Jens Remus
Linux on Z Development (D3303)
jremus@de.ibm.com / jremus@linux.ibm.com
IBM Deutschland Research & Development GmbH; Vorsitzender des Aufsichtsrats: Wolfgang Wendt; Geschäftsführung: David Faller; Sitz der Gesellschaft: Ehningen; Registergericht: Amtsgericht Stuttgart, HRB 243294
IBM Data Privacy Statement: https://www.ibm.com/privacy/
next prev parent reply other threads:[~2026-11-27 15:44 UTC|newest]
Thread overview: 61+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 6:14 [RFC PATCH v2 00/30] unwind: Minimal DWARF CFI unwinding for user and kernel space Ian Rogers
2026-11-25 6:14 ` [RFC PATCH v2 01/30] unwind: Add Minimal DWARF CFI bytecode interpreter Ian Rogers
2026-11-25 6:32 ` sashiko-bot
2026-11-25 7:05 ` bot+bpf-ci
2026-11-27 15:37 ` Jens Remus
2026-11-25 6:14 ` [RFC PATCH v2 02/30] unwind: Add KUnit tests for Minimal DWARF CFI interpreter Ian Rogers
2026-11-25 7:05 ` bot+bpf-ci
2026-11-25 6:14 ` [RFC PATCH v2 03/30] unwind_user: Support Minimal DWARF CFI user-space unwinding Ian Rogers
2026-11-25 7:05 ` bot+bpf-ci
2026-11-27 15:45 ` Jens Remus
2026-11-25 6:14 ` [RFC PATCH v2 04/30] x86: unwind_user: Support Minimal DWARF CFI user unwinding Ian Rogers
2026-11-25 6:47 ` bot+bpf-ci
2026-11-25 6:14 ` [RFC PATCH v2 05/30] scripts: Add min_eh_frame build-time .eh_frame minifier Ian Rogers
2026-11-25 7:06 ` bot+bpf-ci
2026-11-25 6:14 ` [RFC PATCH v2 06/30] kbuild: Wire up CONFIG_UNWINDER_DWARF_CFI_MINIFY object pass Ian Rogers
2026-11-25 6:32 ` sashiko-bot
2026-11-25 6:15 ` [RFC PATCH v2 07/30] objtool/ibt: Ignore .eh_frame relocations during ENDBR validation Ian Rogers
2026-11-25 6:15 ` [RFC PATCH v2 08/30] vmlinux.lds.h: Allow architectures to emit custom RO_DATA sections Ian Rogers
2026-11-25 6:15 ` [RFC PATCH v2 09/30] efi/libstub: Disable unwind tables in x86 and RISC-V EFI stubs Ian Rogers
2026-11-25 6:15 ` [RFC PATCH v2 10/30] tracing: Skip internal ftrace frames under CONFIG_UNWINDER_DWARF_CFI Ian Rogers
2026-11-25 6:15 ` [RFC PATCH v2 11/30] x86: Add DWARF CFI annotations to entry, ftrace, frame, and rethook Ian Rogers
2026-11-25 7:05 ` bot+bpf-ci
2026-11-25 6:15 ` [RFC PATCH v2 12/30] x86/unwind: Add Minimal DWARF CFI kernel unwinder Ian Rogers
2026-11-25 7:06 ` bot+bpf-ci
2026-11-27 15:43 ` Jens Remus [this message]
2026-11-25 6:15 ` [RFC PATCH v2 13/30] lib/Kconfig.debug: Allow LATENCYTOP and fault-injection filter with DWARF CFI Ian Rogers
2026-11-25 6:15 ` [RFC PATCH v2 14/30] arm64: unwind_user: Support Minimal DWARF CFI and FP user unwinding Ian Rogers
2026-11-25 6:15 ` [RFC PATCH v2 15/30] arm64: Add DWARF CFI annotations to entry, ftrace, EFI, BPF, and KASAN Ian Rogers
2026-11-25 7:06 ` bot+bpf-ci
2026-11-25 6:15 ` [RFC PATCH v2 16/30] arm64/unwind: Add Minimal DWARF CFI kernel unwinder Ian Rogers
2026-11-25 7:06 ` bot+bpf-ci
2026-11-25 6:15 ` [RFC PATCH v2 17/30] riscv: unwind_user: Support Minimal DWARF CFI and FP user unwinding Ian Rogers
2026-11-25 6:15 ` [RFC PATCH v2 18/30] riscv: Add DWARF CFI annotations to entry, ftrace, rethook, and BPF JIT Ian Rogers
2026-11-25 7:06 ` bot+bpf-ci
2026-11-25 6:15 ` [RFC PATCH v2 19/30] riscv/unwind: Add Minimal DWARF CFI kernel unwinder Ian Rogers
2026-11-25 6:47 ` sashiko-bot
2026-11-25 7:06 ` bot+bpf-ci
2026-11-25 6:15 ` [RFC PATCH v2 20/30] selftests/perf_events: Add Minimal DWARF CFI deferred user unwind test Ian Rogers
2026-11-25 7:05 ` bot+bpf-ci
2026-11-25 6:15 ` [RFC PATCH v2 21/30] scripts: Add eh_frame_min.py .eh_frame coverage and size analyzer Ian Rogers
2026-11-25 7:05 ` bot+bpf-ci
2026-11-25 6:15 ` [RFC PATCH v2 22/30] tools headers: Add linux/kmsan-checks.h copy from the kernel sources Ian Rogers
2026-11-25 6:15 ` [RFC PATCH v2 23/30] tools headers: Add linux/nospec.h " Ian Rogers
2026-11-25 6:15 ` [RFC PATCH v2 24/30] tools headers: Add linux/unwind_dwarf_cfi.h " Ian Rogers
2026-11-25 6:15 ` [RFC PATCH v2 25/30] tools include: Add linux/uaccess.h stub for userspace tools Ian Rogers
2026-11-25 6:15 ` [RFC PATCH v2 26/30] tools/unwind: Add standalone libLLVM Minimal DWARF CFI verifier Ian Rogers
2026-11-25 6:37 ` sashiko-bot
2026-11-25 7:06 ` bot+bpf-ci
2026-11-25 6:15 ` [RFC PATCH v2 27/30] tools/unwind: Add multi-arch symbolic instruction lifters for verify_cfi Ian Rogers
2026-11-25 6:38 ` sashiko-bot
2026-11-25 7:05 ` bot+bpf-ci
2026-11-25 6:15 ` [RFC PATCH v2 28/30] tools/unwind: Add CFG instruction abstract execution oracle to verify_cfi Ian Rogers
2026-11-25 7:06 ` bot+bpf-ci
2026-11-25 6:15 ` [RFC PATCH v2 29/30] tools/unwind: Add x86-64 ORC cross-check " Ian Rogers
2026-11-25 6:40 ` sashiko-bot
2026-11-25 6:15 ` [RFC PATCH v2 30/30] MAINTAINERS: Add DWARF CFI stack unwinding entry Ian Rogers
2026-11-25 6:48 ` [RFC PATCH v2 00/30] unwind: Minimal DWARF CFI unwinding for user and kernel space sashiko-bot
2026-11-25 16:28 ` Gary Guo
2026-11-25 18:22 ` Steven Rostedt
2026-11-26 4:52 ` Ian Rogers
2026-11-27 15:37 ` Steven Rostedt
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=a07554af-f6df-4a7f-a656-d01b8bc6ab6a@linux.ibm.com \
--to=jremus@linux.ibm.com \
--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=indu.bhagat@oracle.com \
--cc=irogers@google.com \
--cc=jpoimboe@kernel.org \
--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=llvm@lists.linux.dev \
--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=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 \
/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