[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200416053829.130395-1-jiping.ma2@windriver.com>
Date: Thu, 16 Apr 2020 13:38:29 +0800
From: Jiping Ma <jiping.ma2@...driver.com>
To: <will.deacon@....com>, <mark.rutland@....com>,
<catalin.marinas@....com>, <alexander.shishkin@...ux.intel.com>,
<jolsa@...hat.com>, <namhyung@...nel.org>, <peterz@...radead.org>,
<mingo@...hat.com>, <acme@...nel.org>
CC: <linux-kernel@...r.kernel.org>,
<linux-arm-kernel@...ts.infradead.org>, <jiping.ma2@...driver.com>
Subject: [PATCH] Perf: support to unwind userspace application stacks generated with thumb.
Only push sp and lr in the stack for thumb mode. it will go
through the stack find sp and lr.
Change this to the more detailed description of the patch
Signed-off-by: Jiping Ma <jiping.ma2@...driver.com>
---
arch/arm64/kernel/perf_callchain.c | 36 +++++++++++++++++++++++++++---
1 file changed, 33 insertions(+), 3 deletions(-)
diff --git a/arch/arm64/kernel/perf_callchain.c b/arch/arm64/kernel/perf_callchain.c
index bcafd7dcfe8b..97dde271c121 100644
--- a/arch/arm64/kernel/perf_callchain.c
+++ b/arch/arm64/kernel/perf_callchain.c
@@ -104,6 +104,30 @@ compat_user_backtrace(struct compat_frame_tail __user *tail,
return (struct compat_frame_tail __user *)compat_ptr(buftail.fp) - 1;
}
+
+void
+user_backtrace_thumb(struct perf_callchain_entry_ctx *entry,
+ struct pt_regs *regs)
+{
+ u32 sp;
+ u32 *sp_t;
+ /*
+ * Only push sp, lr to stack.
+ */
+ for (sp = regs->compat_sp; (sp < current->mm->start_stack) &&
+ (entry->nr < entry->max_stack); sp += 4) {
+ sp_t = (u32 *)(unsigned long)sp;
+ if ((*sp_t > regs->compat_sp) &&
+ (*sp_t < current->mm->start_stack)) {
+ if (*(sp_t + 1) < current->mm->end_code &&
+ *(sp_t + 1) > current->mm->start_code) {
+ perf_callchain_store(entry, *(sp_t + 1)-1);
+ sp += 4;
+ }
+ }
+ }
+}
+
#endif /* CONFIG_COMPAT */
void perf_callchain_user(struct perf_callchain_entry_ctx *entry,
@@ -132,9 +156,15 @@ void perf_callchain_user(struct perf_callchain_entry_ctx *entry,
tail = (struct compat_frame_tail __user *)regs->compat_fp - 1;
- while ((entry->nr < entry->max_stack) &&
- tail && !((unsigned long)tail & 0x3))
- tail = compat_user_backtrace(tail, entry);
+ if (((unsigned long)tail > current->mm->start_stack) ||
+ ((unsigned long)tail < regs->compat_sp) ||
+ regs->compat_sp == regs->compat_usr(7)) {
+ user_backtrace_thumb(entry, regs);
+ } else {
+ while ((entry->nr < entry->max_stack) &&
+ tail && !((unsigned long)tail & 0x3))
+ tail = compat_user_backtrace(tail, entry);
+ }
#endif
}
}
--
2.18.1
Powered by blists - more mailing lists