Skip to contentSkip to conversation

[3.7] tracing: cleanups and fixes

GIT PULL New Steven Rostedt 2 participants 8 messages Sep 14, 2012

Subsystems (3)
lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

Ingo,

As I believe the -pg removal from perf was holding up the patch set, although Frederic and I are working that out, I rebased my patch set to remove that change, for a later time.

The rest holds fixes to bugs that are in your queue for 3.7.

Please pull the latest tip/perf/core tree, which can be found at:

git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
tip/perf/core

Head SHA1: c6aaf4d0bb86e2154ea31a33804cec300611255f

Josh Triplett (1):
trace: Stop compiling in trace_clock unconditionally

Masami Hiramatsu (3):
ftrace/x86: Adjust x86 regs.ip as like as x86-64 kprobes/x86: Fix kprobes to collectly handle IP on ftrace kprobes/x86: Fix to support jprobes on ftrace-based kprobe

Steven Rostedt (1):
ftrace/x86-64: Allow to change RIP in handlers

Yuanhan Liu (1):
tracing: Skip printing "OK" if failed to disable event

----

 arch/x86/kernel/entry_32.S  |    3 +--
 arch/x86/kernel/entry_64.S  |    4 ++++
 arch/x86/kernel/kprobes.c   |   43 +++++++++++++++++++++++++++++++------------
 kernel/Makefile             |    2 +-
 kernel/kprobes.c            |    3 ---
 kernel/trace/Kconfig        |    5 +++++
 kernel/trace/Makefile       |    6 +-----
 kernel/trace/trace_events.c |    4 +++-
 8 files changed, 46 insertions(+), 24 deletions(-)
author maintainer
#1 lore raw

PATCH v2 1/6 tracing: Skip printing "OK" if failed to disable event

From: Yuanhan Liu <[email protected]>

No acutal case found. But logically, we should skip "OK" in case any error met.

---
 kernel/trace/trace_events.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/trace/trace_events.c +3 -1
index 6825d83..bbb0e63 100644
@@ -1646,9 +1646,11 @@ static __init void event_trace_self_tests(void)
 		event_test_stuff();
 
 		ret = __ftrace_set_clr_event(NULL, system->name, NULL, 0);
-		if (WARN_ON_ONCE(ret))
+		if (WARN_ON_ONCE(ret)) {
 			pr_warning("error disabling system %s\n",
 				   system->name);
+			continue;
+		}
 
 		pr_cont("OK\n");
 	}
Signature · 1 line
1.7.10.4
author maintainer
#2 lore raw

PATCH v2 2/6 trace: Stop compiling in trace_clock unconditionally

In reply to Steven Rostedt

From: Josh Triplett <[email protected]>

Commit 56449f437 "tracing: make the trace clocks available generally", in April 2009, made trace_clock available unconditionally, since CONFIG_X86_DS used it too.

Commit faa4602e47 "x86, perf, bts, mm: Delete the never used BTS-ptrace code", in March 2010, removed CONFIG_X86_DS, and now only CONFIG_RING_BUFFER (split out from CONFIG_TRACING for general use) has a dependency on trace_clock. So, only compile in trace_clock with CONFIG_RING_BUFFER or CONFIG_TRACING enabled.

Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Andrew Morton <[email protected]>
Cc "Eric W. Biederman" <[email protected]>
Cc Al Viro <[email protected]>
---
 kernel/Makefile       |    2 +-
 kernel/trace/Kconfig  |    5 +++++
 kernel/trace/Makefile |    6 +-----
 3 files changed, 7 insertions(+), 6 deletions(-)
kernel/Makefile +1 -1
index c0cc67a..29d993b 100644
@@ -98,7 +98,7 @@ obj-$(CONFIG_COMPAT_BINFMT_ELF) += elfcore.o
 obj-$(CONFIG_BINFMT_ELF_FDPIC) += elfcore.o
 obj-$(CONFIG_FUNCTION_TRACER) += trace/
 obj-$(CONFIG_TRACING) += trace/
-obj-$(CONFIG_X86_DS) += trace/
+obj-$(CONFIG_TRACE_CLOCK) += trace/
 obj-$(CONFIG_RING_BUFFER) += trace/
 obj-$(CONFIG_TRACEPOINTS) += trace/
 obj-$(CONFIG_IRQ_WORK) += irq_work.o
