mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [GIT PULL] tracing/kprobes: kprobes fixes
@ 2009-10-03  2:31 Frederic Weisbecker
  2009-10-03  2:31 ` [PATCH 1/3] tracing/kprobes: Use global event perf buffers in kprobe tracer Frederic Weisbecker
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Frederic Weisbecker @ 2009-10-03  2:31 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: LKML, Frederic Weisbecker, Steven Rostedt, Li Zefan

Ingo,

Please pull the tracing/kprobes tree that can be found at:

  git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git
	tracing/kprobes

(I'm just waiting a bit before pushing the perf probe patches
while we discuss some syntax things).

Thanks.

Masami Hiramatsu (3):
      tracing/kprobes: Use global event perf buffers in kprobe tracer
      x86: Add VIA processor instructions in opcodes decoder
      tracing/ftrace: Fix to check create_event_dir() when adding new events

 arch/x86/lib/x86-opcode-map.txt |    8 +++-
 kernel/trace/trace_events.c     |   25 +++++----
 kernel/trace/trace_kprobe.c     |  115 +++++++++++++++++++++++++--------------
 3 files changed, 94 insertions(+), 54 deletions(-)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/3] tracing/kprobes: Use global event perf buffers in kprobe tracer
  2009-10-03  2:31 [GIT PULL] tracing/kprobes: kprobes fixes Frederic Weisbecker
@ 2009-10-03  2:31 ` Frederic Weisbecker
  2009-10-03  2:31 ` [PATCH 2/3] x86: Add VIA processor instructions in opcodes decoder Frederic Weisbecker
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Frederic Weisbecker @ 2009-10-03  2:31 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: LKML, Masami Hiramatsu, Steven Rostedt, Jim Keniston,
	Ananth N Mavinakayanahalli, Andi Kleen, Christoph Hellwig,
	Frank Ch. Eigler, H. Peter Anvin, Jason Baron, K.Prasad,
	Lai Jiangshan, Li Zefan, Peter Zijlstra, Srikar Dronamraju,
	Tom Zanussi, Frederic Weisbecker

From: Masami Hiramatsu <mhiramat@redhat.com>

Use new percpu global event buffer instead of stack in kprobe
tracer while tracing through perf.

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Acked-by: Ingo Molnar <mingo@elte.hu>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Lai Jiangshan <laijs@cn.fujitsu.com>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <20090925182011.10157.60140.stgit@omoto>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
---
 kernel/trace/trace_kprobe.c |  115 +++++++++++++++++++++++++++----------------
 1 files changed, 73 insertions(+), 42 deletions(-)

diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index 09cba27..97309d4 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -1149,35 +1149,49 @@ static __kprobes int kprobe_profile_func(struct kprobe *kp,
 	struct trace_probe *tp = container_of(kp, struct trace_probe, rp.kp);
 	struct ftrace_event_call *call = &tp->call;
 	struct kprobe_trace_entry *entry;
-	int size, __size, i, pc;
+	struct trace_entry *ent;
+	int size, __size, i, pc, __cpu;
 	unsigned long irq_flags;
+	char *raw_data;
 
-	local_save_flags(irq_flags);
 	pc = preempt_count();
-
 	__size = SIZEOF_KPROBE_TRACE_ENTRY(tp->nr_args);
 	size = ALIGN(__size + sizeof(u32), sizeof(u64));
 	size -= sizeof(u32);
+	if (WARN_ONCE(size > FTRACE_MAX_PROFILE_SIZE,
+		     "profile buffer not large enough"))
+		return 0;
 
-	do {
-		char raw_data[size];
-		struct trace_entry *ent;
-		/*
-		 * Zero dead bytes from alignment to avoid stack leak
-		 * to userspace
-		 */
-		*(u64 *)(&raw_data[size - sizeof(u64)]) = 0ULL;
-		entry = (struct kprobe_trace_entry *)raw_data;
-		ent = &entry->ent;
-
-		tracing_generic_entry_update(ent, irq_flags, pc);
-		ent->type = call->id;
-		entry->nargs = tp->nr_args;
-		entry->ip = (unsigned long)kp->addr;
-		for (i = 0; i < tp->nr_args; i++)
-			entry->args[i] = call_fetch(&tp->args[i].fetch, regs);
-		perf_tp_event(call->id, entry->ip, 1, entry, size);
-	} while (0);
+	/*
+	 * Protect the non nmi buffer
+	 * This also protects the rcu read side
+	 */
+	local_irq_save(irq_flags);
+	__cpu = smp_processor_id();
+
+	if (in_nmi())
+		raw_data = rcu_dereference(trace_profile_buf_nmi);
+	else
+		raw_data = rcu_dereference(trace_profile_buf);
+
+	if (!raw_data)
+		goto end;
+
+	raw_data = per_cpu_ptr(raw_data, __cpu);
+	/* Zero dead bytes from alignment to avoid buffer leak to userspace */
+	*(u64 *)(&raw_data[size - sizeof(u64)]) = 0ULL;
+	entry = (struct kprobe_trace_entry *)raw_data;
+	ent = &entry->ent;
+
+	tracing_generic_entry_update(ent, irq_flags, pc);
+	ent->type = call->id;
+	entry->nargs = tp->nr_args;
+	entry->ip = (unsigned long)kp->addr;
+	for (i = 0; i < tp->nr_args; i++)
+		entry->args[i] = call_fetch(&tp->args[i].fetch, regs);
+	perf_tp_event(call->id, entry->ip, 1, entry, size);
+end:
+	local_irq_restore(irq_flags);
 	return 0;
 }
 
@@ -1188,33 +1202,50 @@ static __kprobes int kretprobe_profile_func(struct kretprobe_instance *ri,
 	struct trace_probe *tp = container_of(ri->rp, struct trace_probe, rp);
 	struct ftrace_event_call *call = &tp->call;
 	struct kretprobe_trace_entry *entry;
-	int size, __size, i, pc;
+	struct trace_entry *ent;
+	int size, __size, i, pc, __cpu;
 	unsigned long irq_flags;
+	char *raw_data;
 
-	local_save_flags(irq_flags);
 	pc = preempt_count();
-
 	__size = SIZEOF_KRETPROBE_TRACE_ENTRY(tp->nr_args);
 	size = ALIGN(__size + sizeof(u32), sizeof(u64));
 	size -= sizeof(u32);
+	if (WARN_ONCE(size > FTRACE_MAX_PROFILE_SIZE,
+		     "profile buffer not large enough"))
+		return 0;
+
+	/*
+	 * Protect the non nmi buffer
+	 * This also protects the rcu read side
+	 */
+	local_irq_save(irq_flags);
+	__cpu = smp_processor_id();
+
+	if (in_nmi())
+		raw_data = rcu_dereference(trace_profile_buf_nmi);
+	else
+		raw_data = rcu_dereference(trace_profile_buf);
+
+	if (!raw_data)
+		goto end;
+
+	raw_data = per_cpu_ptr(raw_data, __cpu);
+	/* Zero dead bytes from alignment to avoid buffer leak to userspace */
+	*(u64 *)(&raw_data[size - sizeof(u64)]) = 0ULL;
+	entry = (struct kretprobe_trace_entry *)raw_data;
+	ent = &entry->ent;
 
-	do {
-		char raw_data[size];
-		struct trace_entry *ent;
-
-		*(u64 *)(&raw_data[size - sizeof(u64)]) = 0ULL;
-		entry = (struct kretprobe_trace_entry *)raw_data;
-		ent = &entry->ent;
-
-		tracing_generic_entry_update(ent, irq_flags, pc);
-		ent->type = call->id;
-		entry->nargs = tp->nr_args;
-		entry->func = (unsigned long)tp->rp.kp.addr;
-		entry->ret_ip = (unsigned long)ri->ret_addr;
-		for (i = 0; i < tp->nr_args; i++)
-			entry->args[i] = call_fetch(&tp->args[i].fetch, regs);
-		perf_tp_event(call->id, entry->ret_ip, 1, entry, size);
-	} while (0);
+	tracing_generic_entry_update(ent, irq_flags, pc);
+	ent->type = call->id;
+	entry->nargs = tp->nr_args;
+	entry->func = (unsigned long)tp->rp.kp.addr;
+	entry->ret_ip = (unsigned long)ri->ret_addr;
+	for (i = 0; i < tp->nr_args; i++)
+		entry->args[i] = call_fetch(&tp->args[i].fetch, regs);
+	perf_tp_event(call->id, entry->ret_ip, 1, entry, size);
+end:
+	local_irq_restore(irq_flags);
 	return 0;
 }
 
-- 
1.6.2.3


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/3] x86: Add VIA processor instructions in opcodes decoder
  2009-10-03  2:31 [GIT PULL] tracing/kprobes: kprobes fixes Frederic Weisbecker
  2009-10-03  2:31 ` [PATCH 1/3] tracing/kprobes: Use global event perf buffers in kprobe tracer Frederic Weisbecker
