From: Haibo Li <haibo.li@mediatek.com>
To: Russell King <linux@armlinux.org.uk>,
Matthias Brugger <matthias.bgg@gmail.com>
Cc: "GitAuthor : Haibo Li" <haibo.li@mediatek.com>,
<xiaoming.yu@mediatek.com>,
<linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>,
<linux-mediatek@lists.infradead.org>
Subject: [PATCH] ARM:Fix incomplete stacktrace when unwind ftrace_regs_caller
Date: Wed, 23 Feb 2022 10:24:28 +0800 [thread overview]
Message-ID: <20220223022428.58385-1-haibo.li@mediatek.com> (raw)
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@mediatek.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
reply other threads:[~2022-02-23 2:24 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220223022428.58385-1-haibo.li@mediatek.com \
--to=haibo.li@mediatek.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux@armlinux.org.uk \
--cc=matthias.bgg@gmail.com \
--cc=xiaoming.yu@mediatek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®