Skip to contentSkip to conversation

Add support for kprobes on ftrace

PATCH New Sven Schnelle 1 participant 5 messages Jul 23, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Add support for kprobes on ftrace

Hi,

these patches add support for running Kprobes on ftrace infrastructure. While at it i also fixed on bug in the code patching function and add Jump labels to the supported features list for PA-RISC.

Regards
Sven

Sven Schnelle (4):
parisc/ftrace: Add ARCH_SUPPORTS_FTRACE_OPS support parisc/ftrace: Add KPROBES_ON_FTRACE
parisc: Update feature list
parisc: fix race condition in patching code

 .../core/jump-labels/arch-support.txt         |  2 +-
 .../debug/kprobes-on-ftrace/arch-support.txt  |  2 +-
 arch/parisc/Kconfig                           |  2 +
 arch/parisc/include/asm/ftrace.h              |  1 +
 arch/parisc/kernel/entry.S                    | 99 +++++++++++++++++++
 arch/parisc/kernel/ftrace.c                   | 67 ++++++++++++-
 6 files changed, 166 insertions(+), 7 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/4 parisc/ftrace: Add ARCH_SUPPORTS_FTRACE_OPS support

Pass ftrace_ops to ftrace functions to ftrace_trace_function().

---
 arch/parisc/include/asm/ftrace.h | 1 +
 arch/parisc/kernel/ftrace.c      | 8 ++++++--
 2 files changed, 7 insertions(+), 2 deletions(-)
arch/parisc/include/asm/ftrace.h +1 -0
index 958c0aa5dbb2..a7cf0d05ccf4 100644
@@ -8,6 +8,7 @@ extern void mcount(void);
 #define MCOUNT_ADDR		((unsigned long)mcount)
 #define MCOUNT_INSN_SIZE	4
 #define CC_USING_NOP_MCOUNT
+#define ARCH_SUPPORTS_FTRACE_OPS 1
 extern unsigned long sys_call_table[];
 
 extern unsigned long return_address(unsigned int);
arch/parisc/kernel/ftrace.c +6 -2
index d784ccdd8fef..ea5c50de0b65 100644
@@ -53,8 +53,12 @@ void notrace __hot ftrace_function_trampoline(unsigned long parent,
 #ifndef CONFIG_DYNAMIC_FTRACE
 	extern ftrace_func_t ftrace_trace_function;
 #endif
-	if (ftrace_trace_function != ftrace_stub)
-		ftrace_trace_function(self_addr, parent, NULL, NULL);
+	extern struct ftrace_ops *function_trace_op;
+
+	if (function_trace_op->flags & FTRACE_OPS_FL_ENABLED &&
+	    ftrace_trace_function != ftrace_stub)
+		ftrace_trace_function(self_addr, parent,
+				function_trace_op, NULL);
 
 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
 	if (ftrace_graph_return != (trace_func_graph_ret_t) ftrace_stub ||
Signature · 1 line
2.20.1
#2 lore raw

PATCH 2/4 parisc/ftrace: Add KPROBES_ON_FTRACE

In reply to Sven Schnelle

Allow KPROBES to use the ftrace infrastructure on PA-RISC.

---
 .../debug/kprobes-on-ftrace/arch-support.txt  |  2 +-
 arch/parisc/Kconfig                           |  2 +
 arch/parisc/kernel/entry.S                    | 99 +++++++++++++++++++
 arch/parisc/kernel/ftrace.c                   | 58 ++++++++++-
 4 files changed, 157 insertions(+), 4 deletions(-)
Documentation/features/debug/kprobes-on-ftrace/arch-support.txt +1 -1
index 68f266944d5f..4fae0464ddff 100644
@@ -21,7 +21,7 @@
     |       nds32: | TODO |
     |       nios2: | TODO |
     |    openrisc: | TODO |
-    |      parisc: | TODO |
+    |      parisc: |  ok  |
     |     powerpc: |  ok  |
     |       riscv: | TODO |
     |        s390: | TODO |
arch/parisc/Kconfig +2 -0
index 6d732e451071..ee59171edffe 100644
@@ -61,6 +61,8 @@ config PARISC
 	select HAVE_KRETPROBES
 	select HAVE_DYNAMIC_FTRACE if $(cc-option,-fpatchable-function-entry=1,1)
 	select HAVE_FTRACE_MCOUNT_RECORD if HAVE_DYNAMIC_FTRACE
+	select HAVE_KPROBES_ON_FTRACE
+	select HAVE_DYNAMIC_FTRACE_WITH_REGS
 
 	help
 	  The PA-RISC microprocessor is designed by Hewlett-Packard and used
arch/parisc/kernel/entry.S +99 -0

117 lines not on this page · raw message

arch/parisc/kernel/ftrace.c +55 -3

88 lines not on this page · raw message

Signature · 1 line
2.20.1
#3 lore raw

PATCH 3/4 parisc: Update feature list

In reply to Sven Schnelle

Add jump labels to the list of supported features.

---
 Documentation/features/core/jump-labels/arch-support.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/features/core/jump-labels/arch-support.txt +1 -1
index 7fc2e243dee9..cae7be2f7725 100644
@@ -21,7 +21,7 @@
     |       nds32: | TODO |
     |       nios2: | TODO |
     |    openrisc: | TODO |
-    |      parisc: | TODO |
+    |      parisc: |  ok  |
     |     powerpc: |  ok  |
     |       riscv: | TODO |
     |        s390: |  ok  |
Signature · 1 line
2.20.1
#4 lore raw

PATCH 4/4 parisc: fix race condition in patching code

In reply to Sven Schnelle

Assume the following ftrace code sequence that was patched in earlier by ftrace_make_call():

PAGE A:
ffc: addr of ftrace_caller()
PAGE B:
000: 0x6fc10080 /* stw,ma r1,40(sp) */
004: 0x48213fd1 /* ldw -18(r1),r1 */
008: 0xe820c002 /* bv,n r0(r1) */
00c: 0xe83f1fdf /* b,l,n .-c,r1 */

When a Code sequences that is to be patched spans a page break, we might have already cleared the part on the PAGE A. If an interrupt is coming in during the remap of the fixed mapping to PAGE B, it might execute the patched function with only parts of the FTRACE code cleared. To prevent this, clear the jump to our mini trampoline first, and clear the remaining parts after this. This might also happen when patch_text() patches a function that it calls during remap.

---
 arch/parisc/kernel/ftrace.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/parisc/kernel/ftrace.c +2 -1
index 2c6086dbfe68..b836fc61a24f 100644
@@ -194,8 +194,9 @@ int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec,
 	for (i = 0; i < ARRAY_SIZE(insn); i++)
 		insn[i] = INSN_NOP;
 
+	__patch_text((void *)rec->ip, INSN_NOP);
 	__patch_text_multiple((void *)rec->ip + 4 - sizeof(insn),
-			      insn, sizeof(insn));
+			      insn, sizeof(insn)-4);
 	return 0;
 }
 #endif
Signature · 1 line
2.20.1