kernel/trace/Kconfig +5 -0
index 9301a0e..4cea4f4 100644
@@ -62,8 +62,12 @@ config HAVE_C_RECORDMCOUNT
 config TRACER_MAX_TRACE
 	bool
 
+config TRACE_CLOCK
+	bool
+
 config RING_BUFFER
 	bool
+	select TRACE_CLOCK
 
 config FTRACE_NMI_ENTER
        bool
@@ -114,6 +118,7 @@ config TRACING
 	select NOP_TRACER
 	select BINARY_PRINTF
 	select EVENT_TRACING
+	select TRACE_CLOCK
 
 config GENERIC_TRACER
 	bool
kernel/trace/Makefile +1 -5
index 8370908..d7e2068 100644
@@ -19,11 +19,7 @@ endif
 
 CFLAGS_trace_events_filter.o := -I$(src)
 
-#
-# Make the trace clocks available generally: it's infrastructure
-# relied on by ptrace for example:
-#
-obj-y += trace_clock.o
+obj-$(CONFIG_TRACE_CLOCK) += trace_clock.o
 
 obj-$(CONFIG_FUNCTION_TRACER) += libftrace.o
 obj-$(CONFIG_RING_BUFFER) += ring_buffer.o
Signature · 1 line
1.7.10.4
author maintainer
#3 lore raw

PATCH v2 3/6 ftrace/x86: Adjust x86 regs.ip as like as x86-64

In reply to Steven Rostedt

From: Masami Hiramatsu <[email protected]>

Adjust x86 regs.ip to ip + MCOUNT_INSN_SIZE as like as on x86-64. This helps us to consolidate codes which use regs->ip on both of x86/x86-64.

Cc Peter Zijlstra <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 arch/x86/kernel/entry_32.S |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/x86/kernel/entry_32.S +1 -2
index 061ac17..f438a44 100644
@@ -1148,7 +1148,6 @@ ENTRY(ftrace_regs_caller)
 	 * ip location, and move flags into the return ip location.
 	 */
 	pushl 4(%esp)	/* save return ip into ip slot */
-	subl $MCOUNT_INSN_SIZE, (%esp)	/* Adjust ip */
 
 	pushl $0	/* Load 0 into orig_ax */
 	pushl %gs
@@ -1169,6 +1168,7 @@ ENTRY(ftrace_regs_caller)
 	movl $__KERNEL_CS,13*4(%esp)
 
 	movl 12*4(%esp), %eax	/* Load ip (1st parameter) */
+	subl $MCOUNT_INSN_SIZE, %eax	/* Adjust ip */
 	movl 0x4(%ebp), %edx	/* Load parent ip (2nd parameter) */
 	leal function_trace_op, %ecx /* Save ftrace_pos in 3rd parameter */
 	pushl %esp		/* Save pt_regs as 4th parameter */
@@ -1180,7 +1180,6 @@ GLOBAL(ftrace_regs_call)
 	movl 14*4(%esp), %eax	/* Move flags back into cs */
 	movl %eax, 13*4(%esp)	/* Needed to keep addl from modifying flags */
 	movl 12*4(%esp), %eax	/* Get return ip from regs->ip */
-	addl $MCOUNT_INSN_SIZE, %eax
 	movl %eax, 14*4(%esp)	/* Put return ip back for ret */
 
 	popl %ebx
Signature · 1 line
1.7.10.4
author maintainer
#4 lore raw

PATCH v2 4/6 kprobes/x86: Fix kprobes to collectly handle IP on ftrace

In reply to Steven Rostedt

From: Masami Hiramatsu <[email protected]>

Current kprobe_ftrace_handler expects regs->ip == ip, but it is incorrect (originally on x86-64). Actually, ftrace handler sets regs->ip = ip + MCOUNT_INSN_SIZE. kprobe_ftrace_handler must take care for that.