@ 2009-10-03  2:31 ` Frederic Weisbecker
  2009-10-03  2:31 ` [PATCH 3/3] tracing/ftrace: Fix to check create_event_dir() when adding new events Frederic Weisbecker
  2009-10-03 10:35 ` [GIT PULL] tracing/kprobes: kprobes fixes Ingo Molnar
  3 siblings, 0 replies; 6+ messages in thread
From: Frederic Weisbecker @ 2009-10-03  2:31 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: LKML, Masami Hiramatsu, Steven Rostedt, Jim Keniston,
	Ananth N Mavinakayanahalli, Andi Kleen, Christoph Hellwig,
	Frank Ch. Eigler, H. Peter Anvin, Jason Baron, K.Prasad,
	Lai Jiangshan, Li Zefan, Peter Zijlstra, Srikar Dronamraju,
	Tom Zanussi, Frederic Weisbecker

From: Masami Hiramatsu <mhiramat@redhat.com>

Add VIA processor's Padlock instructions(MONTMUL, XSHA1, XSHA256)
as parts of the kernel may use them.

This fixes the following crash in opcodes decoder selftests:

 make[2]: `scripts/unifdef' is up to date.
   TEST    posttest
 Error: c145cf71:        f3 0f a6 d0             repz xsha256
 Error: objdump says 4 bytes, but insn_get_length() says 3 (attr:0)
 make[1]: *** [posttest] Error 2
 make: *** [bzImage] Error 2

