2009-09-25 18:18:36

by Masami Hiramatsu

[permalink] [raw]
Subject: [PATCH tracing/kprobes 0/3] tracing/kprobes: kprobe-tracer updates

Hi Frederic,

Here is a few updates for kprobe-tracer which fix reported bugs and
is for catching up the latest ftrace.

- Use dynamic percpu profiling buffer patch is for catching up
the latest ftrace change.
- Checking the result of create_event_dir() patch improves ftrace
code pointed by Li Zefan (thanks!).
- Add VIA instructions to x86 insn decoder patch fixes decoding
bug reported by Ingo Molnar (thanks!).

Soon after this series, I'll send perf-kprobe patch series.

Thank you,

---

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


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

--
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America), Inc.
Software Solutions Division

e-mail: [email protected]


2009-09-25 18:19:09

by Masami Hiramatsu

[permalink] [raw]
Subject: [PATCH tracing/kprobes 1/3] tracing/kprobes: Use global event profile buffer in kprobe tracer

Use new percpu global event profile buffer instead of stack in kprobe
tracer.

Signed-off-by: Masami Hiramatsu <[email protected]>
Cc: Steven Rostedt <[email protected]>
Cc: Jim Keniston <[email protected]>
Cc: Ananth N Mavinakayanahalli <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: Frank Ch. Eigler <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: H. Peter Anvin <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Jason Baron <[email protected]>
Cc: K.Prasad <[email protected]>
Cc: Lai Jiangshan <[email protected]>
Cc: Li Zefan <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Srikar Dronamraju <[email protected]>
Cc: Tom Zanussi <[email protected]>
---

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;
}



--
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America), Inc.
Software Solutions Division

e-mail: [email protected]

2009-09-25 18:19:20

by Masami Hiramatsu

[permalink] [raw]
Subject: [PATCH tracing/kprobes 2/3] x86: Add VIA processor instructions

Add VIA processor's Padlock instructions(MONTMUL, XSHA1, XSHA256).

Signed-off-by: Masami Hiramatsu <[email protected]>
Reported-by: Ingo Molnar <[email protected]>
Cc: Steven Rostedt <[email protected]>
Cc: Jim Keniston <[email protected]>
Cc: Ananth N Mavinakayanahalli <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: Frank Ch. Eigler <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: H. Peter Anvin <[email protected]>
Cc: Jason Baron <[email protected]>
Cc: K.Prasad <[email protected]>
Cc: Lai Jiangshan <[email protected]>
Cc: Li Zefan <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Srikar Dronamraju <[email protected]>
Cc: Tom Zanussi <[email protected]>
---

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


--
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America), Inc.
Software Solutions Division

e-mail: [email protected]

2009-09-25 18:19:44

by Masami Hiramatsu

[permalink] [raw]
Subject: [PATCH tracing/kprobes 3/3] tracing/ftrace: Fix to check create_event_dir() when adding new events

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

Signed-off-by: Masami Hiramatsu <[email protected]>
Cc: Steven Rostedt <[email protected]>
Cc: Jim Keniston <[email protected]>
Cc: Ananth N Mavinakayanahalli <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: Frank Ch. Eigler <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: H. Peter Anvin <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Jason Baron <[email protected]>
Cc: K.Prasad <[email protected]>
Cc: Lai Jiangshan <[email protected]>
Cc: Li Zefan <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Srikar Dronamraju <[email protected]>
Cc: Tom Zanussi <[email protected]>
---

kernel/trace/trace_events.c | 29 +++++++++++++++++++++--------
1 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index a4b7c9a..f03cda3 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -957,12 +957,14 @@ 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);
+ pr_warning("Could not create directory of trace events/%s\n",
+ call->name);
+ else
+ list_add(&call->list, &ftrace_events);
return ret;
}

@@ -1124,10 +1126,15 @@ static void trace_module_add_events(struct module *mod)
return;
}
call->mod = mod;
+ ret = event_create_dir(call, d_events,
+ &file_ops->id, &file_ops->enable,
+ &file_ops->filter, &file_ops->format);
+ if (ret < 0) {
+ pr_warning("Could not create directory of trace "
+ "point events/%s\n", call->name);
+ continue;
+ }
list_add(&call->list, &ftrace_events);
- event_create_dir(call, d_events,
- &file_ops->id, &file_ops->enable,
- &file_ops->filter, &file_ops->format);
}
}