Cc Peter Zijlstra <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 arch/x86/kernel/kprobes.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
arch/x86/kernel/kprobes.c +6 -3
index 47ae102..f49f60c 100644
@@ -1072,7 +1072,8 @@ void __kprobes kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,
 	if (kprobe_running()) {
 		kprobes_inc_nmissed_count(p);
 	} else {
-		regs->ip += sizeof(kprobe_opcode_t);
+		/* Kprobe handler expects regs->ip = ip + 1 as breakpoint hit */
+		regs->ip = ip + sizeof(kprobe_opcode_t);
 
 		__this_cpu_write(current_kprobe, p);
 		kcb->kprobe_status = KPROBE_HIT_ACTIVE;
@@ -1080,13 +1081,15 @@ void __kprobes kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,
 			p->pre_handler(p, regs);
 
 		if (unlikely(p->post_handler)) {
-			/* Emulate singlestep as if there is a 5byte nop */
+			/*
+			 * Emulate singlestep (and also recover regs->ip)
+			 * as if there is a 5byte nop
+			 */
 			regs->ip = ip + MCOUNT_INSN_SIZE;
 			kcb->kprobe_status = KPROBE_HIT_SSDONE;
 			p->post_handler(p, regs, 0);
 		}
 		__this_cpu_write(current_kprobe, NULL);
-		regs->ip = ip;	/* Recover for next callback */
 	}
 end:
 	local_irq_restore(flags);
Signature · 1 line
1.7.10.4
author maintainer
#5 lore raw

PATCH v2 5/6 ftrace/x86-64: Allow to change RIP in handlers

In reply to Steven Rostedt

From: Steven Rostedt <[email protected]>

Allow ftrace handlers to change RIP register (regs->ip) in handlers. This will allow handlers to call another function instead of original function.

Cc Peter Zijlstra <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 arch/x86/kernel/entry_64.S |    4 ++++
 1 file changed, 4 insertions(+)
arch/x86/kernel/entry_64.S +4 -0
index ed767b7..e9cc2b3 100644
@@ -165,6 +165,10 @@ GLOBAL(ftrace_regs_call)
 	movq EFLAGS(%rsp), %rax
 	movq %rax, SS(%rsp)
 
+	/* Handlers can change the RIP */
+	movq RIP(%rsp), %rax
+	movq %rax, SS+8(%rsp)
+
 	/* restore the rest of pt_regs */
 	movq R15(%rsp), %r15
 	movq R14(%rsp), %r14
Signature · 1 line
1.7.10.4
author maintainer
#6 lore raw

PATCH v2 6/6 kprobes/x86: Fix to support jprobes on ftrace-based kprobe

In reply to Steven Rostedt

From: Masami Hiramatsu <[email protected]>

Fix kprobes/x86 to support jprobes on ftrace-based kprobes. Because of -mfentry support of ftrace, ftrace is now put on the beginning of function where jprobes are put.

Originally ftrace-based kprobes doesn't support jprobe because it will change regs->ip and ftrace doesn't support changing IP and ftrace itself doesn't conflict jprobe. However, ftrace -mfentry support moves mcount call on the top of functions where jprobes are put. This means that jprobe always conflicts with ftrace-based kprobe and fails.

This patch allows ftrace-based kprobes to support jprobes by allowing to modify regs->ip and kprobes breakpoint handler also allows to skip singlestepping because there is a ftrace call (not an original instruction).

Cc Peter Zijlstra <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 arch/x86/kernel/kprobes.c |   42 +++++++++++++++++++++++++++++-------------
 kernel/kprobes.c          |    3 ---
 2 files changed, 29 insertions(+), 16 deletions(-)
arch/x86/kernel/kprobes.c +29 -13
index f49f60c..b7c2a85 100644
@@ -541,6 +541,8 @@ reenter_kprobe(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb
 	return 1;
 }
 