Reported-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Acked-by: Ingo Molnar <mingo@elte.hu>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Lai Jiangshan <laijs@cn.fujitsu.com>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <20090925182037.10157.3180.stgit@omoto>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
---
 arch/x86/lib/x86-opcode-map.txt |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/arch/x86/lib/x86-opcode-map.txt b/arch/x86/lib/x86-opcode-map.txt
index 59e20d5..78a0daf 100644
--- a/arch/x86/lib/x86-opcode-map.txt
+++ b/arch/x86/lib/x86-opcode-map.txt
@@ -469,7 +469,7 @@ a2: CPUID
 a3: BT Ev,Gv
 a4: SHLD Ev,Gv,Ib
 a5: SHLD Ev,Gv,CL
-a6:
+a6: GrpPDLK
 a7: GrpRNG
 a8: PUSH GS (d64)
 a9: POP GS (d64)
@@ -803,6 +803,12 @@ GrpTable: Grp16
 3: prefetch T2
 EndTable
 
+GrpTable: GrpPDLK
+0: MONTMUL
+1: XSHA1
+2: XSHA2
+EndTable
+
 GrpTable: GrpRNG
 0: xstore-rng
 1: xcrypt-ecb
-- 
1.6.2.3


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 3/3] tracing/ftrace: Fix to check create_event_dir() when adding new events
  2009-10-03  2:31 [GIT PULL] tracing/kprobes: kprobes fixes Frederic Weisbecker
  2009-10-03  2:31 ` [PATCH 1/3] tracing/kprobes: Use global event perf buffers in kprobe tracer Frederic Weisbecker
  2009-10-03  2:31 ` [PATCH 2/3] x86: Add VIA processor instructions in opcodes decoder Frederic Weisbecker
@ 2009-10-03  2:31 ` Frederic Weisbecker
  2009-10-03 10:35 ` [GIT PULL] tracing/kprobes: kprobes fixes Ingo Molnar
  3 siblings, 0 replies; 6+ messages in thread
From: Frederic Weisbecker @ 2009-10-03  2:31 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: LKML, Masami Hiramatsu, Steven Rostedt, Jim Keniston,
	Ananth N Mavinakayanahalli, Andi Kleen, Christoph Hellwig,
	Frank Ch. Eigler, H. Peter Anvin, Jason Baron, K.Prasad,
	Lai Jiangshan, Li Zefan, Peter Zijlstra, Srikar Dronamraju,
	Tom Zanussi, Frederic Weisbecker

From: Masami Hiramatsu <mhiramat@redhat.com>

Check result of event_create_dir() and add ftrace_event_call to
ftrace_events list only if it is succeeded. Thanks to Li for pointing
it out.

Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Acked-by: Ingo Molnar <mingo@elte.hu>
Cc: Jim Keniston <jkenisto@us.ibm.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Frank Ch. Eigler <fche@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Lai Jiangshan <laijs@cn.fujitsu.com>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <20090925182054.10157.55219.stgit@omoto>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
---
 kernel/trace/trace_events.c |   25 ++++++++++++++-----------
 1 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index a4b7c9a..155b5d5 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -957,12 +957,12 @@ static int __trace_add_event_call(struct ftrace_event_call *call)
 	if (!d_events)
 		return -ENOENT;
 
-	list_add(&call->list, &ftrace_events);
 	ret = event_create_dir(call, d_events, &ftrace_event_id_fops,
 				&ftrace_enable_fops, &ftrace_event_filter_fops,
 				&ftrace_event_format_fops);
