tracing/kprobes: kprobes fixes
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(-)
PATCH 1/3 tracing/kprobes: Use global event perf buffers in kprobe tracer
From: Masami Hiramatsu <[email protected]>
Use new percpu global event buffer instead of stack in kprobe tracer while tracing through perf.
LKML-Reference: <20090925182011.10157.60140.stgit@omoto>
--- kernel/trace/trace_kprobe.c | 115 +++++++++++++++++++++++++++---------------- 1 files changed, 73 insertions(+), 42 deletions(-)
kernel/trace/trace_kprobe.c +73 -42
@@ -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 ; }
Signature · 1 line
1.6.2.3
PATCH 2/3 x86: Add VIA processor instructions in opcodes decoder
In reply to Frederic WeisbeckerFrom: Masami Hiramatsu <[email protected]>
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
LKML-Reference: <20090925182037.10157.3180.stgit@omoto>
--- arch/x86/lib/x86-opcode-map.txt | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-)
arch/x86/lib/x86-opcode-map.txt +7 -1
@@ -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
Signature · 1 line
1.6.2.3
PATCH 3/3 tracing/ftrace: Fix to check create_event_dir() when adding new events
In reply to Frederic WeisbeckerFrom: Masami Hiramatsu <[email protected]>
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.
LKML-Reference: <20090925182054.10157.55219.stgit@omoto>
--- kernel/trace/trace_events.c | 25 ++++++++++++++----------- 1 files changed, 14 insertions(+), 11 deletions(-)
kernel/trace/trace_events.c +14 -11
@@ -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) {
Signature · 1 line
1.6.2.3
Quoted 17 lines · Frederic Weisbecker
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 checkcreate_event_dir()when adding new events
Quoted 4 lines
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
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