aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/trace
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@redhat.com>2013-02-04 11:48:34 -0500
committerOleg Nesterov <oleg@redhat.com>2013-02-08 12:28:07 -0500
commitf42d24a1d20d2e72d1e5d48930f18b138dfad117 (patch)
tree10696fc2f0a21d60a7fb1581efecd172435f0408 /kernel/trace
parent31ba334836c0ac0039084859f14a5b96858493dc (diff)
uprobes/perf: Teach trace_uprobe/perf code to use UPROBE_HANDLER_REMOVE
Change uprobe_trace_func() and uprobe_perf_func() to return "int". Change uprobe_dispatcher() to return "trace_ret | perf_ret" although this is not needed, currently TP_FLAG_TRACE/TP_FLAG_PROFILE are mutually exclusive. The only functional change is that uprobe_perf_func() checks the filtering too and returns UPROBE_HANDLER_REMOVE if nobody wants to trace current. Testing: # perf probe -x /lib/libc.so.6 syscall # perf record -e probe_libc:syscall -i perl -e 'fork; syscall -1 for 1..10; wait' # perf report --show-total-period 100.00% 10 perl libc-2.8.so [.] syscall Before this patch: # cat /sys/kernel/debug/tracing/uprobe_profile /lib/libc.so.6 syscall 20 A child process doesn't have a counter, but still it hits this breakoint "copied" by dup_mmap(). After the patch: # cat /sys/kernel/debug/tracing/uprobe_profile /lib/libc.so.6 syscall 11 The child process hits this int3 only once and does unapply_uprobe(). Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Diffstat (limited to 'kernel/trace')
-rw-r--r--kernel/trace/trace_uprobe.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
index b7850f535acf..2399f1416555 100644
--- a/kernel/trace/trace_uprobe.c
+++ b/kernel/trace/trace_uprobe.c
@@ -486,7 +486,7 @@ static const struct file_operations uprobe_profile_ops = {
486}; 486};
487 487
488/* uprobe handler */ 488/* uprobe handler */
489static void uprobe_trace_func(struct trace_uprobe *tu, struct pt_regs *regs) 489static int uprobe_trace_func(struct trace_uprobe *tu, struct pt_regs *regs)
490{ 490{
491 struct uprobe_trace_entry_head *entry; 491 struct uprobe_trace_entry_head *entry;
492 struct ring_buffer_event *event; 492 struct ring_buffer_event *event;
@@ -504,7 +504,7 @@ static void uprobe_trace_func(struct trace_uprobe *tu, struct pt_regs *regs)
504 event = trace_current_buffer_lock_reserve(&buffer, call->event.type, 504 event = trace_current_buffer_lock_reserve(&buffer, call->event.type,
505 size, irq_flags, pc); 505 size, irq_flags, pc);
506 if (!event) 506 if (!event)
507 return; 507 return 0;
508 508
509 entry = ring_buffer_event_data(event); 509 entry = ring_buffer_event_data(event);
510 entry->ip = instruction_pointer(task_pt_regs(current)); 510 entry->ip = instruction_pointer(task_pt_regs(current));
@@ -514,6 +514,8 @@ static void uprobe_trace_func(struct trace_uprobe *tu, struct pt_regs *regs)
514 514
515 if (!filter_current_check_discard(buffer, call, entry, event)) 515 if (!filter_current_check_discard(buffer, call, entry, event))
516 trace_buffer_unlock_commit(buffer, event, irq_flags, pc); 516 trace_buffer_unlock_commit(buffer, event, irq_flags, pc);
517
518 return 0;
517} 519}
518 520
519/* Event entry printers */ 521/* Event entry printers */
@@ -721,7 +723,7 @@ static bool uprobe_perf_filter(struct uprobe_consumer *uc,
721} 723}
722 724
723/* uprobe profile handler */ 725/* uprobe profile handler */
724static void uprobe_perf_func(struct trace_uprobe *tu, struct pt_regs *regs) 726static int uprobe_perf_func(struct trace_uprobe *tu, struct pt_regs *regs)
725{ 727{
726 struct ftrace_event_call *call = &tu->call; 728 struct ftrace_event_call *call = &tu->call;
727 struct uprobe_trace_entry_head *entry; 729 struct uprobe_trace_entry_head *entry;
@@ -730,11 +732,14 @@ static void uprobe_perf_func(struct trace_uprobe *tu, struct pt_regs *regs)
730 int size, __size, i; 732 int size, __size, i;
731 int rctx; 733 int rctx;
732 734
735 if (!uprobe_perf_filter(&tu->consumer, 0, current->mm))
736 return UPROBE_HANDLER_REMOVE;
737
733 __size = sizeof(*entry) + tu->size; 738 __size = sizeof(*entry) + tu->size;
734 size = ALIGN(__size + sizeof(u32), sizeof(u64)); 739 size = ALIGN(__size + sizeof(u32), sizeof(u64));
735 size -= sizeof(u32); 740 size -= sizeof(u32);
736 if (WARN_ONCE(size > PERF_MAX_TRACE_SIZE, "profile buffer not large enough")) 741 if (WARN_ONCE(size > PERF_MAX_TRACE_SIZE, "profile buffer not large enough"))
737 return; 742 return 0;
738 743
739 preempt_disable(); 744 preempt_disable();
740 745
@@ -752,6 +757,7 @@ static void uprobe_perf_func(struct trace_uprobe *tu, struct pt_regs *regs)
752 757
753 out: 758 out:
754 preempt_enable(); 759 preempt_enable();
760 return 0;
755} 761}
756#endif /* CONFIG_PERF_EVENTS */ 762#endif /* CONFIG_PERF_EVENTS */
757 763
@@ -792,18 +798,19 @@ int trace_uprobe_register(struct ftrace_event_call *event, enum trace_reg type,
792static int uprobe_dispatcher(struct uprobe_consumer *con, struct pt_regs *regs) 798static int uprobe_dispatcher(struct uprobe_consumer *con, struct pt_regs *regs)
793{ 799{
794 struct trace_uprobe *tu; 800 struct trace_uprobe *tu;
801 int ret = 0;
795 802
796 tu = container_of(con, struct trace_uprobe, consumer); 803 tu = container_of(con, struct trace_uprobe, consumer);
797 tu->nhit++; 804 tu->nhit++;
798 805
799 if (tu->flags & TP_FLAG_TRACE) 806 if (tu->flags & TP_FLAG_TRACE)
800 uprobe_trace_func(tu, regs); 807 ret |= uprobe_trace_func(tu, regs);
801 808
802#ifdef CONFIG_PERF_EVENTS 809#ifdef CONFIG_PERF_EVENTS
803 if (tu->flags & TP_FLAG_PROFILE) 810 if (tu->flags & TP_FLAG_PROFILE)
804 uprobe_perf_func(tu, regs); 811 ret |= uprobe_perf_func(tu, regs);
805#endif 812#endif
806 return 0; 813 return ret;
807} 814}
808 815
809static struct trace_event_functions uprobe_funcs = { 816static struct trace_event_functions uprobe_funcs = {