[PATCH v5 0/8] unwind, arm64: add sframe unwinder for kernel

Dylan Hatch posted 8 patches 1 week, 3 days ago
MAINTAINERS                                   |   3 +-
Makefile                                      |   8 +
arch/Kconfig                                  |  27 +-
arch/arm64/Kconfig                            |   1 +
arch/arm64/include/asm/module.h               |   6 +
arch/arm64/include/asm/sections.h             |   1 +
arch/arm64/include/asm/stacktrace/common.h    |   6 +
arch/arm64/include/asm/unwind_sframe.h        |  55 +++
arch/arm64/kernel/entry.S                     |  23 +
arch/arm64/kernel/module.c                    |   8 +
arch/arm64/kernel/setup.c                     |   2 +
arch/arm64/kernel/stacktrace.c                | 246 ++++++++++-
arch/arm64/kernel/vdso/Makefile               |   2 +-
arch/arm64/kernel/vmlinux.lds.S               |   2 +
.../{unwind_user_sframe.h => unwind_sframe.h} |   6 +-
arch/x86/include/asm/unwind_user.h            |  12 +-
include/asm-generic/sections.h                |   4 +
include/asm-generic/vmlinux.lds.h             |  15 +
include/linux/sframe.h                        |  67 ++-
include/linux/unwind_types.h                  |  46 ++
include/linux/unwind_user_types.h             |  41 --
kernel/unwind/Makefile                        |   2 +-
kernel/unwind/sframe.c                        | 410 ++++++++++++++----
kernel/unwind/user.c                          |  41 +-
24 files changed, 827 insertions(+), 207 deletions(-)
create mode 100644 arch/arm64/include/asm/unwind_sframe.h
rename arch/x86/include/asm/{unwind_user_sframe.h => unwind_sframe.h} (50%)
create mode 100644 include/linux/unwind_types.h
[PATCH v5 0/8] unwind, arm64: add sframe unwinder for kernel
Posted by Dylan Hatch 1 week, 3 days ago
Implement a generic kernel sframe-based [1] unwinder. The main goal is
to improve reliable stacktrace on arm64 by unwinding across exception
boundaries.

On x86, the ORC unwinder provides reliable stacktrace through similar
methodology, but arm64 lacks the necessary support from objtool to
create ORC unwind tables.

Currently, there's already a sframe unwinder proposed for userspace: [2].
To maintain common definitions and algorithms for sframe lookup, a
substantial portion of this patch series aims to refactor the sframe
lookup code to support both kernel and userspace sframe sections.

Currently, only GNU Binutils support sframe. This series relies on the
Sframe V3 format, which is supported in binutils 2.46.

These patches are based on Steven Rostedt's sframe/core branch [3],
which is and aggregation of existing work done for x86 sframe userspace
unwind, and contains [2]. This branch is, in turn, based on Linux
v7.0-rc3. This full series (applied to the sframe/core branch) is
available on github: [4].

Ref:
[1]: https://sourceware.org/binutils/docs/sframe-spec.html
[2]: https://lore.kernel.org/lkml/20260127150554.2760964-1-jremus@linux.ibm.com/
[3]: https://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git/log/?h=sframe/core
[4]: https://github.com/dylanbhatch/linux/tree/sframe-v5

Changes since v4:
  - (Jens) Fix some minor nits.
  - Handle .init.text and .exit.text in function address validation.

Changes since v3:

  - (Jens) Clean up patch summaries.
  - (Jens) Rename SFRAME_LOOKUP -> UNWIND_SFRAME_LOOKUP to fit existing
    naming convention.
  - (Randy) Correct typo errors in new config options.
  - (Jens) Move unwind types to a new unwind_types.h to match their
    usage.
  - (Jens) Update KERNEL_[COPY|GET] to use label-based error handling
    like their userspace counterparts.
  - (Jens) Rename SFRAME_UNWINDER -> HAVE_UNWIND_KERNEL_SFRAME and
    ARCH_SUPPORTS_SFRAME_UNWINDER -> ARCH_SUPPORTS_UNWIND_KERNEL_SFRAME
    to match existing naming convention.
  - (Jens) Move HAVE_UNWIND_KERNEL_SFRAME config option to arch/Kconfig.
  - (Jens) Rename/move extern definitions of __[start|end]_sframe into
    include/asm-generic/sections.h.
  - (Jens) Fix up CFI annotations at kernel entry.
  - (Jens) Fix error path for unsorted FDE lookup.
  - (Jens) Zero-out module sframe_section before init.
  - (Jens) For SFRAME_VALIDATION, use an arch-specific function-address
    validation helper so that .rodata.text can be correctly handled on
    arm64 vmlinux.
  - (Jens) Fixup and better comment kernel stacktrace code.

