[PATCH 4/8] powerpc/kprobes_on_ftrace: Skip livepatch_handler() for jprobes

Naveen N. Rao naveen.n.rao at linux.vnet.ibm.com
Thu May 4 14:36:17 AEST 2017


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 at 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



More information about the Linuxppc-dev mailing list