Lines Matching +full:tf +full:- +full:a
1 // SPDX-License-Identifier: GPL-2.0
3 * Fprobe-based tracing events
53 return ev->ops == &trace_fprobe_ops; in is_trace_fprobe()
62 * for_each_trace_fprobe - iterate over the trace_fprobe list
64 * @dpos: the struct dyn_event * to use as a loop cursor
70 static bool trace_fprobe_is_return(struct trace_fprobe *tf) in trace_fprobe_is_return() argument
72 return tf->fp.exit_handler != NULL; in trace_fprobe_is_return()
75 static bool trace_fprobe_is_tracepoint(struct trace_fprobe *tf) in trace_fprobe_is_tracepoint() argument
77 return tf->tpoint != NULL; in trace_fprobe_is_tracepoint()
80 static const char *trace_fprobe_symbol(struct trace_fprobe *tf) in trace_fprobe_symbol() argument
82 return tf->symbol ? tf->symbol : "unknown"; in trace_fprobe_symbol()
87 struct trace_fprobe *tf = to_trace_fprobe(ev); in trace_fprobe_is_busy() local
89 return trace_probe_is_enabled(&tf->tp); in trace_fprobe_is_busy()
92 static bool trace_fprobe_match_command_head(struct trace_fprobe *tf, in trace_fprobe_match_command_head() argument
100 snprintf(buf, sizeof(buf), "%s", trace_fprobe_symbol(tf)); in trace_fprobe_match_command_head()
103 argc--; argv++; in trace_fprobe_match_command_head()
105 return trace_probe_match_command_args(&tf->tp, argc, argv); in trace_fprobe_match_command_head()
111 struct trace_fprobe *tf = to_trace_fprobe(ev); in trace_fprobe_match() local
113 if (event[0] != '\0' && strcmp(trace_probe_name(&tf->tp), event)) in trace_fprobe_match()
116 if (system && strcmp(trace_probe_group_name(&tf->tp), system)) in trace_fprobe_match()
119 return trace_fprobe_match_command_head(tf, argc, argv); in trace_fprobe_match()
122 static bool trace_fprobe_is_registered(struct trace_fprobe *tf) in trace_fprobe_is_registered() argument
124 return fprobe_is_registered(&tf->fp); in trace_fprobe_is_registered()
141 switch (code->op) { in process_fetch_insn()
143 val = regs_get_kernel_stack_nth(regs, code->param); in process_fetch_insn()
153 val = regs_get_kernel_argument(regs, code->param); in process_fetch_insn()
156 case FETCH_NOP_SYMBOL: /* Ignore a place holder */ in process_fetch_insn()
172 __fentry_trace_func(struct trace_fprobe *tf, unsigned long entry_ip, in NOKPROBE_SYMBOL()
177 struct trace_event_call *call = trace_probe_event_call(&tf->tp); in NOKPROBE_SYMBOL()
181 if (WARN_ON_ONCE(call != trace_file->event_call)) in NOKPROBE_SYMBOL()
187 dsize = __get_data_size(&tf->tp, regs); in NOKPROBE_SYMBOL()
190 sizeof(*entry) + tf->tp.size + dsize); in NOKPROBE_SYMBOL()
196 entry->ip = entry_ip; in NOKPROBE_SYMBOL()
197 store_trace_args(&entry[1], &tf->tp, regs, sizeof(*entry), dsize); in NOKPROBE_SYMBOL()
203 fentry_trace_func(struct trace_fprobe *tf, unsigned long entry_ip, in fentry_trace_func() argument
208 trace_probe_for_each_link_rcu(link, &tf->tp) in fentry_trace_func()
209 __fentry_trace_func(tf, entry_ip, regs, link->file); in fentry_trace_func()
215 __fexit_trace_func(struct trace_fprobe *tf, unsigned long entry_ip, in __fexit_trace_func() argument
221 struct trace_event_call *call = trace_probe_event_call(&tf->tp); in __fexit_trace_func()
224 if (WARN_ON_ONCE(call != trace_file->event_call)) in __fexit_trace_func()
230 dsize = __get_data_size(&tf->tp, regs); in __fexit_trace_func()
233 sizeof(*entry) + tf->tp.size + dsize); in __fexit_trace_func()
239 entry->func = entry_ip; in __fexit_trace_func()
240 entry->ret_ip = ret_ip; in __fexit_trace_func()
241 store_trace_args(&entry[1], &tf->tp, regs, sizeof(*entry), dsize); in __fexit_trace_func()
247 fexit_trace_func(struct trace_fprobe *tf, unsigned long entry_ip, in fexit_trace_func() argument
252 trace_probe_for_each_link_rcu(link, &tf->tp) in fexit_trace_func()
253 __fexit_trace_func(tf, entry_ip, ret_ip, regs, link->file); in fexit_trace_func()
259 static int fentry_perf_func(struct trace_fprobe *tf, unsigned long entry_ip, in fentry_perf_func() argument
262 struct trace_event_call *call = trace_probe_event_call(&tf->tp); in fentry_perf_func()
268 head = this_cpu_ptr(call->perf_events); in fentry_perf_func()
272 dsize = __get_data_size(&tf->tp, regs); in fentry_perf_func()
273 __size = sizeof(*entry) + tf->tp.size + dsize; in fentry_perf_func()
275 size -= sizeof(u32); in fentry_perf_func()
281 entry->ip = entry_ip; in fentry_perf_func()
283 store_trace_args(&entry[1], &tf->tp, regs, sizeof(*entry), dsize); in fentry_perf_func()
284 perf_trace_buf_submit(entry, size, rctx, call->event.type, 1, regs, in fentry_perf_func()
291 fexit_perf_func(struct trace_fprobe *tf, unsigned long entry_ip, in fexit_perf_func() argument
294 struct trace_event_call *call = trace_probe_event_call(&tf->tp); in fexit_perf_func()
300 head = this_cpu_ptr(call->perf_events); in fexit_perf_func()
304 dsize = __get_data_size(&tf->tp, regs); in fexit_perf_func()
305 __size = sizeof(*entry) + tf->tp.size + dsize; in fexit_perf_func()
307 size -= sizeof(u32); in fexit_perf_func()
313 entry->func = entry_ip; in fexit_perf_func()
314 entry->ret_ip = ret_ip; in fexit_perf_func()
315 store_trace_args(&entry[1], &tf->tp, regs, sizeof(*entry), dsize); in fexit_perf_func()
316 perf_trace_buf_submit(entry, size, rctx, call->event.type, 1, regs, in fexit_perf_func()
326 struct trace_fprobe *tf = container_of(fp, struct trace_fprobe, fp); in fentry_dispatcher() local
329 if (trace_probe_test_flag(&tf->tp, TP_FLAG_TRACE)) in fentry_dispatcher()
330 fentry_trace_func(tf, entry_ip, regs); in fentry_dispatcher()
332 if (trace_probe_test_flag(&tf->tp, TP_FLAG_PROFILE)) in fentry_dispatcher()
333 ret = fentry_perf_func(tf, entry_ip, regs); in fentry_dispatcher()
343 struct trace_fprobe *tf = container_of(fp, struct trace_fprobe, fp); in fexit_dispatcher() local
345 if (trace_probe_test_flag(&tf->tp, TP_FLAG_TRACE)) in fexit_dispatcher()
346 fexit_trace_func(tf, entry_ip, ret_ip, regs); in fexit_dispatcher()
348 if (trace_probe_test_flag(&tf->tp, TP_FLAG_PROFILE)) in fexit_dispatcher()
349 fexit_perf_func(tf, entry_ip, ret_ip, regs); in fexit_dispatcher()
354 static void free_trace_fprobe(struct trace_fprobe *tf) in free_trace_fprobe() argument
356 if (tf) { in free_trace_fprobe()
357 trace_probe_cleanup(&tf->tp); in free_trace_fprobe()
358 kfree(tf->symbol); in free_trace_fprobe()
359 kfree(tf); in free_trace_fprobe()
373 struct trace_fprobe *tf; in alloc_trace_fprobe() local
374 int ret = -ENOMEM; in alloc_trace_fprobe()
376 tf = kzalloc(struct_size(tf, tp.args, nargs), GFP_KERNEL); in alloc_trace_fprobe()
377 if (!tf) in alloc_trace_fprobe()
380 tf->symbol = kstrdup(symbol, GFP_KERNEL); in alloc_trace_fprobe()
381 if (!tf->symbol) in alloc_trace_fprobe()
385 tf->fp.exit_handler = fexit_dispatcher; in alloc_trace_fprobe()
387 tf->fp.entry_handler = fentry_dispatcher; in alloc_trace_fprobe()
389 tf->tpoint = tpoint; in alloc_trace_fprobe()
390 tf->fp.nr_maxactive = maxactive; in alloc_trace_fprobe()
392 ret = trace_probe_init(&tf->tp, event, group, false); in alloc_trace_fprobe()
396 dyn_event_init(&tf->devent, &trace_fprobe_ops); in alloc_trace_fprobe()
397 return tf; in alloc_trace_fprobe()
399 free_trace_fprobe(tf); in alloc_trace_fprobe()
407 struct trace_fprobe *tf; in find_trace_fprobe() local
409 for_each_trace_fprobe(tf, pos) in find_trace_fprobe()
410 if (strcmp(trace_probe_name(&tf->tp), event) == 0 && in find_trace_fprobe()
411 strcmp(trace_probe_group_name(&tf->tp), group) == 0) in find_trace_fprobe()
412 return tf; in find_trace_fprobe()
416 static inline int __enable_trace_fprobe(struct trace_fprobe *tf) in __enable_trace_fprobe() argument
418 if (trace_fprobe_is_registered(tf)) in __enable_trace_fprobe()
419 enable_fprobe(&tf->fp); in __enable_trace_fprobe()
426 struct trace_fprobe *tf; in __disable_trace_fprobe() local
428 list_for_each_entry(tf, trace_probe_probe_list(tp), tp.list) { in __disable_trace_fprobe()
429 if (!trace_fprobe_is_registered(tf)) in __disable_trace_fprobe()
431 disable_fprobe(&tf->fp); in __disable_trace_fprobe()
443 struct trace_fprobe *tf; in enable_trace_fprobe() local
449 return -ENODEV; in enable_trace_fprobe()
461 list_for_each_entry(tf, trace_probe_probe_list(tp), tp.list) { in enable_trace_fprobe()
463 __enable_trace_fprobe(tf); in enable_trace_fprobe()
481 return -ENODEV; in disable_trace_fprobe()
485 return -ENOENT; in disable_trace_fprobe()
514 struct trace_seq *s = &iter->seq; in print_fentry_event()
517 field = (struct fentry_trace_entry_head *)iter->ent; in print_fentry_event()
525 if (!seq_print_ip_sym(s, field->ip, flags | TRACE_ITER_SYM_OFFSET)) in print_fentry_event()
530 if (trace_probe_print_args(s, tp->args, tp->nr_args, in print_fentry_event()
544 struct trace_seq *s = &iter->seq; in print_fexit_event()
547 field = (struct fexit_trace_entry_head *)iter->ent; in print_fexit_event()
555 if (!seq_print_ip_sym(s, field->ret_ip, flags | TRACE_ITER_SYM_OFFSET)) in print_fexit_event()
558 trace_seq_puts(s, " <- "); in print_fexit_event()
560 if (!seq_print_ip_sym(s, field->func, flags & ~TRACE_ITER_SYM_OFFSET)) in print_fexit_event()
565 if (trace_probe_print_args(s, tp->args, tp->nr_args, in print_fexit_event()
583 return -ENOENT; in fentry_event_define_fields()
598 return -ENOENT; in fexit_event_define_fields()
629 static inline void init_trace_event_call(struct trace_fprobe *tf) in init_trace_event_call() argument
631 struct trace_event_call *call = trace_probe_event_call(&tf->tp); in init_trace_event_call()
633 if (trace_fprobe_is_return(tf)) { in init_trace_event_call()
634 call->event.funcs = &fexit_funcs; in init_trace_event_call()
635 call->class->fields_array = fexit_fields_array; in init_trace_event_call()
637 call->event.funcs = &fentry_funcs; in init_trace_event_call()
638 call->class->fields_array = fentry_fields_array; in init_trace_event_call()
641 call->flags = TRACE_EVENT_FL_FPROBE; in init_trace_event_call()
642 call->class->reg = fprobe_register; in init_trace_event_call()
645 static int register_fprobe_event(struct trace_fprobe *tf) in register_fprobe_event() argument
647 init_trace_event_call(tf); in register_fprobe_event()
649 return trace_probe_register_event_call(&tf->tp); in register_fprobe_event()
652 static int unregister_fprobe_event(struct trace_fprobe *tf) in unregister_fprobe_event() argument
654 return trace_probe_unregister_event_call(&tf->tp); in unregister_fprobe_event()
657 /* Internal register function - just handle fprobe and flags */
658 static int __register_trace_fprobe(struct trace_fprobe *tf) in __register_trace_fprobe() argument
667 if (trace_fprobe_is_registered(tf)) in __register_trace_fprobe()
668 return -EINVAL; in __register_trace_fprobe()
670 for (i = 0; i < tf->tp.nr_args; i++) { in __register_trace_fprobe()
671 ret = traceprobe_update_arg(&tf->tp.args[i]); in __register_trace_fprobe()
676 /* Set/clear disabled flag according to tp->flag */ in __register_trace_fprobe()
677 if (trace_probe_is_enabled(&tf->tp)) in __register_trace_fprobe()
678 tf->fp.flags &= ~FPROBE_FL_DISABLED; in __register_trace_fprobe()
680 tf->fp.flags |= FPROBE_FL_DISABLED; in __register_trace_fprobe()
682 if (trace_fprobe_is_tracepoint(tf)) { in __register_trace_fprobe()
683 struct tracepoint *tpoint = tf->tpoint; in __register_trace_fprobe()
684 unsigned long ip = (unsigned long)tpoint->probestub; in __register_trace_fprobe()
686 * Here, we do 2 steps to enable fprobe on a tracepoint. in __register_trace_fprobe()
688 * and put a fprobe on the stub function. in __register_trace_fprobe()
691 tpoint->probestub, NULL, 0); in __register_trace_fprobe()
694 return register_fprobe_ips(&tf->fp, &ip, 1); in __register_trace_fprobe()
698 return register_fprobe(&tf->fp, tf->symbol, NULL); in __register_trace_fprobe()
701 /* Internal unregister function - just handle fprobe and flags */
702 static void __unregister_trace_fprobe(struct trace_fprobe *tf) in __unregister_trace_fprobe() argument
704 if (trace_fprobe_is_registered(tf)) { in __unregister_trace_fprobe()
705 unregister_fprobe(&tf->fp); in __unregister_trace_fprobe()
706 memset(&tf->fp, 0, sizeof(tf->fp)); in __unregister_trace_fprobe()
707 if (trace_fprobe_is_tracepoint(tf)) { in __unregister_trace_fprobe()
708 tracepoint_probe_unregister(tf->tpoint, in __unregister_trace_fprobe()
709 tf->tpoint->probestub, NULL); in __unregister_trace_fprobe()
710 tf->tpoint = NULL; in __unregister_trace_fprobe()
711 tf->mod = NULL; in __unregister_trace_fprobe()
717 /* Unregister a trace_probe and probe_event */
718 static int unregister_trace_fprobe(struct trace_fprobe *tf) in unregister_trace_fprobe() argument
721 if (trace_probe_has_sibling(&tf->tp)) in unregister_trace_fprobe()
725 if (trace_probe_is_enabled(&tf->tp)) in unregister_trace_fprobe()
726 return -EBUSY; in unregister_trace_fprobe()
728 /* If there's a reference to the dynamic event */ in unregister_trace_fprobe()
729 if (trace_event_dyn_busy(trace_probe_event_call(&tf->tp))) in unregister_trace_fprobe()
730 return -EBUSY; in unregister_trace_fprobe()
733 if (unregister_fprobe_event(tf)) in unregister_trace_fprobe()
734 return -EBUSY; in unregister_trace_fprobe()
737 __unregister_trace_fprobe(tf); in unregister_trace_fprobe()
738 dyn_event_remove(&tf->devent); in unregister_trace_fprobe()
739 trace_probe_unlink(&tf->tp); in unregister_trace_fprobe()
747 struct trace_probe_event *tpe = orig->tp.event; in trace_fprobe_has_same_fprobe()
750 list_for_each_entry(orig, &tpe->probes, tp.list) { in trace_fprobe_has_same_fprobe()
759 for (i = 0; i < orig->tp.nr_args; i++) { in trace_fprobe_has_same_fprobe()
760 if (strcmp(orig->tp.args[i].comm, in trace_fprobe_has_same_fprobe()
761 comp->tp.args[i].comm)) in trace_fprobe_has_same_fprobe()
765 if (i == orig->tp.nr_args) in trace_fprobe_has_same_fprobe()
772 static int append_trace_fprobe(struct trace_fprobe *tf, struct trace_fprobe *to) in append_trace_fprobe() argument
776 if (trace_fprobe_is_return(tf) != trace_fprobe_is_return(to) || in append_trace_fprobe()
777 trace_fprobe_is_tracepoint(tf) != trace_fprobe_is_tracepoint(to)) { in append_trace_fprobe()
780 return -EEXIST; in append_trace_fprobe()
782 ret = trace_probe_compare_arg_type(&tf->tp, &to->tp); in append_trace_fprobe()
787 return -EEXIST; in append_trace_fprobe()
789 if (trace_fprobe_has_same_fprobe(to, tf)) { in append_trace_fprobe()
792 return -EEXIST; in append_trace_fprobe()
796 ret = trace_probe_append(&tf->tp, &to->tp); in append_trace_fprobe()
800 ret = __register_trace_fprobe(tf); in append_trace_fprobe()
802 trace_probe_unlink(&tf->tp); in append_trace_fprobe()
804 dyn_event_add(&tf->devent, trace_probe_event_call(&tf->tp)); in append_trace_fprobe()
809 /* Register a trace_probe and probe_event */
810 static int register_trace_fprobe(struct trace_fprobe *tf) in register_trace_fprobe() argument
817 old_tf = find_trace_fprobe(trace_probe_name(&tf->tp), in register_trace_fprobe()
818 trace_probe_group_name(&tf->tp)); in register_trace_fprobe()
820 ret = append_trace_fprobe(tf, old_tf); in register_trace_fprobe()
825 ret = register_fprobe_event(tf); in register_trace_fprobe()
827 if (ret == -EEXIST) { in register_trace_fprobe()
836 ret = __register_trace_fprobe(tf); in register_trace_fprobe()
838 unregister_fprobe_event(tf); in register_trace_fprobe()
840 dyn_event_add(&tf->devent, trace_probe_event_call(&tf->tp)); in register_trace_fprobe()
852 struct trace_fprobe *tf; in __tracepoint_probe_module_cb() local
859 for_each_trace_fprobe(tf, pos) { in __tracepoint_probe_module_cb()
860 if (tp_mod->mod == tf->mod) { in __tracepoint_probe_module_cb()
861 tracepoint_probe_unregister(tf->tpoint, in __tracepoint_probe_module_cb()
862 tf->tpoint->probestub, NULL); in __tracepoint_probe_module_cb()
863 tf->tpoint = NULL; in __tracepoint_probe_module_cb()
864 tf->mod = NULL; in __tracepoint_probe_module_cb()
886 if (!data->tpoint && !strcmp(data->tp_name, tp->name)) in __find_tracepoint_cb()
887 data->tpoint = tp; in __find_tracepoint_cb()
909 int len = tmp - argv[1]; in parse_symbol_and_return()
915 return -EINVAL; in parse_symbol_and_return()
921 return -ENOMEM; in parse_symbol_and_return()
926 /* If there is $retval, this should be a return fprobe. */ in parse_symbol_and_return()
932 trace_probe_log_err(tmp - argv[i], RETVAL_ON_PROBE); in parse_symbol_and_return()
933 return -EINVAL; in parse_symbol_and_return()
946 * - Add fentry probe: in __trace_fprobe_create()
948 * - Add fexit probe: in __trace_fprobe_create()
950 * - Add tracepoint probe: in __trace_fprobe_create()
956 * $stackN : fetch Nth entry of stack (N:0-) in __trace_fprobe_create()
957 * $argN : fetch Nth argument (N:1-) in __trace_fprobe_create()
960 * @SYM[+|-offs] : fetch memory at SYM +|- offs (SYM is a data symbol) in __trace_fprobe_create()
962 * +|-offs(ARG) : fetch memory at ARG +|- offs address. in __trace_fprobe_create()
968 struct trace_fprobe *tf = NULL; in __trace_fprobe_create() local
986 return -ECANCELED; in __trace_fprobe_create()
1001 len = event - &argv[0][1] - 1; in __trace_fprobe_create()
1004 if (len > MAX_EVENT_NAME_LEN - 1) { in __trace_fprobe_create()
1015 /* fprobe rethook instances are iterated over via a list. The in __trace_fprobe_create()
1026 /* a symbol(or tracepoint) must be specified */ in __trace_fprobe_create()
1040 event - argv[0]); in __trace_fprobe_create()
1046 /* Make a new event name */ in __trace_fprobe_create()
1071 (unsigned long)tpoint->probestub, in __trace_fprobe_create()
1076 argc -= 2; argv += 2; in __trace_fprobe_create()
1089 /* setup a probe */ in __trace_fprobe_create()
1090 tf = alloc_trace_fprobe(group, event, symbol, tpoint, maxactive, in __trace_fprobe_create()
1092 if (IS_ERR(tf)) { in __trace_fprobe_create()
1093 ret = PTR_ERR(tf); in __trace_fprobe_create()
1094 /* This must return -ENOMEM, else there is a bug */ in __trace_fprobe_create()
1095 WARN_ON_ONCE(ret != -ENOMEM); in __trace_fprobe_create()
1096 goto out; /* We know tf is not allocated */ in __trace_fprobe_create()
1100 tf->mod = __module_text_address( in __trace_fprobe_create()
1101 (unsigned long)tf->tpoint->probestub); in __trace_fprobe_create()
1107 ret = traceprobe_parse_probe_arg(&tf->tp, i, argv[i], &ctx); in __trace_fprobe_create()
1109 goto error; /* This can be -ENOMEM */ in __trace_fprobe_create()
1112 ret = traceprobe_set_print_fmt(&tf->tp, in __trace_fprobe_create()
1117 ret = register_trace_fprobe(tf); in __trace_fprobe_create()
1120 if (ret == -EILSEQ) in __trace_fprobe_create()
1122 else if (ret == -ENOENT) in __trace_fprobe_create()
1124 else if (ret != -ENOMEM && ret != -EEXIST) in __trace_fprobe_create()
1137 ret = -EINVAL; in __trace_fprobe_create()
1139 free_trace_fprobe(tf); in __trace_fprobe_create()
1150 struct trace_fprobe *tf = to_trace_fprobe(ev); in trace_fprobe_release() local
1151 int ret = unregister_trace_fprobe(tf); in trace_fprobe_release()
1154 free_trace_fprobe(tf); in trace_fprobe_release()
1160 struct trace_fprobe *tf = to_trace_fprobe(ev); in trace_fprobe_show() local
1163 if (trace_fprobe_is_tracepoint(tf)) in trace_fprobe_show()
1167 if (trace_fprobe_is_return(tf) && tf->fp.nr_maxactive) in trace_fprobe_show()
1168 seq_printf(m, "%d", tf->fp.nr_maxactive); in trace_fprobe_show()
1169 seq_printf(m, ":%s/%s", trace_probe_group_name(&tf->tp), in trace_fprobe_show()
1170 trace_probe_name(&tf->tp)); in trace_fprobe_show()
1172 seq_printf(m, " %s%s", trace_fprobe_symbol(tf), in trace_fprobe_show()
1173 trace_fprobe_is_return(tf) ? "%return" : ""); in trace_fprobe_show()
1175 for (i = 0; i < tf->tp.nr_args; i++) in trace_fprobe_show()
1176 seq_printf(m, " %s=%s", tf->tp.args[i].name, tf->tp.args[i].comm); in trace_fprobe_show()