+static void __kprobes skip_singlestep(struct kprobe *p, struct pt_regs *regs,
+				      struct kprobe_ctlblk *kcb);
 /*
  * Interrupts are disabled on entry as trap3 is an interrupt gate and they
  * remain disabled throughout this function.
@@ -599,6 +601,12 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
 	} else if (kprobe_running()) {
 		p = __this_cpu_read(current_kprobe);
 		if (p->break_handler && p->break_handler(p, regs)) {
+#ifdef KPROBES_CAN_USE_FTRACE
+			if (kprobe_ftrace(p)) {
+				skip_singlestep(p, regs, kcb);
+				return 1;
+			}
+#endif
 			setup_singlestep(p, regs, kcb, 0);
 			return 1;
 		}
@@ -1053,6 +1061,21 @@ int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
 }
 
 #ifdef KPROBES_CAN_USE_FTRACE
+static void __kprobes skip_singlestep(struct kprobe *p, struct pt_regs *regs,
+				      struct kprobe_ctlblk *kcb)
+{
+	/*
+	 * Emulate singlestep (and also recover regs->ip)
+	 * as if there is a 5byte nop
+	 */
+	regs->ip = (unsigned long)p->addr + MCOUNT_INSN_SIZE;
+	if (unlikely(p->post_handler)) {
+		kcb->kprobe_status = KPROBE_HIT_SSDONE;
+		p->post_handler(p, regs, 0);
+	}
+	__this_cpu_write(current_kprobe, NULL);
+}
+
 /* Ftrace callback handler for kprobes */
 void __kprobes kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,
 				     struct ftrace_ops *ops, struct pt_regs *regs)
@@ -1077,19 +1100,12 @@ void __kprobes kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,
 
 		__this_cpu_write(current_kprobe, p);
 		kcb->kprobe_status = KPROBE_HIT_ACTIVE;
-		if (p->pre_handler)
-			p->pre_handler(p, regs);
-
-		if (unlikely(p->post_handler)) {
-			/*
-			 * Emulate singlestep (and also recover regs->ip)
-			 * as if there is a 5byte nop
-			 */
-			regs->ip = ip + MCOUNT_INSN_SIZE;
-			kcb->kprobe_status = KPROBE_HIT_SSDONE;
-			p->post_handler(p, regs, 0);
-		}
-		__this_cpu_write(current_kprobe, NULL);
+		if (!p->pre_handler || !p->pre_handler(p, regs))
+			skip_singlestep(p, regs, kcb);
+		/*
+		 * If pre_handler returns !0, it sets regs->ip and
+		 * resets current kprobe.
+		 */
 	}
 end:
 	local_irq_restore(flags);
kernel/kprobes.c +0 -3
index 35b4315..098f396 100644
@@ -1418,9 +1418,6 @@ static __kprobes int check_kprobe_address_safe(struct kprobe *p,
 		/* Given address is not on the instruction boundary */
 		if ((unsigned long)p->addr != ftrace_addr)
 			return -EILSEQ;
-		/* break_handler (jprobe) can not work with ftrace */
-		if (p->break_handler)
-			return -EINVAL;
 		p->flags |= KPROBE_FLAG_FTRACE;
 #else	/* !KPROBES_CAN_USE_FTRACE */
 		return -EINVAL;
Signature · 1 line
1.7.10.4
#7 lore raw
In reply to Steven Rostedt
Quoted 31 lines · Steven Rostedt

Ingo,

As I believe the -pg removal from perf was holding up the patch set, although Frederic and I are working that out, I rebased my patch set to remove that change, for a later time.

The rest holds fixes to bugs that are in your queue for 3.7.

Please pull the latest tip/perf/core tree, which can be found at:

git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
tip/perf/core

Head SHA1: c6aaf4d0bb86e2154ea31a33804cec300611255f

Josh Triplett (1):
trace: Stop compiling in trace_clock unconditionally

Masami Hiramatsu (3):
ftrace/x86: Adjust x86 regs.ip as like as x86-64 kprobes/x86: Fix kprobes to collectly handle IP on ftrace kprobes/x86: Fix to support jprobes on ftrace-based kprobe

Steven Rostedt (1):
ftrace/x86-64: Allow to change RIP in handlers

Yuanhan Liu (1):
tracing: Skip printing "OK" if failed to disable event

----

Quoted 9 lines
 arch/x86/kernel/entry_32.S  |    3 +--
 arch/x86/kernel/entry_64.S  |    4 ++++
 arch/x86/kernel/kprobes.c   |   43 +++++++++++++++++++++++++++++++------------
 kernel/Makefile             |    2 +-
 kernel/kprobes.c            |    3 ---
 kernel/trace/Kconfig        |    5 +++++
 kernel/trace/Makefile       |    6 +-----
 kernel/trace/trace_events.c |    4 +++-
 8 files changed, 46 insertions(+), 24 deletions(-)

Pulled, thanks Steve!

Ingo