-	if (ret < 0)
-		list_del(&call->list);
+	if (!ret)
+		list_add(&call->list, &ftrace_events);
+
 	return ret;
 }
 
@@ -1124,10 +1124,11 @@ static void trace_module_add_events(struct module *mod)
 				return;
 		}
 		call->mod = mod;
-		list_add(&call->list, &ftrace_events);
-		event_create_dir(call, d_events,
-				 &file_ops->id, &file_ops->enable,
-				 &file_ops->filter, &file_ops->format);
+		ret = event_create_dir(call, d_events,
+				       &file_ops->id, &file_ops->enable,
+				       &file_ops->filter, &file_ops->format);
+		if (!ret)
+			list_add(&call->list, &ftrace_events);
 	}
 }
 
@@ -1267,10 +1268,12 @@ static __init int event_trace_init(void)
 				continue;
 			}
 		}
-		list_add(&call->list, &ftrace_events);
-		event_create_dir(call, d_events, &ftrace_event_id_fops,
-				 &ftrace_enable_fops, &ftrace_event_filter_fops,
-				 &ftrace_event_format_fops);
+		ret = event_create_dir(call, d_events, &ftrace_event_id_fops,
+				       &ftrace_enable_fops,
+				       &ftrace_event_filter_fops,
+				       &ftrace_event_format_fops);
+		if (!ret)
+			list_add(&call->list, &ftrace_events);
 	}
 
 	while (true) {
-- 
1.6.2.3


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [GIT PULL] tracing/kprobes: kprobes fixes
  2009-10-03  2:31 [GIT PULL] tracing/kprobes: kprobes fixes Frederic Weisbecker
                   ` (2 preceding siblings ...)
  2009-10-03  2:31 ` [PATCH 3/3] tracing/ftrace: Fix to check create_event_dir() when adding new events Frederic Weisbecker
@ 2009-10-03 10:35 ` Ingo Molnar
  2009-10-03 10:49   ` Ingo Molnar
  3 siblings, 1 reply; 6+ messages in thread
From: Ingo Molnar @ 2009-10-03 10:35 UTC (permalink / raw)
  To: Frederic Weisbecker; +Cc: LKML, Steven Rostedt, Li Zefan


* Frederic Weisbecker <fweisbec@gmail.com> wrote:

> Ingo,
> 
> Please pull the tracing/kprobes tree that can be found at:
> 
>   git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git
> 	tracing/kprobes
> 
> (I'm just waiting a bit before pushing the perf probe patches
> while we discuss some syntax things).
> 
> Thanks.
> 
> Masami Hiramatsu (3):
>       tracing/kprobes: Use global event perf buffers in kprobe tracer
>       x86: Add VIA processor instructions in opcodes decoder
>       tracing/ftrace: Fix to check create_event_dir() when adding new events
> 
>  arch/x86/lib/x86-opcode-map.txt |    8 +++-
>  kernel/trace/trace_events.c     |   25 +++++----
>  kernel/trace/trace_kprobe.c     |  115 +++++++++++++++++++++++++--------------
>  3 files changed, 94 insertions(+), 54 deletions(-)

Pulled, thanks!

	Ingo

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [GIT PULL] tracing/kprobes: kprobes fixes
  2009-10-03 10:35 ` [GIT PULL] tracing/kprobes: kprobes fixes Ingo Molnar
@ 2009-10-03 10:49   ` Ingo Molnar
  0 siblings, 0 replies; 6+ messages in thread
From: Ingo Molnar @ 2009-10-03 10:49 UTC (permalink / raw)
  To: Frederic Weisbecker; +Cc: LKML, Steven Rostedt, Li Zefan


ok, -tip testing found this new failure:

  TEST    posttest
Error: ffffffff8106ac00:        66 0f 73 fd 04          pslldq $0x4,%xmm5
Error: objdump says 5 bytes, but insn_get_length() says 4 (attr:8000)
make[1]: *** [posttest] Error 2
make: *** [bzImage] Error 2

	Ingo

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-10-03 10:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-03  2:31 [GIT PULL] tracing/kprobes: kprobes fixes Frederic Weisbecker
2009-10-03  2:31 ` [PATCH 1/3] tracing/kprobes: Use global event perf buffers in kprobe tracer Frederic Weisbecker
2009-10-03  2:31 ` [PATCH 2/3] x86: Add VIA processor instructions in opcodes decoder Frederic Weisbecker
2009-10-03  2:31 ` [PATCH 3/3] tracing/ftrace: Fix to check create_event_dir() when adding new events Frederic Weisbecker
2009-10-03 10:35 ` [GIT PULL] tracing/kprobes: kprobes fixes Ingo Molnar
2009-10-03 10:49   ` Ingo Molnar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome