unwind, arm64: add sframe unwinder for kernel
Subsystems (8)
v5 cover unwind, arm64: add sframe unwinder for kernel
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/[email protected]/
[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.hSignature · 1 line
2.54.0.545.g6539524ca2-goog
PATCH v5 1/8 sframe: Allow kernelspace sframe sections
Generalize the sframe lookup code to support kernelspace sections. This is done by defining a SFRAME_LOOKUP option that can be activated separate from HAVE_UNWIND_USER_SFRAME, as there will be other client to this library than just userspace unwind.
Sframe section location is now tracked in a separate sec_type field to determine whether user-access functions are necessary to read the sframe data. Relevant type delarations are moved and renamed to reflect the non-user sframe support.
---
MAINTAINERS | 2 +-
arch/Kconfig | 4 +
.../{unwind_user_sframe.h => unwind_sframe.h} | 6 +-
arch/x86/include/asm/unwind_user.h | 12 +-
include/linux/sframe.h | 48 ++--
include/linux/unwind_types.h | 46 +++
include/linux/unwind_user_types.h | 41 ---
kernel/unwind/Makefile | 2 +-
kernel/unwind/sframe.c | 270 ++++++++++++------
kernel/unwind/user.c | 41 +--
10 files changed, 293 insertions(+), 179 deletions(-)
rename arch/x86/include/asm/{unwind_user_sframe.h => unwind_sframe.h} (50%)
create mode 100644 include/linux/unwind_types.hMAINTAINERS +1 -1
@@ -27557,7 +27557,7 @@ F: Documentation/driver-api/uio-howto.rst F: drivers/uio/ F: include/linux/uio_driver.h -USERSPACE STACK UNWINDING +STACK UNWINDING M: Josh Poimboeuf <[email protected]> M: Steven Rostedt <[email protected]> S: Maintained
arch/Kconfig +4 -0
@@ -486,6 +486,9 @@ config AS_SFRAME3 def_bool $(as-instr,.cfi_startproc\n.cfi_endproc,-Wa$(comma)--gsframe-3) select AS_SFRAME +config UNWIND_SFRAME_LOOKUP + bool + config UNWIND_USER bool
@@ -496,6 +499,7 @@ config HAVE_UNWIND_USER_FP config HAVE_UNWIND_USER_SFRAME bool select UNWIND_USER + select UNWIND_SFRAME_LOOKUP config SFRAME_VALIDATION bool "Enable .sframe section debugging"
arch/x86/include/asm/unwind_sframe.h renamed from arch/x86/include/asm/unwind_user_sframe.h +3 -3
@@ -1,6 +1,6 @@/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _ASM_X86_UNWIND_USER_SFRAME_H -#define _ASM_X86_UNWIND_USER_SFRAME_H +#ifndef _ASM_X86_UNWIND_SFRAME_H +#define _ASM_X86_UNWIND_SFRAME_H#ifdef CONFIG_X86_64
@@ -9,4 +9,4 @@#endif -#endif /* _ASM_X86_UNWIND_USER_SFRAME_H */ +#endif /* _ASM_X86_UNWIND_SFRAME_H */
arch/x86/include/asm/unwind_user.h +6 -6
@@ -55,30 +55,30 @@ static inline int unwind_user_get_reg(unsigned long *val, unsigned int regnum)#define ARCH_INIT_USER_FP_FRAME (ws) \ .cfa = { \ - .rule = UNWIND_USER_CFA_RULE_FP_OFFSET,\ + .rule = UNWIND_CFA_RULE_FP_OFFSET,\ .offset = 2*(ws), \ }, \ .ra = { \ - .rule = UNWIND_USER_RULE_CFA_OFFSET_DEREF,\ + .rule = UNWIND_RULE_CFA_OFFSET_DEREF,\ .offset = -1*(ws), \ }, \ .fp = { \ - .rule = UNWIND_USER_RULE_CFA_OFFSET_DEREF,\ + .rule = UNWIND_RULE_CFA_OFFSET_DEREF,\ .offset = -2*(ws), \ }, \ .outermost = false,#define ARCH_INIT_USER_FP_ENTRY_FRAME (ws) \ .cfa = { \ - .rule = UNWIND_USER_CFA_RULE_SP_OFFSET,\ + .rule = UNWIND_CFA_RULE_SP_OFFSET,\ .offset = 1*(ws), \ }, \ .ra = { \ - .rule = UNWIND_USER_RULE_CFA_OFFSET_DEREF,\ + .rule = UNWIND_RULE_CFA_OFFSET_DEREF,\ .offset = -1*(ws), \ }, \ .fp = { \ - .rule = UNWIND_USER_RULE_RETAIN,\ + .rule = UNWIND_RULE_RETAIN,\ }, \ .outermost = false,
include/linux/sframe.h +30 -18
82 lines not on this page · raw message
include/linux/unwind_types.h new file +46 -0
46 lines not on this page · raw message
include/linux/unwind_user_types.h +0 -41
47 lines not on this page · raw message
kernel/unwind/Makefile +1 -1
@@ -1,2 +1,2 @@ obj-$(CONFIG_UNWIND_USER) += user.o deferred.o - obj-$(CONFIG_HAVE_UNWIND_USER_SFRAME) += sframe.o + obj-$(CONFIG_UNWIND_SFRAME_LOOKUP) += sframe.o
kernel/unwind/sframe.c +181 -89
480 lines not on this page · raw message
kernel/unwind/user.c +21 -20
124 lines not on this page · raw message
Signature · 1 line
2.54.0.545.g6539524ca2-goog
PATCH v5 2/8 arm64, unwind: build kernel with sframe V3 info
In reply to Dylan HatchBuild with -Wa,--gsframe-3 flags to generate a .sframe section. This will be used for in-kernel reliable stacktrace in cases where the frame pointer alone is insufficient.
Currently, the sframe format only supports arm64, x86_64 and s390x architectures.
--- MAINTAINERS | 1 + Makefile | 8 ++++++++ arch/Kconfig | 21 +++++++++++++++++++++ arch/arm64/Kconfig | 1 + arch/arm64/include/asm/unwind_sframe.h | 8 ++++++++ arch/arm64/kernel/vdso/Makefile | 2 +- include/asm-generic/sections.h | 4 ++++ include/asm-generic/vmlinux.lds.h | 15 +++++++++++++++ 8 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/include/asm/unwind_sframe.h
MAINTAINERS +1 -0
@@ -27561,6 +27561,7 @@ STACK UNWINDING M: Josh Poimboeuf <[email protected]> M: Steven Rostedt <[email protected]> S: Maintained +F: arch/*/include/asm/unwind_sframe.h F: include/linux/sframe.h F: include/linux/unwind*.h F: kernel/unwind/
Makefile +8 -0
@@ -1110,6 +1110,14 @@ endif # Ensure compilers do not transform certain loops into calls to wcslen() KBUILD_CFLAGS += -fno-builtin-wcslen +# build with sframe table +ifdef CONFIG_HAVE_UNWIND_KERNEL_SFRAME +CC_FLAGS_SFRAME := -Wa,--gsframe-3 +KBUILD_CFLAGS += $(CC_FLAGS_SFRAME) +KBUILD_AFLAGS += $(CC_FLAGS_SFRAME) +export CC_FLAGS_SFRAME +endif + # change __FILE__ to the relative path to the source directory ifdef building_out_of_srctree KBUILD_CPPFLAGS += -fmacro-prefix-map=$(srcroot)/=
arch/Kconfig +21 -0
@@ -520,6 +520,27 @@ config SFRAME_VALIDATION If unsure, say N. +config ARCH_SUPPORTS_UNWIND_KERNEL_SFRAME + bool + help + An architecture can select this if it enables the SFrame (Simple + Frame) unwinder for unwinding kernel stack traces. It uses an unwind + table that is directly generated by the toolchain based on DWARF CFI + information. + +config HAVE_UNWIND_KERNEL_SFRAME + bool "Sframe unwinder" + depends on AS_SFRAME3 + depends on 64BIT + depends on ARCH_SUPPORTS_UNWIND_KERNEL_SFRAME + select UNWIND_SFRAME_LOOKUP + help + This option enables the SFrame (Simple Frame) unwinder for unwinding + kernel stack traces. It uses unwind an table that is directly + generated by the toolchain based on DWARF CFI information. In + practice, this can provide more reliable stacktrace results than + unwinding with frame pointers alone. + config HAVE_PERF_REGS bool help
arch/arm64/Kconfig +1 -0
@@ -112,6 +112,7 @@ config ARM64 select ARCH_SUPPORTS_SCHED_SMT select ARCH_SUPPORTS_SCHED_CLUSTER select ARCH_SUPPORTS_SCHED_MC + select ARCH_SUPPORTS_UNWIND_KERNEL_SFRAME select ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH select ARCH_WANT_COMPAT_IPC_PARSE_VERSION if COMPAT select ARCH_WANT_DEFAULT_BPF_JIT
arch/arm64/include/asm/unwind_sframe.h new file +8 -0
@@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_ARM64_UNWIND_SFRAME_H +#define _ASM_ARM64_UNWIND_SFRAME_H + +#define SFRAME_REG_SP 31 +#define SFRAME_REG_FP 29 + +#endif /* _ASM_ARM64_UNWIND_SFRAME_H */
arch/arm64/kernel/vdso/Makefile +1 -1
@@ -38,7 +38,7 @@ ccflags-y += -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO CC_FLAGS_REMOVE_VDSO := $(CC_FLAGS_FTRACE) -Os $(CC_FLAGS_SCS) \ $(RANDSTRUCT_CFLAGS) $(KSTACK_ERASE_CFLAGS) \ $(GCC_PLUGINS_CFLAGS) \ - $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) \ + $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) $(CC_FLAGS_SFRAME) \ -Wmissing-prototypes -Wmissing-declarations CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables
include/asm-generic/sections.h +4 -0
@@ -31,6 +31,7 @@* __irqentry_text_start, __irqentry_text_end * __softirqentry_text_start, __softirqentry_text_end * __start_opd, __end_opd +* __start_sframe, __end_sframe */ extern char _text[], _stext[], _etext[];extern char _data[], _sdata[], _edata[];
@@ -53,6 +54,9 @@ extern char __ctors_start[], __ctors_end[];/* Start and end of .opd section - used for function descriptors. */ extern char __start_opd[], __end_opd[]; +/* Start and end of .sframe section - used for stack unwinding. */ +extern char __start_sframe[], __end_sframe[]; +/* Start and end of instrumentation protected text section */ extern char __noinstr_text_start[], __noinstr_text_end[];
include/asm-generic/vmlinux.lds.h +15 -0
@@ -491,6 +491,8 @@ *(.rodata1) \ } \ \ + SFRAME \ + \ /* PCI quirks */ \ .pci_fixup : AT(ADDR(.pci_fixup) - LOAD_OFFSET) { \ BOUNDED_SECTION_PRE_LABEL(.pci_fixup_early, _pci_fixups_early, __start, __end) \
@@ -911,6 +913,19 @@#define TRACEDATA #endif +#ifdef CONFIG_HAVE_UNWIND_KERNEL_SFRAME +#define SFRAME \ +/* sframe */ \ + .sframe : AT(ADDR(.sframe) - LOAD_OFFSET) { \ + __start_sframe = .; \ + KEEP(*(.sframe)) \ + KEEP(*(.init.sframe)) \ + __end_sframe = .; \ + } +#else +#define SFRAME +#endif +#ifdef CONFIG_PRINTK_INDEX #define PRINTK_INDEX \ .printk_index : AT(ADDR(.printk_index) - LOAD_OFFSET) { \
Signature · 1 line
2.54.0.545.g6539524ca2-goog
PATCH v5 3/8 arm64: entry: add unwind info for various kernel entries
In reply to Dylan HatchFrom: Weinan Liu <[email protected]>
DWARF CFI (Call Frame Information) specifies how to recover the return address and callee-saved registers at each PC in a given function. Compilers are able to generate the CFI annotations when they compile the code to assembly language. For handcrafted assembly, we need to annotate them by hand.
Annotate minimal CFI to enable stacktracing using SFrame for kernel exception entries through el1*_64_*() paths and irq entries through call_on_irq_stack()
--- arch/arm64/kernel/entry.S | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
arch/arm64/kernel/entry.S +23 -0
@@ -30,6 +30,12 @@ #include <asm/asm-uaccess.h> #include <asm/unistd.h> +/* + * Do not generate .eh_frame. Only generate .debug_frame and optionally + * .sframe (via assembler option --gsframe[-N]). + */ + .cfi_sections .debug_frame + .macro clear_gp_regs .irp n,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29 mov x\n, xzr
@@ -575,7 +581,16 @@ SYM_CODE_START_LOCAL(el\el\ht\()_\regsize\()_\label) .if \el == 0 b ret_to_user .else + /* + * Minimal DWARF CFI for unwinding across the call above. + * Enable unwinding for el1*_64_*() path only. + */ + .cfi_startproc + .cfi_def_cfa_offset PT_REGS_SIZE + .cfi_offset 29, S_FP - PT_REGS_SIZE + .cfi_offset 30, S_LR - PT_REGS_SIZE b ret_to_kernel + .cfi_endproc .endif SYM_CODE_END(el\el\ht\()_\regsize\()_\label) .endm
@@ -872,6 +887,7 @@ NOKPROBE(ret_from_fork) * Calls func(regs) using this CPU's irq stack and shadow irq stack. */ SYM_FUNC_START(call_on_irq_stack) + .cfi_startproc save_and_disable_daif x9 #ifdef CONFIG_SHADOW_CALL_STACK get_current_task x16
@@ -882,6 +898,9 @@ SYM_FUNC_START(call_on_irq_stack) /* Create a frame record to save our LR and SP (implicit in FP) */ stp x29, x30, [sp, #-16]! mov x29, sp + .cfi_def_cfa 29, 16 + .cfi_offset 29, -16 + .cfi_offset 30, -8 ldr_this_cpu x16, irq_stack_ptr, x17
@@ -897,9 +916,13 @@ SYM_FUNC_START(call_on_irq_stack) */ mov sp, x29 ldp x29, x30, [sp], #16 + .cfi_restore 29 + .cfi_restore 30 + .cfi_def_cfa 31, 0 scs_load_current restore_irq x9 ret + .cfi_endproc SYM_FUNC_END(call_on_irq_stack) NOKPROBE(call_on_irq_stack)
Signature · 1 line
2.54.0.545.g6539524ca2-goog
PATCH v5 4/8 sframe: Provide PC lookup for vmlinux .sframe section
In reply to Dylan HatchWith SFRAME_UNWINDER, read in the .sframe section at boot. This provides unwind data as an alternative/supplement to frame pointer-based unwinding.
--- arch/arm64/kernel/setup.c | 2 ++ include/linux/sframe.h | 14 ++++++++++++++ kernel/unwind/sframe.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+)
arch/arm64/kernel/setup.c +2 -0
@@ -32,6 +32,7 @@#include <linux/sched/task.h> #include <linux/scs.h> #include <linux/mm.h> +#include <linux/sframe.h> #include <asm/acpi.h> #include <asm/fixmap.h>
@@ -375,6 +376,7 @@ void __init __no_sanitize_address setup_arch(char **cmdline_p)"This indicates a broken bootloader or old kernel\n" , boot_args[1], boot_args[2], boot_args[3]); } +init_sframe_table (); }static inline bool cpu_can_disable (unsigned int cpu)
include/linux/sframe.h +14 -0
@@ -69,4 +69,18 @@ static inline int sframe_find_user(unsigned long ip, struct unwind_frame *frame)#endif /* CONFIG_HAVE_UNWIND_USER_SFRAME */ +#ifdef CONFIG_HAVE_UNWIND_KERNEL_SFRAME + +void __init init_sframe_table (void ); +void sframe_module_init (struct module *mod,void *sframe,size_t sframe_size, +void *text,size_t text_size); + +extern int sframe_find_kernel (unsigned long ip,struct unwind_frame *frame); + +#else + +static inline void __init init_sframe_table (void ) {} + +#endif /* CONFIG_HAVE_UNWIND_KERNEL_SFRAME */ +#endif /* _LINUX_SFRAME_H */
kernel/unwind/sframe.c +36 -0
@@ -14,10 +14,20 @@#include <linux/sframe.h> #include <linux/unwind_types.h> #include <asm/unwind_sframe.h> +#ifdef CONFIG_HAVE_UNWIND_KERNEL_SFRAME +#include <linux/kallsyms.h> +#endif #include "sframe.h" #include "sframe_debug.h" +#ifdef CONFIG_HAVE_UNWIND_KERNEL_SFRAME + +static bool sframe_init__ro_after_init ; +static struct sframe_section kernel_sfsec__ro_after_init ; + +#endif /* CONFIG_HAVE_UNWIND_KERNEL_SFRAME */ +struct sframe_fde_internal {unsigned long func_addr;u32 func_size;
@@ -930,3 +940,29 @@ void sframe_free_mm(struct mm_struct *mm) }#endif /* CONFIG_HAVE_UNWIND_USER_SFRAME */ + +#ifdef CONFIG_HAVE_UNWIND_KERNEL_SFRAME + +int sframe_find_kernel (unsigned long ip,struct unwind_frame *frame) +{ +if (!frame || !sframe_init) +return -EINVAL ; + +return __sframe_find (&kernel_sfsec, ip, frame); +} + +void __init init_sframe_table (void ) +{ + kernel_sfsec.sec_type =SFRAME_KERNEL ; + kernel_sfsec.sframe_start = (unsigned long )__start_sframe; + kernel_sfsec.sframe_end = (unsigned long )__end_sframe; + kernel_sfsec.text_start = (unsigned long )_stext; + kernel_sfsec.text_end = (unsigned long )_etext; + +if (WARN_ON (sframe_read_header (&kernel_sfsec))) +return ; + + sframe_init = true; +} + +#endif /* CONFIG_HAVE_UNWIND_KERNEL_SFRAME */
Signature · 1 line
2.54.0.545.g6539524ca2-goog
PATCH v5 5/8 sframe: Allow unsorted FDEs
In reply to Dylan HatchThe .sframe in kernel modules is built without SFRAME_F_FDE_SORTED set. In order to allow sframe PC lookup in modules, add a code path to handle unsorted FDE tables by doing a simple linear search.
--- include/linux/sframe.h | 1 + kernel/unwind/sframe.c | 45 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 41 insertions(+), 5 deletions(-)
include/linux/sframe.h +1 -0
@@ -28,6 +28,7 @@ struct sframe_section {unsigned long fres_start;unsigned long fres_end;unsigned int num_fdes; +bool fdes_sorted;signed char ra_off;signed char fp_off;
kernel/unwind/sframe.c +40 -5
75 lines not on this page · raw message
Signature · 1 line
2.54.0.545.g6539524ca2-goog
PATCH v5 6/8 arm64/module, sframe: Add sframe support for modules
In reply to Dylan HatchAdd sframe table to mod_arch_specific and support sframe PC lookups when an .sframe section can be found on incoming modules.
--- arch/arm64/include/asm/module.h | 6 +++++ arch/arm64/kernel/module.c | 8 +++++++ include/linux/sframe.h | 2 ++ kernel/unwind/sframe.c | 40 +++++++++++++++++++++++++++++++-- 4 files changed, 54 insertions(+), 2 deletions(-)
arch/arm64/include/asm/module.h +6 -0
@@ -6,6 +6,7 @@#define __ASM_MODULE_H#include <asm-generic/module.h> +#include <linux/sframe.h> struct mod_plt_sec {int plt_shndx;
@@ -17,6 +18,11 @@ struct mod_arch_specific {struct mod_plt_sec core;struct mod_plt_sec init; +#ifdef CONFIG_HAVE_UNWIND_KERNEL_SFRAME +struct sframe_section sframe_sec; +bool sframe_init; +#endif +/* for CONFIG_DYNAMIC_FTRACE */ struct plt_entry *ftrace_trampolines;struct plt_entry *init_ftrace_trampolines;
arch/arm64/kernel/module.c +8 -0
@@ -18,6 +18,7 @@#include <linux/moduleloader.h> #include <linux/random.h> #include <linux/scs.h> +#include <linux/sframe.h> #include <asm/alternative.h> #include <asm/insn.h>
@@ -515,5 +516,12 @@ int module_finalize(const Elf_Ehdr *hdr, } } + s =find_section (hdr, sechdrs,".sframe" ); +if (s) { +struct module_memory *t = &me->mem[MOD_TEXT ]; + +sframe_module_init (me, (void *)s->sh_addr, s->sh_size, + t->base, t->size); + }return module_init_ftrace_plt (hdr, sechdrs, me); }
include/linux/sframe.h +2 -0
@@ -81,6 +81,8 @@ extern int sframe_find_kernel(unsigned long ip, struct unwind_frame *frame);#else static inline void __init init_sframe_table (void ) {} +static inline void sframe_module_init (struct module *mod,void *sframe,size_t sframe_size, +void *text,size_t text_size) {}#endif /* CONFIG_HAVE_UNWIND_KERNEL_SFRAME */
kernel/unwind/sframe.c +38 -2
@@ -980,10 +980,27 @@ void sframe_free_mm(struct mm_struct *mm)int sframe_find_kernel (unsigned long ip,struct unwind_frame *frame) { -if (!frame || !sframe_init) +struct sframe_section *sec; + +if (!frame)return -EINVAL ; -return __sframe_find (&kernel_sfsec, ip, frame); +if (is_ksym_addr (ip)) { +if (!sframe_init) +return -EINVAL ; + + sec = &kernel_sfsec; + }else { +struct module *mod; + + mod =__module_address (ip); +if (!mod || !mod->arch.sframe_init) +return -EINVAL ; + + sec = &mod->arch.sframe_sec; + } + +return __sframe_find (sec, ip, frame); }void __init init_sframe_table (void )
@@ -1000,4 +1017,23 @@ void __init init_sframe_table(void) sframe_init = true; } +void sframe_module_init (struct module *mod,void *sframe,size_t sframe_size, +void *text,size_t text_size) +{ +struct sframe_section sec; + +memset (&sec,0 ,sizeof (sec)); + sec.sec_type =SFRAME_KERNEL ; + sec.sframe_start = (unsigned long )sframe; + sec.sframe_end = (unsigned long )sframe + sframe_size; + sec.text_start = (unsigned long )text; + sec.text_end = (unsigned long )text + text_size; + +if (WARN_ON (sframe_read_header (&sec))) +return ; + + mod->arch.sframe_sec = sec; + mod->arch.sframe_init = true; +} +#endif /* CONFIG_HAVE_UNWIND_KERNEL_SFRAME */
Signature · 1 line
2.54.0.545.g6539524ca2-goog
PATCH v5 7/8 sframe: Introduce in-kernel SFRAME_VALIDATION
In reply to Dylan HatchGeneralize the __safe* helpers to support a non-user-access code path.
This requires arch-specific function address validation. This is because arm64 vmlinux keeps .exit.text (normally discarded), and .rodata.text sections both of which lie outside the bounds of the normal .text. .rodata.text contains code that is never executed by the kernel mapping, but for which the toolchain nonetheless generates sframe data, and needs to be considered valid for a PC lookup.
Additionally .init.text lies outside .text for all arches and must be accounted for as well.
--- arch/Kconfig | 2 +- arch/arm64/include/asm/sections.h | 1 + arch/arm64/include/asm/unwind_sframe.h | 47 ++++++++++++++++++++++++++ arch/arm64/kernel/vmlinux.lds.S | 2 ++ include/linux/sframe.h | 2 ++ kernel/unwind/sframe.c | 25 ++++++++++++-- 6 files changed, 76 insertions(+), 3 deletions(-)
arch/Kconfig +1 -1
@@ -503,7 +503,7 @@ config HAVE_UNWIND_USER_SFRAME config SFRAME_VALIDATION bool "Enable .sframe section debugging" - depends on HAVE_UNWIND_USER_SFRAME + depends on UNWIND_SFRAME_LOOKUP depends on DYNAMIC_DEBUG help When adding an .sframe section for a task, validate the entire
arch/arm64/include/asm/sections.h +1 -0
@@ -23,6 +23,7 @@ extern char __irqentry_text_start[], __irqentry_text_end[];extern char __mmuoff_data_start[], __mmuoff_data_end[];extern char __entry_tramp_text_start[], __entry_tramp_text_end[];extern char __relocate_new_kernel_start[], __relocate_new_kernel_end[]; +extern char _srodatatext[], _erodatatext[];static inline size_t entry_tramp_text_size (void ) {
arch/arm64/include/asm/unwind_sframe.h +47 -0
54 lines not on this page · raw message
arch/arm64/kernel/vmlinux.lds.S +2 -0
@@ -213,12 +213,14 @@ SECTIONS /* code sections that are never executed via the kernel mapping */ .rodata.text : { + _srodatatext = .; TRAMP_TEXT HIBERNATE_TEXT KEXEC_TEXT IDMAP_TEXT . = ALIGN(PAGE_SIZE); } + _erodatatext = .; idmap_pg_dir = .; . += PAGE_SIZE;
include/linux/sframe.h +2 -0
@@ -34,6 +34,8 @@ struct sframe_section { signed char fp_off; }; +extern struct sframe_section kernel_sfsec__ro_after_init ; +#endif /* CONFIG_UNWIND_SFRAME_LOOKUP */ #ifdef CONFIG_HAVE_UNWIND_USER_SFRAME
kernel/unwind/sframe.c +23 -2
@@ -21,10 +21,18 @@#include "sframe.h" #include "sframe_debug.h" +#ifndef sframe_func_start_addr_valid +static inline bool sframe_func_start_addr_valid (struct sframe_section *sec, +unsigned long func_addr) +{ +return (sec->text_start <= func_addr && func_addr < sec->text_end); +} +#endif +#ifdef CONFIG_HAVE_UNWIND_KERNEL_SFRAME static bool sframe_init__ro_after_init ; -static struct sframe_section kernel_sfsec__ro_after_init ; +struct sframe_section kernel_sfsec__ro_after_init ;#endif /* CONFIG_HAVE_UNWIND_KERNEL_SFRAME */
@@ -152,7 +160,7 @@ static __always_inline int __read_fde(struct sframe_section *sec, sizeof(struct sframe_fde_v3), Efault); func_addr = fde_addr + _fde.func_start_off; -if (func_addr < sec->text_start || func_addr > sec->text_end) +if (!sframe_func_start_addr_valid (sec, func_addr))return -EINVAL ; fda_addr = sec->fres_start + _fde.fres_off;
@@ -636,6 +644,9 @@ static int safe_read_fde(struct sframe_section *sec, {int ret; +if (sec->sec_type ==SFRAME_KERNEL ) +return __read_fde (sec, fde_num, fde); +if (!user_read_access_begin ((void __user *)sec->sframe_start, sec->sframe_end - sec->sframe_start))return -EFAULT ;
@@ -651,6 +662,9 @@ static int safe_read_fre(struct sframe_section *sec, {int ret; +if (sec->sec_type ==SFRAME_KERNEL ) +return __read_fre (sec, fde, fre_addr, fre); +if (!user_read_access_begin ((void __user *)sec->sframe_start, sec->sframe_end - sec->sframe_start))return -EFAULT ;
@@ -665,6 +679,9 @@ static int safe_read_fre_datawords(struct sframe_section *sec, {int ret; +if (sec->sec_type ==SFRAME_KERNEL ) +return __read_fre_datawords (sec, fde, fre); +if (!user_read_access_begin ((void __user *)sec->sframe_start, sec->sframe_end - sec->sframe_start))return -EFAULT ;
@@ -1013,6 +1030,8 @@ void __init init_sframe_table(void)if (WARN_ON (sframe_read_header (&kernel_sfsec)))return ; +if (WARN_ON (sframe_validate_section (&kernel_sfsec))) +return ; sframe_init = true; }
@@ -1031,6 +1050,8 @@ void sframe_module_init(struct module *mod, void *sframe, size_t sframe_size,if (WARN_ON (sframe_read_header (&sec)))return ; +if (WARN_ON (sframe_validate_section (&sec))) +return ; mod->arch.sframe_sec = sec; mod->arch.sframe_init = true;
Signature · 1 line
2.54.0.545.g6539524ca2-goog
PATCH v5 8/8 unwind: arm64: Use sframe to unwind interrupt frames
In reply to Dylan HatchAdd unwind_next_frame_sframe() function to unwind by sframe info if present. Use this method at exception boundaries, falling back to frame-pointer unwind only on failure. In such failure cases, the stacktrace is considered unreliable.
During normal unwind, prefer frame pointer unwind (for better performance) with sframe as a backup.
This change restores the LR behavior originally introduced in commit c2c6b27b5aa14fa2 ("arm64: stacktrace: unwind exception boundaries"), But later removed in commit 32ed1205682e ("arm64: stacktrace: Skip reporting LR at exception boundaries")
This can be done because the sframe data can be used to determine whether the LR is current for the PC value recovered from pt_regs at the exception boundary.
--- arch/arm64/include/asm/stacktrace/common.h | 6 + arch/arm64/kernel/stacktrace.c | 246 +++++++++++++++++++-- 2 files changed, 232 insertions(+), 20 deletions(-)
arch/arm64/include/asm/stacktrace/common.h +6 -0
@@ -21,6 +21,8 @@ struct stack_info {* * @fp: The fp value in the frame record (or the real fp) * @pc: The lr value in the frame record (or the real lr) +* @sp: The sp value at the call site of the current function. +* @unreliable: Stacktrace is unreliable. * * @stack: The stack currently being unwound. * @stacks: An array of stacks which can be unwound.
@@ -29,7 +31,11 @@ struct stack_info {struct unwind_state {unsigned long fp;unsigned long pc; +#ifdef CONFIG_HAVE_UNWIND_KERNEL_SFRAME +unsigned long sp; +#endif +bool unreliable;struct stack_info stack;struct stack_info *stacks;int nr_stacks;
arch/arm64/kernel/stacktrace.c +226 -20
333 lines not on this page · raw message
Signature · 1 line
2.54.0.545.g6539524ca2-goog
Mark Rutland
reviewerRe: [PATCH v5 3/8] arm64: entry: add unwind info for various kernel entries
In reply to Dylan HatchHi Dylan,
Quoted 10 lines · Dylan Hatch
From: Weinan Liu <[email protected]>
DWARF CFI (Call Frame Information) specifies how to recover the return address and callee-saved registers at each PC in a given function. Compilers are able to generate the CFI annotations when they compile the code to assembly language. For handcrafted assembly, we need to annotate them by hand.
Annotate minimal CFI to enable stacktracing using SFrame for kernel exception entries through el1*_64_*() paths
I thought we were only consuming SFrame when unwinding an exeption boundary?
We shouldn't be taking exceptions _from_ the entry assembly functions unless something has gone horribly wrong, and so I don't see why we'd need CFI entries for the entry assembly functions.
Am I missing some reason we need CFI entries for the entry assembly functions? I strongly suspect it is not necessary to add these, and I'd prefer to omit them.
Quoted 1 line
and irq entries through
call_on_irq_stack()
Needing some sort of unwind annotations for call_on_irq_stack() makes sense to me, but don't we need something for other assembly functions too?
We can interrupt things like memset(); I assume we'll treat those as unreliable until annotated?
Mark.
Quoted 77 lines
Signed-off-by Weinan Liu <[email protected]>Suggested-by Jens Remus <[email protected]>Reviewed-by Jens Remus <[email protected]>Signed-off-by Dylan Hatch <[email protected]>--- arch/arm64/kernel/entry.S | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)arch/arm64/kernel/entry.S +23
-0@@ -30,6 +30,12 @@ #include <asm/asm-uaccess.h> #include <asm/unistd.h> +/* + * Do not generate .eh_frame. Only generate .debug_frame and optionally + * .sframe (via assembler option --gsframe[-N]). + */ + .cfi_sections .debug_frame + .macro clear_gp_regs .irp n,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29 mov x\n, xzr@@ -575,7 +581,16 @@ SYM_CODE_START_LOCAL(el\el\ht\()_\regsize\()_\label) .if \el == 0 b ret_to_user .else + /* + * Minimal DWARF CFI for unwinding across the call above. + * Enable unwinding for el1*_64_*() path only. + */ + .cfi_startproc + .cfi_def_cfa_offset PT_REGS_SIZE + .cfi_offset 29, S_FP - PT_REGS_SIZE + .cfi_offset 30, S_LR - PT_REGS_SIZE b ret_to_kernel + .cfi_endproc .endif SYM_CODE_END(el\el\ht\()_\regsize\()_\label) .endm@@ -872,6 +887,7 @@ NOKPROBE(ret_from_fork) * Calls func(regs) using this CPU's irq stack and shadow irq stack. */ SYM_FUNC_START(call_on_irq_stack) + .cfi_startproc save_and_disable_daif x9 #ifdef CONFIG_SHADOW_CALL_STACK get_current_task x16@@ -882,6 +898,9 @@ SYM_FUNC_START(call_on_irq_stack) /* Create a frame record to save our LR and SP (implicit in FP) */ stp x29, x30, [sp, #-16]! mov x29, sp + .cfi_def_cfa 29, 16 + .cfi_offset 29, -16 + .cfi_offset 30, -8 ldr_this_cpu x16, irq_stack_ptr, x17@@ -897,9 +916,13 @@ SYM_FUNC_START(call_on_irq_stack) */ mov sp, x29 ldp x29, x30, [sp], #16 + .cfi_restore 29 + .cfi_restore 30 + .cfi_def_cfa 31, 0 scs_load_current restore_irq x9 ret + .cfi_endproc SYM_FUNC_END(call_on_irq_stack) NOKPROBE(call_on_irq_stack)Signature · 1 line
2.54.0.545.g6539524ca2-goog
Mark Rutland
reviewerHi Dylan,
Quoted 3 lines · Dylan Hatch
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.
Quoted 119 lines
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/[email protected]/
[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-v5Changes 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) RenameSFRAME_LOOKUP->UNWIND_SFRAME_LOOKUPto fit existing naming convention.
- (Randy) Correct typo errors in new config options.
- (Jens) Move unwind types to a newunwind_types.hto match their usage.
- (Jens) Update KERNEL_[COPY|GET] to use label-based error handling like their userspace counterparts.
- (Jens) RenameSFRAME_UNWINDER->HAVE_UNWIND_KERNEL_SFRAMEandARCH_SUPPORTS_SFRAME_UNWINDER->ARCH_SUPPORTS_UNWIND_KERNEL_SFRAMEto match existing naming convention.
- (Jens) MoveHAVE_UNWIND_KERNEL_SFRAMEconfig option toarch/Kconfig.
- (Jens) Rename/move extern definitions of __[start|end]_sframe intoinclude/asm-generic/sections.h.
- (Jens) Fix up CFI annotations at kernel entry.
- (Jens) Fix error path for unsorted FDE lookup.
- (Jens) Zero-out modulesframe_sectionbefore init.
- (Jens) ForSFRAME_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 supportSFRAME_F_FDE_FUNC_START_PCREL, added in binutils 2.45.
- (Jens) Add check for sframe V3, thus resolving the prior need for V2 andSFRAME_F_FDE_FUNC_START_PCRELsupport.
- (Will) AddARCH_SUPPORTS_SFRAME_UNWINDER, removeSFRAME_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-kernelSFRAME_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-kernelSFRAME_VALIDATION
unwind: arm64: Use sframe to unwind interrupt framesWeinan Liu (1):
arm64: entry: add unwind info for various kernel entriesMAINTAINERS | 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.hSignature · 1 line
2.54.0.545.g6539524ca2-goog
Re: [PATCH v5 5/8] sframe: Allow unsorted FDEs
In reply to Dylan HatchQuoted 6 lines · Dylan Hatch
The .sframe in kernel modules is built without
SFRAME_F_FDE_SORTEDset. In order to allow sframe PC lookup in modules, add a code path to handle unsorted FDE tables by doing a simple linear search.Reviewed-by Jens Remus <[email protected]>Signed-off-by Dylan Hatch <[email protected]>
Indu suggested that it would be preferable if a module's .sframe FDE index table could be sorted during loading of the module to enable binary search instead of having to resort to linear search. I propose to drop everything from this patch except for the following, squash it into the following patch that adds sframe support for modules, and extend that to sort the .sframe FDE index table. See my separate feedback to that patch.
Quoted 22 lines
include/linux/sframe.h +1
-0@@ -28,6 +28,7 @@ struct sframe_section {unsigned long fres_start;unsigned long fres_end;unsigned int num_fdes; +bool fdes_sorted;signed char ra_off;signed char fp_off;kernel/unwind/sframe.c +0
-1@@ -736,7 +771,6 @@ static int sframe_read_header(struct sframe_section *sec)if (shdr.preamble.magic !=SFRAME_MAGIC || shdr.preamble.version !=SFRAME_VERSION_3 || - !(shdr.preamble.flags &SFRAME_F_FDE_SORTED ) || !(shdr.preamble.flags &SFRAME_F_FDE_FUNC_START_PCREL ) || shdr.auxhdr_len) {dbg_sec ("bad/unsupported sframe header\n" );
kernel/unwind/sframe.c static int sframe_read_header(struct sframe_section *sec) · line 806
Quoted 7 lines
kernel/unwind/sframe.c +1
-0@@ -766,6 +800,7 @@ static int sframe_read_header(struct sframe_section *sec)return -EINVAL ; } + sec->fdes_sorted = shdr.preamble.flags &SFRAME_F_FDE_SORTED ; sec->num_fdes = num_fdes; sec->fdes_start = fdes_start; sec->fres_start = fres_start;
Regards,
Jens
Signature · 6 lines
Jens Remus Linux on Z Development (D3303) [email protected] / [email protected] 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/
Re: [PATCH v5 7/8] sframe: Introduce in-kernel SFRAME_VALIDATION
In reply to Dylan HatchQuoted 40 lines · Dylan Hatch
Generalize the __safe* helpers to support a non-user-access code path.
This requires arch-specific function address validation. This is because arm64 vmlinux keeps .exit.text (normally discarded), and .rodata.text sections both of which lie outside the bounds of the normal .text. .rodata.text contains code that is never executed by the kernel mapping, but for which the toolchain nonetheless generates sframe data, and needs to be considered valid for a PC lookup.
Additionally .init.text lies outside .text for all arches and must be accounted for as well.
arch/arm64/include/asm/unwind_sframe.h +19
-0@@ -2,7 +2,54 @@#ifndef _ASM_ARM64_UNWIND_SFRAME_H#define _ASM_ARM64_UNWIND_SFRAME_H +#include <linux/module.h> +#include <linux/sframe.h> +#include <asm/sections.h> +#define SFRAME_REG_SP 31#define SFRAME_REG_FP 29 +static inline bool sframe_func_start_addr_valid (struct sframe_section *sec, +unsigned long func_addr) +{ +/* Common case for unwinding */ +if (sec->text_start <= func_addr && func_addr < sec->text_end) +return true; + +if (sec->sec_type !=SFRAME_KERNEL ) +return false; + +/* +* Account for vmlinux and module code outside the normal .text section. +* The toolchain still generates sframe data for these functions, so +* sframe lookups on them should be allowed. +*/
arch/arm64/include/asm/unwind_sframe.h line 36
Quoted 10 lines
arch/arm64/include/asm/unwind_sframe.h +10
-0+if (sec == &kernel_sfsec) { +if (is_kernel_inittext (func_addr)) +return true; + +/* .exit.text is retained in vmlinux on arm64. */ +if (func_addr >= (unsigned long )__exittext_begin && + func_addr < (unsigned long )__exittext_end) +return true; + +
Nit: Superfluous empty line (2 instead of 1).
arch/arm64/include/asm/unwind_sframe.h line 46
Quoted 10 lines
arch/arm64/include/asm/unwind_sframe.h +10
-0+/* +* .rodata.text is never executed from the kernel mapping, but +* still has sframe data +*/ +if (func_addr >= (unsigned long )_srodatatext && + func_addr < (unsigned long )_erodatatext) +return true; + }else { + struct module *mod = container_of(sec, struct module, + arch.sframe_sec);
This currently does not work properly when sframe_validate_section() is called from sframe_module_init(), which operates on a temporary struct sframe_section section, that is not (yet) the one in struct module. See my feedback to the respective patch for how to resolve.
arch/arm64/include/asm/unwind_sframe.h line 55
Quoted 9 lines
arch/arm64/include/asm/unwind_sframe.h +8
-0+if (within_module_mem_type (func_addr, mod,MOD_INIT_TEXT )) + return true; + } + +return false; +} +#define sframe_func_start_addr_valid sframe_func_start_addr_valid +#endif /* _ASM_ARM64_UNWIND_SFRAME_H */
Regards,
Jens
Signature · 6 lines
Jens Remus Linux on Z Development (D3303) [email protected] / [email protected] 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/
Re: [PATCH v5 6/8] arm64/module, sframe: Add sframe support for modules
In reply to Dylan HatchQuoted 2 lines · Dylan Hatch
Add sframe table to
mod_arch_specificand support sframe PC lookups when an .sframe section can be found on incoming modules.
One small fix and a proposal to sort the module's SFrame FDE index.
kernel/unwind/sframe.c
Quoted 1 line
kernel/unwind/sframe.c +0
-0
A subsequent patch adds a call to sframe_validate_section(), which would operate on the temporary struct sframe_section instance and thus fail to use container_of() to access the struct module instance. To resolve change as follows:
kernel/unwind/sframe.c
Quoted 4 lines
kernel/unwind/sframe.c +4
-0+void sframe_module_init (struct module *mod,void *sframe,size_t sframe_size, +void *text,size_t text_size) +{ +struct sframe_section sec;
struct sframe_section *sec = &mod->arch.sframe_sec;
It is fine to initialize the module's struct sframe_section instance as use of the information is guarded by mod->arch.sframe_init, which is only set if the instance has been full initialized.
kernel/unwind/sframe.c
Quoted 2 lines
kernel/unwind/sframe.c +2
-0+ +memset (&sec,0 ,sizeof (sec));
Can be dropped if struct module instance got zero-initialized.
kernel/unwind/sframe.c
Quoted 5 lines
kernel/unwind/sframe.c +5
-0+ sec.sec_type =SFRAME_KERNEL ; + sec.sframe_start = (unsigned long )sframe; + sec.sframe_end = (unsigned long )sframe + sframe_size; + sec.text_start = (unsigned long )text; + sec.text_end = (unsigned long )text + text_size;
Adjust all lines above to pointer access.
kernel/unwind/sframe.c
Quoted 2 lines
kernel/unwind/sframe.c +2
-0+ +if (WARN_ON (sframe_read_header (&sec)))
Ditto.
kernel/unwind/sframe.c
Quoted 3 lines
kernel/unwind/sframe.c +3
-0+return ; + + mod->arch.sframe_sec = sec;
Drop.
kernel/unwind/sframe.c
Quoted 2 lines
kernel/unwind/sframe.c +2
-0+ mod->arch.sframe_init = true; +}
Indu suggested that it would be preferable if a module's .sframe FDE index table could be sorted during loading of the module to enable binary search instead of having to resort to linear search. I propose to change this patch as follows to sort the module .sframe FDE index table in sframe_module_init(). Note that the patch assumes above changes have been implemented. The sorting is very similar to sorting of ORC tables in arch/x86/kernel/unwind_orc.c in unwind_module_init().
kernel/unwind/sframe.c +47 -0
@@ -12,6 +12,7 @@#include <linux/mm.h> #include <linux/string_helpers.h> #include <linux/sframe.h> +#include <linux/sort.h> #include <linux/unwind_types.h> #include <asm/unwind_sframe.h> #ifdef CONFIG_HAVE_UNWIND_KERNEL_SFRAME
@@ -1038,6 +1039,50 @@ void __init init_sframe_table(void) sframe_init = true; } +static int sframe_sort_cmp_fde (const void *a,const void *b) +{ +const struct sframe_fde_v3 *fde_a = a, *fde_b = b; +unsigned long func_start_a, func_start_b; + + func_start_a = (unsigned long )fde_a + fde_a->func_start_off; + func_start_b = (unsigned long )fde_b + fde_b->func_start_off; + +return cmp_int (func_start_a, func_start_b); +} + +static void sframe_sort_swap_fde (void *a,void *b,int size) +{ +struct sframe_fde_v3 *fde_a = a, *fde_b = b; +struct sframe_fde_v3 temp; +long delta; + +/* Swap potentially unaligned FDE */ +memcpy (&temp, fde_a,sizeof (struct sframe_fde_v3 )); +memcpy (fde_a, fde_b,sizeof (struct sframe_fde_v3 )); +memcpy (fde_b, &temp,sizeof (struct sframe_fde_v3 )); + +/* Adjust FDE function start offset from FDE */ + delta = (long )((unsigned long )fde_b - (unsigned long )fde_a); + fde_a->func_start_off += delta; + fde_b->func_start_off -= delta; +} + +static int sframe_sort_fdes (struct sframe_section *sec) +{ +void *fdes = (void *)sec->fdes_start; +size_t num_fdes = sec->num_fdes; + +if (sec->sec_type !=SFRAME_KERNEL ) +return -EINVAL ; +if (sec->fdes_sorted) +return 0 ; + +sort (fdes, num_fdes,sizeof (struct sframe_fde_v3 ), + sframe_sort_cmp_fde, sframe_sort_swap_fde); + sec->fdes_sorted = true; +return 0 ; +} +void sframe_module_init (struct module *mod,void *sframe,size_t sframe_size,void *text,size_t text_size) {
@@ -1053,6 +1098,8 @@ void sframe_module_init(struct module *mod, void *sframe, size_t sframe_size,if (WARN_ON (sframe_read_header (sec)))return ; +if (WARN_ON (sframe_sort_fdes (sec))) +return ;if (WARN_ON (sframe_validate_section (sec)))return ;
Regards,
Jens
Signature · 6 lines
Jens Remus Linux on Z Development (D3303) [email protected] / [email protected] 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/
Quoted 3 lines · Dylan Hatch
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)"?
kernel/unwind/sframe.c +4 -0
@@ -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)))
kernel/unwind/sframe_debug.h +12 -0
@@ -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
Signature · 6 lines
Jens Remus Linux on Z Development (D3303) [email protected] / [email protected] 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/
Mark Rutland
reviewerRe: [PATCH v5 8/8] unwind: arm64: Use sframe to unwind interrupt frames
In reply to Dylan HatchHi Dylan,
Thanks for putting this together. I think this is looking pretty good. However, there are some things that aren't quite right and need some work, which I've commented on below.
More generally, there are a few things that aren't addressed by this series that we will also need to address. Importantly:
(1) For correctness, we'll need to address a latent issue with unwinding across an fgraph return trampoline, where the return address is transiently unrecoverable.
Before this series, that doesn't matter for livepatching because the livepatching code isn't called synchronously within the fgraph handler, and unwinds which cross an exception boundary are marked as unreliable.
After this series, that does matter as we can unwind across an exception boundary, and might happen to interrupt that transient window.
I think we can solve that with some restructuring of that code, restoring the original address *before* removing that from the fgraph return stack, and ensuring that the unwinder can find it.
I'm not immediately sure whether kretprobes has a similar issue.
(2) To make unwinding generally possible, we'll need to annotate some assembly functions as unwindable. We'll need to do that for string routines under lib/, and probably some crypto code, but we don't need to do that for most code in head.S, entry.S, etc.
The vast majority of relevant assembly functions are leaf functions (where the return address is never moved out of the LR), so we can probably get away with a simple annotation for those that avoids the need for open-coded CFI directives everywhere.
I've pushed some reliable stacktrace tests to:
git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git stacktrace/tests
That finds the fgraph issue (regardless of this series). When merged with this series triggers a warning in kunwind_next_frame_record_meta(), where unwind_next_frame_sframe() calls that erroneously as a fallback.
As noted below, I think that fallback path should be removed, and unwind_next_frame_sframe() should return an error in that case.
Quoted 7 lines · Dylan Hatch
Add
unwind_next_frame_sframe()function to unwind by sframe info if present. Use this method at exception boundaries, falling back to frame-pointer unwind only on failure. In such failure cases, the stacktrace is considered unreliable.During normal unwind, prefer frame pointer unwind (for better performance) with sframe as a backup.
We should certainly use SFrame at an exception boundary. However, when frame point unwind fails I do not think we should use it as a backup. That only fails when something is already wrong, and an SFrame unwind isn't necessarily going to be better. I think we should immediately fail in those cases.
Quoted 32 lines
This change restores the LR behavior originally introduced in commit
c2c6b27b5aa14fa2("arm64: stacktrace: unwind exception boundaries"), But later removed in commit32ed1205682e("arm64: stacktrace: Skip reporting LR at exception boundaries")This can be done because the sframe data can be used to determine whether the LR is current for the PC value recovered from
pt_regsat the exception boundary.Signed-off-by Weinan Liu <[email protected]>Reviewed-by Prasanna Kumar T S M <[email protected]>Reviewed-by Jens Remus <[email protected]>Signed-off-by Dylan Hatch <[email protected]>--- arch/arm64/include/asm/stacktrace/common.h | 6 + arch/arm64/kernel/stacktrace.c | 246 +++++++++++++++++++-- 2 files changed, 232 insertions(+), 20 deletions(-)arch/arm64/include/asm/stacktrace/common.h +2
-0@@ -21,6 +21,8 @@ struct stack_info {* * @fp: The fp value in the frame record (or the real fp) * @pc: The lr value in the frame record (or the real lr) +* @sp: The sp value at the call site of the current function. +* @unreliable: Stacktrace is unreliable. * * @stack: The stack currently being unwound. * @stacks: An array of stacks which can be unwound.
arch/arm64/include/asm/stacktrace/common.h struct stack_info { · line 36
Quoted 6 lines
arch/arm64/include/asm/stacktrace/common.h +3
-0@@ -29,7 +31,11 @@ struct stack_info {struct unwind_state {unsigned long fp;unsigned long pc; +#ifdef CONFIG_HAVE_UNWIND_KERNEL_SFRAME +unsigned long sp; +#endif
As this is only used by the kernel unwinder (and not the hyp unwinder), this should live in struct kunwind_state in stacktrace.c.
That said, for unwinding across exception boundaries we should not need this, as the SP value will be in the pt_regs. If we only use SFrame for the exception boundary case, we can remove this entirely. I would strongly prefer that we do that.
arch/arm64/include/asm/stacktrace/common.h struct stack_info { · line 37
Quoted 1 line
arch/arm64/include/asm/stacktrace/common.h +1
-0+bool unreliable;
Likewise, this should live in struct kunwind_state.
arch/arm64/kernel/stacktrace.c line 17
Quoted 12 lines
arch/arm64/include/asm/stacktrace/common.h +0
-0struct stack_info stack;struct stack_info *stacks;int nr_stacks;arch/arm64/kernel/stacktrace.c +1
-0@@ -14,6 +14,7 @@#include <linux/sched/debug.h> #include <linux/sched/task_stack.h> #include <linux/stacktrace.h> +#include <linux/sframe.h>
Nit: these are supposed to be ordered alphabetically, so the include of <linux/sframe.h> should be just before <linux/stacktrace.h>.
Quoted 12 lines
arch/arm64/kernel/stacktrace.c +1
-0#include <asm/efi.h> #include <asm/irq.h> @@ -26,6 +27,7 @@ enum kunwind_source {KUNWIND_SOURCE_CALLER ,KUNWIND_SOURCE_TASK ,KUNWIND_SOURCE_REGS_PC , + KUNWIND_SOURCE_REGS_LR, }; union unwind_flags {
arch/arm64/kernel/stacktrace.c kunwind_init_from_regs(struct kunwind_state *state, · line 92
Quoted 6 lines
arch/arm64/kernel/stacktrace.c +3
-0@@ -85,6 +87,9 @@ kunwind_init_from_regs(struct kunwind_state *state, state->regs = regs; state->common.fp = regs->regs[29 ]; state->common.pc = regs->pc; +#ifdef CONFIG_HAVE_UNWIND_KERNEL_SFRAME + state->common.sp = regs->sp; +#endif
As above, I don't think we need to stash the SP, as it only matters when performing the next unwind from the KUNWIND_SOURCE_REGS_PC state, and in that state we have the regs.
arch/arm64/kernel/stacktrace.c kunwind_init_from_caller(struct kunwind_state *state) · line 115
Quoted 12 lines
arch/arm64/kernel/stacktrace.c +3
-0state->source =KUNWIND_SOURCE_REGS_PC ; }@@ -103,6 +108,9 @@ kunwind_init_from_caller(struct kunwind_state *state) state->common.fp = (unsigned long )__builtin_frame_address (1 ); state->common.pc = (unsigned long )__builtin_return_address (0 ); +#ifdef CONFIG_HAVE_UNWIND_KERNEL_SFRAME + state->common.sp = (unsigned long )__builtin_frame_address (0 ); +#endif state->source =KUNWIND_SOURCE_CALLER ; }
This is not correct. On arm64, __builtin_frame_address(0) returns the address of the current function's frame record. That's not the same as the SP of the caller (which would necessarily differ by at least the size of that frame record).
For example, the following:
void *return_own_frame(void)
{
return __builtin_frame_address(0);
}... is compiled by GCC 15.2.0 as:
0000000000000000 <return_own_frame>: 0: d503233f paciasp 4: a9bf7bfd stp x29, x30, [sp, #-16]! 8: 910003fd mov x29, sp c: aa1d03e0 mov x0, x29 10: a8c17bfd ldp x29, x30, [sp], #16 14: d50323bf autiasp 18: d65f03c0 ret 1c: d503201f nop
As above, I think we can remove unwind_state:sp entirely, and omit this.
arch/arm64/kernel/stacktrace.c kunwind_init_from_task(struct kunwind_state *state, · line 139
Quoted 9 lines
arch/arm64/kernel/stacktrace.c +3
-0@@ -124,6 +132,9 @@ kunwind_init_from_task(struct kunwind_state *state, state->common.fp =thread_saved_fp (task); state->common.pc =thread_saved_pc (task); +#ifdef CONFIG_HAVE_UNWIND_KERNEL_SFRAME + state->common.sp =thread_saved_sp (task); +#endif state->source =KUNWIND_SOURCE_TASK ; }
As above, I think we can remove unwind_state:sp entirely, and omit this.
In contrast to kunwind_init_from_caller() above, given the way the cpu_switch_to() assembly function saves the FP/PC/SP, those should all be consistent with the values in the caller immediately after the caller is returned to.
Quoted 9 lines
arch/arm64/kernel/stacktrace.c +0
-1@@ -181,7 +192,6 @@ int kunwind_next_regs_pc(struct kunwind_state *state) state->regs = regs; state->common.pc = regs->pc; state->common.fp = regs->regs[29 ]; - state->regs =NULL ; state->source =KUNWIND_SOURCE_REGS_PC ;return 0 ; }
arch/arm64/kernel/stacktrace.c kunwind_next_frame_record(struct kunwind_state *state) · line 252
Quoted 6 lines
arch/arm64/kernel/stacktrace.c +3
-0@@ -237,6 +247,9 @@ kunwind_next_frame_record(struct kunwind_state *state)unwind_consume_stack (&state->common, info, fp,sizeof (*record)); +#ifdef CONFIG_HAVE_UNWIND_KERNEL_SFRAME + state->common.sp = state->common.fp; +#endif
This is not correct. The caller's frame record can be anywhere in the caller's stack frame, and we definitely have cases today where FP != SP at a function call boundary.
For example, the add_random_kstack_offset() logic in invoke_syscall() typically results in the SP being decremented after the frame record has been placed on the stack.
That looks roughly like the following:
void callee(void *ptr);
void caller(size_t size)
{
void *ptr = __builtin_alloca(size);
callee(ptr);
}... which GCC 15.2.0 can compile as:
0000000000000000 <caller>: 0: d503233f paciasp 4: 91003c00 add x0, x0, #0xf 8: a9bf7bfd stp x29, x30, [sp, #-16]! c: 927cec00 and x0, x0, #0xfffffffffffffff0 10: 910003fd mov x29, sp 14: cb2063ff sub sp, sp, x0 18: 910003e0 mov x0, sp 1c: 94000000 bl 0 <callee> 20: 910003bf mov sp, x29 24: a8c17bfd ldp x29, x30, [sp], #16 28: d50323bf autiasp 2c: d65f03c0 ret
As above, I think we can remove unwind_state:sp entirely, and omit this.
Quoted 27 lines
arch/arm64/kernel/stacktrace.c +20
-0state->common.fp = new_fp; state->common.pc = new_pc; state->source =KUNWIND_SOURCE_FRAME ;@@ -244,6 +257,176 @@ kunwind_next_frame_record(struct kunwind_state *state)return 0 ; } +#ifdef CONFIG_HAVE_UNWIND_KERNEL_SFRAME + +static __always_inline struct stack_info * +get_word (struct unwind_state *state,unsigned long *word) +{ +unsigned long addr = *word; +struct stack_info *info; + + info =unwind_find_stack (state, addr,sizeof (addr)); +if (!info) +return info; + + *word =READ_ONCE (*(unsigned long *)addr); + +return info; +} + +static __always_inline int +get_consume_word (struct unwind_state *state,unsigned long *word) +{
arch/arm64/kernel/stacktrace.c kunwind_next_frame_record(struct kunwind_state *state) · line 289
Quoted 10 lines
arch/arm64/kernel/stacktrace.c +10
-0+struct stack_info *info; +unsigned long addr = *word; + + info =get_word (state, word); +if (!info) +return -EINVAL ; + +unwind_consume_stack (state, info, addr,sizeof (addr)); +return 0 ; +}
I was hoping that we wouldn't need these if we only used SFrame to determine whether to use the LR or frame record, but I see that there could be cases where the frame record might be partially constructed.
arch/arm64/kernel/stacktrace.c kunwind_next_frame_record(struct kunwind_state *state) · line 302
Quoted 13 lines
arch/arm64/kernel/stacktrace.c +13
-0+ +/* +* Unwind to the next frame according to sframe. +*/ +static __always_inline int +unwind_next_frame_sframe (struct kunwind_state *state) +{ +struct unwind_frame frame; +unsigned long cfa, fp, ra; +enum kunwind_source source =KUNWIND_SOURCE_FRAME ; +struct pt_regs *regs = state->regs; + +int err;
As above, we should only use this for unwinding from the regs, after a KUNWIND_SOURCE_REGS_PC step.
With that in mind, it would be good to:
(1) Rename this to something like kunwind_next_regs_sframe(). Note 'kunwind' rather than 'unwind' for consistency with the rest of this file.
(2) Add the following sanity checks:
if (WARN_ON_ONCE(state->source != KUNWIND_SOURCE_REGS_PC))
return -EINVAL;
if (WARN_ON_ONCE(!state->regs))
return -EINVAL;
... which will also allow the code below to be simplified.Quoted 5 lines
arch/arm64/kernel/stacktrace.c +5
-0+ +/* FP/SP alignment 8 bytes */ +if (state->common.fp &0x7 || state->common.sp &0x7 ) +return -EINVAL ; +
arch/arm64/kernel/stacktrace.c kunwind_next_frame_record(struct kunwind_state *state) · line 317
Quoted 10 lines
arch/arm64/kernel/stacktrace.c +10
-0+/* +* Most/all outermost functions are not visible to sframe. So, check for +* a meta frame record if the sframe lookup fails. +*/ + err =sframe_find_kernel (state->common.pc, &frame); +if (err) +return kunwind_next_frame_record_meta (state); + +if (frame.outermost) +return -ENOENT ;
I don't think we ever expect an outermost frame within the kernel. We haven't added any annotations for that, and we expect to unwind all the way to a FRAME_META_TYPE_FINAL frame.
We cannot fall back to kunwind_next_frame_record_meta() here. We don't know that the next frame is a meta frame (and this results in a warning noted above), and we don't know the result is going to be reliable if we don't have SFrame data, so the right thing to do is return an error.
I think this should be:
/* * A kernel unwind should always end at a FRAME_META_TYPE_FINAL * frame. There should be no outermost frames within the kernel. */ if (frame.outermost) return -EINVAL; err = sframe_find_kernel(state->common.pc, &frame); if (err) return -EINVAL;
Quoted 7 lines
arch/arm64/kernel/stacktrace.c +7
-0+/* Get the Canonical Frame Address (CFA) */ +switch (frame.cfa.rule) { +case UNWIND_CFA_RULE_SP_OFFSET : + cfa = state->common.sp; +break ; +case UNWIND_CFA_RULE_FP_OFFSET : +if (state->common.fp < state->common.sp)
arch/arm64/kernel/stacktrace.c kunwind_next_frame_record(struct kunwind_state *state) · line 335
Quoted 10 lines
arch/arm64/kernel/stacktrace.c +10
-0+return -EINVAL ; + cfa = state->common.fp; +break ; +case UNWIND_CFA_RULE_REG_OFFSET : +case UNWIND_CFA_RULE_REG_OFFSET_DEREF : +/* regs only available in topmost/interrupt frame */ +if (!regs || frame.cfa.regnum >30 ) +return -EINVAL ; + cfa = regs->regs[frame.cfa.regnum]; +break ;
Do we ever expect to see UNWIND_CFA_RULE_REG_OFFSET or UNWIND_CFA_RULE_REG_OFFSET_DEREF in practice for kernel code?
arch/arm64/kernel/stacktrace.c kunwind_next_frame_record(struct kunwind_state *state) · line 348
Quoted 13 lines
arch/arm64/kernel/stacktrace.c +13
-0+default : +WARN_ON_ONCE (1 ); +return -EINVAL ; + } + cfa += frame.cfa.offset; + +/* +* CFA typically points to a higher address than RA or FP, so don't +* consume from the stack when we read it. +*/ +if (frame.cfa.rule &UNWIND_RULE_DEREF && + !get_word (&state->common, &cfa)) +return -EINVAL ;
Per the switch above, this could only be UNWIND_CFA_RULE_REG_OFFSET_DEREF. As above, do we ever expect to encounter that in practice for kernel code?
arch/arm64/kernel/stacktrace.c kunwind_next_frame_record(struct kunwind_state *state) · line 352
Quoted 4 lines
arch/arm64/kernel/stacktrace.c +4
-0+ +/* CFA alignment 8 bytes */ +if (cfa &0x7 ) +return -EINVAL ;
If the CFA is the SP upon entry to the function, then per AAPCS64 rules it should be aligned to 16 bytes. Otherwise, where has this 8 byte alignment requirement come from? Does SFrame mandate that?
arch/arm64/kernel/stacktrace.c kunwind_next_frame_record(struct kunwind_state *state) · line 363
Quoted 11 lines
arch/arm64/kernel/stacktrace.c +11
-0+ +/* Get the Return Address (RA) */ +switch (frame.ra.rule) { +case UNWIND_RULE_RETAIN : +/* regs only available in topmost/interrupt frame */ +if (!regs) +return -EINVAL ; + ra = regs->regs[30 ]; + source =KUNWIND_SOURCE_REGS_LR ; +break ; +/* UNWIND_USER_RULE_CFA_OFFSET not implemented on purpose */
It would be better for the comment to say *why* that's not implemented.
I assume that's because UNWIND_USER_RULE_CFA_OFFSET would mean that the return address is a stack address, and that's obviously not legitimate.
arch/arm64/kernel/stacktrace.c kunwind_next_frame_record(struct kunwind_state *state) · line 374
Quoted 11 lines
arch/arm64/kernel/stacktrace.c +11
-0+case UNWIND_RULE_CFA_OFFSET_DEREF : + ra = cfa + frame.ra.offset; +break ; +case UNWIND_RULE_REG_OFFSET : +case UNWIND_RULE_REG_OFFSET_DEREF : +/* regs only available in topmost/interrupt frame */ +if (!regs) +return -EINVAL ; + ra = regs->regs[frame.cfa.regnum]; + ra += frame.ra.offset; +break ;
Do we ever expect UNWIND_RULE_REG_OFFSET or UNWIND_RULE_REG_OFFSET_DEREF in practice for kernel code?
I don't think we expect UNWIND_RULE_REG_OFFSET unless that's sometimes used instead of UNWIND_RULE_RETAIN to express that the return address is in x30 (with zero offset).
Similarly, if the address is on the stack it should be in a frame record. Would we ever expect UNWIND_RULE_REG_OFFSET_DEREF rather than UNWIND_RULE_CFA_OFFSET_DEREF?
arch/arm64/kernel/stacktrace.c kunwind_next_frame_record(struct kunwind_state *state) · line 385
Quoted 11 lines
arch/arm64/kernel/stacktrace.c +11
-0+default : +WARN_ON_ONCE (1 ); +return -EINVAL ; + } + +/* Get the Frame Pointer (FP) */ +switch (frame.fp.rule) { +case UNWIND_RULE_RETAIN : + fp = state->common.fp; +break ; +/* UNWIND_USER_RULE_CFA_OFFSET not implemented on purpose */
As for RA, the comment should explain why that's not implemented.
Quoted 13 lines
arch/arm64/kernel/stacktrace.c +13
-0+case UNWIND_RULE_CFA_OFFSET_DEREF : + fp = cfa + frame.fp.offset; +break ; +case UNWIND_RULE_REG_OFFSET : +case UNWIND_RULE_REG_OFFSET_DEREF : +/* regs only available in topmost/interrupt frame */ +if (!regs) +return -EINVAL ; + fp = regs->regs[frame.fp.regnum]; + fp += frame.fp.offset; +break ; +default : +WARN_ON_ONCE (1 );
arch/arm64/kernel/stacktrace.c kunwind_next_frame_record(struct kunwind_state *state) · line 408
Quoted 10 lines
arch/arm64/kernel/stacktrace.c +10
-0+return -EINVAL ; + } + +/* +* Consume RA and FP from the stack. The frame record puts FP at a lower +* address than RA, so we always read FP first. +*/ +if (frame.fp.rule &UNWIND_RULE_DEREF && + !get_word (&state->common, &fp)) +return -EINVAL ;
Why is this get_word() rather than get_consume_word()?
arch/arm64/kernel/stacktrace.c kunwind_next_frame_record(struct kunwind_state *state) · line 415
Quoted 7 lines
arch/arm64/kernel/stacktrace.c +7
-0+ +if (frame.ra.rule &UNWIND_RULE_DEREF && +get_consume_word (&state->common, &ra)) +return -EINVAL ; + + state->common.pc = ra; + state->common.sp = cfa;
As above, the SP can be removed.
Quoted 21 lines
arch/arm64/kernel/stacktrace.c +14
-0+ state->common.fp = fp; + + state->source = source; + +return 0 ; +} + +#else /* !CONFIG_HAVE_UNWIND_KERNEL_SFRAME */ + +static __always_inline int +unwind_next_frame_sframe (struct kunwind_state *state) {return -EINVAL ; } + +#endif /* !CONFIG_HAVE_UNWIND_KERNEL_SFRAME*/ +/* * Unwind from one frame record (A) to the next frame record (B). * @@ -259,12 +442,25 @@ kunwind_next(struct kunwind_state *state) state->flags.all =0 ;switch (state->source) {
arch/arm64/kernel/stacktrace.c kunwind_next(struct kunwind_state *state) · line 454
Quoted 10 lines
arch/arm64/kernel/stacktrace.c +10
-0+case KUNWIND_SOURCE_REGS_PC : + err =unwind_next_frame_sframe (state); + +if (err && err != -ENOENT ) { +/* Fallback to FP based unwinder */ + err =kunwind_next_frame_record (state); + state->common.unreliable = true; + } + state->regs =NULL ; +break ;
This makes sense to me.
arch/arm64/kernel/stacktrace.c kunwind_next(struct kunwind_state *state) · line 461
Quoted 8 lines
arch/arm64/kernel/stacktrace.c +3
-1case KUNWIND_SOURCE_FRAME :case KUNWIND_SOURCE_CALLER :case KUNWIND_SOURCE_TASK : -case KUNWIND_SOURCE_REGS_PC : +case KUNWIND_SOURCE_REGS_LR : err =kunwind_next_frame_record (state); +if (err && err != -ENOENT ) + err =unwind_next_frame_sframe (state);
This isn't sound as we cannot track the SP reliably across all transitions.
If a regular frame pointer unwind has failed, something is already wrong, and we should give up immediately.
Please remove the fallback to sframe here.
arch/arm64/kernel/stacktrace.c kunwind_next(struct kunwind_state *state) · line 464
Quoted 3 lines
arch/arm64/kernel/stacktrace.c +1
-0break ; +default :
No need for this whitespace change.
arch/arm64/kernel/stacktrace.c kunwind_stack_walk(kunwind_consume_fn consume_state, · line 551
Quoted 9 lines
arch/arm64/kernel/stacktrace.c +3
-0err = -EINVAL ; }@@ -350,6 +546,9 @@ kunwind_stack_walk(kunwind_consume_fn consume_state, .common = { .stacks = stacks, .nr_stacks = ARRAY_SIZE(stacks), +#ifdef CONFIG_HAVE_UNWIND_KERNEL_SFRAME + .sp = 0, +#endif
As above, this can go.
Thanks,
Mark.
Quoted 73 lines
arch/arm64/kernel/stacktrace.c +25
-18}, };@@ -390,34 +589,40 @@ noinline noinstr void arch_stack_walk(stack_trace_consume_fn consume_entry,kunwind_stack_walk (arch_kunwind_consume_entry, &data, task, regs); } +struct kunwind_reliable_consume_entry_data { +stack_trace_consume_fn consume_entry; +void *cookie; +bool unreliable; +}; + static __always_inline bool -arch_reliable_kunwind_consume_entry (const struct kunwind_state *state,void *cookie) +arch_kunwind_reliable_consume_entry (const struct kunwind_state *state,void *cookie) { -/* -* At an exception boundary we can reliably consume the saved PC. We do -* not know whether the LR was live when the exception was taken, and -* so we cannot perform the next unwind step reliably. -* -* All that matters is whether the *entire* unwind is reliable, so give -* up as soon as we hit an exception boundary. -*/ -if (state->source ==KUNWIND_SOURCE_REGS_PC ) -return false; +struct kunwind_reliable_consume_entry_data *data = cookie; -return arch_kunwind_consume_entry (state, cookie); +if (state->common.unreliable) { + data->unreliable = true; +return false; + } +return data->consume_entry (data->cookie, state->common.pc); } -noinline noinstr int arch_stack_walk_reliable(stack_trace_consume_fn consume_entry, -void *cookie, -struct task_struct *task) +noinline notrace int arch_stack_walk_reliable( +stack_trace_consume_fn consume_entry, +void *cookie,struct task_struct *task) { -struct kunwind_consume_entry_data data = { +struct kunwind_reliable_consume_entry_data data = { .consume_entry = consume_entry, .cookie = cookie, + .unreliable = false, }; -return kunwind_stack_walk (arch_reliable_kunwind_consume_entry, &data, - task,NULL ); +kunwind_stack_walk (arch_kunwind_reliable_consume_entry, &data, task,NULL ); + +if (data.unreliable) +return -EINVAL ; + +return 0 ; }struct bpf_unwind_consume_entry_data {@@ -452,6 +657,7 @@ static const char *state_source_string(const struct kunwind_state *state)case KUNWIND_SOURCE_CALLER :return "C" ;case KUNWIND_SOURCE_TASK :return "T" ;case KUNWIND_SOURCE_REGS_PC :return "P" ; +case KUNWIND_SOURCE_REGS_LR :return "L" ;default :return "U" ; } }Signature · 1 line
2.54.0.545.g6539524ca2-goog
Re: [PATCH v5 8/8] unwind: arm64: Use sframe to unwind interrupt frames
Hello Mark,
I mostly have comments regarding your the SFrame related remarks.
Quoted 9 lines · Mark Rutland
Thanks for putting this together. I think this is looking pretty good. However, there are some things that aren't quite right and need some work, which I've commented on below.
(2) To make unwinding generally possible, we'll need to annotate some assembly functions as unwindable. We'll need to do that for string routines under
lib/, and probably some crypto code, but we don't need to do that for most code inhead.S,entry.S, etc.
Quoted 4 lines
The vast majority of relevant assembly functions are leaf functions (where the return address is never moved out of the LR), so we can probably get away with a simple annotation for those that avoids the need for open-coded CFI directives everywhere.
Wrapping them in .cfi_startproc ... .cfi_endproc should do. For instance by extending SYM_FUNC_START() and SYM_FUNC_END() or introducing flavors that do. Or where you thinking of something else?
Quoted 87 lines · Dylan Hatch
Quoted 13 lines
arch/arm64/include/asm/stacktrace/common.h +2
-0@@ -21,6 +21,8 @@ struct stack_info {* * @fp: The fp value in the frame record (or the real fp) * @pc: The lr value in the frame record (or the real lr) +* @sp: The sp value at the call site of the current function. +* @unreliable: Stacktrace is unreliable. * * @stack: The stack currently being unwound. * @stacks: An array of stacks which can be unwound. arch/arm64/include/asm/stacktrace/common.h struct stack_info { · line 36
Quoted 6 lines
arch/arm64/include/asm/stacktrace/common.h +3
-0@@ -29,7 +31,11 @@ struct stack_info {struct unwind_state {unsigned long fp;unsigned long pc; +#ifdef CONFIG_HAVE_UNWIND_KERNEL_SFRAME +unsigned long sp; +#endif As this is only used by the kernel unwinder (and not the hyp unwinder), this should live in struct
kunwind_stateinstacktrace.c.That said, for unwinding across exception boundaries we should not need this, as the SP value will be in the
pt_regs. If we only use SFrame for the exception boundary case, we can remove this entirely. I would strongly prefer that we do that.Quoted 4 lines
arch/arm64/kernel/stacktrace.c +2
-0+/* +* Unwind to the next frame according to sframe. arch/arm64/kernel/stacktrace.c kunwind_next_frame_record(struct kunwind_state *state) · line 302
Quoted 10 lines
arch/arm64/kernel/stacktrace.c +10
-0+*/ +static __always_inline int +unwind_next_frame_sframe (struct kunwind_state *state) +{ +struct unwind_frame frame; +unsigned long cfa, fp, ra; +enum kunwind_source source =KUNWIND_SOURCE_FRAME ; +struct pt_regs *regs = state->regs; + +int err;As above, we should only use this for unwinding from the regs, after a
KUNWIND_SOURCE_REGS_PCstep.With that in mind, it would be good to:
(1) Rename this to something like
kunwind_next_regs_sframe(). Note 'kunwind' rather than 'unwind' for consistency with the rest of this file.(2) Add the following sanity checks:
if (WARN_ON_ONCE(state->source != KUNWIND_SOURCE_REGS_PC)) return -EINVAL; if (WARN_ON_ONCE(!state->regs)) return -EINVAL; ... which will also allow the code below to be simplified.Quoted 5 lines
arch/arm64/kernel/stacktrace.c +5
-0+ +/* FP/SP alignment 8 bytes */ +if (state->common.fp &0x7 || state->common.sp &0x7 ) +return -EINVAL ; +arch/arm64/kernel/stacktrace.c kunwind_next_frame_record(struct kunwind_state *state) · line 317
Quoted 10 lines
arch/arm64/kernel/stacktrace.c +10
-0+/* +* Most/all outermost functions are not visible to sframe. So, check for +* a meta frame record if the sframe lookup fails. +*/ + err =sframe_find_kernel (state->common.pc, &frame); +if (err) +return kunwind_next_frame_record_meta (state); + +if (frame.outermost) +return -ENOENT ;I don't think we ever expect an outermost frame within the kernel. We haven't added any annotations for that, and we expect to unwind all the way to a
FRAME_META_TYPE_FINALframe.We cannot fall back to
kunwind_next_frame_record_meta()here. We don't know that the next frame is a meta frame (and this results in a warning noted above), and we don't know the result is going to be reliable if we don't have SFrame data, so the right thing to do is return an error.
Quoted 8 lines
I think this should be:
/* * A kernel unwind should always end at a FRAME_META_TYPE_FINAL * frame. There should be no outermost frames within the kernel. */ if (frame.outermost) return -EINVAL;
Makes sense.
Quoted 9 lines
err = sframe_find_kernel(state->common.pc, &frame); if (err) return -EINVAL;arch/arm64/kernel/stacktrace.c kunwind_next_frame_record(struct kunwind_state *state) · line 322
Quoted 4 lines
arch/arm64/kernel/stacktrace.c +4
-0+/* Get the Canonical Frame Address (CFA) */ +switch (frame.cfa.rule) { +case UNWIND_CFA_RULE_SP_OFFSET : + cfa = state->common.sp;
IIUC you suggest this to be changed as follows?
cfa = regs->regs[31];
Quoted 8 lines
Quoted 8 lines
arch/arm64/kernel/stacktrace.c +8
-0+break ; +case UNWIND_CFA_RULE_FP_OFFSET : +if (state->common.fp < state->common.sp) +return -EINVAL ; + cfa = state->common.fp; +break ; +case UNWIND_CFA_RULE_REG_OFFSET : +case UNWIND_CFA_RULE_REG_OFFSET_DEREF :
Quoted 8 lines
arch/arm64/kernel/stacktrace.c kunwind_next_frame_record(struct kunwind_state *state) · line 335
Quoted 5 lines
arch/arm64/kernel/stacktrace.c +5
-0+/* regs only available in topmost/interrupt frame */ +if (!regs || frame.cfa.regnum >30 ) +return -EINVAL ; + cfa = regs->regs[frame.cfa.regnum]; +break ;Do we ever expect to see
UNWIND_CFA_RULE_REG_OFFSETorUNWIND_CFA_RULE_REG_OFFSET_DEREFin practice for kernel code?
No. Those can only occur with SFrame V3 flexible FDE, which are currently not generated by GNU assembler for arm64/aarch64, and thus could be omitted in the arm64-specific kernel sframe unwinder:
I must admit that while reviewing I thought it would be future-proof to have support for rules that can only be represented with SFrame V3 flexible FDE, even if they are currently not used on arm64. Ideally kunwind_next_sframe() could be made common, if another architecture would implement kernel unwinding using sframe.
Quoted 10 lines
Quoted 10 lines
arch/arm64/kernel/stacktrace.c +9
-0+default : +WARN_ON_ONCE (1 ); +return -EINVAL ; + } + cfa += frame.cfa.offset; + +/* +* CFA typically points to a higher address than RA or FP, so don't +* consume from the stack when we read it.
Quoted 8 lines
arch/arm64/kernel/stacktrace.c kunwind_next_frame_record(struct kunwind_state *state) · line 348
Quoted 4 lines
arch/arm64/kernel/stacktrace.c +4
-0+*/ +if (frame.cfa.rule &UNWIND_RULE_DEREF && + !get_word (&state->common, &cfa)) +return -EINVAL ;Per the switch above, this could only be
UNWIND_CFA_RULE_REG_OFFSET_DEREF. As above, do we ever expect to encounter that in practice for kernel code?
No. See above.
Quoted 9 lines
arch/arm64/kernel/stacktrace.c kunwind_next_frame_record(struct kunwind_state *state) · line 352
Quoted 5 lines
arch/arm64/kernel/stacktrace.c +4
-0+ +/* CFA alignment 8 bytes */ +if (cfa &0x7 ) +return -EINVAL ;If the CFA is the SP upon entry to the function, then per AAPCS64 rules it should be aligned to 16 bytes. Otherwise, where has this 8 byte alignment requirement come from? Does SFrame mandate that?
That originates from the common unwind user logic (see kernel/unwind/user.c, unwind_user_next_common()), which currently assumes 8-byte/4-byte SP alignment for all 64-bit/32-bit architectures.
So checking for 16-byte alignment here would make sense.
Quoted 12 lines
arch/arm64/kernel/stacktrace.c kunwind_next_frame_record(struct kunwind_state *state) · line 363
Quoted 12 lines
arch/arm64/kernel/stacktrace.c +11
-0+ +/* Get the Return Address (RA) */ +switch (frame.ra.rule) { +case UNWIND_RULE_RETAIN : +/* regs only available in topmost/interrupt frame */ +if (!regs) +return -EINVAL ; + ra = regs->regs[30 ]; + source =KUNWIND_SOURCE_REGS_LR ; +break ; +/* UNWIND_USER_RULE_CFA_OFFSET not implemented on purpose */
Nit: s/UNWIND_USER_RULE_CFA_OFFSET/UNWIND_RULE_CFA_OFFSET/
Quoted 5 lines
It would be better for the comment to say *why* that's not implemented.
I assume that's because
UNWIND_USER_RULE_CFA_OFFSETwould mean that the return address is a stack address, and that's obviously not legitimate.
That and SFrame V3 currently cannot represent FP/RA as CFA + offset (i.e. UNWIND_RULE_CFA_OFFSET; .cfi_val_offset FP/RA).
The comment originates from the common unwind user logic (see kernel/unwind/user.c). I am open to improve that. What about:
/*
* UNWIND_RULE_CFA_OFFSET not implemented on purpose, as a stack
* address cannot be a legitimate return address value. It is
* also not used (e.g. not represented in sframe). */
Quoted 15 lines
arch/arm64/kernel/stacktrace.c kunwind_next_frame_record(struct kunwind_state *state) · line 374
Quoted 12 lines
arch/arm64/kernel/stacktrace.c +11
-0+case UNWIND_RULE_CFA_OFFSET_DEREF : + ra = cfa + frame.ra.offset; +break ; +case UNWIND_RULE_REG_OFFSET : +case UNWIND_RULE_REG_OFFSET_DEREF : +/* regs only available in topmost/interrupt frame */ +if (!regs) +return -EINVAL ; + ra = regs->regs[frame.cfa.regnum]; + ra += frame.ra.offset; +break ;Do we ever expect
UNWIND_RULE_REG_OFFSETorUNWIND_RULE_REG_OFFSET_DEREFin practice for kernel code?
No. See above (SFrame V3 flexible FDE).
Quoted 4 lines
I don't think we expect
UNWIND_RULE_REG_OFFSETunless that's sometimes used instead ofUNWIND_RULE_RETAINto express that the return address is in x30 (with zero offset).
No. Unless there would be nonsense .cfi_register 30, 30, which would require SFrame V3 flexible FDE to be represented.
@Indu: We may consider to treat .cfi_register <reg>, <reg> (for FP/RA) like .cfi_restore <reg> in the GNU assembler?
Quoted 4 lines
Similarly, if the address is on the stack it should be in a frame record. Would we ever expect
UNWIND_RULE_REG_OFFSET_DEREFrather thanUNWIND_RULE_CFA_OFFSET_DEREF?
No. See above (SFrame V3 flexible FDE).
Quoted 14 lines
arch/arm64/kernel/stacktrace.c kunwind_next_frame_record(struct kunwind_state *state) · line 385
Quoted 12 lines
arch/arm64/kernel/stacktrace.c +11
-0+default : +WARN_ON_ONCE (1 ); +return -EINVAL ; + } + +/* Get the Frame Pointer (FP) */ +switch (frame.fp.rule) { +case UNWIND_RULE_RETAIN : + fp = state->common.fp; +break ; +/* UNWIND_USER_RULE_CFA_OFFSET not implemented on purpose */ As for RA, the comment should explain why that's not implemented.
I am open to improve the comment in the the common unwind user logic. What about:
/* * UNWIND_RULE_CFA_OFFSET not implemented on purpose, as it is * not used (e.g. not represented in sframe). */
Quoted 12 lines
arch/arm64/kernel/stacktrace.c kunwind_next_frame_record(struct kunwind_state *state) · line 396
Quoted 12 lines
arch/arm64/kernel/stacktrace.c +11
-0+case UNWIND_RULE_CFA_OFFSET_DEREF : + fp = cfa + frame.fp.offset; +break ; +case UNWIND_RULE_REG_OFFSET : +case UNWIND_RULE_REG_OFFSET_DEREF : +/* regs only available in topmost/interrupt frame */ +if (!regs) +return -EINVAL ; + fp = regs->regs[frame.fp.regnum]; + fp += frame.fp.offset; +break ;
Likewise neither UNWIND_RULE_REG_OFFSET nor UNWIND_RULE_REG_OFFSET_DEREF can currently occur on arm64. See above (SFrame V3 flexible FDE).
Quoted 25 lines
arch/arm64/kernel/stacktrace.c kunwind_next_frame_record(struct kunwind_state *state) · line 408
Quoted 12 lines
arch/arm64/kernel/stacktrace.c +12
-0+default : +WARN_ON_ONCE (1 ); +return -EINVAL ; + } + +/* +* Consume RA and FP from the stack. The frame record puts FP at a lower +* address than RA, so we always read FP first. +*/ +if (frame.fp.rule &UNWIND_RULE_DEREF && + !get_word (&state->common, &fp)) +return -EINVAL ;Why is this
get_word()rather thanget_consume_word()?arch/arm64/kernel/stacktrace.c kunwind_next_frame_record(struct kunwind_state *state) · line 415
Quoted 7 lines
arch/arm64/kernel/stacktrace.c +7
-0+ +if (frame.ra.rule &UNWIND_RULE_DEREF && +get_consume_word (&state->common, &ra)) +return -EINVAL ; + + state->common.pc = ra; + state->common.sp = cfa;As above, the SP can be removed.
Quoted 6 lines
arch/arm64/kernel/stacktrace.c kunwind_next_frame_record(struct kunwind_state *state) · line 421
Quoted 6 lines
arch/arm64/kernel/stacktrace.c +6
-0+ state->common.fp = fp; + + state->source = source; + +return 0 ; +}
Regards,
Jens
Signature · 6 lines
Jens Remus Linux on Z Development (D3303) [email protected] / [email protected] 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/
Mark Rutland
reviewerRe: [PATCH v5 8/8] unwind: arm64: Use sframe to unwind interrupt frames
Quoted 3 lines · Jens Remus
Hello Mark,
I mostly have comments regarding your the SFrame related remarks.
Thanks for this; I have a few more questions and comments below.
Quoted 10 lines · Mark Rutland
Quoted 9 lines
Thanks for putting this together. I think this is looking pretty good. However, there are some things that aren't quite right and need some work, which I've commented on below.
(2) To make unwinding generally possible, we'll need to annotate some assembly functions as unwindable. We'll need to do that for string routines under
lib/, and probably some crypto code, but we don't need to do that for most code inhead.S,entry.S, etc.
Quoted 8 lines
Quoted 4 lines
The vast majority of relevant assembly functions are leaf functions (where the return address is never moved out of the LR), so we can probably get away with a simple annotation for those that avoids the need for open-coded CFI directives everywhere.
Wrapping them in .cfi_startproc ... .cfi_endproc should do. For instance by extending
SYM_FUNC_START()andSYM_FUNC_END()or introducing flavors that do. Or where you thinking of something else?
I was expecting we'd do something like that, either with distinct versions, or some entirely separate annotation.
We can't override SYM_FUNC_START() or SYM_FUNC_END() since those are also used for non-leaf functions. The bulk of the work is going to be making sure we only annotate leaf functions specifically, which will require some human analysis.
Quoted 28 lines
Quoted 27 lines · Dylan Hatch
Quoted 12 lines
arch/arm64/include/asm/stacktrace/common.h +2
-0@@ -21,6 +21,8 @@ struct stack_info {* * @fp: The fp value in the frame record (or the real fp) * @pc: The lr value in the frame record (or the real lr) +* @sp: The sp value at the call site of the current function. +* @unreliable: Stacktrace is unreliable. * * @stack: The stack currently being unwound. * @stacks: An array of stacks which can be unwound. arch/arm64/include/asm/stacktrace/common.h struct stack_info { · line 36
Quoted 6 lines
arch/arm64/include/asm/stacktrace/common.h +3
-0@@ -29,7 +31,11 @@ struct stack_info {struct unwind_state {unsigned long fp;unsigned long pc; +#ifdef CONFIG_HAVE_UNWIND_KERNEL_SFRAME +unsigned long sp; +#endif As this is only used by the kernel unwinder (and not the hyp unwinder), this should live in struct
kunwind_stateinstacktrace.c.That said, for unwinding across exception boundaries we should not need this, as the SP value will be in the
pt_regs. If we only use SFrame for the exception boundary case, we can remove this entirely. I would strongly prefer that we do that.
Quoted 8 lines
Quoted 4 lines
arch/arm64/include/asm/stacktrace/common.h struct stack_info { · line 40
Quoted 4 lines
arch/arm64/include/asm/stacktrace/common.h +4
-0+/* Get the Canonical Frame Address (CFA) */ +switch (frame.cfa.rule) { +case UNWIND_CFA_RULE_SP_OFFSET : + cfa = state->common.sp;IIUC you suggest this to be changed as follows?
cfa = regs->regs[31];
I was suggesting:
cfa = regs->sp;
Note: arm64's struct pt_regs has:
union {
struct user_pt_regs user_regs;
struct {
u64 regs[31];
u64 sp;
u64 pc;
u64 pstate;
};
}; ... so regs->regs[31] would be an out-of-bounds array access.
[...]
Quoted 11 lines
Quoted 10 lines
arch/arm64/include/asm/stacktrace/common.h struct stack_info {
Quoted 7 lines
arch/arm64/include/asm/stacktrace/common.h +7
-0+case UNWIND_CFA_RULE_REG_OFFSET : +case UNWIND_CFA_RULE_REG_OFFSET_DEREF : +/* regs only available in topmost/interrupt frame */ +if (!regs || frame.cfa.regnum >30 ) +return -EINVAL ; + cfa = regs->regs[frame.cfa.regnum]; +break ;Do we ever expect to see
UNWIND_CFA_RULE_REG_OFFSETorUNWIND_CFA_RULE_REG_OFFSET_DEREFin practice for kernel code?
Quoted 5 lines
No. Those can only occur with SFrame V3 flexible FDE, which are currently not generated by GNU assembler for arm64/aarch64, and thus could be omitted in the arm64-specific kernel sframe unwinder:
Ok.
Do we know whether there are currently cases on aarch64 that cannot be encoded in SFrame (without flexible FDE), or whether SFrame without flexible FDE is sufficient for arm64 as-is? ... or do we have counter-examples today?
Looking at:
https://sourceware.org/binutils/docs/sframe-spec.html#Flexible-FDE-Type-Interpretation-1
For arm64 I'm not sure whether we'd encounter the DRAP or stack realignment cases within the kernel (perhaps with SVE?), nor whether the Register-based RA/FP Locations cases would apply if we assume that we continue to use frame records.
[... ]
Quoted 5 lines
I must admit that while reviewing I thought it would be future-proof to have support for rules that can only be represented with SFrame V3 flexible FDE, even if they are currently not used on arm64. Ideally
kunwind_next_sframe()could be made common, if another architecture would implement kernel unwinding using sframe.
While I understand that principle, I think that for now it would be better to keep this arch-specific and minimal:
* We have arch-specific concerns (e.g. the FRAME_META_TYPE_FINAL frames), and factoring that into generic code is going to be painful to adapt (which we're likely to need to do in the near future), and to maintain going forwards. Keeping that arch-specific for now will make it easier/quicker to get to a stable state.
* Code which isn't used is liable to be wrong or made wrong by accident. For example, with all the SP cases I mentioned in my initial reply.
We can certainly look at making that more generic in future, but for now I'd prefer to omit the code that cannot be used (and have some sort of build or boot/module-load time check that SFrame only has elements that we expect), and make sure that we thoroughly test the cases that do exist in practice.
Do we expect SFrame V3 flexible FDE to be generated by toolchains in the near future?
[...]
Quoted 8 lines
Quoted 7 lines
arch/arm64/include/asm/stacktrace/common.h
Quoted 3 lines
arch/arm64/include/asm/stacktrace/common.h +3
-0+/* CFA alignment 8 bytes */ +if (cfa &0x7 ) +return -EINVAL ;If the CFA is the SP upon entry to the function, then per AAPCS64 rules it should be aligned to 16 bytes. Otherwise, where has this 8 byte alignment requirement come from? Does SFrame mandate that?
Quoted 5 lines
That originates from the common unwind user logic (see
kernel/unwind/user.c,unwind_user_next_common()), which currently assumes 8-byte/4-byte SP alignment for all 64-bit/32-bit architectures.So checking for 16-byte alignment here would make sense.
Just to confirm, am I correct to understand that the SFrame definition of CFA is intended to be the same as the DWARF definition of CFA, and so for arm64 the CFA is the SP when the function is called?
That's the case for DWARF on arm64:
https://github.com/ARM-software/abi-aa/releases/download/2025Q4/aadwarf64.pdf
https://github.com/ARM-software/abi-aa/blob/daa7a94ca55973736c0e434a67a6e4bbcd35d7fa/aadwarf64/aadwarf64.rst
| The CFA is the value of the stack pointer (sp) at the call site in the | previous frame.
I couldn't find an explciit statement to that effect in:
https://sourceware.org/binutils/docs/sframe-spec.html
... but I guess that is implied, given the other bits inherited from DWARF.
I see that the documented behaviour for CFA on AMD64 and s390x are consistent with their DWARF behaviour.
Quoted 23 lines
Quoted 11 lines
arch/arm64/include/asm/stacktrace/common.h
Quoted 11 lines
arch/arm64/include/asm/stacktrace/common.h +11
-0+ +/* Get the Return Address (RA) */ +switch (frame.ra.rule) { +case UNWIND_RULE_RETAIN : +/* regs only available in topmost/interrupt frame */ +if (!regs) +return -EINVAL ; + ra = regs->regs[30 ]; + source =KUNWIND_SOURCE_REGS_LR ; +break ; +/* UNWIND_USER_RULE_CFA_OFFSET not implemented on purpose */ Nit: s/UNWIND_USER_RULE_CFA_OFFSET/UNWIND_RULE_CFA_OFFSET/
Quoted 5 lines
It would be better for the comment to say *why* that's not implemented.
I assume that's because
UNWIND_USER_RULE_CFA_OFFSETwould mean that the return address is a stack address, and that's obviously not legitimate.That and SFrame V3 currently cannot represent FP/RA as CFA + offset (i.e.
UNWIND_RULE_CFA_OFFSET; .cfi_val_offset FP/RA).
Quoted 8 lines
The comment originates from the common unwind user logic (see
kernel/unwind/user.c). I am open to improve that. What about:/*
*UNWIND_RULE_CFA_OFFSETnot implemented on purpose, as a stack
* address cannot be a legitimate return address value. It is
* also not used (e.g. not represented in sframe). */
I'd go with something simpler, e.g.
/* * UNWIND_RULE_CFA_OFFSET doesn't make sense for RA. * The return address cannot legitimately be a stack addres. */
[...]
Quoted 7 lines
Quoted 4 lines
I don't think we expect
UNWIND_RULE_REG_OFFSETunless that's sometimes used instead ofUNWIND_RULE_RETAINto express that the return address is in x30 (with zero offset).No. Unless there would be nonsense .cfi_register 30, 30, which would require SFrame V3 flexible FDE to be represented.
Ok.
Quoted 8 lines
@Indu: We may consider to treat .cfi_register <reg>, <reg> (for FP/RA) like .cfi_restore <reg> in the GNU assembler?
Quoted 3 lines
Similarly, if the address is on the stack it should be in a frame record. Would we ever expect
UNWIND_RULE_REG_OFFSET_DEREFrather thanUNWIND_RULE_CFA_OFFSET_DEREF?No. See above (SFrame V3 flexible FDE).
Ok.
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
arch/arm64/include/asm/stacktrace/common.h +5
-0+default : +WARN_ON_ONCE (1 ); +return -EINVAL ; + } +Quoted 8 lines
arch/arm64/include/asm/stacktrace/common.h
Quoted 6 lines
arch/arm64/include/asm/stacktrace/common.h +6
-0+/* Get the Frame Pointer (FP) */ +switch (frame.fp.rule) { +case UNWIND_RULE_RETAIN : + fp = state->common.fp; +break ; +/* UNWIND_USER_RULE_CFA_OFFSET not implemented on purpose */ As for RA, the comment should explain why that's not implemented.
Quoted 7 lines
I am open to improve the comment in the the common unwind user logic. What about:
/* * UNWIND_RULE_CFA_OFFSET not implemented on purpose, as it is * not used (e.g. not represented in sframe). */
For me, this wording raises more questions, e.g.
* Does 'not used' mean that toolchains don't use that, or that the spec doesn't permit that?
* Does 'not represented' mean that this is not represntable, or that toolchains currently don't generate SFrame with the appropriate elements.
IIUC you're saying that this *is* representable with flexible FDE, but current toolchains don't generate that.
Mark.
Re: [PATCH v5 8/8] unwind: arm64: Use sframe to unwind interrupt frames
Quoted 21 lines · Mark Rutland
Quoted 11 lines · Jens Remus
Quoted 9 lines · Mark Rutland
Thanks for putting this together. I think this is looking pretty good. However, there are some things that aren't quite right and need some work, which I've commented on below.
(2) To make unwinding generally possible, we'll need to annotate some assembly functions as unwindable. We'll need to do that for string routines under
lib/, and probably some crypto code, but we don't need to do that for most code inhead.S,entry.S, etc.Quoted 8 lines
Quoted 4 lines
The vast majority of relevant assembly functions are leaf functions (where the return address is never moved out of the LR), so we can probably get away with a simple annotation for those that avoids the need for open-coded CFI directives everywhere.
Wrapping them in .cfi_startproc ... .cfi_endproc should do. For instance by extending
SYM_FUNC_START()andSYM_FUNC_END()or introducing flavors that do. Or where you thinking of something else?
Quoted 7 lines
I was expecting we'd do something like that, either with distinct versions, or some entirely separate annotation.
We can't override
SYM_FUNC_START()orSYM_FUNC_END()since those are also used for non-leaf functions. The bulk of the work is going to be making sure we only annotate leaf functions specifically, which will require some human analysis.
Makes sense.
Quoted 53 lines
Quoted 28 lines
Quoted 27 lines · Dylan Hatch
Quoted 12 lines
arch/arm64/include/asm/stacktrace/common.h +2
-0@@ -21,6 +21,8 @@ struct stack_info {* * @fp: The fp value in the frame record (or the real fp) * @pc: The lr value in the frame record (or the real lr) +* @sp: The sp value at the call site of the current function. +* @unreliable: Stacktrace is unreliable. * * @stack: The stack currently being unwound. * @stacks: An array of stacks which can be unwound. arch/arm64/include/asm/stacktrace/common.h struct stack_info { · line 36
Quoted 6 lines
arch/arm64/include/asm/stacktrace/common.h +3
-0@@ -29,7 +31,11 @@ struct stack_info {struct unwind_state {unsigned long fp;unsigned long pc; +#ifdef CONFIG_HAVE_UNWIND_KERNEL_SFRAME +unsigned long sp; +#endif As this is only used by the kernel unwinder (and not the hyp unwinder), this should live in struct
kunwind_stateinstacktrace.c.That said, for unwinding across exception boundaries we should not need this, as the SP value will be in the
pt_regs. If we only use SFrame for the exception boundary case, we can remove this entirely. I would strongly prefer that we do that.Quoted 8 lines
Quoted 4 lines
arch/arm64/include/asm/stacktrace/common.h struct stack_info { · line 40
Quoted 4 lines
arch/arm64/include/asm/stacktrace/common.h +4
-0+/* Get the Canonical Frame Address (CFA) */ +switch (frame.cfa.rule) { +case UNWIND_CFA_RULE_SP_OFFSET : + cfa = state->common.sp;IIUC you suggest this to be changed as follows?
cfa = regs->regs[31];I was suggesting:
cfa = regs->sp;Note: arm64's struct
pt_regshas:union { struct user_pt_regs user_regs; struct { u64 regs[31]; u64 sp; u64 pc; u64 pstate; }; };
Quoted 1 line
... so regs->regs[31] would be an out-of-bounds array access.
Aww, my bad! Of course!
Quoted 18 lines
[...]
Quoted 15 lines
Quoted 10 lines
arch/arm64/include/asm/stacktrace/common.h
Quoted 7 lines
arch/arm64/include/asm/stacktrace/common.h +7
-0+case UNWIND_CFA_RULE_REG_OFFSET : +case UNWIND_CFA_RULE_REG_OFFSET_DEREF : +/* regs only available in topmost/interrupt frame */ +if (!regs || frame.cfa.regnum >30 ) +return -EINVAL ; + cfa = regs->regs[frame.cfa.regnum]; +break ;Do we ever expect to see
UNWIND_CFA_RULE_REG_OFFSETorUNWIND_CFA_RULE_REG_OFFSET_DEREFin practice for kernel code?No. Those can only occur with SFrame V3 flexible FDE, which are currently not generated by GNU assembler for arm64/aarch64, and thus could be omitted in the arm64-specific kernel sframe unwinder:
Quoted 8 lines
Quoted 1 line
Ok.
Do we know whether there are currently cases on aarch64 that cannot be encoded in SFrame (without flexible FDE), or whether SFrame without flexible FDE is sufficient for arm64 as-is? ... or do we have counter-examples today?
Not that I am aware of. IIUC this is why Indu, the SFrame maintainer, did not enable SFrame V3 flexible FDE for arm64/aarch64 in the GNU assembler.
Quoted 8 lines
Looking at:
https://sourceware.org/binutils/docs/sframe-spec.html#Flexible-FDE-Type-Interpretation-1
For arm64 I'm not sure whether we'd encounter the DRAP or stack realignment cases within the kernel (perhaps with SVE?), nor whether the Register-based RA/FP Locations cases would apply if we assume that we continue to use frame records.
@Indu: Can you provide more insight?
Quoted 17 lines
[... ]
Quoted 5 lines
I must admit that while reviewing I thought it would be future-proof to have support for rules that can only be represented with SFrame V3 flexible FDE, even if they are currently not used on arm64. Ideally
kunwind_next_sframe()could be made common, if another architecture would implement kernel unwinding using sframe.While I understand that principle, I think that for now it would be better to keep this arch-specific and minimal:
* We have arch-specific concerns (e.g. the
FRAME_META_TYPE_FINALframes), and factoring that into generic code is going to be painful to adapt (which we're likely to need to do in the near future), and to maintain going forwards. Keeping that arch-specific for now will make it easier/quicker to get to a stable state.
Quoted 8 lines
* Code which isn't used is liable to be wrong or made wrong by accident. For example, with all the SP cases I mentioned in my initial reply.
We can certainly look at making that more generic in future, but for now I'd prefer to omit the code that cannot be used (and have some sort of build or boot/module-load time check that SFrame only has elements that we expect), and make sure that we thoroughly test the cases that do exist in practice.
Makes sense.
Quoted 2 lines
Do we expect SFrame V3 flexible FDE to be generated by toolchains in the near future?
There is work in progress to implement SFrame V3 generation in LLVM. Their implementation could be less restrictive regarding to which SFrame V3 feature to enable on arm64/aarch64. But even then for SFrame V3 flexible FDE to be generated there must be DWARF CFI patterns that can only be represented using those. So if those do not exist (see your previous question above), then they should not be generated.
@Indu: What are your thoughts on this?
Quoted 10 lines
[...]
Quoted 8 lines
Quoted 7 lines
arch/arm64/include/asm/stacktrace/common.h
Quoted 3 lines
arch/arm64/include/asm/stacktrace/common.h +3
-0+/* CFA alignment 8 bytes */ +if (cfa &0x7 ) +return -EINVAL ;If the CFA is the SP upon entry to the function, then per AAPCS64 rules it should be aligned to 16 bytes. Otherwise, where has this 8 byte alignment requirement come from? Does SFrame mandate that?
Quoted 8 lines
Quoted 5 lines
That originates from the common unwind user logic (see
kernel/unwind/user.c,unwind_user_next_common()), which currently assumes 8-byte/4-byte SP alignment for all 64-bit/32-bit architectures.So checking for 16-byte alignment here would make sense.
Just to confirm, am I correct to understand that the SFrame definition of CFA is intended to be the same as the DWARF definition of CFA, and so
Correct.
Quoted 1 line
for arm64 the CFA is the SP when the function is called?
Correct.
Quoted 9 lines
That's the case for DWARF on arm64:
https://github.com/ARM-software/abi-aa/releases/download/2025Q4/aadwarf64.pdf
https://github.com/ARM-software/abi-aa/blob/daa7a94ca55973736c0e434a67a6e4bbcd35d7fa/aadwarf64/aadwarf64.rst| The CFA is the value of the stack pointer (sp) at the call site in the | previous frame.
Quoted 6 lines
I couldn't find an explciit statement to that effect in:
https://sourceware.org/binutils/docs/sframe-spec.html
... but I guess that is implied, given the other bits inherited from DWARF.
I assume so.
Quoted 3 lines
I see that the documented behaviour for CFA on AMD64 and s390x are consistent with their DWARF behaviour.
Yes.
Quoted 33 lines
Quoted 24 lines
Quoted 12 lines
arch/arm64/include/asm/stacktrace/common.h
Quoted 12 lines
arch/arm64/include/asm/stacktrace/common.h +11
-0+ +/* Get the Return Address (RA) */ +switch (frame.ra.rule) { +case UNWIND_RULE_RETAIN : +/* regs only available in topmost/interrupt frame */ +if (!regs) +return -EINVAL ; + ra = regs->regs[30 ]; + source =KUNWIND_SOURCE_REGS_LR ; +break ; +/* UNWIND_USER_RULE_CFA_OFFSET not implemented on purpose */ Nit: s/UNWIND_USER_RULE_CFA_OFFSET/UNWIND_RULE_CFA_OFFSET/
Quoted 5 lines
It would be better for the comment to say *why* that's not implemented.
I assume that's because
UNWIND_USER_RULE_CFA_OFFSETwould mean that the return address is a stack address, and that's obviously not legitimate.That and SFrame V3 currently cannot represent FP/RA as CFA + offset (i.e.
UNWIND_RULE_CFA_OFFSET; .cfi_val_offset FP/RA).Quoted 8 lines
The comment originates from the common unwind user logic (see
kernel/unwind/user.c). I am open to improve that. What about:/*
*UNWIND_RULE_CFA_OFFSETnot implemented on purpose, as a stack
* address cannot be a legitimate return address value. It is
* also not used (e.g. not represented in sframe). */
Quoted 6 lines
I'd go with something simpler, e.g.
/* * UNWIND_RULE_CFA_OFFSET doesn't make sense for RA. * The return address cannot legitimately be a stack addres. */
Thanks! I have updated the comments accordingly in my latest unwind user sframe patch series sent today:
[PATCH v14 14/19] unwind_user: Flexible FP/RA recovery rules
https://lore.kernel.org/all/[email protected]/
[...]
Quoted 22 lines
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
arch/arm64/include/asm/stacktrace/common.h +5
-0+default : +WARN_ON_ONCE (1 ); +return -EINVAL ; + } +Quoted 8 lines
arch/arm64/include/asm/stacktrace/common.h
Quoted 6 lines
arch/arm64/include/asm/stacktrace/common.h +6
-0+/* Get the Frame Pointer (FP) */ +switch (frame.fp.rule) { +case UNWIND_RULE_RETAIN : + fp = state->common.fp; +break ; +/* UNWIND_USER_RULE_CFA_OFFSET not implemented on purpose */ As for RA, the comment should explain why that's not implemented.
Quoted 7 lines
I am open to improve the comment in the the common unwind user logic. What about:
/* * UNWIND_RULE_CFA_OFFSET not implemented on purpose, as it is * not used (e.g. not represented in sframe). */
Quoted 4 lines
For me, this wording raises more questions, e.g.
* Does 'not used' mean that toolchains don't use that, or that the spec doesn't permit that?
unwind user currently only supports frame pointer, with SFrame to be hopefully added soon. Out of these only SFrame requires ("uses") these elaborated rules.
Quoted 4 lines
* Does 'not represented' mean that this is not represntable, or that toolchains currently don't generate SFrame with the appropriate elements.
In DWARF CFI it is representable using .cfi_val_offset <FP>, <offset>. But SFrame V3 currently cannot represent this:
"Note that, using a value of 0 as padding data word, does mean that currently, e.g., for RA [JR: FP likewise], the rule RA = CFA + 0 cannot be encoded. NB: RA = CFA + 0 is distinct from RA = *(CFA + 0)."
https://sourceware.org/binutils/docs/sframe-spec.html#Flexible-FDE-Type-Interpretation-1
Quoted 3 lines
IIUC you're saying that this *is* representable with flexible FDE, but current toolchains don't generate that.
Thanks for the feedback! I changed it as follows to clarify:
/* * UNWIND_USER_RULE_CFA_OFFSET is currently not used for FP * (e.g. SFrame cannot represent this rule). */
Regards,
Jens
Signature · 6 lines
Jens Remus Linux on Z Development (D3303) [email protected] / [email protected] 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/
Quoted 9 lines · Jens Remus
Quoted 3 lines · Dylan Hatch
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.
Sounds good, I'll add this in as a separate patch in the next version.
Quoted 4 lines
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)"?
I don't have a strong preference, though I agree it makes sense to indicate that the section is from a module. For now I'll add the parentheses "(<module-name>)".
Quoted 52 lines
kernel/unwind/sframe.c +4
-0@@ -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)))kernel/unwind/sframe_debug.h +12
-0@@ -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)
[email protected] / [email protected]
Quoted 3 lines
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/
Thanks for the suggestion,
Dylan
Re: [PATCH v5 8/8] unwind: arm64: Use sframe to unwind interrupt frames
In reply to Mark RutlandHi Mark,
Thanks for all the feedback and help on this. I'm planning on getting your comments addressed in the coming days, but I have some initial clarifying questions.
Quoted 19 lines · Mark Rutland
Hi Dylan,
Thanks for putting this together. I think this is looking pretty good. However, there are some things that aren't quite right and need some work, which I've commented on below.
More generally, there are a few things that aren't addressed by this series that we will also need to address. Importantly:
(1) For correctness, we'll need to address a latent issue with unwinding across an fgraph return trampoline, where the return address is transiently unrecoverable.
Before this series, that doesn't matter for livepatching because the livepatching code isn't called synchronously within the fgraph handler, and unwinds which cross an exception boundary are marked as unreliable.
Quoted 7 lines
After this series, that does matter as we can unwind across an exception boundary, and might happen to interrupt that transient window.
I think we can solve that with some restructuring of that code, restoring the original address *before* removing that from the fgraph return stack, and ensuring that the unwinder can find it.
If my understanding is correct, the issue arrises in return_to_handler as the return address is recovered:
mov x0, sp
bl ftrace_return_to_handler // addr = ftrace_return_to_hander(fregs); mov x30, x0 // restore the original return address
Because ftrace_return_to_handler pops the return address from the return stack before it can be restored into the LR, it cannot be recovered.
Based on this, I believe you are suggesting to restructure this code path such that the return address is removed from the return stack only after it has been restored to LR. But since kernel/trace/fgraph.c is core kernel code, will this end up requiring either (1) a similar restructuring of other arches supporting ftrace, or (2) an arm64-specific implementation of this recovery logic?
It looks to me like there is essentially the same recovery pattern on other arches; is there a reason this transient unrecoverability isn't an issue for reliable unwind on other platforms?
Quoted 8 lines
I'm not immediately sure whether kretprobes has a similar issue.
(2) To make unwinding generally possible, we'll need to annotate some assembly functions as unwindable. We'll need to do that for string routines under
lib/, and probably some crypto code, but we don't need to do that for most code inhead.S,entry.S, etc.
Quoted 4 lines
The vast majority of relevant assembly functions are leaf functions (where the return address is never moved out of the LR), so we can probably get away with a simple annotation for those that avoids the need for open-coded CFI directives everywhere.
Are you suggesting something like a SYM_LEAF_FUNC_(START|END), that wraps CFI directives for leaf functions?
Quoted 8 lines
I've pushed some reliable stacktrace tests to:
git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.gitstacktrace/testsThat finds the fgraph issue (regardless of this series). When merged with this series triggers a warning in
kunwind_next_frame_record_meta(), whereunwind_next_frame_sframe()calls that erroneously as a fallback.
Thanks for the pointer on these tests, they're super useful! I've been able to reproduce the fgraph failure you mentioned.
Thanks,
Dylan
Re: [PATCH v5 8/8] unwind: arm64: Use sframe to unwind interrupt frames
Hello Dylan and Mark!
Quoted 26 lines · Dylan Hatch
Quoted 12 lines · Mark Rutland
More generally, there are a few things that aren't addressed by this series that we will also need to address. Importantly:
(1) For correctness, we'll need to address a latent issue with unwinding across an fgraph return trampoline, where the return address is transiently unrecoverable.
Before this series, that doesn't matter for livepatching because the livepatching code isn't called synchronously within the fgraph handler, and unwinds which cross an exception boundary are marked as unreliable.
Quoted 7 lines
After this series, that does matter as we can unwind across an exception boundary, and might happen to interrupt that transient window.
I think we can solve that with some restructuring of that code, restoring the original address *before* removing that from the fgraph return stack, and ensuring that the unwinder can find it.
If my understanding is correct, the issue arrises in
return_to_handleras the return address is recovered:
Quoted 7 lines
mov x0, sp bl
ftrace_return_to_handler// addr =ftrace_return_to_hander(fregs); mov x30, x0 // restore the original return addressBecause
ftrace_return_to_handlerpops the return address from the return stack before it can be restored into the LR, it cannot be recovered.
Based on reliable-stacktrace.rst section "4.4 Rewriting of return addresses" I wonder whether the following might work:
- If an unwound RA points at return_to_handler the actual RA needs to be obtained using ftrace_graph_ret_addr(). This might already be taken into account if ftrace_graph_ret_addr() is used unconditionally.
- If an unwound RA points into return_to_handler() mark the stack trace as unreliable. This could be accomplished by marking LR in return_to_handler() as undefined (i.e. .cfi_undefined 30) to use SFrame's outermost frame indication to stop and mark the stack trace as unreliable:
arch/arm64/kernel/entry-ftrace.S +8 -0
@@ -329,8 +329,12 @@ SYM_FUNC_END(ftrace_stub_graph) * @fp is checked against the value passed by ftrace_graph_caller(). */ SYM_CODE_START(return_to_handler) + .cfi_startproc + /* Mark unwinding of LR as unreliable */ + .cfi_undefined 30 /* Make room for ftrace_regs */ sub sp, sp, #FREGS_SIZE + .cfi_adjust_cfa_offset -FREGS_SIZE /* Save return value regs */ stp x0, x1, [sp, #FREGS_X0]
@@ -344,6 +348,8 @@ SYM_CODE_START(return_to_handler) mov x0, sp bl ftrace_return_to_handler // addr = ftrace_return_to_hander(fregs); mov x30, x0 // restore the original return address + /* Mark unwinding of LR as reliable */ + .cfi_restore 30 /* Restore return value regs */ ldp x0, x1, [sp, #FREGS_X0]
@@ -351,7 +357,9 @@ SYM_CODE_START(return_to_handler) ldp x4, x5, [sp, #FREGS_X4] ldp x6, x7, [sp, #FREGS_X6] add sp, sp, #FREGS_SIZE + .cfi_adjust_cfa_offset FREGS_SIZE ret + .cfi_endproc SYM_CODE_END(return_to_handler) #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
Notes regarding above:
- return_to_handler() saves the caller's FP in ftrace_regs but never restores it. I suppose this is because ftrace_regs is an input to ftrace_return_to_handler(). The DWARF CFI above assumes SP and FP can be restored at all times as SP=CFA and FP=FP.
- One might be tempted to add a .cfi_register 30, 0 after the call to ftrace_return_to_handler. This would be wrong, because if unwinding comes from ftrace_return_to_handler() the unwound RA will point there and the unwinding logic would erroneously assume x0 to contain the RA.
- The DWARF CFI could be simplified as follows to just convey that unwinding through return_to_handler is impossible at all times:
arch/arm64/kernel/entry-ftrace.S +4 -0
@@ -329,6 +329,9 @@ SYM_FUNC_END(ftrace_stub_graph) * @fp is checked against the value passed by ftrace_graph_caller(). */ SYM_CODE_START(return_to_handler) + .cfi_startproc simple + /* Mark unwinding of LR as unreliable */ + .cfi_undefined 30 /* Make room for ftrace_regs */ sub sp, sp, #FREGS_SIZE
@@ -353,5 +356,6 @@ SYM_CODE_START(return_to_handler) add sp, sp, #FREGS_SIZE ret + .cfi_endproc SYM_CODE_END(return_to_handler) #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
Quoted 8 lines
Based on this, I believe you are suggesting to restructure this code path such that the return address is removed from the return stack only after it has been restored to LR. But since
kernel/trace/fgraph.cis core kernel code, will this end up requiring either (1) a similar restructuring of other arches supporting ftrace, or (2) an arm64-specific implementation of this recovery logic?
Quoted 6 lines
It looks to me like there is essentially the same recovery pattern on other arches; is there a reason this transient unrecoverability isn't an issue for reliable unwind on other platforms?
Quoted 2 lines
I'm not immediately sure whether kretprobes has a similar issue.
Regards,
Jens
Signature · 6 lines
Jens Remus Linux on Z Development (D3303) [email protected] / [email protected] 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/
Mark Rutland
reviewerRe: [PATCH v5 8/8] unwind: arm64: Use sframe to unwind interrupt frames
In reply to Dylan HatchQuoted 37 lines · Dylan Hatch
Hi Mark,
Thanks for all the feedback and help on this. I'm planning on getting your comments addressed in the coming days, but I have some initial clarifying questions.
Quoted 19 lines · Mark Rutland
Hi Dylan,
Thanks for putting this together. I think this is looking pretty good. However, there are some things that aren't quite right and need some work, which I've commented on below.
More generally, there are a few things that aren't addressed by this series that we will also need to address. Importantly:
(1) For correctness, we'll need to address a latent issue with unwinding across an fgraph return trampoline, where the return address is transiently unrecoverable.
Before this series, that doesn't matter for livepatching because the livepatching code isn't called synchronously within the fgraph handler, and unwinds which cross an exception boundary are marked as unreliable.
Quoted 7 lines
After this series, that does matter as we can unwind across an exception boundary, and might happen to interrupt that transient window.
I think we can solve that with some restructuring of that code, restoring the original address *before* removing that from the fgraph return stack, and ensuring that the unwinder can find it.
If my understanding is correct, the issue arrises in
return_to_handleras the return address is recovered:
Quoted 7 lines
mov x0, sp
blftrace_return_to_handler// addr =ftrace_return_to_hander(fregs); mov x30, x0 // restore the original return addressBecause
ftrace_return_to_handlerpops the return address from the return stack before it can be restored into the LR, it cannot be recovered.
Yes.
To be clear, please don't worry about solving that for the next version of this series; let's get the SFrame bits into shape first. I just wanted to highlight that there's some more general work that we'll need to do.
I think we can *detect* this case (and mark the unwind as unreliable) with some tiny changes to the arm64 code. I'm happy to put that together.
Quoted 6 lines
Based on this, I believe you are suggesting to restructure this code path such that the return address is removed from the return stack only after it has been restored to LR. But since
kernel/trace/fgraph.cis core kernel code, will this end up requiring either (1) a similar restructuring of other arches supporting ftrace, or (2) an arm64-specific implementation of this recovery logic?
Yes, I am say that to *recover* the address we'd need to make changes to core code.
In the mean time we can *detect* this case with some minimal changes to arm64 code, and abort. As above, I'm happy to go put that together.
Quoted 3 lines
It looks to me like there is essentially the same recovery pattern on other arches; is there a reason this transient unrecoverability isn't an issue for reliable unwind on other platforms?
Yep; on all architectures there's a transient period where the address cannot be recovered. It's not a correctness issue so long as the architecture detects this case and marks the unwind as unreliable.
IIUC x86 will mark the unwind as unreliable in this case.
I don't know whether other architectures detect this reliably. That's a question for loonarch, parisc, powerpc, and s390 folk.
Quoted 7 lines
Quoted 7 lines
I'm not immediately sure whether kretprobes has a similar issue.
(2) To make unwinding generally possible, we'll need to annotate some assembly functions as unwindable. We'll need to do that for string routines under
lib/, and probably some crypto code, but we don't need to do that for most code inhead.S,entry.S, etc.
Quoted 7 lines
Quoted 4 lines
The vast majority of relevant assembly functions are leaf functions (where the return address is never moved out of the LR), so we can probably get away with a simple annotation for those that avoids the need for open-coded CFI directives everywhere.
Are you suggesting something like a
SYM_LEAF_FUNC_(START|END), that wraps CFI directives for leaf functions?
Yep; that's exactly the sort of thing I was thinking of.
That or have a seaprate annotation we can add, e.g.
SYM_FUNC_START(foo)SYM_FUN_END(foo)SYM_FUNC_IS_LEAF_AND_DOES_NOT_TOUCH_LR(foo)
Quoted 10 lines
Quoted 7 lines
I've pushed some reliable stacktrace tests to:
git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.gitstacktrace/testsThat finds the fgraph issue (regardless of this series). When merged with this series triggers a warning in
kunwind_next_frame_record_meta(), whereunwind_next_frame_sframe()calls that erroneously as a fallback.Thanks for the pointer on these tests, they're super useful! I've been able to reproduce the fgraph failure you mentioned.
Great!
Mark.
Mark Rutland
reviewerRe: [PATCH v5 8/8] unwind: arm64: Use sframe to unwind interrupt frames
In reply to Jens RemusQuoted 30 lines · Jens Remus
Quoted 14 lines · Dylan Hatch
Quoted 7 lines · Mark Rutland
(1) For correctness, we'll need to address a latent issue with unwinding across an fgraph return trampoline, where the return address is transiently unrecoverable.
I think we can solve that with some restructuring of that code, restoring the original address *before* removing that from the fgraph return stack, and ensuring that the unwinder can find it.
If my understanding is correct, the issue arrises in
return_to_handleras the return address is recovered:Quoted 7 lines
mov x0, sp bl
ftrace_return_to_handler// addr =ftrace_return_to_hander(fregs); mov x30, x0 // restore the original return addressBecause
ftrace_return_to_handlerpops the return address from the return stack before it can be restored into the LR, it cannot be recovered.Based on
reliable-stacktrace.rstsection "4.4 Rewriting of return addresses" I wonder whether the following might work:- If an unwound RA points at
return_to_handlerthe actual RA needs to be obtained usingftrace_graph_ret_addr(). This might already be taken into account ifftrace_graph_ret_addr()is used unconditionally.
Quoted 5 lines
- If an unwound RA points into
return_to_handler()mark the stack trace as unreliable. This could be accomplished by marking LR inreturn_to_handler()as undefined (i.e. .cfi_undefined 30) to use SFrame's outermost frame indication to stop and mark the stack trace as unreliable:
We don't currently have any CFI annotations for return_to_handler(), so if we interrupt that, any unwind will naturally be marked as unreliable.
The problem is that we can try an unwind from an interrupted *callee* of return_to_handler(). In that case, we'll unwind through return_to_handler() using the frame pointer, without consulting SFrame. In that case, the PC will be part-way through return_to_handler(), but we only call ftrace_graph_ret_addr() when the PC is the start of return_to_handler, and so we don't even try to recover the return address.
We can handle that better by checking whether the PC is *within* return_to_handler(), and aborting when the original return address cannot be recoverted. I'm happy to go put that together, nad longer term I would like to do the better reovery I described above such that we can *always* recover the return address.
Mark.
Re: [PATCH v5 3/8] arm64: entry: add unwind info for various kernel entries
In reply to Mark RutlandQuoted 18 lines · Mark Rutland
Hi Dylan,
Quoted 10 lines · Dylan Hatch
From: Weinan Liu <[email protected]>
DWARF CFI (Call Frame Information) specifies how to recover the return address and callee-saved registers at each PC in a given function. Compilers are able to generate the CFI annotations when they compile the code to assembly language. For handcrafted assembly, we need to annotate them by hand.
Annotate minimal CFI to enable stacktracing using SFrame for kernel exception entries through el1*_64_*() paths
I thought we were only consuming SFrame when unwinding an exeption boundary?
Quoted 7 lines
We shouldn't be taking exceptions _from_ the entry assembly functions unless something has gone horribly wrong, and so I don't see why we'd need CFI entries for the entry assembly functions.
Am I missing some reason we need CFI entries for the entry assembly functions? I strongly suspect it is not necessary to add these, and I'd prefer to omit them.
I believe the el1 entry functions are called in an exception, and are called before call_on_irq_stack. Example stacktrace segment:
[ 262.119564] handle_percpu_devid_irq+0xb4/0x348 [ 262.119913] handle_irq_desc+0x3c/0x68 [ 262.120196] generic_handle_domain_irq+0x20/0x40 [ 262.120678] gic_handle_irq+0x48/0xe0 [ 262.121005] call_on_irq_stack+0x30/0x48 [ 262.121412] do_interrupt_handler+0x88/0xa0 [ 262.121779] el1_interrupt+0x38/0x58 [ 262.122089] el1h_64_irq_handler+0x18/0x30 [ 262.122617] el1h_64_irq+0x6c/0x70 [ 262.123159] _raw_spin_unlock_irq+0x10/0x60 (P) [ 262.123720] __filemap_add_folio+0x200/0x580 (L) [ 262.124145] filemap_add_folio+0xec/0x300 [ 262.124674] page_cache_ra_unbounded+0x128/0x368 [ 262.125338] do_page_cache_ra+0x70/0x98 [ 262.125875] page_cache_ra_order+0x460/0x4e0
Here, el1h_64_irq is the last function that appears in the exception stack before _raw_spin_unlock_irq and __filemap_add_folio are recovered from the saved PC and LR, respectively. So we therefore need the CFI annotations in order to unwind through the full exception boundary.
Is my interpretation here correct?
Quoted 9 lines
Quoted 2 lines
and irq entries through
call_on_irq_stack()Needing some sort of unwind annotations for
call_on_irq_stack()makes sense to me, but don't we need something for other assembly functions too?We can interrupt things like
memset(); I assume we'll treat those as unreliable until annotated?
While looking into adding these annotations, I noticed a pattern where a sibling call is made to a local function:
SYM_FUNC_START(__pi_memset)alternative_if_not ARM64_HAS_MOPS
b __pi_memset_genericalternative_else_nop_endif
mov dst, dstin
setp [dst]!, count!, val_x
setm [dst]!, count!, val_x
sete [dst]!, count!, val_x retSYM_FUNC_END(__pi_memset)
In this case, do we consider the stacktrace unreliable since __pi_memset may not appear in the trace? Or is this not important because assembly functions cannot be directly livepatched anyway?
Thanks,
Dylan
Mark Rutland
reviewerRe: [PATCH v5 3/8] arm64: entry: add unwind info for various kernel entries
Quoted 20 lines · Dylan Hatch
Quoted 19 lines · Mark Rutland
Quoted 10 lines · Dylan Hatch
From: Weinan Liu <[email protected]>
DWARF CFI (Call Frame Information) specifies how to recover the return address and callee-saved registers at each PC in a given function. Compilers are able to generate the CFI annotations when they compile the code to assembly language. For handcrafted assembly, we need to annotate them by hand.
Annotate minimal CFI to enable stacktracing using SFrame for kernel exception entries through el1*_64_*() paths
I thought we were only consuming SFrame when unwinding an exeption boundary?
We shouldn't be taking exceptions _from_ the entry assembly functions unless something has gone horribly wrong, and so I don't see why we'd need CFI entries for the entry assembly functions.
Quoted 6 lines
Quoted 3 lines
Am I missing some reason we need CFI entries for the entry assembly functions? I strongly suspect it is not necessary to add these, and I'd prefer to omit them.
I believe the el1 entry functions are called in an exception, and are called before
call_on_irq_stack.
Yes, but I don't think that matters. See below for more details.
Quoted 11 lines
Example stacktrace segment:
[ 262.119564] handle_percpu_devid_irq+0xb4/0x348 [ 262.119913] handle_irq_desc+0x3c/0x68 [ 262.120196] generic_handle_domain_irq+0x20/0x40 [ 262.120678] gic_handle_irq+0x48/0xe0 [ 262.121005] call_on_irq_stack+0x30/0x48 [ 262.121412] do_interrupt_handler+0x88/0xa0 [ 262.121779] el1_interrupt+0x38/0x58 [ 262.122089] el1h_64_irq_handler+0x18/0x30 [ 262.122617] el1h_64_irq+0x6c/0x70
The segment immediately above can be unwound using FP, as frame records were created consistently, and there are no exception boundaries. No CFI needed.
It's legitimate to take an exception from parts of call_on_irq_stack(), so it makes sense for that to have CFI, but for the specific unwind segment above, CFI isn't necessary.
Everything in the stacktrace segment above was executed *after* HW took the exception.
<< EXCEPTION BOUNDARY HERE >>
Everything in the stacktrace segment(s) below was executed *before* HW took the exception.
The unwinder knows that it has crossed this exception boundary by virtue of finding a FRAME_META_TYPE_PT_REGS frame record.
Quoted 1 line
[ 262.123159] _raw_spin_unlock_irq+0x10/0x60 (P)
The unwinder knows that the value of pt_regs::pc was *definitely* the PC at the time the exception was taken, so that entry is reliable. No CFI needed.
Quoted 1 line
[ 262.123720] __filemap_add_folio+0x200/0x580 (L)
The unwinder doesn't know whether the LR should be used, and needs CFI to determine that.
After this point, an FP unwind can be used until we encounter the next exception boundary.
Quoted 4 lines
[ 262.124145] filemap_add_folio+0xec/0x300 [ 262.124674] page_cache_ra_unbounded+0x128/0x368 [ 262.125338] do_page_cache_ra+0x70/0x98 [ 262.125875] page_cache_ra_order+0x460/0x4e0
The segment immediately above can be unwound using FP. No CFI needed.
Quoted 7 lines
Here,
el1h_64_irqis the last function that appears in the exception stack before_raw_spin_unlock_irqand__filemap_add_folioare recovered from the saved PC and LR, respectively. So we therefore need the CFI annotations in order to unwind through the full exception boundary.Is my interpretation here correct?
Given you say "full exception boundary" here, I think we might be using the term "exception boundary" to mean different things.
As per the example above, I'm using "exception boundary" to mean the a point between two entries in the stacktrace where HW took an exception.
Did my comments on the example help?
Quoted 21 lines
Quoted 8 lines
Quoted 1 line
and irq entries through
call_on_irq_stack()Needing some sort of unwind annotations for
call_on_irq_stack()makes sense to me, but don't we need something for other assembly functions too?We can interrupt things like
memset(); I assume we'll treat those as unreliable until annotated?While looking into adding these annotations, I noticed a pattern where a sibling call is made to a local function:
SYM_FUNC_START(__pi_memset)alternative_if_notARM64_HAS_MOPS
b__pi_memset_genericalternative_else_nop_endifmov dst, dstin setp [dst]!, count!, val_x setm [dst]!, count!, val_x sete [dst]!, count!, val_x
Quoted 5 lines
ret
SYM_FUNC_END(__pi_memset)In this case, do we consider the stacktrace unreliable since
__pi_memsetmay not appear in the trace?
This is a tail-call, and __pi_memset_generic() will not return to __pi_memset(). Once the branch to __pi_memset_generic() has been executed, it's fine for __pi_memset() to not show up in the trace.
The key thing is that no more instructions from __pi_memset() itself will be executed unless it was called again (from its entry point).
Quoted 2 lines
Or is this not important because assembly functions cannot be directly livepatched anyway?
To the best of my knowledge, reliable stacktrace is only used to determine whether any thread is still within an old version of a patchable function (including where it's within a callee thereof).
I am not aware of a case where we'd need to detect whether a thread is still within a non-patchable function, but I can't rule out that as a possibility.
That's more of a question for the livepatching maintainers.
Thanks,
Mark.
Quoted 13 lines · Dylan Hatch
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.
Quoted 9 lines
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].
Not sure if related, but after updating my toolchain
(aarch64-linux-gnu-gcc (Debian 15.2.0-4) 15.2.0), I hit link errors:
ld.lld: error: arch/arm64/kernel/vdso/vgettimeofday.o:(.sframe) is being placed in '.sframe' ld.lld: error: arch/arm64/kernel/vdso/vgetrandom.o:(.sframe) is being placed in '.sframe`
I applied this series hoping that fix it, but it doesn't, so far I have this hack :
arch/arm64/kernel/vdso/vdso.lds.S +1 -1
@@ -77,7 +77,7 @@ SECTIONS /DISCARD/ : { *(.data .data.* .gnu.linkonce.d.* .sdata*) *(.bss .sbss .dynbss .dynsbss) - *(.eh_frame .eh_frame_hdr) + *(.eh_frame .eh_frame_hdr .sframe) } }
include/asm-generic/vmlinux.lds.h +1 -0
@@ -1064,6 +1064,7 @@/* ld.bfd warns about .gnu.version* even when not emitted */ \ *(.gnu.version*) \ *(__tracepoint_check) \ + *(.sframe) \#define DISCARDS \ /DISCARD/ : { \
Thanks,
Mostafa
Hi Mostafa,
Quoted 25 lines · Mostafa Saleh
Quoted 13 lines · Dylan Hatch
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.
Quoted 9 lines
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].
Quoted 4 lines
Not sure if related, but after updating my toolchain
(aarch64-linux-gnu-gcc (Debian 15.2.0-4) 15.2.0), I hit link errors:
ld.lld: error: arch/arm64/kernel/vdso/vgettimeofday.o:(.sframe) is being placed in '.sframe' ld.lld: error: arch/arm64/kernel/vdso/vgetrandom.o:(.sframe) is being placed in '.sframe`
Previously when developing against the SFrame V2 format, I had fixed these warnings with the VDSO Makefile change currently in this series:
arch/arm64/kernel/vdso/Makefile +1 -1
@@ -38,7 +38,7 @@ ccflags-y += -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO CC_FLAGS_REMOVE_VDSO := $(CC_FLAGS_FTRACE) -Os $(CC_FLAGS_SCS) \ $(RANDSTRUCT_CFLAGS) $(KSTACK_ERASE_CFLAGS) \ $(GCC_PLUGINS_CFLAGS) \ - $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) \ + $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) $(CC_FLAGS_SFRAME) \ -Wmissing-prototypes -Wmissing-declarations CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables
But the warnings seem to have returned after upgrading my toolchain, possibly due to SFrame V3 or some confounding change in GCC. The --gsframe in the assembler should be set to 'no' by default, so perhaps GCC is providing an override --gsframe internally?
Quoted 21 lines
I applied this series hoping that fix it, but it doesn't, so far I have this hack :
arch/arm64/kernel/vdso/vdso.lds.S +1
-1@@ -77,7 +77,7 @@ SECTIONS /DISCARD/ : { *(.data .data.* .gnu.linkonce.d.* .sdata*) *(.bss .sbss .dynbss .dynsbss) - *(.eh_frame .eh_frame_hdr) + *(.eh_frame .eh_frame_hdr .sframe) } }include/asm-generic/vmlinux.lds.h +0
-0
include/asm-generic/vmlinux.lds.h line 1070
Quoted 7 lines
include/asm-generic/vmlinux.lds.h +1
-0@@ -1064,6 +1064,7 @@/* ld.bfd warns about .gnu.version* even when not emitted */ \ *(.gnu.version*) \ *(__tracepoint_check) \ + *(.sframe) \#define DISCARDS \ /DISCARD/ : { \
Since this series only handles kernel stacktrace, I believe it's better to omit the .sframe section entirely in the case where only ARCH_SUPPORTS_UNWIND_KERNEL_SFRAME is enabled. I think this hack may work better for this purpose:
arch/arm64/kernel/vdso/Makefile +0 -0
@@ -41,7 +41,7 @@ CC_FLAGS_REMOVE_VDSO := $(CC_FLAGS_FTRACE) -Os
$(CC_FLAGS_SCS) \
$(CC_FLAGS_LTO) $(CC_FLAGS_CFI) $(CC_FLAGS_SFRAME) \
-Wmissing-prototypes -Wmissing-declarations-CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables +CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables -Wa,--gsframe=no
CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_REMOVE_VDSO) CFLAGS_REMOVE_vgetrandom.o = $(CC_FLAGS_REMOVE_VDSO)
Though, I don't understand why it is necessary to provide --gsframe=no explicitly. If this approach seems ok to other folks/maintainers, I can fold this into my series.
On the topic of SFrame for VDSO, Jens has a patch adding support for this as part of a series to support userspace SFrame unwinding for arm64:
Quoted 5 lines
Thanks,
Mostafa
Thanks,
Dylan
Re: [PATCH v5 3/8] arm64: entry: add unwind info for various kernel entries
In reply to Mark RutlandQuoted 43 lines · Mark Rutland
Quoted 20 lines · Dylan Hatch
Quoted 19 lines · Mark Rutland
Quoted 10 lines · Dylan Hatch
From: Weinan Liu <[email protected]>
DWARF CFI (Call Frame Information) specifies how to recover the return address and callee-saved registers at each PC in a given function. Compilers are able to generate the CFI annotations when they compile the code to assembly language. For handcrafted assembly, we need to annotate them by hand.
Annotate minimal CFI to enable stacktracing using SFrame for kernel exception entries through el1*_64_*() paths
I thought we were only consuming SFrame when unwinding an exeption boundary?
We shouldn't be taking exceptions _from_ the entry assembly functions unless something has gone horribly wrong, and so I don't see why we'd need CFI entries for the entry assembly functions.
Quoted 6 lines
Quoted 3 lines
Am I missing some reason we need CFI entries for the entry assembly functions? I strongly suspect it is not necessary to add these, and I'd prefer to omit them.
I believe the el1 entry functions are called in an exception, and are called before
call_on_irq_stack.Yes, but I don't think that matters. See below for more details.
Quoted 11 lines
Example stacktrace segment:
[ 262.119564] handle_percpu_devid_irq+0xb4/0x348 [ 262.119913] handle_irq_desc+0x3c/0x68 [ 262.120196] generic_handle_domain_irq+0x20/0x40 [ 262.120678] gic_handle_irq+0x48/0xe0 [ 262.121005] call_on_irq_stack+0x30/0x48 [ 262.121412] do_interrupt_handler+0x88/0xa0 [ 262.121779] el1_interrupt+0x38/0x58 [ 262.122089] el1h_64_irq_handler+0x18/0x30 [ 262.122617] el1h_64_irq+0x6c/0x70
Quoted 3 lines
The segment immediately above can be unwound using FP, as frame records were created consistently, and there are no exception boundaries. No CFI needed.
Ah right -- with the logic in stacktrace.c changed to use SFrame only when recovering the next frame from a pt_regs, the FP alone is sufficient if we know these entry functions won't take an exception. This patch was originally implemented with an SFrame-only unwinder in mind, so my mental model still hadn't back-propagated the new logic to this patch :)
Quoted 22 lines
It's legitimate to take an exception from parts of
call_on_irq_stack(), so it makes sense for that to have CFI, but for the specific unwind segment above, CFI isn't necessary.Everything in the stacktrace segment above was executed *after* HW took the exception.
<< EXCEPTION BOUNDARY HERE >>
Everything in the stacktrace segment(s) below was executed *before* HW took the exception.
The unwinder knows that it has crossed this exception boundary by virtue of finding a
FRAME_META_TYPE_PT_REGSframe record.Quoted 1 line
[ 262.123159] _raw_spin_unlock_irq+0x10/0x60 (P)The unwinder knows that the value of
pt_regs::pcwas *definitely* the PC at the time the exception was taken, so that entry is reliable. No CFI needed.
Quoted 7 lines
Quoted 1 line
[ 262.123720] __filemap_add_folio+0x200/0x580 (L)The unwinder doesn't know whether the LR should be used, and needs CFI to determine that.
After this point, an FP unwind can be used until we encounter the next exception boundary.
Right, and this is what is implemented in the final patch of this series.
Quoted 16 lines
Quoted 5 lines
[ 262.124145] filemap_add_folio+0xec/0x300 [ 262.124674] page_cache_ra_unbounded+0x128/0x368 [ 262.125338] do_page_cache_ra+0x70/0x98 [ 262.125875] page_cache_ra_order+0x460/0x4e0The segment immediately above can be unwound using FP. No CFI needed.
Quoted 7 lines
Here,
el1h_64_irqis the last function that appears in the exception stack before_raw_spin_unlock_irqand__filemap_add_folioare recovered from the saved PC and LR, respectively. So we therefore need the CFI annotations in order to unwind through the full exception boundary.Is my interpretation here correct?
Quoted 7 lines
Given you say "full exception boundary" here, I think we might be using the term "exception boundary" to mean different things.
As per the example above, I'm using "exception boundary" to mean the a point between two entries in the stacktrace where HW took an exception.
Did my comments on the example help?
I admit I may have been using the term "exception boundary" with a vague definition, which was partly the source of my confusion. Thanks for the example, it did help.
Quoted 42 lines
Quoted 22 lines
Quoted 9 lines
Quoted 2 lines
and irq entries through
call_on_irq_stack()Needing some sort of unwind annotations for
call_on_irq_stack()makes sense to me, but don't we need something for other assembly functions too?We can interrupt things like
memset(); I assume we'll treat those as unreliable until annotated?While looking into adding these annotations, I noticed a pattern where a sibling call is made to a local function:
SYM_FUNC_START(__pi_memset)alternative_if_notARM64_HAS_MOPS
b__pi_memset_genericalternative_else_nop_endifmov dst, dstin setp [dst]!, count!, val_x setm [dst]!, count!, val_x sete [dst]!, count!, val_xQuoted 5 lines
ret
SYM_FUNC_END(__pi_memset)In this case, do we consider the stacktrace unreliable since
__pi_memsetmay not appear in the trace?This is a tail-call, and
__pi_memset_generic()will not return to__pi_memset(). Once the branch to__pi_memset_generic()has been executed, it's fine for__pi_memset()to not show up in the trace.The key thing is that no more instructions from
__pi_memset()itself will be executed unless it was called again (from its entry point).Quoted 2 lines
Or is this not important because assembly functions cannot be directly livepatched anyway?
To the best of my knowledge, reliable stacktrace is only used to determine whether any thread is still within an old version of a patchable function (including where it's within a callee thereof).
Quoted 8 lines
I am not aware of a case where we'd need to detect whether a thread is still within a non-patchable function, but I can't rule out that as a possibility.
That's more of a question for the livepatching maintainers.
Thanks,
Mark.
Thanks,
Dylan
Re: [PATCH v5 8/8] unwind: arm64: Use sframe to unwind interrupt frames
In reply to Mark RutlandHi Mark,
I'm sending a v6 shortly that should address all/most of your feedback, but I wanted to circle back on a question you had:
Quoted 9 lines · Mark Rutland
arch/arm64/kernel/stacktrace.c kunwind_next_frame_record(struct kunwind_state *state) · line 408
Quoted 7 lines
arch/arm64/kernel/stacktrace.c +7
-0+/* +* Consume RA and FP from the stack. The frame record puts FP at a lower +* address than RA, so we always read FP first. +*/ +if (frame.fp.rule &UNWIND_RULE_DEREF && + !get_word (&state->common, &fp)) +return -EINVAL ;Why is this
get_word()rather thanget_consume_word()?
I use get_word() here because get_consume_word(), in calling unwind_consume_stack() under the hood, consumes the stack up to the given address+size such that another unwind step cannot consume it again. If the subsequent call to get_consume_word() fails, the stack needs to be in a state such that we can fall back on a frame pointer unwind. But if we were to use get_consume_word() here, the fallback call to kunwind_next_frame_record() would not be able to consume the FP from the stack because it would already have been consumed by the failed call to unwind_next_frame_sframe().
By only calling get_consume_word() on the RA at the end, we defer making any changes to the underlying unwind state stack until we are sure the SFrame unwind step will succeed.
Quoted 8 lines
arch/arm64/kernel/stacktrace.c kunwind_next_frame_record(struct kunwind_state *state) · line 415
Quoted 8 lines
arch/arm64/kernel/stacktrace.c +7
-0+ +if (frame.ra.rule &UNWIND_RULE_DEREF && +get_consume_word (&state->common, &ra)) +return -EINVAL ; + + state->common.pc = ra; + state->common.sp = cfa;
Please let me know if this reasoning seems sound.
Thanks,
Dylan
Hi Dylan and Mostafa!
Quoted 47 lines · Dylan Hatch
Quoted 24 lines · Mostafa Saleh
Quoted 13 lines · Dylan Hatch
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.
Quoted 9 lines
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].
Quoted 4 lines
Not sure if related, but after updating my toolchain
(aarch64-linux-gnu-gcc (Debian 15.2.0-4) 15.2.0), I hit link errors:
ld.lld: error: arch/arm64/kernel/vdso/vgettimeofday.o:(.sframe) is being placed in '.sframe' ld.lld: error: arch/arm64/kernel/vdso/vgetrandom.o:(.sframe) is being placed in '.sframe`Previously when developing against the SFrame V2 format, I had fixed these warnings with the VDSO
Makefilechange currently in this series:arch/arm64/kernel/vdso/Makefile +1
-1@@ -38,7 +38,7 @@ ccflags-y += -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO CC_FLAGS_REMOVE_VDSO := $(CC_FLAGS_FTRACE) -Os $(CC_FLAGS_SCS) \ $(RANDSTRUCT_CFLAGS) $(KSTACK_ERASE_CFLAGS) \ $(GCC_PLUGINS_CFLAGS) \ - $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) \ + $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) $(CC_FLAGS_SFRAME) \ -Wmissing-prototypes -Wmissing-declarations CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables
Quoted 4 lines
But the warnings seem to have returned after upgrading my toolchain, possibly due to SFrame V3 or some confounding change in GCC. The --gsframe in the assembler should be set to 'no' by default, so perhaps GCC is providing an override --gsframe internally?
Could it be that your build of binutils was configured with --enable-default-sframe, so that the GNU assembler defaults to generate .sframe? AFAIK this configure option was meant for distributors and package maintainers.
You can check as follows whether --gsframe defaults to "no" or "yes":
$ as --help | grep -A1 gsframe
--gsframe[={no|yes}] whether to generate SFrame stack trace information
(default: no)
...Quoted 51 lines
Quoted 22 lines
I applied this series hoping that fix it, but it doesn't, so far I have this hack :
arch/arm64/kernel/vdso/vdso.lds.S +1
-1@@ -77,7 +77,7 @@ SECTIONS /DISCARD/ : { *(.data .data.* .gnu.linkonce.d.* .sdata*) *(.bss .sbss .dynbss .dynsbss) - *(.eh_frame .eh_frame_hdr) + *(.eh_frame .eh_frame_hdr .sframe) } }include/asm-generic/vmlinux.lds.h +0
-0include/asm-generic/vmlinux.lds.h line 1070
Quoted 7 lines
include/asm-generic/vmlinux.lds.h +1
-0@@ -1064,6 +1064,7 @@/* ld.bfd warns about .gnu.version* even when not emitted */ \ *(.gnu.version*) \ *(__tracepoint_check) \ + *(.sframe) \#define DISCARDS \ /DISCARD/ : { \Since this series only handles kernel stacktrace, I believe it's better to omit the .sframe section entirely in the case where only
ARCH_SUPPORTS_UNWIND_KERNEL_SFRAMEis enabled. I think this hack may work better for this purpose:arch/arm64/kernel/vdso/Makefile +1
-2@@ -41,7 +41,7 @@ CC_FLAGS_REMOVE_VDSO := $(CC_FLAGS_FTRACE) -Os $(CC_FLAGS_SCS) \ $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) $(CC_FLAGS_SFRAME) \ -Wmissing-prototypes -Wmissing-declarations -CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables +CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tables -Wa,--gsframe=no CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_REMOVE_VDSO) CFLAGS_REMOVE_vgetrandom.o = $(CC_FLAGS_REMOVE_VDSO)
Quoted 3 lines
Though, I don't understand why it is necessary to provide --gsframe=no explicitly. If this approach seems ok to other folks/maintainers, I can fold this into my series.
Maybe build the VDSO separately with V=1 to see what assembler/compiler options are effectively used (e.g. for vgettimeofday.o and vgetrandom.o mentioned in the linker error message above)?
$ make mrproper $ make defconfig $ ./scripts/config --enable HAVE_UNWIND_KERNEL_SFRAME # enable kernel sframe unwinder $ make arch/arm64/kernel/vdso/ V=1
Quoted 6 lines
On the topic of SFrame for VDSO, Jens has a patch adding support for this as part of a series to support userspace SFrame unwinding for arm64:
Any feedback is very welcome. :-)
Regards,
Jens
Signature · 6 lines
Jens Remus Linux on Z Development (D3303) [email protected] / [email protected] 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/
Hi Jens,
Quoted 1 line · Jens Remus
Hi Dylan and Mostafa!
I also work at the same company as Dylan and Mostafa, and am therefore probably using the same company-maintained Linux distribution.
Quoted 6 lines · Dylan Hatch
Quoted 5 lines · Mostafa Saleh
Quoted 4 lines
Not sure if related, but after updating my toolchain
(aarch64-linux-gnu-gcc (Debian 15.2.0-4) 15.2.0), I hit link errors:
ld.lld: error: arch/arm64/kernel/vdso/vgettimeofday.o:(.sframe) is being placed in '.sframe' ld.lld: error: arch/arm64/kernel/vdso/vgetrandom.o:(.sframe) is being placed in '.sframe`
I've also been hitting this for some time, and I'd like to see if I can figure out what's going wrong. My current workaround is:
Makefile +2 -0
@@ -946,6 +946,8 @@ ifdef CONFIG_CC_IS_GCC KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0) KBUILD_CFLAGS += $(call cc-option,-fno-allow-store-data-races) endif +# No sframe generation for kernel if enabled by default +KBUILD_CFLAGS += $(call cc-option,-Xassembler --gsframe=no) ifdef CONFIG_READABLE_ASM # Disable optimizations that make assembler listings hard to read.
Quoted 27 lines
Quoted 17 lines
Previously when developing against the SFrame V2 format, I had fixed these warnings with the VDSO
Makefilechange currently in this series:arch/arm64/kernel/vdso/Makefile +1
-1@@ -38,7 +38,7 @@ ccflags-y += -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO CC_FLAGS_REMOVE_VDSO := $(CC_FLAGS_FTRACE) -Os $(CC_FLAGS_SCS) \ $(RANDSTRUCT_CFLAGS) $(KSTACK_ERASE_CFLAGS) \ $(GCC_PLUGINS_CFLAGS) \ - $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) \ + $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) $(CC_FLAGS_SFRAME) \ -Wmissing-prototypes -Wmissing-declarations CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tablesQuoted 4 lines
But the warnings seem to have returned after upgrading my toolchain, possibly due to SFrame V3 or some confounding change in GCC. The --gsframe in the assembler should be set to 'no' by default, so perhaps GCC is providing an override --gsframe internally?
Could it be that your build of binutils was configured with --enable-default-sframe, so that the GNU assembler defaults to generate .sframe? AFAIK this configure option was meant for distributors and package maintainers.
Quoted 6 lines
You can check as follows whether --gsframe defaults to "no" or "yes":
$ as --help | grep -A1 gsframe --gsframe[={no|yes}] whether to generate SFrame stack trace information (default: no) ...
$ aarch64-linux-gnu-as --help | grep -A1 gsframe
--gsframe[={no|yes}] whether to generate SFrame stack trace information
(default: no)
--
--gsframe-<N> generate SFrame version <N> information. 3 == <N>
--scfi=experimental Synthesize DWARF CFI for hand-written asmQuoted 3 lines
Maybe build the VDSO separately with V=1 to see what assembler/compiler options are effectively used (e.g. for vgettimeofday.o and vgetrandom.o mentioned in the linker error message above)?
A slightly tweaked version of my vgetrandom.o build line:
# CC arch/arm64/kernel/vdso/vgetrandom.o
aarch64-linux-gnu-gcc -Wp,-MMD,arch/arm64/kernel/vdso/.vgetrandom.o.d -nostdinc -I./arch/arm64/include -I./arch/arm64/include/generated -I./include -I./include -I./arch/arm64/include/uapi -I./arch/arm64/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/compiler-version.h -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__ -mlittle-endian -DCC_USING_PATCHABLE_FUNCTION_ENTRY -DKASAN_SHADOW_SCALE_SHIFT= -Werror -fshort-wchar -funsigned-char -fno-common -fno-PIE -fno-strict-aliasing -std=gnu11 -fms-extensions -mgeneral-regs-only -DCONFIG_CC_HAS_K_CONSTRAINT=1 -Wno-psabi -mabi=lp64 -fno-asynchronous-unwind-tables -fno-unwind-tables -mbranch-protection=pac-ret -Wa,-march=armv8.5-a -DARM64_ASM_ARCH='"armv8.5-a"' -DKASAN_SHADOW_SCALE_SHIFT= -fno-delete-null-pointer-checks -O2 -fno-allow-store-data-races -fstack-protector-strong -fno-omit-frame-pointer -fno-optimize-sibling-calls -ftrivial-auto-var-init=zero -fzero-init-padding-bits=all -fno-stack-clash-protection -fno-inline-functions-called-once -fmin-function-alignment=8 -fstrict-flex-arrays=3 -fno-strict-overflow -fno-stack-check -fconserve-stack -fno-builtin-wcslen -Wall -Wextra -Wundef -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Werror=strict-prototypes -Wno-format-security -Wno-trigraphs -Wno-frame-address -Wno-address-of-packed-member -Wframe-larger-than=2048 -Wno-main -Wno-type-limits -Wno-dangling-pointer -Wvla-larger-than=1 -Wno-pointer-sign -Wcast-function-type -Wno-unterminated-string-initialization -Wno-array-bounds -Wno-stringop-overflow -Wno-alloc-size-larger-than -Wimplicit-fallthrough=5 -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -Wenum-conversion -Wunused -Wno-unused-but-set-variable -Wno-unused-const-variable -Wno-packed-not-aligned -Wno-format-overflow -Wno-format-truncation -Wno-stringop-truncation -Wno-override-init -Wno-missing-field-initializers -Wno-shift-negative-value -Wno-maybe-uninitialized -Wno-sign-compare -Wno-unused-parameter -g -mstack-protector-guard=sysreg -mstack-protector-guard-reg=sp_el0 -mstack-protector-guard-offset=1344 -fno-common -fno-builtin -fno-stack-protector -ffixed-x18 -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO -O2 -mcmodel=tiny -fasynchronous-unwind-tables -include ./lib/vdso/getrandom.c -I./arch/arm64/kernel/vdso -Iarch/arm64/kernel/vdso -DKBUILD_MODFILE='"arch/arm64/kernel/vdso/vgetrandom"' -DKBUILD_BASENAME='"vgetrandom"' -DKBUILD_MODNAME='"vgetrandom"' -D__KBUILD_MODNAME=vgetrandom -c -o arch/arm64/kernel/vdso/vgetrandom.o ./arch/arm64/kernel/vdso/vgetrandom.c
I mostly don't know what I'm looking for w.r.t. gsframe features, but I'm willing to poke at my compiler/assembler/build-process.
Brian
Hi Brian!
Quoted 11 lines · Brian Norris
On Tue, May 19, 2026 at 01:05:23PM +0200, Jens Remus wrote:
I also work at the same company as Dylan and Mostafa, and am therefore probably using the same company-maintained Linux distribution.
Quoted 6 lines · Dylan Hatch
Quoted 5 lines · Mostafa Saleh
Quoted 4 lines
Not sure if related, but after updating my toolchain
(aarch64-linux-gnu-gcc (Debian 15.2.0-4) 15.2.0), I hit link errors:
ld.lld: error: arch/arm64/kernel/vdso/vgettimeofday.o:(.sframe) is being placed in '.sframe' ld.lld: error: arch/arm64/kernel/vdso/vgetrandom.o:(.sframe) is being placed in '.sframe`
My understanding of above message is that the linker complains that the input object (e.g. vgettimeofday.o) has an .sframe section for which the linker script does not have any rule, so that it defaults to place it in .sframe in the output, which could not be the desired result.
Quoted 56 lines
I've also been hitting this for some time, and I'd like to see if I can figure out what's going wrong. My current workaround is:
Makefile +2
-0@@ -946,6 +946,8 @@ ifdef CONFIG_CC_IS_GCC KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0) KBUILD_CFLAGS += $(call cc-option,-fno-allow-store-data-races) endif +# No sframe generation for kernel if enabled by default +KBUILD_CFLAGS += $(call cc-option,-Xassembler --gsframe=no) ifdef CONFIG_READABLE_ASM # Disable optimizations that make assembler listings hard to read.Quoted 28 lines
Quoted 18 lines
Previously when developing against the SFrame V2 format, I had fixed these warnings with the VDSO
Makefilechange currently in this series:arch/arm64/kernel/vdso/Makefile +1
-1@@ -38,7 +38,7 @@ ccflags-y += -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO CC_FLAGS_REMOVE_VDSO := $(CC_FLAGS_FTRACE) -Os $(CC_FLAGS_SCS) \ $(RANDSTRUCT_CFLAGS) $(KSTACK_ERASE_CFLAGS) \ $(GCC_PLUGINS_CFLAGS) \ - $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) \ + $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) $(CC_FLAGS_SFRAME) \ -Wmissing-prototypes -Wmissing-declarations CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tablesQuoted 4 lines
But the warnings seem to have returned after upgrading my toolchain, possibly due to SFrame V3 or some confounding change in GCC. The --gsframe in the assembler should be set to 'no' by default, so perhaps GCC is providing an override --gsframe internally?
Could it be that your build of binutils was configured with --enable-default-sframe, so that the GNU assembler defaults to generate .sframe? AFAIK this configure option was meant for distributors and package maintainers.
Quoted 6 lines
You can check as follows whether --gsframe defaults to "no" or "yes":
$ as --help | grep -A1 gsframe --gsframe[={no|yes}] whether to generate SFrame stack trace information (default: no) ...$ aarch64-linux-gnu-as --help | grep -A1 gsframe --gsframe[={no|yes}] whether to generate SFrame stack trace information (default: no) -- --gsframe-<N> generate SFrame version <N> information. 3 == <N> --scfi=experimental Synthesize DWARF CFI for hand-written asm
Quoted 8 lines
Quoted 3 lines
Maybe build the VDSO separately with V=1 to see what assembler/compiler options are effectively used (e.g. for vgettimeofday.o and vgetrandom.o mentioned in the linker error message above)?
A slightly tweaked version of my vgetrandom.o build line:
# CC
arch/arm64/kernel/vdso/vgetrandom.o
aarch64-linux-gnu-gcc -Wp,-MMD,arch/arm64/kernel/vdso/.vgetrandom.o.d -nostdinc -I./arch/arm64/include -I./arch/arm64/include/generated -I./include -I./include -I./arch/arm64/include/uapi -I./arch/arm64/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include./include/linux/compiler-version.h-include./include/linux/kconfig.h-include./include/linux/compiler_types.h-D__KERNEL__ -mlittle-endian -DCC_USING_PATCHABLE_FUNCTION_ENTRY -DKASAN_SHADOW_SCALE_SHIFT= -Werror -fshort-wchar -funsigned-char -fno-common -fno-PIE -fno-strict-aliasing -std=gnu11 -fms-extensions -mgeneral-regs-only -DCONFIG_CC_HAS_K_CONSTRAINT=1 -Wno-psabi -mabi=lp64 -fno-asynchronous-unwind-tables -fno-unwind-tables -mbranch-protection=pac-ret -Wa,-march=armv8.5-a -DARM64_ASM_ARCH='"armv8.5-a"' -DKASAN_SHADOW_SCALE_SHIFT= -fno-delete-null-pointer-checks -O2 -fno-allow-store-data-races -fstack-protector-strong -fno-omit-frame-pointer -fno-optimize-sibling-calls -ftrivial-auto-var-init=zero -fzero-init-padding-bits=all -fno-stack-clash-protection -fno-inline-functions-called-once -fmin-function-alignment=8 -fstrict-flex-arrays=3 -fno-strict-overflow -fno-stack-check -fconserve-stack -fno-builtin-wcslen -Wall -Wextra -Wundef -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Werror=strict-prototypes -Wno-format-security -Wno-trigraphs -Wno-frame-address -Wno-address-of-packed-member -Wframe-larger-than=2048 -Wno-main -Wno-type-limits -Wno-dangling-pointer -Wvla-larger-than=1 -Wno-pointer-sign -Wcast-function-type -Wno-unterminated-string-initialization -Wno-array-bounds -Wno-stringop-overflow -Wno-alloc-size-larger-than -Wimplicit-fallthrough=5 -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -Wenum-conversion -Wunused -Wno-unused-but-set-variable -Wno-unused-const-variable -Wno-packed-not-aligned -Wno-format-overflow -Wno-format-truncation -Wno-stringop-truncation -Wno-override-init -Wno-missing-field-initializers -Wno-shift-negative-value -Wno-maybe-uninitialized -Wno-sign-compare -Wno-unused-parameter -g -mstack-protector-guard=sysreg -mstack-protector-guard-reg=sp_el0 -mstack-protector-guard-offset=1344 -fno-common -fno-builtin -fno-stack-protector -ffixed-x18 -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO -O2 -mcmodel=tiny -fasynchronous-unwind-tables -include./lib/vdso/getrandom.c-I./arch/arm64/kernel/vdso -Iarch/arm64/kernel/vdso -DKBUILD_MODFILE='"arch/arm64/kernel/vdso/vgetrandom"' -DKBUILD_BASENAME='"vgetrandom"' -DKBUILD_MODNAME='"vgetrandom"' -D__KBUILD_MODNAME=vgetrandom -c -oarch/arm64/kernel/vdso/vgetrandom.o./arch/arm64/kernel/vdso/vgetrandom.c
That command line does not have any --gsframe[-3] (e.g. -Wa,--gsframe). I am not aware of any binutils release / repository state where the --gsframe default was broken.
@Indu: Do you have any idea what could be going on?
Quoted 2 lines
I mostly don't know what I'm looking for w.r.t. gsframe features, but I'm willing to poke at my compiler/assembler/build-process.
Could it be that your gcc injects --gsframe e.g. via its spec file? Maybe that would show up if you run above command manually and append gcc option -v?
Does the intermediate source or assembler source have any ".cfi_section .sframe" statement?
$ make arch/arm64/kernel/vdso/vgetrandom.i $ make arch/arm64/kernel/vdso/vgetrandom.s
Can you please verify that your arch/arm64/kernel/vdso/vgetrandom.o actually contains an .sframe section:
$ readelf -WS arch/arm64/kernel/vdso/vgetrandom.o
Thanks and regards,
Jens
Signature · 6 lines
Jens Remus Linux on Z Development (D3303) [email protected] / [email protected] 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/
Hi Jens,
Thanks for looking! Lots more output below. Feel free to ask for more info you tink could help.`
Quoted 13 lines · Jens Remus
Quoted 11 lines · Brian Norris
On Tue, May 19, 2026 at 01:05:23PM +0200, Jens Remus wrote:
I also work at the same company as Dylan and Mostafa, and am therefore probably using the same company-maintained Linux distribution.
Quoted 6 lines · Dylan Hatch
Quoted 5 lines · Mostafa Saleh
Quoted 4 lines
Not sure if related, but after updating my toolchain
(aarch64-linux-gnu-gcc (Debian 15.2.0-4) 15.2.0), I hit link errors:
ld.lld: error: arch/arm64/kernel/vdso/vgettimeofday.o:(.sframe) is being placed in '.sframe' ld.lld: error: arch/arm64/kernel/vdso/vgetrandom.o:(.sframe) is being placed in '.sframe`
Quoted 4 lines
My understanding of above message is that the linker complains that the input object (e.g. vgettimeofday.o) has an .sframe section for which the linker script does not have any rule, so that it defaults to place it in .sframe in the output, which could not be the desired result.
Not sure if it's obvious to you, but I also found a few more details:
* This is most noticeable with CONFIG_WERROR=y, which turns the linker warning into an error.
* It appears both with LD=ld.lld and with the default (bfd linker). bfd shows:
/usr/bin/aarch64-linux-gnu-ld.bfd: error: unplaced orphan section .sframe' from arch/arm64/kernel/vdso/vgettimeofday.o' /usr/bin/aarch64-linux-gnu-ld.bfd: error: unplaced orphan section .sframe' from arch/arm64/kernel/vdso/vgetrandom.o'
Otherwise, I don't have to do much special to hit this. Just cross-compile ARCH=arm64 defconfig.
Quoted 60 lines
Quoted 60 lines
I've also been hitting this for some time, and I'd like to see if I can figure out what's going wrong. My current workaround is:
Makefile +2
-0@@ -946,6 +946,8 @@ ifdef CONFIG_CC_IS_GCC KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0) KBUILD_CFLAGS += $(call cc-option,-fno-allow-store-data-races) endif +# No sframe generation for kernel if enabled by default +KBUILD_CFLAGS += $(call cc-option,-Xassembler --gsframe=no) ifdef CONFIG_READABLE_ASM # Disable optimizations that make assembler listings hard to read.Quoted 28 lines
Quoted 18 lines
Previously when developing against the SFrame V2 format, I had fixed these warnings with the VDSO
Makefilechange currently in this series:arch/arm64/kernel/vdso/Makefile +1
-1@@ -38,7 +38,7 @@ ccflags-y += -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO CC_FLAGS_REMOVE_VDSO := $(CC_FLAGS_FTRACE) -Os $(CC_FLAGS_SCS) \ $(RANDSTRUCT_CFLAGS) $(KSTACK_ERASE_CFLAGS) \ $(GCC_PLUGINS_CFLAGS) \ - $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) \ + $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) $(CC_FLAGS_SFRAME) \ -Wmissing-prototypes -Wmissing-declarations CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tablesQuoted 4 lines
But the warnings seem to have returned after upgrading my toolchain, possibly due to SFrame V3 or some confounding change in GCC. The --gsframe in the assembler should be set to 'no' by default, so perhaps GCC is providing an override --gsframe internally?
Could it be that your build of binutils was configured with --enable-default-sframe, so that the GNU assembler defaults to generate .sframe? AFAIK this configure option was meant for distributors and package maintainers.
Quoted 6 lines
You can check as follows whether --gsframe defaults to "no" or "yes":
$ as --help | grep -A1 gsframe --gsframe[={no|yes}] whether to generate SFrame stack trace information (default: no) ...$ aarch64-linux-gnu-as --help | grep -A1 gsframe --gsframe[={no|yes}] whether to generate SFrame stack trace information (default: no) -- --gsframe-<N> generate SFrame version <N> information. 3 == <N> --scfi=experimental Synthesize DWARF CFI for hand-written asmQuoted 3 lines
Maybe build the VDSO separately with V=1 to see what assembler/compiler options are effectively used (e.g. for vgettimeofday.o and vgetrandom.o mentioned in the linker error message above)?
Quoted 8 lines
Quoted 4 lines
A slightly tweaked version of my vgetrandom.o build line:
# CC
arch/arm64/kernel/vdso/vgetrandom.o
aarch64-linux-gnu-gcc -Wp,-MMD,arch/arm64/kernel/vdso/.vgetrandom.o.d -nostdinc -I./arch/arm64/include -I./arch/arm64/include/generated -I./include -I./include -I./arch/arm64/include/uapi -I./arch/arm64/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include./include/linux/compiler-version.h-include./include/linux/kconfig.h-include./include/linux/compiler_types.h-D__KERNEL__ -mlittle-endian -DCC_USING_PATCHABLE_FUNCTION_ENTRY -DKASAN_SHADOW_SCALE_SHIFT= -Werror -fshort-wchar -funsigned-char -fno-common -fno-PIE -fno-strict-aliasing -std=gnu11 -fms-extensions -mgeneral-regs-only -DCONFIG_CC_HAS_K_CONSTRAINT=1 -Wno-psabi -mabi=lp64 -fno-asynchronous-unwind-tables -fno-unwind-tables -mbranch-protection=pac-ret -Wa,-march=armv8.5-a -DARM64_ASM_ARCH='"armv8.5-a"' -DKASAN_SHADOW_SCALE_SHIFT= -fno-delete-null-pointer-checks -O2 -fno-allow-store-data-races -fstack-protector-strong -fno-omit-frame-pointer -fno-optimize-sibling-calls -ftrivial-auto-var-init=zero -fzero-init-padding-bits=all -fno-stack-clash-protection -fno-inline-functions-called-once -fmin-function-alignment=8 -fstrict-flex-arrays=3 -fno-strict-overflow -fno-stack-check -fconserve-stack -fno-builtin-wcslen -Wall -Wextra -Wundef -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Werror=strict-prototypes -Wno-format-security -Wno-trigraphs -Wno-frame-address -Wno-address-of-packed-member -Wframe-larger-than=2048 -Wno-main -Wno-type-limits -Wno-dangling-pointer -Wvla-larger-than=1 -Wno-pointer-sign -Wcast-function-type -Wno-unterminated-string-initialization -Wno-array-bounds -Wno-stringop-overflow -Wno-alloc-size-larger-than -Wimplicit-fallthrough=5 -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -Wenum-conversion -Wunused -Wno-unused-but-set-variable -Wno-unused-const-variable -Wno-packed-not-aligned -Wno-format-overflow -Wno-format-truncation -Wno-stringop-truncation -Wno-override-init -Wno-missing-field-initializers -Wno-shift-negative-value -Wno-maybe-uninitialized -Wno-sign-compare -Wno-unused-parameter -g -mstack-protector-guard=sysreg -mstack-protector-guard-reg=sp_el0 -mstack-protector-guard-offset=1344 -fno-common -fno-builtin -fno-stack-protector -ffixed-x18 -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO -O2 -mcmodel=tiny -fasynchronous-unwind-tables -include./lib/vdso/getrandom.c-I./arch/arm64/kernel/vdso -Iarch/arm64/kernel/vdso -DKBUILD_MODFILE='"arch/arm64/kernel/vdso/vgetrandom"' -DKBUILD_BASENAME='"vgetrandom"' -DKBUILD_MODNAME='"vgetrandom"' -D__KBUILD_MODNAME=vgetrandom -c -oarch/arm64/kernel/vdso/vgetrandom.o./arch/arm64/kernel/vdso/vgetrandom.cThat command line does not have any --gsframe[-3] (e.g. -Wa,--gsframe). I am not aware of any binutils release / repository state where the --gsframe default was broken.
FWIW, I'm usually testing on both v7.1 and approx v7.2-rc3, to make sure my results are consistent, and it's not already somehow fixed.
Quoted 8 lines
@Indu: Do you have any idea what could be going on?
Quoted 2 lines
I mostly don't know what I'm looking for w.r.t. gsframe features, but I'm willing to poke at my compiler/assembler/build-process.
Could it be that your gcc injects --gsframe e.g. via its spec file? Maybe that would show up if you run above command manually and append gcc option -v?
I've dumped most of the output below. I see that the 'as' invocation includes --gsframe, but I'm not sure why.
$ aarch64-linux-gnu-gcc -Wp,-MMD,arch/arm64/kernel/vdso/.vgetrandom.o.d -nostdinc -I./arch/arm64/include -I./arch/arm64/include/generated -I./include -I./include -I./arch/arm64/include/uapi -I./arch/arm64/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/compiler-version.h -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__ -mlittle-endian -DKASAN_SHADOW_SCALE_SHIFT= -Werror -fshort-wchar -funsigned-char -fno-common -fno-PIE -fno-strict-aliasing -std=gnu11 -fms-extensions -mgeneral-regs-only -DCONFIG_CC_HAS_K_CONSTRAINT=1 -Wno-psabi -mabi=lp64 -fno-asynchronous-unwind-tables -fno-unwind-tables -mbranch-protection=pac-ret -Wa,-march=armv8.5-a -DARM64_ASM_ARCH='"armv8.5-a"' -DKASAN_SHADOW_SCALE_SHIFT= -fno-delete-null-pointer-checks -O2 -fno-allow-store-data-races -fstack-protector-strong -fno-omit-frame-pointer -fno-optimize-sibling-calls -ftrivial-auto-var-init=zero -fzero-init-padding-bits=all -fno-stack-clash-protection -fmin-function-alignment=4 -fstrict-flex-arrays=3 -fno-strict-overflow -fno-stack-check -fconserve-stack -fno-builtin-wcslen -Wall -Wextra -Wundef -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Werror=strict-prototypes -Wno-format-security -Wno-trigraphs -Wno-frame-address -Wno-address-of-packed-member -Wframe-larger-than=2048 -Wno-main -Wno-type-limits -Wno-dangling-pointer -Wvla-larger-than=1 -Wno-pointer-sign -Wcast-function-type -Wno-unterminated-string-initialization -Wno-array-bounds -Wno-stringop-overflow -Wno-alloc-size-larger-than -Wimplicit-fallthrough=5 -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -Wenum-conversion -Wunused -Wno-unused-but-set-variable -Wno-unused-const-variable -Wno-packed-not-aligned -Wno-format-overflow -Wno-format-truncation -Wno-stringop-truncation -Wno-override-init -Wno-missing-field-initializers -Wno-shift-negative-value -Wno-maybe-uninitialized -Wno-sign-compare -Wno-unused-parameter -g -fno-var-tracking -femit-struct-debug-baseonly -mstack-protector-guard=sysreg -mstack-protector-guard-reg=sp_el0 -mstack-protector-guard-offset=1344 -fno-common -fno-builtin -fno-stack-protector -ffixed-x18 -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO -O2 -mcmodel=tiny -fasynchronous-unwind-tables -include $LINUX/lib/vdso/getrandom.c -DKBUILD_MODFILE='"arch/arm64/kernel/vdso/vgetrandom"' -DKBUILD_BASENAME='"vgetrandom"' -DKBUILD_MODNAME='"vgetrandom"' -D__KBUILD_MODNAME=vgetrandom -c -o arch/arm64/kernel/vdso/vgetrandom.o arch/arm64/kernel/vdso/vgetrandom.c -v Using built-in specs. COLLECT_AS_OPTIONS='-march=armv8.5-a' COLLECT_GCC=aarch64-linux-gnu-gcc Target: aarch64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Debian 15.2.0-4' --with-bugurl=file:///usr/share/doc/gcc-15/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2,cobol,algol68 --prefix=/usr --with-gcc-major-version-only --program-suffix=-15 --enable-shared --enable-linker-build-id --libexecdir=/usr/libexec --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-libstdcxx-backtrace --enable-gnu-unique-object --disable-libquadmath --disable-libquadmath-support --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --without-target-system-zlib --enable-multiarch --enable-fix-cortex-a53-843419 --disable-werror --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=aarch64-linux-gnu --program-prefix=aarch64-linux-gnu- --includedir=/usr/aarch64-linux-gnu/include --with-build-config=bootstrap-lto-lean --enable-link-serialization=32 Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 15.2.0 (Debian 15.2.0-4) COLLECT_GCC_OPTIONS='-nostdinc' '-I' './arch/arm64/include' '-I' './arch/arm64/include/generated' '-I' './include' '-I' './include' '-I' './arch/arm64/include/uapi' '-I' './arch/arm64/include/generated/uapi' '-I' './include/uapi' '-I' './include/generated/uapi' '-include' './include/linux/compiler-version.h' '-include' './include/linux/kconfig.h' '-include' './include/linux/compiler_types.h' '-D' '__KERNEL__' '-mlittle-endian' '-D' 'KASAN_SHADOW_SCALE_SHIFT=' '-Werror' '-fshort-wchar' '-funsigned-char' '-fno-PIE' '-fno-strict-aliasing' '-std=gnu11' '-fms-extensions' '-mgeneral-regs-only' '-D' 'CONFIG_CC_HAS_K_CONSTRAINT=1' '-Wno-psabi' '-mabi=lp64' '-fno-unwind-tables' '-mbranch-protection=pac-ret' '-D' 'ARM64_ASM_ARCH="armv8.5-a"' '-D' 'KASAN_SHADOW_SCALE_SHIFT=' '-fno-delete-null-pointer-checks' '-O2' '-fno-allow-store-data-races' '-fstack-protector-strong' '-fno-omit-frame-pointer' '-fno-optimize-sibling-calls' '-ftrivial-auto-var-init=zero' '-fzero-init-padding-bits=all' '-fno-stack-clash-protection' '-fmin-function-alignment=4' '-fstrict-flex-arrays=3' '-fno-strict-overflow' '-fstack-check=no' '-fconserve-stack' '-fno-builtin-wcslen' '-Wall' '-Wextra' '-Wundef' '-Werror=implicit-function-declaration' '-Werror=implicit-int' '-Werror=return-type' '-Werror=strict-prototypes' '-Wno-format-security' '-Wno-trigraphs' '-Wno-frame-address' '-Wno-address-of-packed-member' '-Wframe-larger-than=2048' '-Wno-main' '-Wno-type-limits' '-Wdangling-pointer=0' '-Wvla-larger-than=1' '-Wno-pointer-sign' '-Wcast-function-type' '-Wno-unterminated-string-initialization' '-Warray-bounds=0' '-Wstringop-overflow=0' '-Walloc-size-larger-than=$XXX' '-Wimplicit-fallthrough=5' '-Werror=date-time' '-Werror=incompatible-pointer-types' '-Werror=designated-init' '-Wenum-conversion' '-Wunused' '-Wno-unused-but-set-variable' '-Wunused-const-variable=0' '-Wno-packed-not-aligned' '-Wformat-overflow=0' '-Wformat-truncation=0' '-Wno-stringop-truncation' '-Wno-override-init' '-Wno-missing-field-initializers' '-Wno-shift-negative-value' '-Wno-maybe-uninitialized' '-Wno-sign-compare' '-Wno-unused-parameter' '-g' '-fno-var-tracking' '-femit-struct-debug-baseonly' '-mstack-protector-guard=sysreg' '-mstack-protector-guard-reg=sp_el0' '-mstack-protector-guard-offset=1344' '-fno-common' '-fno-builtin' '-fno-stack-protector' '-ffixed-x18' '-D' 'DISABLE_BRANCH_PROFILING' '-D' 'BUILD_VDSO' '-O2' '-mcmodel=tiny' '-fasynchronous-unwind-tables' '-include' '$LINUX/lib/vdso/getrandom.c' '-D' 'KBUILD_MODFILE="arch/arm64/kernel/vdso/vgetrandom"' '-D' 'KBUILD_BASENAME="vgetrandom"' '-D' 'KBUILD_MODNAME="vgetrandom"' '-D' '__KBUILD_MODNAME=vgetrandom' '-c' '-o' 'arch/arm64/kernel/vdso/vgetrandom.o' '-v' '-dumpdir' 'arch/arm64/kernel/vdso/' /usr/libexec/gcc-cross/aarch64-linux-gnu/15/cc1 -quiet -nostdinc -v -I ./arch/arm64/include -I ./arch/arm64/include/generated -I ./include -I ./include -I ./arch/arm64/include/uapi -I ./arch/arm64/include/generated/uapi -I ./include/uapi -I ./include/generated/uapi -imultiarch aarch64-linux-gnu -D __KERNEL__ -D KASAN_SHADOW_SCALE_SHIFT= -D CONFIG_CC_HAS_K_CONSTRAINT=1 -D ARM64_ASM_ARCH="armv8.5-a" -D KASAN_SHADOW_SCALE_SHIFT= -D DISABLE_BRANCH_PROFILING -D BUILD_VDSO -D KBUILD_MODFILE="arch/arm64/kernel/vdso/vgetrandom" -D KBUILD_BASENAME="vgetrandom" -D KBUILD_MODNAME="vgetrandom" -D __KBUILD_MODNAME=vgetrandom -include ./include/linux/compiler-version.h -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -include /usr/local/google/home/briannorris/git/linux/lib/vdso/getrandom.c -MMD arch/arm64/kernel/vdso/.vgetrandom.o.d arch/arm64/kernel/vdso/vgetrandom.c -quiet -dumpdir arch/arm64/kernel/vdso/ -dumpbase vgetrandom.c -dumpbase-ext .c -mlittle-endian -mgeneral-regs-only -mabi=lp64 -mbranch-protection=pac-ret -mstack-protector-guard=sysreg -mstack-protector-guard-reg=sp_el0 -mstack-protector-guard-offset=1344 -mcmodel=tiny -g -O2 -O2 -Werror -Wno-psabi -Wall -Wextra -Wundef -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Werror=strict-prototypes -Wno-format-security -Wno-trigraphs -Wno-frame-address -Wno-address-of-packed-member -Wframe-larger-than=2048 -Wno-main -Wno-type-limits -Wdangling-pointer=0 -Wvla-larger-than=1 -Wno-pointer-sign -Wcast-function-type -Wno-unterminated-string-initialization -Warray-bounds=0 -Wstringop-overflow=0 -Walloc-size-larger-than=18446744073709551615EiB -Wimplicit-fallthrough=5 -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -Wenum-conversion -Wunused -Wno-unused-but-set-variable -Wunused-const-variable=0 -Wno-packed-not-aligned -Wformat-overflow=0 -Wformat-truncation=0 -Wno-stringop-truncation -Wno-override-init -Wno-missing-field-initializers -Wno-shift-negative-value -Wno-maybe-uninitialized -Wno-sign-compare -Wno-unused-parameter -std=gnu11 -version -fshort-wchar -funsigned-char -fno-PIE -fno-strict-aliasing -fms-extensions -fno-unwind-tables -fno-delete-null-pointer-checks -fno-allow-store-data-races -fstack-protector-strong -fno-omit-frame-pointer -fno-optimize-sibling-calls -ftrivial-auto-var-init=zero -fzero-init-padding-bits=all -fno-stack-clash-protection -fmin-function-alignment=4 -fstrict-flex-arrays=3 -fno-strict-overflow -fstack-check=no -fconserve-stack -fno-builtin-wcslen -fno-var-tracking -femit-struct-debug-baseonly -fno-common -fno-builtin -fno-stack-protector -ffixed-x18 -fasynchronous-unwind-tables -fasynchronous-unwind-tables -o /tmp/cc6nO0fY.s GNU C11 (Debian 15.2.0-4) version 15.2.0 (aarch64-linux-gnu) compiled by GNU C version 15.2.0, GMP version 6.3.0, MPFR version 4.2.2, MPC version 1.3.1, isl version isl-0.27-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring duplicate directory "./include"
#include "..." search starts here:
#include <...> search starts here:
./arch/arm64/include
./arch/arm64/include/generated
./include
./arch/arm64/include/uapi
./arch/arm64/include/generated/uapi
./include/uapi
./include/generated/uapi
End of search list.
Compiler executable checksum: 2014541e26adcb350b182f07eff54ec5
COLLECT_GCC_OPTIONS='-nostdinc' '-I' './arch/arm64/include' '-I' './arch/arm64/include/generated' '-I' './include' '-I' './include' '-I' './arch/arm64/include/uapi' '-I' './arch/arm64/include/generated/uapi' '-I' './include/uapi' '-I' './include/generated/uapi' '-include' './include/linux/compiler-version.h' '-include' './include/linux/kconfig.h' '-include' './include/linux/compiler_types.h' '-D' '__KERNEL__' '-mlittle-endian' '-D' 'KASAN_SHADOW_SCALE_SHIFT=' '-Werror' '-fshort-wchar' '-funsigned-char' '-fno-PIE' '-fno-strict-aliasing' '-std=gnu11' '-fms-extensions' '-mgeneral-regs-only' '-D' 'CONFIG_CC_HAS_K_CONSTRAINT=1' '-Wno-psabi' '-mabi=lp64' '-fno-unwind-tables' '-mbranch-protection=pac-ret' '-D' 'ARM64_ASM_ARCH="armv8.5-a"' '-D' 'KASAN_SHADOW_SCALE_SHIFT=' '-fno-delete-null-pointer-checks' '-O2' '-fno-allow-store-data-races' '-fstack-protector-strong' '-fno-omit-frame-pointer' '-fno-optimize-sibling-calls' '-ftrivial-auto-var-init=zero' '-fzero-init-padding-bits=all' '-fno-stack-clash-protection' '-fmin-function-alignment=4' '-fstrict-flex-arrays=3' '-fno-strict-overflow' '-fstack-check=no' '-fconserve-stack' '-fno-builtin-wcslen' '-Wall' '-Wextra' '-Wundef' '-Werror=implicit-function-declaration' '-Werror=implicit-int' '-Werror=return-type' '-Werror=strict-prototypes' '-Wno-format-security' '-Wno-trigraphs' '-Wno-frame-address' '-Wno-address-of-packed-member' '-Wframe-larger-than=2048' '-Wno-main' '-Wno-type-limits' '-Wdangling-pointer=0' '-Wvla-larger-than=1' '-Wno-pointer-sign' '-Wcast-function-type' '-Wno-unterminated-string-initialization' '-Warray-bounds=0' '-Wstringop-overflow=0' '-Walloc-size-larger-than=$XXX' '-Wimplicit-fallthrough=5' '-Werror=date-time' '-Werror=incompatible-pointer-types' '-Werror=designated-init' '-Wenum-conversion' '-Wunused' '-Wno-unused-but-set-variable' '-Wunused-const-variable=0' '-Wno-packed-not-aligned' '-Wformat-overflow=0' '-Wformat-truncation=0' '-Wno-stringop-truncation' '-Wno-override-init' '-Wno-missing-field-initializers' '-Wno-shift-negative-value' '-Wno-maybe-uninitialized' '-Wno-sign-compare' '-Wno-unused-parameter' '-g' '-fno-var-tracking' '-femit-struct-debug-baseonly' '-mstack-protector-guard=sysreg' '-mstack-protector-guard-reg=sp_el0' '-mstack-protector-guard-offset=1344' '-fno-common' '-fno-builtin' '-fno-stack-protector' '-ffixed-x18' '-D' 'DISABLE_BRANCH_PROFILING' '-D' 'BUILD_VDSO' '-O2' '-mcmodel=tiny' '-fasynchronous-unwind-tables' '-include' '/usr/local/google/home/briannorris/git/linux/lib/vdso/getrandom.c' '-D' 'KBUILD_MODFILE="arch/arm64/kernel/vdso/vgetrandom"' '-D' 'KBUILD_BASENAME="vgetrandom"' '-D' 'KBUILD_MODNAME="vgetrandom"' '-D' '__KBUILD_MODNAME=vgetrandom' '-c' '-o' 'arch/arm64/kernel/vdso/vgetrandom.o' '-v' '-dumpdir' 'arch/arm64/kernel/vdso/'
/usr/lib/gcc-cross/aarch64-linux-gnu/15/../../../../aarch64-linux-gnu/bin/as -v -I ./arch/arm64/include -I ./arch/arm64/include/generated -I ./include -I ./include -I ./arch/arm64/include/uapi -I ./arch/arm64/include/generated/uapi -I ./include/uapi -I ./include/generated/uapi --gsframe --gdwarf-5 -EL -mabi=lp64 -march=armv8.5-a -o arch/arm64/kernel/vdso/vgetrandom.o /tmp/cc6nO0fY.s
GNU assembler version 2.46.50 (aarch64-linux-gnu) using BFD version (GNU Binutils for Debian) 2.46.50.20260617
COMPILER_PATH=/usr/libexec/gcc-cross/aarch64-linux-gnu/15/:/usr/libexec/gcc-cross/aarch64-linux-gnu/15/:/usr/libexec/gcc-cross/aarch64-linux-gnu/:/usr/lib/gcc-cross/aarch64-linux-gnu/15/:/usr/lib/gcc-cross/aarch64-linux-gnu/:/usr/lib/gcc-cross/aarch64-linux-gnu/15/../../../../aarch64-linux-gnu/bin/
LIBRARY_PATH=/usr/lib/gcc-cross/aarch64-linux-gnu/15/:/usr/lib/gcc-cross/aarch64-linux-gnu/15/../../../../aarch64-linux-gnu/lib/../lib/:/lib/aarch64-linux-gnu/:/lib/../lib/:/usr/lib/aarch64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc-cross/aarch64-linux-gnu/15/../../../../aarch64-linux-gnu/lib/:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-nostdinc' '-I' './arch/arm64/include' '-I' './arch/arm64/include/generated' '-I' './include' '-I' './include' '-I' './arch/arm64/include/uapi' '-I' './arch/arm64/include/generated/uapi' '-I' './include/uapi' '-I' './include/generated/uapi' '-include' './include/linux/compiler-version.h' '-include' './include/linux/kconfig.h' '-include' './include/linux/compiler_types.h' '-D' '__KERNEL__' '-mlittle-endian' '-D' 'KASAN_SHADOW_SCALE_SHIFT=' '-Werror' '-fshort-wchar' '-funsigned-char' '-fno-PIE' '-fno-strict-aliasing' '-std=gnu11' '-fms-extensions' '-mgeneral-regs-only' '-D' 'CONFIG_CC_HAS_K_CONSTRAINT=1' '-Wno-psabi' '-mabi=lp64' '-fno-unwind-tables' '-mbranch-protection=pac-ret' '-D' 'ARM64_ASM_ARCH="armv8.5-a"' '-D' 'KASAN_SHADOW_SCALE_SHIFT=' '-fno-delete-null-pointer-checks' '-O2' '-fno-allow-store-data-races' '-fstack-protector-strong' '-fno-omit-frame-pointer' '-fno-optimize-sibling-calls' '-ftrivial-auto-var-init=zero' '-fzero-init-padding-bits=all' '-fno-stack-clash-protection' '-fmin-function-alignment=4' '-fstrict-flex-arrays=3' '-fno-strict-overflow' '-fstack-check=no' '-fconserve-stack' '-fno-builtin-wcslen' '-Wall' '-Wextra' '-Wundef' '-Werror=implicit-function-declaration' '-Werror=implicit-int' '-Werror=return-type' '-Werror=strict-prototypes' '-Wno-format-security' '-Wno-trigraphs' '-Wno-frame-address' '-Wno-address-of-packed-member' '-Wframe-larger-than=2048' '-Wno-main' '-Wno-type-limits' '-Wdangling-pointer=0' '-Wvla-larger-than=1' '-Wno-pointer-sign' '-Wcast-function-type' '-Wno-unterminated-string-initialization' '-Warray-bounds=0' '-Wstringop-overflow=0' '-Walloc-size-larger-than=$XXX' '-Wimplicit-fallthrough=5' '-Werror=date-time' '-Werror=incompatible-pointer-types' '-Werror=designated-init' '-Wenum-conversion' '-Wunused' '-Wno-unused-but-set-variable' '-Wunused-const-variable=0' '-Wno-packed-not-aligned' '-Wformat-overflow=0' '-Wformat-truncation=0' '-Wno-stringop-truncation' '-Wno-override-init' '-Wno-missing-field-initializers' '-Wno-shift-negative-value' '-Wno-maybe-uninitialized' '-Wno-sign-compare' '-Wno-unused-parameter' '-g' '-fno-var-tracking' '-femit-struct-debug-baseonly' '-mstack-protector-guard=sysreg' '-mstack-protector-guard-reg=sp_el0' '-mstack-protector-guard-offset=1344' '-fno-common' '-fno-builtin' '-fno-stack-protector' '-ffixed-x18' '-D' 'DISABLE_BRANCH_PROFILING' '-D' 'BUILD_VDSO' '-O2' '-mcmodel=tiny' '-fasynchronous-unwind-tables' '-include' '/usr/local/google/home/briannorris/git/linux/lib/vdso/getrandom.c' '-D' 'KBUILD_MODFILE="arch/arm64/kernel/vdso/vgetrandom"' '-D' 'KBUILD_BASENAME="vgetrandom"' '-D' 'KBUILD_MODNAME="vgetrandom"' '-D' '__KBUILD_MODNAME=vgetrandom' '-c' '-o' 'arch/arm64/kernel/vdso/vgetrandom.o' '-v' '-dumpdir' 'arch/arm64/kernel/vdso/vgetrandom.'
Quoted 4 lines
Does the intermediate source or assembler source have any ".cfi_section .sframe" statement?
$ make arch/arm64/kernel/vdso/vgetrandom.i
This fails to build with WERROR, because it seems to require the linker step that fails, so I have to disable WERROR. Afterward:
$ grep -i sframe arch/arm64/kernel/vdso/vgetrandom.i // (empty)
Quoted 1 line
$ make arch/arm64/kernel/vdso/vgetrandom.s
This fails to build.
$ make CROSS_COMPILE='ccache aarch64-linux-gnu-' ARCH=arm64 -j80 arch/arm64/kernel/vdso/vgetrandom.s
CC arch/arm64/kernel/vdso/vgetrandom.s
arch/arm64/kernel/vdso/vgetrandom.c:5:8: error: ‘__cvdso_getrandom’ undeclared here (not in a function)
5 | typeof(__cvdso_getrandom) __kernel_getrandom;
| ^~~~~~~~~~~~~~~~~
arch/arm64/kernel/vdso/vgetrandom.c:7:1: error: unknown type name ‘ssize_t’
7 | ssize_t __kernel_getrandom(void *buffer, size_t len, unsigned int flags, void *opaque_state, size_t opaque_len)
| ^~~~~~~
arch/arm64/kernel/vdso/vgetrandom.c:7:42: error: unknown type name ‘size_t’
7 | ssize_t __kernel_getrandom(void *buffer, size_t len, unsigned int flags, void *opaque_state, size_t opaque_len)
| ^~~~~~
arch/arm64/kernel/vdso/vgetrandom.c:4:1: note: ‘size_t’ is defined in header ‘<stddef.h>’; this is probably fixable by adding ‘#include <stddef.h>’
3 | #include <uapi/asm-generic/errno.h>
+++ |+#include <stddef.h>
4 |
arch/arm64/kernel/vdso/vgetrandom.c:7:94: error: unknown type name ‘size_t’
7 | ssize_t __kernel_getrandom(void *buffer, size_t len, unsigned int flags, void *opaque_state, size_t opaque_len)
| ^~~~~~
arch/arm64/kernel/vdso/vgetrandom.c:7:94: note: ‘size_t’ is defined in header ‘<stddef.h>’; this is probably fixable by adding ‘#include <stddef.h>’
make[4]: *** [scripts/Makefile.build:184: arch/arm64/kernel/vdso/vgetrandom.s] Error 1
make[3]: *** [scripts/Makefile.build:549: arch/arm64/kernel] Error 2
make[2]: *** [scripts/Makefile.build:549: arch/arm64] Error 2Quoted 4 lines
Can you please verify that your
arch/arm64/kernel/vdso/vgetrandom.oactually contains an .sframe section:$ readelf -WS arch/arm64/kernel/vdso/vgetrandom.o
$ readelf -WS arch/arm64/kernel/vdso/vgetrandom.o | grep -i sframe [22] .sframe GNU_SFRAME 0000000000000000 002438 000083 00 A 0 0 8 [23] .rela.sframe RELA 0000000000000000 003988 000018 18 I 24 22 8
Brian
Quoted 146 lines · Brian Norris
Thanks for looking! Lots more output below. Feel free to ask for more info you tink could help.`
Quoted 13 lines · Jens Remus
Quoted 11 lines · Brian Norris
On Tue, May 19, 2026 at 01:05:23PM +0200, Jens Remus wrote:
I also work at the same company as Dylan and Mostafa, and am therefore probably using the same company-maintained Linux distribution.
Quoted 6 lines · Dylan Hatch
Quoted 5 lines · Mostafa Saleh
Quoted 4 lines
Not sure if related, but after updating my toolchain
(aarch64-linux-gnu-gcc (Debian 15.2.0-4) 15.2.0), I hit link errors:
ld.lld: error: arch/arm64/kernel/vdso/vgettimeofday.o:(.sframe) is being placed in '.sframe' ld.lld: error: arch/arm64/kernel/vdso/vgetrandom.o:(.sframe) is being placed in '.sframe`Quoted 4 lines
My understanding of above message is that the linker complains that the input object (e.g. vgettimeofday.o) has an .sframe section for which the linker script does not have any rule, so that it defaults to place it in .sframe in the output, which could not be the desired result.
Not sure if it's obvious to you, but I also found a few more details:
* This is most noticeable with
CONFIG_WERROR=y, which turns the linker warning into an error.* It appears both with LD=ld.lld and with the default (bfd linker). bfd shows:
/usr/bin/aarch64-linux-gnu-ld.bfd: error: unplaced orphan section.sframe' fromarch/arm64/kernel/vdso/vgettimeofday.o'/usr/bin/aarch64-linux-gnu-ld.bfd: error: unplaced orphan section.sframe' fromarch/arm64/kernel/vdso/vgetrandom.o'Otherwise, I don't have to do much special to hit this. Just cross-compile ARCH=arm64 defconfig.
Quoted 60 lines
Quoted 60 lines
I've also been hitting this for some time, and I'd like to see if I can figure out what's going wrong. My current workaround is:
Makefile +2
-0@@ -946,6 +946,8 @@ ifdef CONFIG_CC_IS_GCC KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0) KBUILD_CFLAGS += $(call cc-option,-fno-allow-store-data-races) endif +# No sframe generation for kernel if enabled by default +KBUILD_CFLAGS += $(call cc-option,-Xassembler --gsframe=no) ifdef CONFIG_READABLE_ASM # Disable optimizations that make assembler listings hard to read.Quoted 28 lines
Quoted 18 lines
Previously when developing against the SFrame V2 format, I had fixed these warnings with the VDSO
Makefilechange currently in this series:arch/arm64/kernel/vdso/Makefile +1
-1@@ -38,7 +38,7 @@ ccflags-y += -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO CC_FLAGS_REMOVE_VDSO := $(CC_FLAGS_FTRACE) -Os $(CC_FLAGS_SCS) \ $(RANDSTRUCT_CFLAGS) $(KSTACK_ERASE_CFLAGS) \ $(GCC_PLUGINS_CFLAGS) \ - $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) \ + $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) $(CC_FLAGS_SFRAME) \ -Wmissing-prototypes -Wmissing-declarations CC_FLAGS_ADD_VDSO := -O2 -mcmodel=tiny -fasynchronous-unwind-tablesQuoted 4 lines
But the warnings seem to have returned after upgrading my toolchain, possibly due to SFrame V3 or some confounding change in GCC. The --gsframe in the assembler should be set to 'no' by default, so perhaps GCC is providing an override --gsframe internally?
Could it be that your build of binutils was configured with --enable-default-sframe, so that the GNU assembler defaults to generate .sframe? AFAIK this configure option was meant for distributors and package maintainers.
Quoted 6 lines
You can check as follows whether --gsframe defaults to "no" or "yes":
$ as --help | grep -A1 gsframe --gsframe[={no|yes}] whether to generate SFrame stack trace information (default: no) ...$ aarch64-linux-gnu-as --help | grep -A1 gsframe --gsframe[={no|yes}] whether to generate SFrame stack trace information (default: no) -- --gsframe-<N> generate SFrame version <N> information. 3 == <N> --scfi=experimental Synthesize DWARF CFI for hand-written asmQuoted 3 lines
Maybe build the VDSO separately with V=1 to see what assembler/compiler options are effectively used (e.g. for vgettimeofday.o and vgetrandom.o mentioned in the linker error message above)?
Quoted 8 lines
Quoted 4 lines
A slightly tweaked version of my vgetrandom.o build line:
# CC
arch/arm64/kernel/vdso/vgetrandom.o
aarch64-linux-gnu-gcc -Wp,-MMD,arch/arm64/kernel/vdso/.vgetrandom.o.d -nostdinc -I./arch/arm64/include -I./arch/arm64/include/generated -I./include -I./include -I./arch/arm64/include/uapi -I./arch/arm64/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include./include/linux/compiler-version.h-include./include/linux/kconfig.h-include./include/linux/compiler_types.h-D__KERNEL__ -mlittle-endian -DCC_USING_PATCHABLE_FUNCTION_ENTRY -DKASAN_SHADOW_SCALE_SHIFT= -Werror -fshort-wchar -funsigned-char -fno-common -fno-PIE -fno-strict-aliasing -std=gnu11 -fms-extensions -mgeneral-regs-only -DCONFIG_CC_HAS_K_CONSTRAINT=1 -Wno-psabi -mabi=lp64 -fno-asynchronous-unwind-tables -fno-unwind-tables -mbranch-protection=pac-ret -Wa,-march=armv8.5-a -DARM64_ASM_ARCH='"armv8.5-a"' -DKASAN_SHADOW_SCALE_SHIFT= -fno-delete-null-pointer-checks -O2 -fno-allow-store-data-races -fstack-protector-strong -fno-omit-frame-pointer -fno-optimize-sibling-calls -ftrivial-auto-var-init=zero -fzero-init-padding-bits=all -fno-stack-clash-protection -fno-inline-functions-called-once -fmin-function-alignment=8 -fstrict-flex-arrays=3 -fno-strict-overflow -fno-stack-check -fconserve-stack -fno-builtin-wcslen -Wall -Wextra -Wundef -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Werror=strict-prototypes -Wno-format-security -Wno-trigraphs -Wno-frame-address -Wno-address-of-packed-member -Wframe-larger-than=2048 -Wno-main -Wno-type-limits -Wno-dangling-pointer -Wvla-larger-than=1 -Wno-pointer-sign -Wcast-function-type -Wno-unterminated-string-initialization -Wno-array-bounds -Wno-stringop-overflow -Wno-alloc-size-larger-than -Wimplicit-fallthrough=5 -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -Wenum-conversion -Wunused -Wno-unused-but-set-variable -Wno-unused-const-variable -Wno-packed-not-aligned -Wno-format-overflow -Wno-format-truncation -Wno-stringop-truncation -Wno-override-init -Wno-missing-field-initializers -Wno-shift-negative-value -Wno-maybe-uninitialized -Wno-sign-compare -Wno-unused-parameter -g -mstack-protector-guard=sysreg -mstack-protector-guard-reg=sp_el0 -mstack-protector-guard-offset=1344 -fno-common -fno-builtin -fno-stack-protector -ffixed-x18 -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO -O2 -mcmodel=tiny -fasynchronous-unwind-tables -include./lib/vdso/getrandom.c-I./arch/arm64/kernel/vdso -Iarch/arm64/kernel/vdso -DKBUILD_MODFILE='"arch/arm64/kernel/vdso/vgetrandom"' -DKBUILD_BASENAME='"vgetrandom"' -DKBUILD_MODNAME='"vgetrandom"' -D__KBUILD_MODNAME=vgetrandom -c -oarch/arm64/kernel/vdso/vgetrandom.o./arch/arm64/kernel/vdso/vgetrandom.cThat command line does not have any --gsframe[-3] (e.g. -Wa,--gsframe). I am not aware of any binutils release / repository state where the --gsframe default was broken.
FWIW, I'm usually testing on both v7.1 and approx v7.2-rc3, to make sure my results are consistent, and it's not already somehow fixed.
Quoted 8 lines
@Indu: Do you have any idea what could be going on?
Quoted 2 lines
I mostly don't know what I'm looking for w.r.t. gsframe features, but I'm willing to poke at my compiler/assembler/build-process.
Could it be that your gcc injects --gsframe e.g. via its spec file? Maybe that would show up if you run above command manually and append gcc option -v?
I've dumped most of the output below. I see that the 'as' invocation includes --gsframe, but I'm not sure why.
$ aarch64-linux-gnu-gcc -Wp,-MMD,arch/arm64/kernel/vdso/.vgetrandom.o.d -nostdinc -I./arch/arm64/include -I./arch/arm64/include/generated -I./include -I./include -I./arch/arm64/include/uapi -I./arch/arm64/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/compiler-version.h -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__ -mlittle-endian -DKASAN_SHADOW_SCALE_SHIFT= -Werror -fshort-wchar -funsigned-char -fno-common -fno-PIE -fno-strict-aliasing -std=gnu11 -fms-extensions -mgeneral-regs-only -DCONFIG_CC_HAS_K_CONSTRAINT=1 -Wno-psabi -mabi=lp64 -fno-asynchronous-unwind-tables -fno-unwind-tables -mbranch-protection=pac-ret -Wa,-march=armv8.5-a -DARM64_ASM_ARCH='"armv8.5-a"' -DKASAN_SHADOW_SCALE_SHIFT= -fno-delete-null-pointer-checks -O2 -fno-allow-store-data-races -fstack-protector-strong -fno-omit-frame-pointer -fno-optimize-sibling-calls -ftrivial-auto-var-init=zero -fzero-init-padding-bits=all -fno-stack-clash-protection -fmin-function-alignment=4 -fstrict-flex-arrays=3 -fno-strict-overflow -fno-stack-check -fconserve-stack -fno-builtin-wcslen -Wall -Wextra -Wundef -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Werror=strict-prototypes -Wno-format-security -Wno-trigraphs -Wno-frame-address -Wno-address-of-packed-member -Wframe-larger-than=2048 -Wno-main -Wno-type-limits -Wno-dangling-pointer -Wvla-larger-than=1 -Wno-pointer-sign -Wcast-function-type -Wno-unterminated-string-initialization -Wno-array-bounds -Wno-stringop-overflow -Wno-alloc-size-larger-than -Wimplicit-fallthrough=5 -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -Wenum-conversion -Wunused -Wno-unused-but-set-variable -Wno-unused-const-variable -Wno-packed-not-aligned -Wno-format-overflow -Wno-format-truncation -Wno-stringop-truncation -Wno-override-init -Wno-missing-field-initializers -Wno-shift-negative-value -Wno-maybe-uninitialized -Wno-sign-compare -Wno-unused-parameter -g -fno-var-tracking -femit-struct-debug-baseonly -mstack-protector-guard=sysreg -mstack-protector-guard-reg=sp_el0 -mstack-protector-guard-offset=1344 -fno-common -fno-builtin -fno-stack-protector -ffixed-x18 -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO -O2 -mcmodel=tiny -fasynchronous-unwind-tables -include $LINUX/lib/vdso/getrandom.c -DKBUILD_MODFILE='"arch/arm64/kernel/vdso/vgetrandom"' -DKBUILD_BASENAME='"vgetrandom"' -DKBUILD_MODNAME='"vgetrandom"' -D__KBUILD_MODNAME=vgetrandom -c -o arch/arm64/kernel/vdso/vgetrandom.o arch/arm64/kernel/vdso/vgetrandom.c -v Using built-in specs. COLLECT_AS_OPTIONS='-march=armv8.5-a' COLLECT_GCC=aarch64-linux-gnu-gcc Target: aarch64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Debian 15.2.0-4' --with-bugurl=file:///usr/share/doc/gcc-15/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2,cobol,algol68 --prefix=/usr --with-gcc-major-version-only --program-suffix=-15 --enable-shared --enable-linker-build-id --libexecdir=/usr/libexec --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-libstdcxx-backtrace --enable-gnu-unique-object --disable-libquadmath --disable-libquadmath-support --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --without-target-system-zlib --enable-multiarch --enable-fix-cortex-a53-843419 --disable-werror --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=aarch64-linux-gnu --program-prefix=aarch64-linux-gnu- --includedir=/usr/aarch64-linux-gnu/include --with-build-config=bootstrap-lto-lean --enable-link-serialization=32 Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 15.2.0 (Debian 15.2.0-4) COLLECT_GCC_OPTIONS='-nostdinc' '-I' './arch/arm64/include' '-I' './arch/arm64/include/generated' '-I' './include' '-I' './include' '-I' './arch/arm64/include/uapi' '-I' './arch/arm64/include/generated/uapi' '-I' './include/uapi' '-I' './include/generated/uapi' '-include' './include/linux/compiler-version.h' '-include' './include/linux/kconfig.h' '-include' './include/linux/compiler_types.h' '-D' '__KERNEL__' '-mlittle-endian' '-D' 'KASAN_SHADOW_SCALE_SHIFT=' '-Werror' '-fshort-wchar' '-funsigned-char' '-fno-PIE' '-fno-strict-aliasing' '-std=gnu11' '-fms-extensions' '-mgeneral-regs-only' '-D' 'CONFIG_CC_HAS_K_CONSTRAINT=1' '-Wno-psabi' '-mabi=lp64' '-fno-unwind-tables' '-mbranch-protection=pac-ret' '-D' 'ARM64_ASM_ARCH="armv8.5-a"' '-D' 'KASAN_SHADOW_SCALE_SHIFT=' '-fno-delete-null-pointer-checks' '-O2' '-fno-allow-store-data-races' '-fstack-protector-strong' '-fno-omit-frame-pointer' '-fno-optimize-sibling-calls' '-ftrivial-auto-var-init=zero' '-fzero-init-padding-bits=all' '-fno-stack-clash-protection' '-fmin-function-alignment=4' '-fstrict-flex-arrays=3' '-fno-strict-overflow' '-fstack-check=no' '-fconserve-stack' '-fno-builtin-wcslen' '-Wall' '-Wextra' '-Wundef' '-Werror=implicit-function-declaration' '-Werror=implicit-int' '-Werror=return-type' '-Werror=strict-prototypes' '-Wno-format-security' '-Wno-trigraphs' '-Wno-frame-address' '-Wno-address-of-packed-member' '-Wframe-larger-than=2048' '-Wno-main' '-Wno-type-limits' '-Wdangling-pointer=0' '-Wvla-larger-than=1' '-Wno-pointer-sign' '-Wcast-function-type' '-Wno-unterminated-string-initialization' '-Warray-bounds=0' '-Wstringop-overflow=0' '-Walloc-size-larger-than=$XXX' '-Wimplicit-fallthrough=5' '-Werror=date-time' '-Werror=incompatible-pointer-types' '-Werror=designated-init' '-Wenum-conversion' '-Wunused' '-Wno-unused-but-set-variable' '-Wunused-const-variable=0' '-Wno-packed-not-aligned' '-Wformat-overflow=0' '-Wformat-truncation=0' '-Wno-stringop-truncation' '-Wno-override-init' '-Wno-missing-field-initializers' '-Wno-shift-negative-value' '-Wno-maybe-uninitialized' '-Wno-sign-compare' '-Wno-unused-parameter' '-g' '-fno-var-tracking' '-femit-struct-debug-baseonly' '-mstack-protector-guard=sysreg' '-mstack-protector-guard-reg=sp_el0' '-mstack-protector-guard-offset=1344' '-fno-common' '-fno-builtin' '-fno-stack-protector' '-ffixed-x18' '-D' 'DISABLE_BRANCH_PROFILING' '-D' 'BUILD_VDSO' '-O2' '-mcmodel=tiny' '-fasynchronous-unwind-tables' '-include' '$LINUX/lib/vdso/getrandom.c' '-D' 'KBUILD_MODFILE="arch/arm64/kernel/vdso/vgetrandom"' '-D' 'KBUILD_BASENAME="vgetrandom"' '-D' 'KBUILD_MODNAME="vgetrandom"' '-D' '__KBUILD_MODNAME=vgetrandom' '-c' '-o' 'arch/arm64/kernel/vdso/vgetrandom.o' '-v' '-dumpdir' 'arch/arm64/kernel/vdso/' /usr/libexec/gcc-cross/aarch64-linux-gnu/15/cc1 -quiet -nostdinc -v -I ./arch/arm64/include -I ./arch/arm64/include/generated -I ./include -I ./include -I ./arch/arm64/include/uapi -I ./arch/arm64/include/generated/uapi -I ./include/uapi -I ./include/generated/uapi -imultiarch aarch64-linux-gnu -D __KERNEL__ -D KASAN_SHADOW_SCALE_SHIFT= -D CONFIG_CC_HAS_K_CONSTRAINT=1 -D ARM64_ASM_ARCH="armv8.5-a" -D KASAN_SHADOW_SCALE_SHIFT= -D DISABLE_BRANCH_PROFILING -D BUILD_VDSO -D KBUILD_MODFILE="arch/arm64/kernel/vdso/vgetrandom" -D KBUILD_BASENAME="vgetrandom" -D KBUILD_MODNAME="vgetrandom" -D __KBUILD_MODNAME=vgetrandom -include ./include/linux/compiler-version.h -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -include /usr/local/google/home/briannorris/git/linux/lib/vdso/getrandom.c -MMD arch/arm64/kernel/vdso/.vgetrandom.o.d arch/arm64/kernel/vdso/vgetrandom.c -quiet -dumpdir arch/arm64/kernel/vdso/ -dumpbase vgetrandom.c -dumpbase-ext .c -mlittle-endian -mgeneral-regs-only -mabi=lp64 -mbranch-protection=pac-ret -mstack-protector-guard=sysreg -mstack-protector-guard-reg=sp_el0 -mstack-protector-guard-offset=1344 -mcmodel=tiny -g -O2 -O2 -Werror -Wno-psabi -Wall -Wextra -Wundef -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Werror=strict-prototypes -Wno-format-security -Wno-trigraphs -Wno-frame-address -Wno-address-of-packed-member -Wframe-larger-than=2048 -Wno-main -Wno-type-limits -Wdangling-pointer=0 -Wvla-larger-than=1 -Wno-pointer-sign -Wcast-function-type -Wno-unterminated-string-initialization -Warray-bounds=0 -Wstringop-overflow=0 -Walloc-size-larger-than=18446744073709551615EiB -Wimplicit-fallthrough=5 -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -Wenum-conversion -Wunused -Wno-unused-but-set-variable -Wunused-const-variable=0 -Wno-packed-not-aligned -Wformat-overflow=0 -Wformat-truncation=0 -Wno-stringop-truncation -Wno-override-init -Wno-missing-field-initializers -Wno-shift-negative-value -Wno-maybe-uninitialized -Wno-sign-compare -Wno-unused-parameter -std=gnu11 -version -fshort-wchar -funsigned-char -fno-PIE -fno-strict-aliasing -fms-extensions -fno-unwind-tables -fno-delete-null-pointer-checks -fno-allow-store-data-races -fstack-protector-strong -fno-omit-frame-pointer -fno-optimize-sibling-calls -ftrivial-auto-var-init=zero -fzero-init-padding-bits=all -fno-stack-clash-protection -fmin-function-alignment=4 -fstrict-flex-arrays=3 -fno-strict-overflow -fstack-check=no -fconserve-stack -fno-builtin-wcslen -fno-var-tracking -femit-struct-debug-baseonly -fno-common -fno-builtin -fno-stack-protector -ffixed-x18 -fasynchronous-unwind-tables -fasynchronous-unwind-tables -o /tmp/cc6nO0fY.s GNU C11 (Debian 15.2.0-4) version 15.2.0 (aarch64-linux-gnu) compiled by GNU C version 15.2.0, GMP version 6.3.0, MPFR version 4.2.2, MPC version 1.3.1, isl version isl-0.27-GMPGGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 ignoring duplicate directory "./include"
#include "..." search starts here:
#include <...> search starts here:
./arch/arm64/include
./arch/arm64/include/generated
./include
./arch/arm64/include/uapi
./arch/arm64/include/generated/uapi
./include/uapi
./include/generated/uapi
Quoted 8 lines
End of search list.
Compiler executable checksum:2014541e26adcb350b182f07eff54ec5
COLLECT_GCC_OPTIONS='-nostdinc' '-I' './arch/arm64/include' '-I' './arch/arm64/include/generated' '-I' './include' '-I' './include' '-I' './arch/arm64/include/uapi' '-I' './arch/arm64/include/generated/uapi' '-I' './include/uapi' '-I' './include/generated/uapi' '-include' './include/linux/compiler-version.h' '-include' './include/linux/kconfig.h' '-include' './include/linux/compiler_types.h' '-D' '__KERNEL__' '-mlittle-endian' '-D' 'KASAN_SHADOW_SCALE_SHIFT=' '-Werror' '-fshort-wchar' '-funsigned-char' '-fno-PIE' '-fno-strict-aliasing' '-std=gnu11' '-fms-extensions' '-mgeneral-regs-only' '-D' 'CONFIG_CC_HAS_K_CONSTRAINT=1' '-Wno-psabi' '-mabi=lp64' '-fno-unwind-tables' '-mbranch-protection=pac-ret' '-D' 'ARM64_ASM_ARCH="armv8.5-a"' '-D' 'KASAN_SHADOW_SCALE_SHIFT=' '-fno-delete-null-pointer-checks' '-O2' '-fno-allow-store-data-races' '-fstack-protector-strong' '-fno-omit-frame-pointer' '-fno-optimize-sibling-calls' '-ftrivial-auto-var-init=zero' '-fzero-init-padding-bits=all' '-fno-stack-clash-protection' '-fmin-function-alignment=4' '-fstrict-flex-arrays=3' '-fno-strict-overflow' '-fstack-check=no' '-fconserve-stack' '-fno-builtin-wcslen' '-Wall' '-Wextra' '-Wundef' '-Werror=implicit-function-declaration' '-Werror=implicit-int' '-Werror=return-type' '-Werror=strict-prototypes' '-Wno-format-security' '-Wno-trigraphs' '-Wno-frame-address' '-Wno-address-of-packed-member' '-Wframe-larger-than=2048' '-Wno-main' '-Wno-type-limits' '-Wdangling-pointer=0' '-Wvla-larger-than=1' '-Wno-pointer-sign' '-Wcast-function-type' '-Wno-unterminated-string-initialization' '-Warray-bounds=0' '-Wstringop-overflow=0' '-Walloc-size-larger-than=$XXX' '-Wimplicit-fallthrough=5' '-Werror=date-time' '-Werror=incompatible-pointer-types' '-Werror=designated-init' '-Wenum-conversion' '-Wunused' '-Wno-unused-but-set-variable' '-Wunused-const-variable=0' '-Wno-packed-not-aligned' '-Wformat-overflow=0' '-Wformat-truncation=0' '-Wno-stringop-truncation' '-Wno-override-init' '-Wno-missing-field-initializers' '-Wno-shift-negative-value' '-Wno-maybe-uninitialized' '-Wno-sign-compare' '-Wno-unused-parameter' '-g' '-fno-var-tracking' '-femit-struct-debug-baseonly' '-mstack-protector-guard=sysreg' '-mstack-protector-guard-reg=sp_el0' '-mstack-protector-guard-offset=1344' '-fno-common' '-fno-builtin' '-fno-stack-protector' '-ffixed-x18' '-D' 'DISABLE_BRANCH_PROFILING' '-D' 'BUILD_VDSO' '-O2' '-mcmodel=tiny' '-fasynchronous-unwind-tables' '-include' '/usr/local/google/home/briannorris/git/linux/lib/vdso/getrandom.c' '-D' 'KBUILD_MODFILE="arch/arm64/kernel/vdso/vgetrandom"' '-D' 'KBUILD_BASENAME="vgetrandom"' '-D' 'KBUILD_MODNAME="vgetrandom"' '-D' '__KBUILD_MODNAME=vgetrandom' '-c' '-o' 'arch/arm64/kernel/vdso/vgetrandom.o' '-v' '-dumpdir' 'arch/arm64/kernel/vdso/'
/usr/lib/gcc-cross/aarch64-linux-gnu/15/../../../../aarch64-linux-gnu/bin/as-v -I./arch/arm64/include-I./arch/arm64/include/generated-I ./include -I ./include -I./arch/arm64/include/uapi-I./arch/arm64/include/generated/uapi-I./include/uapi-I./include/generated/uapi--gsframe --gdwarf-5 -EL -mabi=lp64 -march=armv8.5-a -oarch/arm64/kernel/vdso/vgetrandom.o/tmp/cc6nO0fY.s
GNU assembler version 2.46.50 (aarch64-linux-gnu) using BFD version (GNU Binutils for Debian) 2.46.50.20260617
COMPILER_PATH=/usr/libexec/gcc-cross/aarch64-linux-gnu/15/:/usr/libexec/gcc-cross/aarch64-linux-gnu/15/:/usr/libexec/gcc-cross/aarch64-linux-gnu/:/usr/lib/gcc-cross/aarch64-linux-gnu/15/:/usr/lib/gcc-cross/aarch64-linux-gnu/:/usr/lib/gcc-cross/aarch64-linux-gnu/15/../../../../aarch64-linux-gnu/bin/
LIBRARY_PATH=/usr/lib/gcc-cross/aarch64-linux-gnu/15/:/usr/lib/gcc-cross/aarch64-linux-gnu/15/../../../../aarch64-linux-gnu/lib/../lib/:/lib/aarch64-linux-gnu/:/lib/../lib/:/usr/lib/aarch64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc-cross/aarch64-linux-gnu/15/../../../../aarch64-linux-gnu/lib/:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-nostdinc' '-I' './arch/arm64/include' '-I' './arch/arm64/include/generated' '-I' './include' '-I' './include' '-I' './arch/arm64/include/uapi' '-I' './arch/arm64/include/generated/uapi' '-I' './include/uapi' '-I' './include/generated/uapi' '-include' './include/linux/compiler-version.h' '-include' './include/linux/kconfig.h' '-include' './include/linux/compiler_types.h' '-D' '__KERNEL__' '-mlittle-endian' '-D' 'KASAN_SHADOW_SCALE_SHIFT=' '-Werror' '-fshort-wchar' '-funsigned-char' '-fno-PIE' '-fno-strict-aliasing' '-std=gnu11' '-fms-extensions' '-mgeneral-regs-only' '-D' 'CONFIG_CC_HAS_K_CONSTRAINT=1' '-Wno-psabi' '-mabi=lp64' '-fno-unwind-tables' '-mbranch-protection=pac-ret' '-D' 'ARM64_ASM_ARCH="armv8.5-a"' '-D' 'KASAN_SHADOW_SCALE_SHIFT=' '-fno-delete-null-pointer-checks' '-O2' '-fno-allow-store-data-races' '-fstack-protector-strong' '-fno-omit-frame-pointer' '-fno-optimize-sibling-calls' '-ftrivial-auto-var-init=zero' '-fzero-init-padding-bits=all' '-fno-stack-clash-protection' '-fmin-function-alignment=4' '-fstrict-flex-arrays=3' '-fno-strict-overflow' '-fstack-check=no' '-fconserve-stack' '-fno-builtin-wcslen' '-Wall' '-Wextra' '-Wundef' '-Werror=implicit-function-declaration' '-Werror=implicit-int' '-Werror=return-type' '-Werror=strict-prototypes' '-Wno-format-security' '-Wno-trigraphs' '-Wno-frame-address' '-Wno-address-of-packed-member' '-Wframe-larger-than=2048' '-Wno-main' '-Wno-type-limits' '-Wdangling-pointer=0' '-Wvla-larger-than=1' '-Wno-pointer-sign' '-Wcast-function-type' '-Wno-unterminated-string-initialization' '-Warray-bounds=0' '-Wstringop-overflow=0' '-Walloc-size-larger-than=$XXX' '-Wimplicit-fallthrough=5' '-Werror=date-time' '-Werror=incompatible-pointer-types' '-Werror=designated-init' '-Wenum-conversion' '-Wunused' '-Wno-unused-but-set-variable' '-Wunused-const-variable=0' '-Wno-packed-not-aligned' '-Wformat-overflow=0' '-Wformat-truncation=0' '-Wno-stringop-truncation' '-Wno-override-init' '-Wno-missing-field-initializers' '-Wno-shift-negative-value' '-Wno-maybe-uninitialized' '-Wno-sign-compare' '-Wno-unused-parameter' '-g' '-fno-var-tracking' '-femit-struct-debug-baseonly' '-mstack-protector-guard=sysreg' '-mstack-protector-guard-reg=sp_el0' '-mstack-protector-guard-offset=1344' '-fno-common' '-fno-builtin' '-fno-stack-protector' '-ffixed-x18' '-D' 'DISABLE_BRANCH_PROFILING' '-D' 'BUILD_VDSO' '-O2' '-mcmodel=tiny' '-fasynchronous-unwind-tables' '-include' '/usr/local/google/home/briannorris/git/linux/lib/vdso/getrandom.c' '-D' 'KBUILD_MODFILE="arch/arm64/kernel/vdso/vgetrandom"' '-D' 'KBUILD_BASENAME="vgetrandom"' '-D' 'KBUILD_MODNAME="vgetrandom"' '-D' '__KBUILD_MODNAME=vgetrandom' '-c' '-o' 'arch/arm64/kernel/vdso/vgetrandom.o' '-v' '-dumpdir' 'arch/arm64/kernel/vdso/vgetrandom.'
This proves thet assembler option --gsframe did not originate from the kernel Makefile, but was supplied by GCC for the assembly step. I guess it gets injected by some GCC .specs file. Please review the output of:
for "sframe":
$ aarch64-linux-gnu-gcc -dumpspecs
Quoted 29 lines
Quoted 4 lines
Does the intermediate source or assembler source have any ".cfi_section .sframe" statement?
$ make arch/arm64/kernel/vdso/vgetrandom.iThis fails to build with WERROR, because it seems to require the linker step that fails, so I have to disable WERROR. Afterward:
$ grep -i sframe arch/arm64/kernel/vdso/vgetrandom.i // (empty)Quoted 1 line
$ make arch/arm64/kernel/vdso/vgetrandom.sThis fails to build.
$ make CROSS_COMPILE='ccache aarch64-linux-gnu-' ARCH=arm64 -j80 arch/arm64/kernel/vdso/vgetrandom.s CC arch/arm64/kernel/vdso/vgetrandom.s arch/arm64/kernel/vdso/vgetrandom.c:5:8: error: ‘__cvdso_getrandom’ undeclared here (not in a function) 5 | typeof(__cvdso_getrandom) __kernel_getrandom; | ^~~~~~~~~~~~~~~~~ arch/arm64/kernel/vdso/vgetrandom.c:7:1: error: unknown type name ‘ssize_t’ 7 | ssize_t __kernel_getrandom(void *buffer, size_t len, unsigned int flags, void *opaque_state, size_t opaque_len) | ^~~~~~~ arch/arm64/kernel/vdso/vgetrandom.c:7:42: error: unknown type name ‘size_t’ 7 | ssize_t __kernel_getrandom(void *buffer, size_t len, unsigned int flags, void *opaque_state, size_t opaque_len) | ^~~~~~ arch/arm64/kernel/vdso/vgetrandom.c:4:1: note: ‘size_t’ is defined in header ‘<stddef.h>’; this is probably fixable by adding ‘#include <stddef.h>’ 3 | #include <uapi/asm-generic/errno.h> +++ |+#include <stddef.h>
Quoted 8 lines
4 |
arch/arm64/kernel/vdso/vgetrandom.c:7:94: error: unknown type name ‘size_t’
7 | ssize_t __kernel_getrandom(void *buffer, size_t len, unsigned int flags, void *opaque_state, size_t opaque_len)
| ^~~~~~
arch/arm64/kernel/vdso/vgetrandom.c:7:94: note: ‘size_t’ is defined in header ‘<stddef.h>’; this is probably fixable by adding ‘#include <stddef.h>’
make[4]: *** [scripts/Makefile.build:184: arch/arm64/kernel/vdso/vgetrandom.s] Error 1
make[3]: *** [scripts/Makefile.build:549: arch/arm64/kernel] Error 2
make[2]: *** [scripts/Makefile.build:549: arch/arm64] Error 2No idea.
Quoted 8 lines
Quoted 4 lines
Can you please verify that your
arch/arm64/kernel/vdso/vgetrandom.oactually contains an .sframe section:$ readelf -WS arch/arm64/kernel/vdso/vgetrandom.o$ readelf -WS arch/arm64/kernel/vdso/vgetrandom.o | grep -i sframe [22] .sframe GNU_SFRAME 0000000000000000 002438 000083 00 A 0 0 8 [23] .rela.sframe RELA 0000000000000000 003988 000018 18 I 24 22 8
This proves that there is an .sframe section, which is expected given that GCC specified --gsframe during assembly.
Regards,
Jens
Signature · 6 lines
Jens Remus Linux on Z Development (D3303) [email protected] / [email protected] 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/
Hi Jens,
Quoted 6 lines · Jens Remus
This proves thet assembler option --gsframe did not originate from the kernel
Makefile, but was supplied by GCC for the assembly step. I guess it gets injected by some GCC .specs file. Please review the output of:
for "sframe":$ aarch64-linux-gnu-gcc -dumpspecs
Thanks for all the pointers!
$ aarch64-linux-gnu-gcc -dumpspecs | grep -B 1 sframe
*asm_options:
%{-target-help:%:print-asm-header()} %{v} %{w:-W} %{I*} %{!m16:%{!m32:%{!mx32:%{!ffreestanding:--gsframe}}}}%(asm_debug_option) %{gz|gz=zlib:--compress-debug-sections=zlib} %{gz=none:--compress-debug-sections=none} %{gz=zstd:--compress-debug-sections=zstd} %{gz=zlib-gnu:}%a %Y %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}
--
*distro_defaults_asm:
%{!m16:%{!m32:%{!mx32:%{!ffreestanding:--gsframe}}}}I looked further into the bug trackers here, and I see that:
(1) it seems Debian testing(?) and Ubuntu may have enabled sframe by default
(2) my distro is Debian-testing-based
(3) other people have already requested my distro disable sframe, due to
issues like the following:
https://github.com/rust-lang/rust/issues/155704
https://salsa.debian.org/toolchain-team/gcc/-/commit/bd33f862a3f93c3d3b1fbc8dfb6b0366905d7ab4I'll follow up with these to make sure #3 is fully resolved. Hopefully that resolves this problem too.
Thanks again,
Brian