mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiping Ma <jiping.ma2@windriver.com>
To: <will.deacon@arm.com>, <mark.rutland@arm.com>,
	<catalin.marinas@arm.com>, <alexander.shishkin@linux.intel.com>,
	<jolsa@redhat.com>, <namhyung@kernel.org>, <peterz@infradead.org>,
	<mingo@redhat.com>, <acme@kernel.org>
Cc: <linux-kernel@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<jiping.ma2@windriver.com>
Subject: [PATCH] Perf: support to unwind userspace application stacks generated with thumb.
Date: Thu, 16 Apr 2020 13:38:29 +0800	[thread overview]
Message-ID: <20200416053829.130395-1-jiping.ma2@windriver.com> (raw)

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@windriver.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


             reply	other threads:[~2020-04-16  5:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-16  5:38 Jiping Ma [this message]
2020-04-16  7:10 ` Will Deacon
2020-04-22  2:56   ` Jiping Ma
2020-04-22  8:19     ` Will Deacon

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=20200416053829.130395-1-jiping.ma2@windriver.com \
    --to=jiping.ma2@windriver.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=catalin.marinas@arm.com \
    --cc=jolsa@redhat.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=will.deacon@arm.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®