aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/trace/trace_kprobe.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/trace/trace_kprobe.c')
-rw-r--r--kernel/trace/trace_kprobe.c378
1 files changed, 274 insertions, 104 deletions
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index 27d13b36b8b..00d527c945a 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -343,6 +343,14 @@ DEFINE_BASIC_FETCH_FUNCS(deref)
343DEFINE_FETCH_deref(string) 343DEFINE_FETCH_deref(string)
344DEFINE_FETCH_deref(string_size) 344DEFINE_FETCH_deref(string_size)
345 345
346static __kprobes void update_deref_fetch_param(struct deref_fetch_param *data)
347{
348 if (CHECK_FETCH_FUNCS(deref, data->orig.fn))
349 update_deref_fetch_param(data->orig.data);
350 else if (CHECK_FETCH_FUNCS(symbol, data->orig.fn))
351 update_symbol_cache(data->orig.data);
352}
353
346static __kprobes void free_deref_fetch_param(struct deref_fetch_param *data) 354static __kprobes void free_deref_fetch_param(struct deref_fetch_param *data)
347{ 355{
348 if (CHECK_FETCH_FUNCS(deref, data->orig.fn)) 356 if (CHECK_FETCH_FUNCS(deref, data->orig.fn))
@@ -377,6 +385,19 @@ DEFINE_BASIC_FETCH_FUNCS(bitfield)
377#define fetch_bitfield_string_size NULL 385#define fetch_bitfield_string_size NULL
378 386
379static __kprobes void 387static __kprobes void
388update_bitfield_fetch_param(struct bitfield_fetch_param *data)
389{
390 /*
391 * Don't check the bitfield itself, because this must be the
392 * last fetch function.
393 */
394 if (CHECK_FETCH_FUNCS(deref, data->orig.fn))
395 update_deref_fetch_param(data->orig.data);
396 else if (CHECK_FETCH_FUNCS(symbol, data->orig.fn))
397 update_symbol_cache(data->orig.data);
398}
399
400static __kprobes void
380free_bitfield_fetch_param(struct bitfield_fetch_param *data) 401free_bitfield_fetch_param(struct bitfield_fetch_param *data)
381{ 402{
382 /* 403 /*
@@ -389,6 +410,7 @@ free_bitfield_fetch_param(struct bitfield_fetch_param *data)
389 free_symbol_cache(data->orig.data); 410 free_symbol_cache(data->orig.data);
390 kfree(data); 411 kfree(data);
391} 412}
413
392/* Default (unsigned long) fetch type */ 414/* Default (unsigned long) fetch type */
393#define __DEFAULT_FETCH_TYPE(t) u##t 415#define __DEFAULT_FETCH_TYPE(t) u##t
394#define _DEFAULT_FETCH_TYPE(t) __DEFAULT_FETCH_TYPE(t) 416#define _DEFAULT_FETCH_TYPE(t) __DEFAULT_FETCH_TYPE(t)
@@ -536,6 +558,7 @@ struct probe_arg {
536/* Flags for trace_probe */ 558/* Flags for trace_probe */
537#define TP_FLAG_TRACE 1 559#define TP_FLAG_TRACE 1
538#define TP_FLAG_PROFILE 2 560#define TP_FLAG_PROFILE 2
561#define TP_FLAG_REGISTERED 4
539 562
540struct trace_probe { 563struct trace_probe {
541 struct list_head list; 564 struct list_head list;
@@ -555,16 +578,49 @@ struct trace_probe {
555 (sizeof(struct probe_arg) * (n))) 578 (sizeof(struct probe_arg) * (n)))
556 579
557 580
558static __kprobes int probe_is_return(struct trace_probe *tp) 581static __kprobes int trace_probe_is_return(struct trace_probe *tp)
559{ 582{
560 return tp->rp.handler != NULL; 583 return tp->rp.handler != NULL;
561} 584}
562 585
563static __kprobes const char *probe_symbol(struct trace_probe *tp) 586static __kprobes const char *trace_probe_symbol(struct trace_probe *tp)
564{ 587{
565 return tp->symbol ? tp->symbol : "unknown"; 588 return tp->symbol ? tp->symbol : "unknown";
566} 589}
567 590
591static __kprobes unsigned long trace_probe_offset(struct trace_probe *tp)
592{
593 return tp->rp.kp.offset;
594}
595
596static __kprobes bool trace_probe_is_enabled(struct trace_probe *tp)
597{
598 return !!(tp->flags & (TP_FLAG_TRACE | TP_FLAG_PROFILE));
599}
600
601static __kprobes bool trace_probe_is_registered(struct trace_probe *tp)
602{
603 return !!(tp->flags & TP_FLAG_REGISTERED);
604}
605
606static __kprobes bool trace_probe_has_gone(struct trace_probe *tp)
607{
608 return !!(kprobe_gone(&tp->rp.kp));
609}
610
611static __kprobes bool trace_probe_within_module(struct trace_probe *tp,
612 struct module *mod)
613{
614 int len = strlen(mod->name);
615 const char *name = trace_probe_symbol(tp);
616 return strncmp(mod->name, name, len) == 0 && name[len] == ':';
617}
618
619static __kprobes bool trace_probe_is_on_module(struct trace_probe *tp)
620{
621 return !!strchr(trace_probe_symbol(tp), ':');
622}
623
568static int register_probe_event(struct trace_probe *tp); 624static int register_probe_event(struct trace_probe *tp);
569static void unregister_probe_event(struct trace_probe *tp); 625static void unregister_probe_event(struct trace_probe *tp);
570 626
@@ -646,6 +702,16 @@ error:
646 return ERR_PTR(ret); 702 return ERR_PTR(ret);
647} 703}
648 704
705static void update_probe_arg(struct probe_arg *arg)
706{
707 if (CHECK_FETCH_FUNCS(bitfield, arg->fetch.fn))
708 update_bitfield_fetch_param(arg->fetch.data);
709 else if (CHECK_FETCH_FUNCS(deref, arg->fetch.fn))
710 update_deref_fetch_param(arg->fetch.data);
711 else if (CHECK_FETCH_FUNCS(symbol, arg->fetch.fn))
712 update_symbol_cache(arg->fetch.data);
713}
714
649static void free_probe_arg(struct probe_arg *arg) 715static void free_probe_arg(struct probe_arg *arg)
650{ 716{
651 if (CHECK_FETCH_FUNCS(bitfield, arg->fetch.fn)) 717 if (CHECK_FETCH_FUNCS(bitfield, arg->fetch.fn))
@@ -671,7 +737,7 @@ static void free_trace_probe(struct trace_probe *tp)
671 kfree(tp); 737 kfree(tp);
672} 738}
673 739
674static struct trace_probe *find_probe_event(const char *event, 740static struct trace_probe *find_trace_probe(const char *event,
675 const char *group) 741 const char *group)
676{ 742{
677 struct trace_probe *tp; 743 struct trace_probe *tp;
@@ -683,15 +749,104 @@ static struct trace_probe *find_probe_event(const char *event,
683 return NULL; 749 return NULL;
684} 750}
685 751
686/* Unregister a trace_probe and probe_event: call with locking probe_lock */ 752/* Enable trace_probe - @flag must be TP_FLAG_TRACE or TP_FLAG_PROFILE */
687static void unregister_trace_probe(struct trace_probe *tp) 753static int enable_trace_probe(struct trace_probe *tp, int flag)
688{ 754{
689 if (probe_is_return(tp)) 755 int ret = 0;
690 unregister_kretprobe(&tp->rp); 756
757 tp->flags |= flag;
758 if (trace_probe_is_enabled(tp) && trace_probe_is_registered(tp) &&
759 !trace_probe_has_gone(tp)) {
760 if (trace_probe_is_return(tp))
761 ret = enable_kretprobe(&tp->rp);
762 else
763 ret = enable_kprobe(&tp->rp.kp);
764 }
765
766 return ret;
767}
768
769/* Disable trace_probe - @flag must be TP_FLAG_TRACE or TP_FLAG_PROFILE */
770static void disable_trace_probe(struct trace_probe *tp, int flag)
771{
772 tp->flags &= ~flag;
773 if (!trace_probe_is_enabled(tp) && trace_probe_is_registered(tp)) {
774 if (trace_probe_is_return(tp))
775 disable_kretprobe(&tp->rp);
776 else
777 disable_kprobe(&tp->rp.kp);
778 }
779}
780
781/* Internal register function - just handle k*probes and flags */
782static int __register_trace_probe(struct trace_probe *tp)
783{
784 int i, ret;
785
786 if (trace_probe_is_registered(tp))
787 return -EINVAL;
788
789 for (i = 0; i < tp->nr_args; i++)
790 update_probe_arg(&tp->args[i]);
791
792 /* Set/clear disabled flag according to tp->flag */
793 if (trace_probe_is_enabled(tp))
794 tp->rp.kp.flags &= ~KPROBE_FLAG_DISABLED;
795 else
796 tp->rp.kp.flags |= KPROBE_FLAG_DISABLED;
797
798 if (trace_probe_is_return(tp))
799 ret = register_kretprobe(&tp->rp);
691 else 800 else
692 unregister_kprobe(&tp->rp.kp); 801 ret = register_kprobe(&tp->rp.kp);
802
803 if (ret == 0)
804 tp->flags |= TP_FLAG_REGISTERED;
805 else {
806 pr_warning("Could not insert probe at %s+%lu: %d\n",
807 trace_probe_symbol(tp), trace_probe_offset(tp), ret);
808 if (ret == -ENOENT && trace_probe_is_on_module(tp)) {
809 pr_warning("This probe might be able to register after"
810 "target module is loaded. Continue.\n");
811 ret = 0;
812 } else if (ret == -EILSEQ) {
813 pr_warning("Probing address(0x%p) is not an "
814 "instruction boundary.\n",
815 tp->rp.kp.addr);
816 ret = -EINVAL;
817 }
818 }
819
820 return ret;
821}
822
823/* Internal unregister function - just handle k*probes and flags */
824static void __unregister_trace_probe(struct trace_probe *tp)
825{
826 if (trace_probe_is_registered(tp)) {
827 if (trace_probe_is_return(tp))
828 unregister_kretprobe(&tp->rp);
829 else
830 unregister_kprobe(&tp->rp.kp);
831 tp->flags &= ~TP_FLAG_REGISTERED;
832 /* Cleanup kprobe for reuse */
833 if (tp->rp.kp.symbol_name)
834 tp->rp.kp.addr = NULL;
835 }
836}
837
838/* Unregister a trace_probe and probe_event: call with locking probe_lock */
839static int unregister_trace_probe(struct trace_probe *tp)
840{
841 /* Enabled event can not be unregistered */
842 if (trace_probe_is_enabled(tp))
843 return -EBUSY;
844
845 __unregister_trace_probe(tp);
693 list_del(&tp->list); 846 list_del(&tp->list);
694 unregister_probe_event(tp); 847 unregister_probe_event(tp);
848
849 return 0;
695} 850}
696 851
697/* Register a trace_probe and probe_event */ 852/* Register a trace_probe and probe_event */
@@ -702,41 +857,68 @@ static int register_trace_probe(struct trace_probe *tp)
702 857
703 mutex_lock(&probe_lock); 858 mutex_lock(&probe_lock);
704 859
705 /* register as an event */ 860 /* Delete old (same name) event if exist */
706 old_tp = find_probe_event(tp->call.name, tp->call.class->system); 861 old_tp = find_trace_probe(tp->call.name, tp->call.class->system);
707 if (old_tp) { 862 if (old_tp) {
708 /* delete old event */ 863 ret = unregister_trace_probe(old_tp);
709 unregister_trace_probe(old_tp); 864 if (ret < 0)
865 goto end;
710 free_trace_probe(old_tp); 866 free_trace_probe(old_tp);
711 } 867 }
868
869 /* Register new event */
712 ret = register_probe_event(tp); 870 ret = register_probe_event(tp);
713 if (ret) { 871 if (ret) {
714 pr_warning("Failed to register probe event(%d)\n", ret); 872 pr_warning("Failed to register probe event(%d)\n", ret);
715 goto end; 873 goto end;
716 } 874 }
717 875
718 tp->rp.kp.flags |= KPROBE_FLAG_DISABLED; 876 /* Register k*probe */
719 if (probe_is_return(tp)) 877 ret = __register_trace_probe(tp);
720 ret = register_kretprobe(&tp->rp); 878 if (ret < 0)
721 else
722 ret = register_kprobe(&tp->rp.kp);
723
724 if (ret) {
725 pr_warning("Could not insert probe(%d)\n", ret);
726 if (ret == -EILSEQ) {
727 pr_warning("Probing address(0x%p) is not an "
728 "instruction boundary.\n",
729 tp->rp.kp.addr);
730 ret = -EINVAL;
731 }
732 unregister_probe_event(tp); 879 unregister_probe_event(tp);
733 } else 880 else
734 list_add_tail(&tp->list, &probe_list); 881 list_add_tail(&tp->list, &probe_list);
882
735end: 883end:
736 mutex_unlock(&probe_lock); 884 mutex_unlock(&probe_lock);
737 return ret; 885 return ret;
738} 886}
739 887
888/* Module notifier call back, checking event on the module */
889static int trace_probe_module_callback(struct notifier_block *nb,
890 unsigned long val, void *data)
891{
892 struct module *mod = data;
893 struct trace_probe *tp;
894 int ret;
895
896 if (val != MODULE_STATE_COMING)
897 return NOTIFY_DONE;
898
899 /* Update probes on coming module */
900 mutex_lock(&probe_lock);
901 list_for_each_entry(tp, &probe_list, list) {
902 if (trace_probe_within_module(tp, mod)) {
903 /* Don't need to check busy - this should have gone. */
904 __unregister_trace_probe(tp);
905 ret = __register_trace_probe(tp);
906 if (ret)
907 pr_warning("Failed to re-register probe %s on"
908 "%s: %d\n",
909 tp->call.name, mod->name, ret);
910 }
911 }
912 mutex_unlock(&probe_lock);
913
914 return NOTIFY_DONE;
915}
916
917static struct notifier_block trace_probe_module_nb = {
918 .notifier_call = trace_probe_module_callback,
919 .priority = 1 /* Invoked after kprobe module callback */
920};
921
740/* Split symbol and offset. */ 922/* Split symbol and offset. */
741static int split_symbol_offset(char *symbol, unsigned long *offset) 923static int split_symbol_offset(char *symbol, unsigned long *offset)
742{ 924{
@@ -962,8 +1144,8 @@ static int create_trace_probe(int argc, char **argv)
962{ 1144{
963 /* 1145 /*
964 * Argument syntax: 1146 * Argument syntax:
965 * - Add kprobe: p[:[GRP/]EVENT] KSYM[+OFFS]|KADDR [FETCHARGS] 1147 * - Add kprobe: p[:[GRP/]EVENT] [MOD:]KSYM[+OFFS]|KADDR [FETCHARGS]
966 * - Add kretprobe: r[:[GRP/]EVENT] KSYM[+0] [FETCHARGS] 1148 * - Add kretprobe: r[:[GRP/]EVENT] [MOD:]KSYM[+0] [FETCHARGS]
967 * Fetch args: 1149 * Fetch args:
968 * $retval : fetch return value 1150 * $retval : fetch return value
969 * $stack : fetch stack address 1151 * $stack : fetch stack address
@@ -1025,17 +1207,18 @@ static int create_trace_probe(int argc, char **argv)
1025 return -EINVAL; 1207 return -EINVAL;
1026 } 1208 }
1027 mutex_lock(&probe_lock); 1209 mutex_lock(&probe_lock);
1028 tp = find_probe_event(event, group); 1210 tp = find_trace_probe(event, group);
1029 if (!tp) { 1211 if (!tp) {
1030 mutex_unlock(&probe_lock); 1212 mutex_unlock(&probe_lock);
1031 pr_info("Event %s/%s doesn't exist.\n", group, event); 1213 pr_info("Event %s/%s doesn't exist.\n", group, event);
1032 return -ENOENT; 1214 return -ENOENT;
1033 } 1215 }
1034 /* delete an event */ 1216 /* delete an event */
1035 unregister_trace_probe(tp); 1217 ret = unregister_trace_probe(tp);
1036 free_trace_probe(tp); 1218 if (ret == 0)
1219 free_trace_probe(tp);
1037 mutex_unlock(&probe_lock); 1220 mutex_unlock(&probe_lock);
1038 return 0; 1221 return ret;
1039 } 1222 }
1040 1223
1041 if (argc < 2) { 1224 if (argc < 2) {
@@ -1144,20 +1327,30 @@ error:
1144 return ret; 1327 return ret;
1145} 1328}
1146 1329
1147static void cleanup_all_probes(void) 1330static int release_all_trace_probes(void)
1148{ 1331{
1149 struct trace_probe *tp; 1332 struct trace_probe *tp;
1333 int ret = 0;
1150 1334
1151 mutex_lock(&probe_lock); 1335 mutex_lock(&probe_lock);
1336 /* Ensure no probe is in use. */
1337 list_for_each_entry(tp, &probe_list, list)
1338 if (trace_probe_is_enabled(tp)) {
1339 ret = -EBUSY;
1340 goto end;
1341 }
1152 /* TODO: Use batch unregistration */ 1342 /* TODO: Use batch unregistration */
1153 while (!list_empty(&probe_list)) { 1343 while (!list_empty(&probe_list)) {
1154 tp = list_entry(probe_list.next, struct trace_probe, list); 1344 tp = list_entry(probe_list.next, struct trace_probe, list);
1155 unregister_trace_probe(tp); 1345 unregister_trace_probe(tp);
1156 free_trace_probe(tp); 1346 free_trace_probe(tp);
1157 } 1347 }
1348
1349end:
1158 mutex_unlock(&probe_lock); 1350 mutex_unlock(&probe_lock);
1159}
1160 1351
1352 return ret;
1353}
1161 1354
1162/* Probes listing interfaces */ 1355/* Probes listing interfaces */
1163static void *probes_seq_start(struct seq_file *m, loff_t *pos) 1356static void *probes_seq_start(struct seq_file *m, loff_t *pos)
@@ -1181,15 +1374,16 @@ static int probes_seq_show(struct seq_file *m, void *v)
1181 struct trace_probe *tp = v; 1374 struct trace_probe *tp = v;
1182 int i; 1375 int i;
1183 1376
1184 seq_printf(m, "%c", probe_is_return(tp) ? 'r' : 'p'); 1377 seq_printf(m, "%c", trace_probe_is_return(tp) ? 'r' : 'p');
1185 seq_printf(m, ":%s/%s", tp->call.class->system, tp->call.name); 1378 seq_printf(m, ":%s/%s", tp->call.class->system, tp->call.name);
1186 1379
1187 if (!tp->symbol) 1380 if (!tp->symbol)
1188 seq_printf(m, " 0x%p", tp->rp.kp.addr); 1381 seq_printf(m, " 0x%p", tp->rp.kp.addr);
1189 else if (tp->rp.kp.offset) 1382 else if (tp->rp.kp.offset)
1190 seq_printf(m, " %s+%u", probe_symbol(tp), tp->rp.kp.offset); 1383 seq_printf(m, " %s+%u", trace_probe_symbol(tp),
1384 tp->rp.kp.offset);
1191 else 1385 else
1192 seq_printf(m, " %s", probe_symbol(tp)); 1386 seq_printf(m, " %s", trace_probe_symbol(tp));
1193 1387
1194 for (i = 0; i < tp->nr_args; i++) 1388 for (i = 0; i < tp->nr_args; i++)
1195 seq_printf(m, " %s=%s", tp->args[i].name, tp->args[i].comm); 1389 seq_printf(m, " %s=%s", tp->args[i].name, tp->args[i].comm);
@@ -1207,9 +1401,13 @@ static const struct seq_operations probes_seq_op = {
1207 1401
1208static int probes_open(struct inode *inode, struct file *file) 1402static int probes_open(struct inode *inode, struct file *file)
1209{ 1403{
1210 if ((file->f_mode & FMODE_WRITE) && 1404 int ret;
1211 (file->f_flags & O_TRUNC)) 1405
1212 cleanup_all_probes(); 1406 if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_TRUNC)) {
1407 ret = release_all_trace_probes();
1408 if (ret < 0)
1409 return ret;
1410 }
1213 1411
1214 return seq_open(file, &probes_seq_op); 1412 return seq_open(file, &probes_seq_op);
1215} 1413}
@@ -1397,7 +1595,8 @@ static __kprobes void kprobe_trace_func(struct kprobe *kp, struct pt_regs *regs)
1397 store_trace_args(sizeof(*entry), tp, regs, (u8 *)&entry[1], dsize); 1595 store_trace_args(sizeof(*entry), tp, regs, (u8 *)&entry[1], dsize);
1398 1596
1399 if (!filter_current_check_discard(buffer, call, entry, event)) 1597 if (!filter_current_check_discard(buffer, call, entry, event))
1400 trace_nowake_buffer_unlock_commit(buffer, event, irq_flags, pc); 1598 trace_nowake_buffer_unlock_commit_regs(buffer, event,
1599 irq_flags, pc, regs);
1401} 1600}
1402 1601
1403/* Kretprobe handler */ 1602/* Kretprobe handler */
@@ -1429,7 +1628,8 @@ static __kprobes void kretprobe_trace_func(struct kretprobe_instance *ri,
1429 store_trace_args(sizeof(*entry), tp, regs, (u8 *)&entry[1], dsize); 1628 store_trace_args(sizeof(*entry), tp, regs, (u8 *)&entry[1], dsize);
1430 1629
1431 if (!filter_current_check_discard(buffer, call, entry, event)) 1630 if (!filter_current_check_discard(buffer, call, entry, event))
1432 trace_nowake_buffer_unlock_commit(buffer, event, irq_flags, pc); 1631 trace_nowake_buffer_unlock_commit_regs(buffer, event,
1632 irq_flags, pc, regs);
1433} 1633}
1434 1634
1435/* Event entry printers */ 1635/* Event entry printers */
@@ -1511,30 +1711,6 @@ partial:
1511 return TRACE_TYPE_PARTIAL_LINE; 1711 return TRACE_TYPE_PARTIAL_LINE;
1512} 1712}
1513 1713
1514static int probe_event_enable(struct ftrace_event_call *call)
1515{
1516 struct trace_probe *tp = (struct trace_probe *)call->data;
1517
1518 tp->flags |= TP_FLAG_TRACE;
1519 if (probe_is_return(tp))
1520 return enable_kretprobe(&tp->rp);
1521 else
1522 return enable_kprobe(&tp->rp.kp);
1523}
1524
1525static void probe_event_disable(struct ftrace_event_call *call)
1526{
1527 struct trace_probe *tp = (struct trace_probe *)call->data;
1528
1529 tp->flags &= ~TP_FLAG_TRACE;
1530 if (!(tp->flags & (TP_FLAG_TRACE | TP_FLAG_PROFILE))) {
1531 if (probe_is_return(tp))
1532 disable_kretprobe(&tp->rp);
1533 else
1534 disable_kprobe(&tp->rp.kp);
1535 }
1536}
1537
1538#undef DEFINE_FIELD 1714#undef DEFINE_FIELD
1539#define DEFINE_FIELD(type, item, name, is_signed) \ 1715#define DEFINE_FIELD(type, item, name, is_signed) \
1540 do { \ 1716 do { \
@@ -1596,7 +1772,7 @@ static int __set_print_fmt(struct trace_probe *tp, char *buf, int len)
1596 1772
1597 const char *fmt, *arg; 1773 const char *fmt, *arg;
1598 1774
1599 if (!probe_is_return(tp)) { 1775 if (!trace_probe_is_return(tp)) {
1600 fmt = "(%lx)"; 1776 fmt = "(%lx)";
1601 arg = "REC->" FIELD_STRING_IP; 1777 arg = "REC->" FIELD_STRING_IP;
1602 } else { 1778 } else {
@@ -1713,49 +1889,25 @@ static __kprobes void kretprobe_perf_func(struct kretprobe_instance *ri,
1713 head = this_cpu_ptr(call->perf_events); 1889 head = this_cpu_ptr(call->perf_events);
1714 perf_trace_buf_submit(entry, size, rctx, entry->ret_ip, 1, regs, head); 1890 perf_trace_buf_submit(entry, size, rctx, entry->ret_ip, 1, regs, head);
1715} 1891}
1716
1717static int probe_perf_enable(struct ftrace_event_call *call)
1718{
1719 struct trace_probe *tp = (struct trace_probe *)call->data;
1720
1721 tp->flags |= TP_FLAG_PROFILE;
1722
1723 if (probe_is_return(tp))
1724 return enable_kretprobe(&tp->rp);
1725 else
1726 return enable_kprobe(&tp->rp.kp);
1727}
1728
1729static void probe_perf_disable(struct ftrace_event_call *call)
1730{
1731 struct trace_probe *tp = (struct trace_probe *)call->data;
1732
1733 tp->flags &= ~TP_FLAG_PROFILE;
1734
1735 if (!(tp->flags & TP_FLAG_TRACE)) {
1736 if (probe_is_return(tp))
1737 disable_kretprobe(&tp->rp);
1738 else
1739 disable_kprobe(&tp->rp.kp);
1740 }
1741}
1742#endif /* CONFIG_PERF_EVENTS */ 1892#endif /* CONFIG_PERF_EVENTS */
1743 1893
1744static __kprobes 1894static __kprobes
1745int kprobe_register(struct ftrace_event_call *event, enum trace_reg type) 1895int kprobe_register(struct ftrace_event_call *event, enum trace_reg type)
1746{ 1896{
1897 struct trace_probe *tp = (struct trace_probe *)event->data;
1898
1747 switch (type) { 1899 switch (type) {
1748 case TRACE_REG_REGISTER: 1900 case TRACE_REG_REGISTER:
1749 return probe_event_enable(event); 1901 return enable_trace_probe(tp, TP_FLAG_TRACE);
1750 case TRACE_REG_UNREGISTER: 1902 case TRACE_REG_UNREGISTER:
1751 probe_event_disable(event); 1903 disable_trace_probe(tp, TP_FLAG_TRACE);
1752 return 0; 1904 return 0;
1753 1905
1754#ifdef CONFIG_PERF_EVENTS 1906#ifdef CONFIG_PERF_EVENTS
1755 case TRACE_REG_PERF_REGISTER: 1907 case TRACE_REG_PERF_REGISTER:
1756 return probe_perf_enable(event); 1908 return enable_trace_probe(tp, TP_FLAG_PROFILE);
1757 case TRACE_REG_PERF_UNREGISTER: 1909 case TRACE_REG_PERF_UNREGISTER:
1758 probe_perf_disable(event); 1910 disable_trace_probe(tp, TP_FLAG_PROFILE);
1759 return 0; 1911 return 0;
1760#endif 1912#endif
1761 } 1913 }
@@ -1805,7 +1957,7 @@ static int register_probe_event(struct trace_probe *tp)
1805 1957
1806 /* Initialize ftrace_event_call */ 1958 /* Initialize ftrace_event_call */
1807 INIT_LIST_HEAD(&call->class->fields); 1959 INIT_LIST_HEAD(&call->class->fields);
1808 if (probe_is_return(tp)) { 1960 if (trace_probe_is_return(tp)) {
1809 call->event.funcs = &kretprobe_funcs; 1961 call->event.funcs = &kretprobe_funcs;
1810 call->class->define_fields = kretprobe_event_define_fields; 1962 call->class->define_fields = kretprobe_event_define_fields;
1811 } else { 1963 } else {
@@ -1844,6 +1996,9 @@ static __init int init_kprobe_trace(void)
1844 struct dentry *d_tracer; 1996 struct dentry *d_tracer;
1845 struct dentry *entry; 1997 struct dentry *entry;
1846 1998
1999 if (register_module_notifier(&trace_probe_module_nb))
2000 return -EINVAL;
2001
1847 d_tracer = tracing_init_dentry(); 2002 d_tracer = tracing_init_dentry();
1848 if (!d_tracer) 2003 if (!d_tracer)
1849 return 0; 2004 return 0;
@@ -1897,12 +2052,12 @@ static __init int kprobe_trace_self_tests_init(void)
1897 warn++; 2052 warn++;
1898 } else { 2053 } else {
1899 /* Enable trace point */ 2054 /* Enable trace point */
1900 tp = find_probe_event("testprobe", KPROBE_EVENT_SYSTEM); 2055 tp = find_trace_probe("testprobe", KPROBE_EVENT_SYSTEM);
1901 if (WARN_ON_ONCE(tp == NULL)) { 2056 if (WARN_ON_ONCE(tp == NULL)) {
1902 pr_warning("error on getting new probe.\n"); 2057 pr_warning("error on getting new probe.\n");
1903 warn++; 2058 warn++;
1904 } else 2059 } else
1905 probe_event_enable(&tp->call); 2060 enable_trace_probe(tp, TP_FLAG_TRACE);
1906 } 2061 }
1907 2062
1908 ret = command_trace_probe("r:testprobe2 kprobe_trace_selftest_target " 2063 ret = command_trace_probe("r:testprobe2 kprobe_trace_selftest_target "
@@ -1912,12 +2067,12 @@ static __init int kprobe_trace_self_tests_init(void)
1912 warn++; 2067 warn++;
1913 } else { 2068 } else {
1914 /* Enable trace point */ 2069 /* Enable trace point */
1915 tp = find_probe_event("testprobe2", KPROBE_EVENT_SYSTEM); 2070 tp = find_trace_probe("testprobe2", KPROBE_EVENT_SYSTEM);
1916 if (WARN_ON_ONCE(tp == NULL)) { 2071 if (WARN_ON_ONCE(tp == NULL)) {
1917 pr_warning("error on getting new probe.\n"); 2072 pr_warning("error on getting new probe.\n");
1918 warn++; 2073 warn++;
1919 } else 2074 } else
1920 probe_event_enable(&tp->call); 2075 enable_trace_probe(tp, TP_FLAG_TRACE);
1921 } 2076 }
1922 2077
1923 if (warn) 2078 if (warn)
@@ -1925,6 +2080,21 @@ static __init int kprobe_trace_self_tests_init(void)
1925 2080
1926 ret = target(1, 2, 3, 4, 5, 6); 2081 ret = target(1, 2, 3, 4, 5, 6);
1927 2082
2083 /* Disable trace points before removing it */
2084 tp = find_trace_probe("testprobe", KPROBE_EVENT_SYSTEM);
2085 if (WARN_ON_ONCE(tp == NULL)) {
2086 pr_warning("error on getting test probe.\n");
2087 warn++;
2088 } else
2089 disable_trace_probe(tp, TP_FLAG_TRACE);
2090
2091 tp = find_trace_probe("testprobe2", KPROBE_EVENT_SYSTEM);
2092 if (WARN_ON_ONCE(tp == NULL)) {
2093 pr_warning("error on getting 2nd test probe.\n");
2094 warn++;
2095 } else
2096 disable_trace_probe(tp, TP_FLAG_TRACE);
2097
1928 ret = command_trace_probe("-:testprobe"); 2098 ret = command_trace_probe("-:testprobe");
1929 if (WARN_ON_ONCE(ret)) { 2099 if (WARN_ON_ONCE(ret)) {
1930 pr_warning("error on deleting a probe.\n"); 2100 pr_warning("error on deleting a probe.\n");
@@ -1938,7 +2108,7 @@ static __init int kprobe_trace_self_tests_init(void)
1938 } 2108 }
1939 2109
1940end: 2110end:
1941 cleanup_all_probes(); 2111 release_all_trace_probes();
1942 if (warn) 2112 if (warn)
1943 pr_cont("NG: Some tests are failed. Please check them.\n"); 2113 pr_cont("NG: Some tests are failed. Please check them.\n");
1944 else 2114 else