From: "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>
To: Michael Ellerman <mpe@ellerman.id.au>
Cc: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>,
Masami Hiramatsu <mhiramat@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Anton Blanchard <anton@samba.org>,
linuxppc-dev@lists.ozlabs.org
Subject: [PATCH 4/8] powerpc/kprobes_on_ftrace: Skip livepatch_handler() for jprobes
Date: Thu, 4 May 2017 10:06:17 +0530 [thread overview]
Message-ID: <afea3d1eee9eb546e52cd91b2a9b6be062800b95.1493831558.git.naveen.n.rao@linux.vnet.ibm.com> (raw)
In-Reply-To: <cover.1493831558.git.naveen.n.rao@linux.vnet.ibm.com>
In-Reply-To: <cover.1493831558.git.naveen.n.rao@linux.vnet.ibm.com>
ftrace_caller() depends on a modified regs->nip to detect if a certain
function has been livepatched. However, with KPROBES_ON_FTRACE, it is
possible for regs->nip to have been modified by the jprobes pre_handler.
In this case, we do not want to invoke the livepatch_handler so as not
to consume the livepatch stack.
To distinguish between the two (jprobes and livepatch), we compare the
returned NIP with R12. Jprobes setjmp_pre_handler() sets up both NIP
and R12 to the global entry point of the jprobes hook, while livepatch
handler only sets up NIP and R12 is setup in livepatch_handler.
So, if NIP == R12, we know we came here due to jprobes and we just
branch to the new IP. Otherwise, we continue with livepatch processing
as usual.
Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
---
arch/powerpc/kernel/trace/ftrace_64_mprofile.S | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/arch/powerpc/kernel/trace/ftrace_64_mprofile.S b/arch/powerpc/kernel/trace/ftrace_64_mprofile.S
index d8d75f4eb853..b1bad68ea6db 100644
--- a/arch/powerpc/kernel/trace/ftrace_64_mprofile.S
+++ b/arch/powerpc/kernel/trace/ftrace_64_mprofile.S
@@ -153,8 +153,18 @@ _GLOBAL(ftrace_stub)
*
* r0 can't be used as the base register for a DS-form load or store, so
* we temporarily shuffle r1 (stack pointer) into r0 and then put it back.
+ *
+ * But, before we can do all that, we first need to confirm that we are
+ * indeed here due to livepatch and not due to jprobes. The difference
+ * between the two handlers is that jprobes additionally sets up r12.
+ * So, we can compare nip with r12 as a test to determine if we are here
+ * due to livepatch or due to jprobes.
*/
livepatch_handler:
+ mfctr r0
+ cmpd r0, r12
+ beqctr
+
CURRENT_THREAD_INFO(r12, r1)
/* Save stack pointer into r0 */
--
2.12.2
next prev parent reply other threads:[~2017-05-04 4:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-04 4:36 [PATCH 0/8] powerpc: Various fixes and enhancements for kprobes and ftrace Naveen N. Rao
2017-05-04 4:36 ` [PATCH 1/8] powerpc/kprobes: Pause function_graph tracing during jprobes handling Naveen N. Rao
[not found] ` <20170503155819.0cbd04e5@gandalf.local.home>
2017-05-04 4:35 ` Naveen N. Rao
2017-05-04 4:36 ` [PATCH 2/8] powerpc/ftrace: Pass the correct stack pointer for DYNAMIC_FTRACE_WITH_REGS Naveen N. Rao
2017-05-04 4:36 ` [PATCH 3/8] powerpc/ftrace: Remove redundant saving of LR in ftrace[_graph]_caller Naveen N. Rao
2017-05-04 4:36 ` Naveen N. Rao [this message]
2017-05-04 4:36 ` [PATCH 5/8] powerpc/ftrace: Eliminate duplicate stack setup for ftrace_graph_caller() Naveen N. Rao
2017-05-04 4:36 ` [PATCH 6/8] powerpc/ftrace: Add support for HAVE_FUNCTION_GRAPH_FP_TEST for -mprofile-kernel Naveen N. Rao
2017-05-04 4:36 ` [PATCH 7/8] powerpc/livepatch: Clarify location of mcount call site Naveen N. Rao
2017-05-04 4:36 ` [PATCH 8/8] powerpc/xmon: Disable function_graph tracing while in xmon Naveen N. Rao
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=afea3d1eee9eb546e52cd91b2a9b6be062800b95.1493831558.git.naveen.n.rao@linux.vnet.ibm.com \
--to=naveen.n.rao@linux.vnet.ibm.com \
--cc=ananth@linux.vnet.ibm.com \
--cc=anton@samba.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mhiramat@kernel.org \
--cc=mpe@ellerman.id.au \
--cc=rostedt@goodmis.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;
as well as URLs for NNTP newsgroup(s).