[F][PATCH 1/2] s390/ftrace: save traced function caller

frank.heimes at canonical.com frank.heimes at canonical.com
Tue Mar 3 16:37:12 UTC 2020

From: Vasily Gorbik <gor at linux.ibm.com>

BugLink: https://bugs.launchpad.net/bugs/1865858

A typical backtrace acquired from ftraced function currently looks like
the following (e.g. for "path_openat"):

0x3e0007e3c98 <- ftraced function caller (should be do_filp_open+0x7c/0xe8)

Note random "0x3e0007e3c98" stack value as ftraced function caller. This
value causes either imprecise unwinder result or unwinding failure.
That "0x3e0007e3c98" comes from r14 of ftraced function stack frame, which
it haven't had a chance to initialize since the very first instruction
calls ftrace code ("ftrace_caller"). (ftraced function might never
save r14 as well). Nevertheless according to s390 ABI any function
is called with stack frame allocated for it and r14 contains return
address. "ftrace_caller" itself is called with "brasl %r0,ftrace_caller".
So, to fix this issue simply always save traced function caller onto
ftraced function stack frame.

Reported-by: Sven Schnelle <svens at linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor at linux.ibm.com>
(cherry picked from commit b4adfe55915d8363e244e42386d69567db1719b9)
Signed-off-by: Frank Heimes <frank.heimes at canonical.com>
 arch/s390/kernel/mcount.S | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/s390/kernel/mcount.S b/arch/s390/kernel/mcount.S
index 3431b2d5e334..f942341429b1 100644
--- a/arch/s390/kernel/mcount.S
+++ b/arch/s390/kernel/mcount.S
@@ -41,6 +41,7 @@ EXPORT_SYMBOL(_mcount)
 	.globl	ftrace_regs_caller
 	.set	ftrace_regs_caller,ftrace_caller
+	stg	%r14,(__SF_GPRS+8*8)(%r15)	# save traced function caller
 	lgr	%r1,%r15
 #if !(defined(CC_USING_HOTPATCH) || defined(CC_USING_NOP_MCOUNT))

More information about the kernel-team mailing list