From: Rob Gardner <rob.gardner@oracle.com>
To: sparclinux@vger.kernel.org
Subject: [PATCH 1/2] sparc64: Ensure perf can access user stacks
Date: Wed, 23 Dec 2015 04:16:06 +0000 [thread overview]
Message-ID: <1450844167-7327-1-git-send-email-rob.gardner@oracle.com> (raw)
When an interrupt (such as a perf counter interrupt) is delivered
while executing in user space, the trap entry code puts ASI_AIUS in
%asi so that copy_from_user() and copy_to_user() will access the
correct memory. But if a perf counter interrupt is delivered while the
cpu is already executing in kernel space, then the trap entry code
will put ASI_P in %asi, and this will prevent copy_from_user() from
reading any useful stack data in either of the perf_callchain_user_X
functions, and thus no user callgraph data will be collected for this
sample period. An additional problem is that a fault is guaranteed
to occur, and though it will be silently covered up, it wastes time
and could perturb state.
In perf_callchain_user(), we ensure that %asi contains ASI_AIUS
because we know for a fact that the subsequent calls to
copy_from_user() are intended to read the user's stack.
Signed-off-by: Rob Gardner <rob.gardner@oracle.com>
Signed-off-by: Dave Aldridge <david.j.aldridge@oracle.com>
---
arch/sparc/kernel/perf_event.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/arch/sparc/kernel/perf_event.c b/arch/sparc/kernel/perf_event.c
index 689db65..55a6caa 100644
--- a/arch/sparc/kernel/perf_event.c
+++ b/arch/sparc/kernel/perf_event.c
@@ -1810,11 +1810,19 @@ static void perf_callchain_user_32(struct perf_callchain_entry *entry,
void
perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
{
+ u8 saved_asi;
+
perf_callchain_store(entry, regs->tpc);
if (!current->mm)
return;
+ /* ensure we get user memory when trying to read stacks */
+ __asm__ __volatile__ ("rd %%asi, %0\n" : "=r" (saved_asi));
+ if (saved_asi != ASI_AIUS)
+ __asm__ __volatile__ (
+ "wr %%g0, %0, %%asi\n" : : "i" (ASI_AIUS));
+
flushw_user();
pagefault_disable();
@@ -1825,4 +1833,8 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
perf_callchain_user_64(entry, regs);
pagefault_enable();
+
+ if (saved_asi != ASI_AIUS)
+ __asm__ __volatile__ (
+ "wr %%g0, %0, %%asi\n" : : "r" (saved_asi));
}
--
1.7.9.5
next reply other threads:[~2015-12-23 4:16 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-23 4:16 Rob Gardner [this message]
2015-12-23 5:45 ` [PATCH 1/2] sparc64: Ensure perf can access user stacks David Miller
2015-12-24 16:43 ` David Miller
2015-12-24 17:39 ` Rob Gardner
2015-12-26 4:25 ` David Miller
2015-12-26 5:02 ` Rob Gardner
2015-12-26 6:27 ` David Miller
2015-12-26 22:25 ` Rob Gardner
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=1450844167-7327-1-git-send-email-rob.gardner@oracle.com \
--to=rob.gardner@oracle.com \
--cc=sparclinux@vger.kernel.org \
/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