@@ -1267,10 +1274,16 @@ static __init int event_trace_init(void)
continue;
}
}
+ 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) {
+ pr_warning("Could not create directory of trace "
+ "point events/%s\n", call->name);
+ 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);
}

while (true) {


--
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America), Inc.
Software Solutions Division

e-mail: [email protected]

2009-09-26 09:09:58

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH tracing/kprobes 0/3] tracing/kprobes: kprobe-tracer updates

On Fri, 2009-09-25 at 11:19 -0700, Masami Hiramatsu wrote:
> Hi Frederic,
>
> Here is a few updates for kprobe-tracer which fix reported bugs and
> is for catching up the latest ftrace.
>
> - Use dynamic percpu profiling buffer patch is for catching up
> the latest ftrace change.
> - Checking the result of create_event_dir() patch improves ftrace
> code pointed by Li Zefan (thanks!).
> - Add VIA instructions to x86 insn decoder patch fixes decoding
> bug reported by Ingo Molnar (thanks!).
>
> Soon after this series, I'll send perf-kprobe patch series.

Acked-by: Steven Rostedt <[email protected]>

-- Steve

2009-10-03 00:56:51

by Frederic Weisbecker

[permalink] [raw]
Subject: Re: [PATCH tracing/kprobes 3/3] tracing/ftrace: Fix to check create_event_dir() when adding new events

On Fri, Sep 25, 2009 at 11:20:54AM -0700, Masami Hiramatsu wrote:
> Check result of create_event_dir() and add ftrace_event_call to
> ftrace_events list only if it is succeeded. Thanks Li for pointing it out.
>
> Signed-off-by: Masami Hiramatsu <[email protected]>
> Cc: Steven Rostedt <[email protected]>
> Cc: Jim Keniston <[email protected]>
> Cc: Ananth N Mavinakayanahalli <[email protected]>
> Cc: Andi Kleen <[email protected]>
> Cc: Christoph Hellwig <[email protected]>
> Cc: Frank Ch. Eigler <[email protected]>
> Cc: Frederic Weisbecker <[email protected]>
> Cc: H. Peter Anvin <[email protected]>
> Cc: Ingo Molnar <[email protected]>
> Cc: Jason Baron <[email protected]>
> Cc: K.Prasad <[email protected]>
> Cc: Lai Jiangshan <[email protected]>
> Cc: Li Zefan <[email protected]>
> Cc: Peter Zijlstra <[email protected]>
> Cc: Srikar Dronamraju <[email protected]>
> Cc: Tom Zanussi <[email protected]>
> ---
>
> kernel/trace/trace_events.c | 29 +++++++++++++++++++++--------
> 1 files changed, 21 insertions(+), 8 deletions(-)
>
> diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
> index a4b7c9a..f03cda3 100644
> --- a/kernel/trace/trace_events.c
> +++ b/kernel/trace/trace_events.c
> @@ -957,12 +957,14 @@ 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);
> + pr_warning("Could not create directory of trace events/%s\n",
> + call->name);




We already have such warnings in event_create_dir, with even more granularity
against the failure reason. The patch is fine, but I'll just remove the warning
introduced inside while applying it.

Thanks.


PS: Also I guess we could add the event in the list right from
event_create_dir()...

2009-10-03 00:57:34

by Frederic Weisbecker

[permalink] [raw]
Subject: Re: [PATCH tracing/kprobes 0/3] tracing/kprobes: kprobe-tracer updates

On Fri, Sep 25, 2009 at 11:19:52AM -0700, Masami Hiramatsu wrote:
> Hi Frederic,
>
> Here is a few updates for kprobe-tracer which fix reported bugs and
> is for catching up the latest ftrace.
>
> - Use dynamic percpu profiling buffer patch is for catching up
> the latest ftrace change.
> - Checking the result of create_event_dir() patch improves ftrace
> code pointed by Li Zefan (thanks!).
> - Add VIA instructions to x86 insn decoder patch fixes decoding
> bug reported by Ingo Molnar (thanks!).
>
> Soon after this series, I'll send perf-kprobe patch series.
>
> Thank you,


Applied, thanks Masami!

2009-10-17 10:03:16

by Masami Hiramatsu

[permalink] [raw]
Subject: [tip:perf/probes] tracing/kprobes: Use global event perf buffers in kprobe tracer