Changes since v2:

The biggest change from v2 is the switch from adding a dedicated,
in-kernel sframe-lookup library, to refactoring/using the existing
library developed by Josh, Jens, and Steve. Consequently, this series
now depends on Sframe V3, though this upgrade would likely have been
necessary anyway. Below is a full accounting of the changes since v2.

  - (Josh) Add stricter reliability checks during unwind.
  - (Puranjay, Indu, Jens) Update to use a common sframe library with
    userpace unwind, thus resolving the need to support
    SFRAME_F_FDE_FUNC_START_PCREL, added in binutils 2.45.
  - (Jens) Add check for sframe V3, thus resolving the prior need for V2
    and SFRAME_F_FDE_FUNC_START_PCREL support.
  - (Will) Add ARCH_SUPPORTS_SFRAME_UNWINDER, remove SFRAME_UNWIND_TABLE
  - (Indu) add support for unsorted FDE tables, allowing for module
    sframe lookups.
  - (Mark) Prefer frame-pointer unwind when possible, for better
    performance.
  - Simplify compile-time logic, adding stubbs when necessary.
  - Add support for in-kernel SFRAME_VALIDATION.
  - Rebase onto core/sframe (with v7.0-rc3 base)

Dylan Hatch (7):
  sframe: Allow kernelspace sframe sections
  arm64, unwind: build kernel with sframe V3 info
  sframe: Provide PC lookup for vmlinux .sframe section
  sframe: Allow unsorted FDEs
  arm64/module, sframe: Add sframe support for modules
  sframe: Introduce in-kernel SFRAME_VALIDATION
  unwind: arm64: Use sframe to unwind interrupt frames

Weinan Liu (1):
  arm64: entry: add unwind info for various kernel entries

 MAINTAINERS                                   |   3 +-
 Makefile                                      |   8 +
 arch/Kconfig                                  |  27 +-
 arch/arm64/Kconfig                            |   1 +
 arch/arm64/include/asm/module.h               |   6 +
 arch/arm64/include/asm/sections.h             |   1 +
 arch/arm64/include/asm/stacktrace/common.h    |   6 +
 arch/arm64/include/asm/unwind_sframe.h        |  55 +++
 arch/arm64/kernel/entry.S                     |  23 +
 arch/arm64/kernel/module.c                    |   8 +
 arch/arm64/kernel/setup.c                     |   2 +
 arch/arm64/kernel/stacktrace.c                | 246 ++++++++++-
 arch/arm64/kernel/vdso/Makefile               |   2 +-
 arch/arm64/kernel/vmlinux.lds.S               |   2 +
 .../{unwind_user_sframe.h => unwind_sframe.h} |   6 +-
 arch/x86/include/asm/unwind_user.h            |  12 +-
 include/asm-generic/sections.h                |   4 +
 include/asm-generic/vmlinux.lds.h             |  15 +
 include/linux/sframe.h                        |  67 ++-
 include/linux/unwind_types.h                  |  46 ++
 include/linux/unwind_user_types.h             |  41 --
 kernel/unwind/Makefile                        |   2 +-
 kernel/unwind/sframe.c                        | 410 ++++++++++++++----
 kernel/unwind/user.c                          |  41 +-
 24 files changed, 827 insertions(+), 207 deletions(-)
 create mode 100644 arch/arm64/include/asm/unwind_sframe.h
 rename arch/x86/include/asm/{unwind_user_sframe.h => unwind_sframe.h} (50%)
 create mode 100644 include/linux/unwind_types.h

-- 
2.54.0.545.g6539524ca2-goog
Re: [PATCH v5 0/8] unwind, arm64: add sframe unwinder for kernel
Posted by Mark Rutland 1 week, 2 days ago
Hi Dylan,

On Tue, Apr 28, 2026 at 06:36:35PM +0000, Dylan Hatch wrote:
> Implement a generic kernel sframe-based [1] unwinder. The main goal is
> to improve reliable stacktrace on arm64 by unwinding across exception
> boundaries.

Thanks for this!

Just as a holding reply: I'm going over the series now, and I have some
partially-written comments that I'll try to finish up and get out
tomorrow.

Mark.

> On x86, the ORC unwinder provides reliable stacktrace through similar
> methodology, but arm64 lacks the necessary support from objtool to
> create ORC unwind tables.
> 
> Currently, there's already a sframe unwinder proposed for userspace: [2].
> To maintain common definitions and algorithms for sframe lookup, a
> substantial portion of this patch series aims to refactor the sframe
> lookup code to support both kernel and userspace sframe sections.
> 
> Currently, only GNU Binutils support sframe. This series relies on the
> Sframe V3 format, which is supported in binutils 2.46.
> 
> These patches are based on Steven Rostedt's sframe/core branch [3],
> which is and aggregation of existing work done for x86 sframe userspace
> unwind, and contains [2]. This branch is, in turn, based on Linux
> v7.0-rc3. This full series (applied to the sframe/core branch) is
> available on github: [4].
> 
> Ref:
> [1]: https://sourceware.org/binutils/docs/sframe-spec.html
> [2]: https://lore.kernel.org/lkml/20260127150554.2760964-1-jremus@linux.ibm.com/
> [3]: https://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git/log/?h=sframe/core
> [4]: https://github.com/dylanbhatch/linux/tree/sframe-v5
> 
> Changes since v4:
>   - (Jens) Fix some minor nits.
>   - Handle .init.text and .exit.text in function address validation.
> 
> Changes since v3:
> 
>   - (Jens) Clean up patch summaries.
>   - (Jens) Rename SFRAME_LOOKUP -> UNWIND_SFRAME_LOOKUP to fit existing
>     naming convention.
>   - (Randy) Correct typo errors in new config options.
>   - (Jens) Move unwind types to a new unwind_types.h to match their
>     usage.
>   - (Jens) Update KERNEL_[COPY|GET] to use label-based error handling
>     like their userspace counterparts.
>   - (Jens) Rename SFRAME_UNWINDER -> HAVE_UNWIND_KERNEL_SFRAME and
>     ARCH_SUPPORTS_SFRAME_UNWINDER -> ARCH_SUPPORTS_UNWIND_KERNEL_SFRAME
>     to match existing naming convention.
>   - (Jens) Move HAVE_UNWIND_KERNEL_SFRAME config option to arch/Kconfig.
>   - (Jens) Rename/move extern definitions of __[start|end]_sframe into
>     include/asm-generic/sections.h.
>   - (Jens) Fix up CFI annotations at kernel entry.
>   - (Jens) Fix error path for unsorted FDE lookup.
>   - (Jens) Zero-out module sframe_section before init.
>   - (Jens) For SFRAME_VALIDATION, use an arch-specific function-address
>     validation helper so that .rodata.text can be correctly handled on
>     arm64 vmlinux.
>   - (Jens) Fixup and better comment kernel stacktrace code.
> 
> Changes since v2:
> 
> The biggest change from v2 is the switch from adding a dedicated,
> in-kernel sframe-lookup library, to refactoring/using the existing
> library developed by Josh, Jens, and Steve. Consequently, this series
> now depends on Sframe V3, though this upgrade would likely have been
> necessary anyway. Below is a full accounting of the changes since v2.
> 
>   - (Josh) Add stricter reliability checks during unwind.
>   - (Puranjay, Indu, Jens) Update to use a common sframe library with
>     userpace unwind, thus resolving the need to support
>     SFRAME_F_FDE_FUNC_START_PCREL, added in binutils 2.45.
>   - (Jens) Add check for sframe V3, thus resolving the prior need for V2
>     and SFRAME_F_FDE_FUNC_START_PCREL support.
>   - (Will) Add ARCH_SUPPORTS_SFRAME_UNWINDER, remove SFRAME_UNWIND_TABLE
>   - (Indu) add support for unsorted FDE tables, allowing for module
>     sframe lookups.
>   - (Mark) Prefer frame-pointer unwind when possible, for better
>     performance.
>   - Simplify compile-time logic, adding stubbs when necessary.
>   - Add support for in-kernel SFRAME_VALIDATION.
>   - Rebase onto core/sframe (with v7.0-rc3 base)
> 
> Dylan Hatch (7):
>   sframe: Allow kernelspace sframe sections
>   arm64, unwind: build kernel with sframe V3 info
>   sframe: Provide PC lookup for vmlinux .sframe section
>   sframe: Allow unsorted FDEs
>   arm64/module, sframe: Add sframe support for modules
>   sframe: Introduce in-kernel SFRAME_VALIDATION
>   unwind: arm64: Use sframe to unwind interrupt frames
> 
> Weinan Liu (1):
>   arm64: entry: add unwind info for various kernel entries
> 
>  MAINTAINERS                                   |   3 +-
>  Makefile                                      |   8 +
>  arch/Kconfig                                  |  27 +-
>  arch/arm64/Kconfig                            |   1 +
>  arch/arm64/include/asm/module.h               |   6 +
>  arch/arm64/include/asm/sections.h             |   1 +
>  arch/arm64/include/asm/stacktrace/common.h    |   6 +
>  arch/arm64/include/asm/unwind_sframe.h        |  55 +++
>  arch/arm64/kernel/entry.S                     |  23 +
>  arch/arm64/kernel/module.c                    |   8 +
>  arch/arm64/kernel/setup.c                     |   2 +
>  arch/arm64/kernel/stacktrace.c                | 246 ++++++++++-
>  arch/arm64/kernel/vdso/Makefile               |   2 +-
>  arch/arm64/kernel/vmlinux.lds.S               |   2 +
>  .../{unwind_user_sframe.h => unwind_sframe.h} |   6 +-
>  arch/x86/include/asm/unwind_user.h            |  12 +-
>  include/asm-generic/sections.h                |   4 +
>  include/asm-generic/vmlinux.lds.h             |  15 +
>  include/linux/sframe.h                        |  67 ++-
>  include/linux/unwind_types.h                  |  46 ++
>  include/linux/unwind_user_types.h             |  41 --
>  kernel/unwind/Makefile                        |   2 +-
>  kernel/unwind/sframe.c                        | 410 ++++++++++++++----
>  kernel/unwind/user.c                          |  41 +-
>  24 files changed, 827 insertions(+), 207 deletions(-)
>  create mode 100644 arch/arm64/include/asm/unwind_sframe.h
>  rename arch/x86/include/asm/{unwind_user_sframe.h => unwind_sframe.h} (50%)
>  create mode 100644 include/linux/unwind_types.h
> 
> -- 
> 2.54.0.545.g6539524ca2-goog
>
Re: [PATCH v5 0/8] unwind, arm64: add sframe unwinder for kernel
Posted by Jens Remus 1 week, 1 day ago
On 4/28/2026 8:36 PM, Dylan Hatch wrote:
> Implement a generic kernel sframe-based [1] unwinder. The main goal is
> to improve reliable stacktrace on arm64 by unwinding across exception
> boundaries.

Please add support to initialize the optional sframe unwinder debug
information.  Either in the appropriate patches in this series or as a
separate patch.

Note that for the module case I wonder whether it would be preferable
to somehow indicate that it is a module name in the string, e.g.
"(<module-name>)" or "<module-name> (module)"?

diff --git a/kernel/unwind/sframe.c b/kernel/unwind/sframe.c
--- a/kernel/unwind/sframe.c
+++ b/kernel/unwind/sframe.c
@@ -1028,6 +1028,8 @@ void __init init_sframe_table(void)
 	kernel_sfsec.text_start		= (unsigned long)_stext;
 	kernel_sfsec.text_end		= (unsigned long)_etext;
 
+	dbg_init(&kernel_sfsec);
+
 	if (WARN_ON(sframe_read_header(&kernel_sfsec)))
 		return;
 	if (WARN_ON(sframe_validate_section(&kernel_sfsec)))
@@ -1047,6 +1049,8 @@ void sframe_module_init(struct module *mod, void *sframe, size_t sframe_size,
 	sec->text_start   = (unsigned long)text;
 	sec->text_end     = (unsigned long)text + text_size;
 
+	dbg_init(sec);
+
 	if (WARN_ON(sframe_read_header(sec)))
 		return;
 	if (WARN_ON(sframe_validate_section(sec)))
diff --git a/kernel/unwind/sframe_debug.h b/kernel/unwind/sframe_debug.h
--- a/kernel/unwind/sframe_debug.h
+++ b/kernel/unwind/sframe_debug.h
@@ -32,6 +32,18 @@ static inline void dbg_init(struct sframe_section *sec)
 	struct mm_struct *mm = current->mm;
 	struct vm_area_struct *vma;
 
+	if (sec->sec_type == SFRAME_KERNEL) {
+		if (sec == &kernel_sfsec) {
+			sec->filename = kstrdup("(vmlinux)", GFP_KERNEL);
+		} else {
+			struct module *mod = container_of(sec, struct module,
+							  arch.sframe_sec);
+			sec->filename = kstrdup(mod->name, GFP_KERNEL);
+		}
+
+		return;
+	}
+
 	guard(mmap_read_lock)(mm);
 	vma = vma_lookup(mm, sec->sframe_start);
 	if (!vma)

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/