[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20220223022428.58385-1-haibo.li@mediatek.com>
Date: Wed, 23 Feb 2022 10:24:28 +0800
From: Haibo Li <haibo.li@...iatek.com>
To: Russell King <linux@...linux.org.uk>,
Matthias Brugger <matthias.bgg@...il.com>
CC: "GitAuthor : Haibo Li" <haibo.li@...iatek.com>,
<xiaoming.yu@...iatek.com>, <linux-arm-kernel@...ts.infradead.org>,
<linux-kernel@...r.kernel.org>,
<linux-mediatek@...ts.infradead.org>
Subject: [PATCH] ARM:Fix incomplete stacktrace when unwind ftrace_regs_caller
We can use register_ftrace_function(&ops) to
register a function callback.
if we set FTRACE_OPS_FL_SAVE_REGS in ftrace flags(flags in ops),
then do stack unwind
like dump_stack or WARN in the callback,we get incomplete stacktrace.
The stack unwind ends in ftrace_regs_caller.
Below is the output from test code.
The test code do register_ftrace_function
with FTRACE_OPS_FL_SAVE_REGS set,
and set sysrq_handle_loglevel as filter,then do dump_stack
in callback.It can not continue to
unwind the stack from ftrace_regs_call
echo 7 >/proc/sysrq-trigger
sysrq: Changing Loglevel
CPU: 1 PID: 145 Comm: sh Not tainted
5.17.0-rc4-00002-gb0dc07624ccd-dirty #2
[ 9.023226][ T145] Hardware name: Generic DT based system
[ 9.023670][ T145] unwind_backtrace from show_stack+0x28/0x2c
[ 9.024070][ T145] show_stack from dump_stack_lvl+0x48/0x54
[ 9.024298][ T145] dump_stack_lvl from ftrace_regs_call+0x4/0x18
[ 9.024650][ T145] sysrq: Loglevel set to 7
Fix it by adding unwind directives in ftrace_regs_caller.
Signed-off-by: Haibo Li <haibo.li@...iatek.com>
---
arch/arm/kernel/entry-ftrace.S | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/arch/arm/kernel/entry-ftrace.S b/arch/arm/kernel/entry-ftrace.S
index a74289ebc803..eafa0c9b8992 100644
--- a/arch/arm/kernel/entry-ftrace.S
+++ b/arch/arm/kernel/entry-ftrace.S
@@ -75,15 +75,18 @@
add ip, sp, #12 @ move in IP the value of SP as it was
@ before the push {lr} of the mcount mechanism
-
+ UNWIND(.movsp ip)
str lr, [sp, #0] @ store LR instead of PC
+ UNWIND(.save{pc}) @it is the caller of ftrace_regs_caller
ldr lr, [sp, #8] @ get previous LR
str r0, [sp, #8] @ write r0 as OLD_R0 over previous LR
stmdb sp!, {ip, lr}
+ UNWIND(.save{ip,lr})
stmdb sp!, {r0-r11, lr}
+ UNWIND(.save{r0-r11,lr})
@ stack content at this point:
@ 0 4 48 52 56 60 64 68 72
--
2.25.1
Powered by blists - more mailing lists