Commit-ID: a1a138d05fa060ac4238c19a1e890aacc25ed3ba
Gitweb: http://git.kernel.org/tip/a1a138d05fa060ac4238c19a1e890aacc25ed3ba
Author: Masami Hiramatsu <[email protected]>
AuthorDate: Fri, 25 Sep 2009 11:20:12 -0700
Committer: Frederic Weisbecker <[email protected]>
CommitDate: Sat, 3 Oct 2009 02:21:39 +0200

tracing/kprobes: Use global event perf buffers in kprobe tracer

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

Signed-off-by: Masami Hiramatsu <[email protected]>
Acked-by: Steven Rostedt <[email protected]>
Acked-by: Ingo Molnar <[email protected]>
Cc: Jim Keniston <[email protected]>
Cc: Ananth N Mavinakayanahalli <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: Frank Ch. Eigler <[email protected]>
Cc: H. Peter Anvin <[email protected]>
Cc: Jason Baron <[email protected]>
Cc: K.Prasad <[email protected]>
Cc: Lai Jiangshan <[email protected]>
Cc: Li Zefan <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Srikar Dronamraju <[email protected]>
Cc: Tom Zanussi <[email protected]>
LKML-Reference: <20090925182011.10157.60140.stgit@omoto>
Signed-off-by: Frederic Weisbecker <[email protected]>
---
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;
}

2009-10-17 10:03:25

by Masami Hiramatsu

[permalink] [raw]
Subject: [tip:perf/probes] x86: Add VIA processor instructions in opcodes decoder

Commit-ID: c0b11d3af164947c71e2491912c5b8418900dafb
Gitweb: http://git.kernel.org/tip/c0b11d3af164947c71e2491912c5b8418900dafb
Author: Masami Hiramatsu <[email protected]>
AuthorDate: Fri, 25 Sep 2009 11:20:38 -0700
Committer: Frederic Weisbecker <[email protected]>
CommitDate: Sat, 3 Oct 2009 02:43:00 +0200

x86: Add VIA processor instructions in opcodes decoder

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 <[email protected]>
Signed-off-by: Masami Hiramatsu <[email protected]>
Acked-by: Steven Rostedt <[email protected]>
Acked-by: Ingo Molnar <[email protected]>
Cc: Jim Keniston <[email protected]>
Cc: Ananth N Mavinakayanahalli <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: Frank Ch. Eigler <[email protected]>
Cc: H. Peter Anvin <[email protected]>
Cc: Jason Baron <[email protected]>
Cc: K.Prasad <[email protected]>
Cc: Lai Jiangshan <[email protected]>
Cc: Li Zefan <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Srikar Dronamraju <[email protected]>
Cc: Tom Zanussi <[email protected]>
LKML-Reference: <20090925182037.10157.3180.stgit@omoto>
Signed-off-by: Frederic Weisbecker <[email protected]>
---
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

2009-10-17 10:03:42

by Masami Hiramatsu

[permalink] [raw]
Subject: [tip:perf/probes] tracing/ftrace: Fix to check create_event_dir() when adding new events

Commit-ID: 88f70d7590538e427c8405a2e02ac2624847386c
Gitweb: http://git.kernel.org/tip/88f70d7590538e427c8405a2e02ac2624847386c
Author: Masami Hiramatsu <[email protected]>
AuthorDate: Fri, 25 Sep 2009 11:20:54 -0700
Committer: Frederic Weisbecker <[email protected]>
CommitDate: Sat, 3 Oct 2009 03:04:58 +0200

tracing/ftrace: Fix to check create_event_dir() when adding new events

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 <[email protected]>
Acked-by: Steven Rostedt <[email protected]>
Acked-by: Ingo Molnar <[email protected]>
Cc: Jim Keniston <[email protected]>
Cc: Ananth N Mavinakayanahalli <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: Frank Ch. Eigler <[email protected]>
Cc: H. Peter Anvin <[email protected]>
Cc: Jason Baron <[email protected]>
Cc: K.Prasad <[email protected]>
Cc: Lai Jiangshan <[email protected]>
Cc: Li Zefan <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Srikar Dronamraju <[email protected]>
Cc: Tom Zanussi <[email protected]>
LKML-Reference: <20090925182054.10157.55219.stgit@omoto>
Signed-off-by: Frederic Weisbecker <[email protected]>
---
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) {