From: Rob Gardner <rob.gardner@oracle.com>
To: sparclinux@vger.kernel.org
Subject: Re: [PATCH 1/2] sparc64: Ensure perf can access user stacks
Date: Thu, 24 Dec 2015 17:39:05 +0000 [thread overview]
Message-ID: <567C2DB9.2070201@oracle.com> (raw)
In-Reply-To: <1450844167-7327-1-git-send-email-rob.gardner@oracle.com>
On 12/24/2015 09:43 AM, David Miller wrote:
> From: Rob Gardner <rob.gardner@oracle.com>
> Date: Tue, 22 Dec 2015 21:16:06 -0700
>
>> 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>
> I applied this, but modified it slightly.
>
> We have shorthand helpers "get_fs()" and "set_fs()" for doing this
> kind of work, and as you can see in arch/sparc/kernel/process_64.c
> and elsewhere this is the canonical way to adjust the %asi value in
> these kinds of circumstances.
>
> Also, set_fs() updates the thread's current_ds value properly. Notice
> that NGmemcpy.S uses the TI_CURRENT_DS value via the RESTORE_ASI()
> macro. So if that's not set properly, the %asi restore won't be done
> properly.
Sorry I should have noted this in the log message, but we intentionally
did not use get_fs() and set_fs() there because they are not safe to use
in a "nested" interrupt context. n.b. get_fs() is not guaranteed to
report a value consistent with %asi while we're executing the perf
interrupt handler, because it may have interrupted kernel code where
%asi is inconsistent with the thread_info current_ds value. This is
common, e.g. right in NGmemcpy.
Rob
next prev parent reply other threads:[~2015-12-24 17:39 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-23 4:16 [PATCH 1/2] sparc64: Ensure perf can access user stacks Rob Gardner
2015-12-23 5:45 ` David Miller
2015-12-24 16:43 ` David Miller
2015-12-24 17:39 ` Rob Gardner [this message]
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=567C2DB9.2070201@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.