Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1580762

[PATCH 3/3] powerpc: kprobes: prefer ftrace when probing function entry

From "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>
Newsgroups linux.kernel
Subject [PATCH 3/3] powerpc: kprobes: prefer ftrace when probing function entry
Date 2017-02-14 20:10 +0100
Message-ID <taQEa-5KD-27@gated-at.bofh.it> (permalink)
References <taQut-5rZ-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


KPROBES_ON_FTRACE avoids much of the overhead with regular kprobes as it
eliminates the need for a trap, as well as the need to emulate or
single-step instructions.

Though OPTPROBES provides us with similar performance, we have limited
optprobes trampoline slots. As such, when asked to probe at a function
entry, default to using the ftrace infrastructure.

With:
	# cd /sys/kernel/debug/tracing
	# echo 'p _do_fork' > kprobe_events

before patch:
	# cat ../kprobes/list
	c0000000000daf08  k  _do_fork+0x8    [DISABLED]
	c000000000044fc0  k  kretprobe_trampoline+0x0    [OPTIMIZED]

and after patch:
	# cat ../kprobes/list
	c0000000000d074c  k  _do_fork+0xc    [DISABLED][FTRACE]
	c0000000000412b0  k  kretprobe_trampoline+0x0    [OPTIMIZED]

Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
---
 arch/powerpc/include/asm/kprobes.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/arch/powerpc/include/asm/kprobes.h b/arch/powerpc/include/asm/kprobes.h
index 3305a12286fa..09e74edee625 100644
--- a/arch/powerpc/include/asm/kprobes.h
+++ b/arch/powerpc/include/asm/kprobes.h
@@ -60,12 +60,32 @@ extern kprobe_opcode_t optprobe_template_end[];
 
 #ifdef PPC64_ELF_ABI_v2
 /* PPC64 ABIv2 needs local entry point */
+#ifdef CONFIG_KPROBES_ON_FTRACE
+/*
+ * Per livepatch.h, ftrace location is always within the first 16 bytes
+ * of a function on powerpc with -mprofile-kernel.
+ */
+#define kprobe_lookup_name(name, addr, offset)				\
+{									\
+	addr = (kprobe_opcode_t *)kallsyms_lookup_name(name);		\
+	if (addr && !(offset)) {					\
+		unsigned long faddr;					\
+		faddr = ftrace_location_range((unsigned long)addr,	\
+					      (unsigned long)addr + 16);\
+		if (faddr)						\
+			addr = (kprobe_opcode_t *)faddr;		\
+		else							\
+			addr = (kprobe_opcode_t *)ppc_function_entry(addr);	\
+	}								\
+}
+#else
 #define kprobe_lookup_name(name, addr, offset)				\
 {									\
 	addr = (kprobe_opcode_t *)kallsyms_lookup_name(name);		\
 	if (addr && !(offset))						\
 		addr = (kprobe_opcode_t *)ppc_function_entry(addr);	\
 }
+#endif
 #elif defined(PPC64_ELF_ABI_v1)
 /*
  * 64bit powerpc ABIv1 uses function descriptors:
-- 
2.11.0

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 1/3] powerpc: kprobes: add support for KPROBES_ON_FTRACE "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> - 2017-02-14 20:00 +0100
  [PATCH 3/3] powerpc: kprobes: prefer ftrace when probing function entry "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> - 2017-02-14 20:10 +0100
  [PATCH 2/3] powerpc: introduce a new helper to obtain function entry points "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> - 2017-02-14 20:10 +0100
  Re: [PATCH 1/3] powerpc: kprobes: add support for KPROBES_ON_FTRACE Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com> - 2017-02-15 05:30 +0100
    Re: [PATCH 1/3] powerpc: kprobes: add support for KPROBES_ON_FTRACE "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> - 2017-02-16 20:50 +0100
  Re: [PATCH 1/3] powerpc: kprobes: add support for KPROBES_ON_FTRACE Masami Hiramatsu <mhiramat@kernel.org> - 2017-02-15 08:20 +0100
    Re: [PATCH 1/3] powerpc: kprobes: add support for KPROBES_ON_FTRACE "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> - 2017-02-16 21:00 +0100

csiph-web