[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251205171446.2814872-1-jremus@linux.ibm.com>
Date: Fri, 5 Dec 2025 18:14:31 +0100
From: Jens Remus <jremus@...ux.ibm.com>
To: linux-kernel@...r.kernel.org, linux-trace-kernel@...r.kernel.org,
linux-s390@...r.kernel.org, bpf@...r.kernel.org, x86@...nel.org,
Steven Rostedt <rostedt@...nel.org>
Cc: Jens Remus <jremus@...ux.ibm.com>, Heiko Carstens <hca@...ux.ibm.com>,
Vasily Gorbik <gor@...ux.ibm.com>,
Ilya Leoshkevich <iii@...ux.ibm.com>,
Josh Poimboeuf <jpoimboe@...nel.org>,
Masami Hiramatsu <mhiramat@...nel.org>,
Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
Peter Zijlstra <peterz@...radead.org>, Ingo Molnar <mingo@...nel.org>,
Jiri Olsa <jolsa@...nel.org>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Namhyung Kim <namhyung@...nel.org>,
Thomas Gleixner <tglx@...utronix.de>,
Andrii Nakryiko <andrii@...nel.org>,
Indu Bhagat <indu.bhagat@...cle.com>,
"Jose E. Marchesi" <jemarch@....org>,
Beau Belgrave <beaub@...ux.microsoft.com>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Florian Weimer <fweimer@...hat.com>, Kees Cook <kees@...nel.org>,
"Carlos O'Donell" <codonell@...hat.com>, Sam James <sam@...too.org>,
Dylan Hatch <dylanbhatch@...gle.com>
Subject: [RFC PATCH v2 00/15] s390: SFrame user space unwinding
This RFC series adds s390 support for unwinding of user space using
SFrame. It is based on Josh's, Steven's, and my work (see prerequisites
below). The generic unwind user (sframe) frameworks are extended to
enable support for a few s390-particularities (see patches 8-11),
including unwinding of user space using back chain (see patch 12).
The latter could be broken apart as a separate patch series.
Changes in RFC v2:
- Rebased on latest "unwind user" enhancements from Peter Zijlstra and
my latest "unwind user sframe" series v12.
- Incorporated RFC v1 review feedback.
- No new config options (except for unwind user backchain).
Motivation:
On s390 unwinding using frame pointer (FP) is unsupported, because of
lack of proper s390 64-bit (s390x) ABI specification and compiler
support. The ABI does only specify a "preferred" FP register. Both GCC
and Clang, regardless of compiler option -fno-omit-frame-pointer, setup
the preferred FP register as late as possible, which usually is after
static stack allocation, so that the CFA cannot be deduced from the FP
without any further data, such as provided by DWARF CFI or SFrame.
In theory there is a s390-specific alternative of unwinding using
back chain (compiler option -mbackchain), but this has its own
limitations. Ubuntu is currently the only distribution that that
builds user space with back chain.
As a consequence the Kernel stack tracer cannot unwind user space
(except if it is built with back chain). Recording call graphs of user
space using perf is limited to stack dump sampling (i.e. perf record
--call-graph dwarf), which generates a fairly large amount of data and
has limitations.
Initial testing of recording call graphs using perf using the s390
support for SFrame provided by RFC v1 of this series shows that
data size notably improves:
perf record data size is greatly reduced (smaller perf.data):
SFrame (--call-graph fp):
# perf record -F 9999 --call-graph fp objdump -wdWF objdump
[ perf record: Woken up 9 times to write data ]
[ perf record: Captured and wrote 2.498 MB perf.data (10891 samples) ]
Stack sampling (--call-graph dwarf) with a default stack size of 8192:
# perf record -F 9999 --call-graph dwarf objdump -wdWF objdump
[ perf record: Woken up 270 times to write data ]
[ perf record: Captured and wrote 67.467 MB perf.data (8241 samples) ]
Prerequirements:
This RFC series applies on top of the latest unwind user sframe series
"[PATCH v12 00/13] unwind_deferred: Implement sframe handling":
https://lore.kernel.org/all/20251119132323.1281768-1-jremus@linux.ibm.com/
It depends on binutils 2.45 to build executables and libraries
(e.g. vDSO) with SFrame on s390, including the latest SFrame V2 with
PC-relative FDE encoding. Optionally a binutils mainline build is
required for SFrame V2 with outermost frame indication.
The unwind user sframe series depends on a Glibc patch from Josh, that
adds support for the prctls introduced in the Kernel:
https://lore.kernel.org/all/20250122023517.lmztuocecdjqzfhc@jpoimboe/
Note that Josh's Glibc patch needs to be adjusted for the updated prctl
numbers from "[PATCH v12 13/13] unwind_user/sframe: Add prctl()
interface for registering .sframe sections":
https://lore.kernel.org/all/20251119132323.1281768-14-jremus@linux.ibm.com/
Overview:
Patches 1-3 originate from my "[PATCH v3 0/3] unwind_user: Cleanups"
series and can be ignored here (please review in the respective series):
https://lore.kernel.org/all/20251202150814.3505869-1-jremus@linux.ibm.com/
Patch 4 aligns asm/dwarf.h to x86 asm/dwarf2.h.
Patch 5 replicates Josh's x86 patch "x86/asm: Avoid emitting DWARF
CFI for non-VDSO" for s390.
Patch 6 changes the build of the vDSO on s390 to keep the function
symbols for stack tracing purposes.
Patch 7 replicates Josh's patch "x86/vdso: Enable sframe generation
in VDSO" for s390. It enables generation of SFrame stack trace
information (.sframe section) for the vDSO if the assembler supports it.
Patches 8-11 enable Josh's generic unwind user (sframe) frameworks to
support the following s390 particularities:
- Patch 8 adds support for architectures that define their CFA as SP at
callsite + offset.
- Patch 9 adds support support for architectures that pass the return
address (RA) in a register instead of on the stack and that do not
necessarily save the RA on the stack (or in another register) in the
topmost frame (e.g. in the prologue or in leaf functions).
- Patch 10 adds support for architectures that save RA/FP in other
registers instead of on the stack, e.g. in leaf functions.
- Patch 11 adds support for architectures that store the CFA offset
from CFA base register (e.g. SP or FP) in SFrame encoded. For
instance on s390 the CFA offset is stored adjusted by -160 and
then scaled down by 8 to enable and improve the use of signed 8-bit
SFrame offsets (i.e. CFA, RA, and FP offset).
Patch 12 introduces frame_pointer() in ptrace on s390, which is a
prerequisite for enabling unwind user.
Patch 13 adds support for unwinding of user space using SFrame on
s390. It leverages the extensions of the generic unwind user (sframe)
frameworks from patches 8-11.
Patch 14 introduces unwind user backchain to perform unwinding of user
space using back chain, such as on s390.
Patch 15 adds support for unwinding of user space using back chain on
s390. Main reasons to support back chain on s390 are:
- With Ubuntu there is a major distribution that builds user space with
back chain.
- Java JREs, such as OpenJDK, do maintain the back chain in jitted code.
Limitations:
Unwinding of user space using back chain cannot - by design - restore
the FP. Therefore unwinding of subsequent frames using e.g. SFrame may
fail, if the FP is the CFA base register.
Thanks and regards,
Jens
Jens Remus (15):
unwind_user: Enhance comments on get CFA, FP, and RA
unwind_user/fp: Use dummies instead of ifdef
x86/unwind_user: Guard unwind_user_word_size() by UNWIND_USER
s390: asm/dwarf.h should only be included in assembly files
s390/vdso: Avoid emitting DWARF CFI for non-vDSO
s390/vdso: Keep function symbols in vDSO
s390/vdso: Enable SFrame generation in vDSO
unwind_user: Enable archs that define CFA = SP_callsite + offset
unwind_user: Enable archs that pass RA in a register
unwind_user: Enable archs that save RA/FP in other registers
unwind_user/sframe: Enable archs with encoded SFrame CFA offsets
s390/ptrace: Provide frame_pointer()
s390/unwind_user/sframe: Enable HAVE_UNWIND_USER_SFRAME
unwind_user/backchain: Introduce back chain user space unwinding
s390/unwind_user/backchain: Enable HAVE_UNWIND_USER_BACKCHAIN
arch/Kconfig | 9 ++
arch/s390/Kconfig | 2 +
arch/s390/include/asm/dwarf.h | 53 ++++++----
arch/s390/include/asm/ptrace.h | 18 +++-
arch/s390/include/asm/unwind_user.h | 100 ++++++++++++++++++
arch/s390/include/asm/unwind_user_sframe.h | 33 ++++++
arch/s390/kernel/Makefile | 2 +
arch/s390/kernel/unwind_user_backchain.c | 112 +++++++++++++++++++++
arch/s390/kernel/vdso64/Makefile | 9 +-
arch/s390/kernel/vdso64/vdso64.lds.S | 9 ++
arch/x86/include/asm/unwind_user.h | 50 ++++++---
include/asm-generic/Kbuild | 1 +
include/asm-generic/unwind_user_sframe.h | 35 +++++++
include/linux/unwind_user.h | 36 ++++++-
include/linux/unwind_user_backchain.h | 20 ++++
include/linux/unwind_user_types.h | 21 +++-
kernel/unwind/sframe.c | 13 +--
kernel/unwind/sframe.h | 14 +++
kernel/unwind/user.c | 75 ++++++++++----
19 files changed, 548 insertions(+), 64 deletions(-)
create mode 100644 arch/s390/include/asm/unwind_user.h
create mode 100644 arch/s390/include/asm/unwind_user_sframe.h
create mode 100644 arch/s390/kernel/unwind_user_backchain.c
create mode 100644 include/asm-generic/unwind_user_sframe.h
create mode 100644 include/linux/unwind_user_backchain.h
--
2.51.0
Powered by blists - more mailing lists