1 // SPDX-License-Identifier: GPL-2.0
3 * Kprobes-based tracing events
5 * Created by Masami Hiramatsu <mhiramat@redhat.com>
8 #define pr_fmt(fmt) "trace_kprobe: " fmt
10 #include <linux/module.h>
11 #include <linux/uaccess.h>
12 #include <linux/rculist.h>
13 #include <linux/error-injection.h>
15 #include <asm/setup.h> /* for COMMAND_LINE_SIZE */
17 #include "trace_dynevent.h"
18 #include "trace_kprobe_selftest.h"
19 #include "trace_probe.h"
20 #include "trace_probe_tmpl.h"
22 #define KPROBE_EVENT_SYSTEM "kprobes"
23 #define KRETPROBE_MAXACTIVE_MAX 4096
24 #define MAX_KPROBE_CMDLINE_SIZE 1024
26 /* Kprobe early definition from command line */
27 static char kprobe_boot_events_buf[COMMAND_LINE_SIZE] __initdata;
28 static bool kprobe_boot_events_enabled __initdata;
30 static int __init set_kprobe_boot_events(char *str)
32 strlcpy(kprobe_boot_events_buf, str, COMMAND_LINE_SIZE);
35 __setup("kprobe_event=", set_kprobe_boot_events);
37 static int trace_kprobe_create(int argc, const char **argv);
38 static int trace_kprobe_show(struct seq_file *m, struct dyn_event *ev);
39 static int trace_kprobe_release(struct dyn_event *ev);
40 static bool trace_kprobe_is_busy(struct dyn_event *ev);
41 static bool trace_kprobe_match(const char *system, const char *event,
42 int argc, const char **argv, struct dyn_event *ev);
44 static struct dyn_event_operations trace_kprobe_ops = {
45 .create = trace_kprobe_create,
46 .show = trace_kprobe_show,
47 .is_busy = trace_kprobe_is_busy,
48 .free = trace_kprobe_release,
49 .match = trace_kprobe_match,
53 * Kprobe event core functions
56 struct dyn_event devent;
57 struct kretprobe rp; /* Use rp.kp for kprobe use */
58 unsigned long __percpu *nhit;
59 const char *symbol; /* symbol name */
60 struct trace_probe tp;
63 static bool is_trace_kprobe(struct dyn_event *ev)
65 return ev->ops == &trace_kprobe_ops;
68 static struct trace_kprobe *to_trace_kprobe(struct dyn_event *ev)
70 return container_of(ev, struct trace_kprobe, devent);
74 * for_each_trace_kprobe - iterate over the trace_kprobe list
75 * @pos: the struct trace_kprobe * for each entry
76 * @dpos: the struct dyn_event * to use as a loop cursor
78 #define for_each_trace_kprobe(pos, dpos) \
79 for_each_dyn_event(dpos) \
80 if (is_trace_kprobe(dpos) && (pos = to_trace_kprobe(dpos)))
82 #define SIZEOF_TRACE_KPROBE(n) \
83 (offsetof(struct trace_kprobe, tp.args) + \
84 (sizeof(struct probe_arg) * (n)))
86 static nokprobe_inline bool trace_kprobe_is_return(struct trace_kprobe *tk)
88 return tk->rp.handler != NULL;
91 static nokprobe_inline const char *trace_kprobe_symbol(struct trace_kprobe *tk)
93 return tk->symbol ? tk->symbol : "unknown";
96 static nokprobe_inline unsigned long trace_kprobe_offset(struct trace_kprobe *tk)
98 return tk->rp.kp.offset;
101 static nokprobe_inline bool trace_kprobe_has_gone(struct trace_kprobe *tk)
103 return !!(kprobe_gone(&tk->rp.kp));
106 static nokprobe_inline bool trace_kprobe_within_module(struct trace_kprobe *tk,
109 int len = strlen(mod->name);
110 const char *name = trace_kprobe_symbol(tk);
111 return strncmp(mod->name, name, len) == 0 && name[len] == ':';
114 static nokprobe_inline bool trace_kprobe_module_exist(struct trace_kprobe *tk)
121 p = strchr(tk->symbol, ':');
125 mutex_lock(&module_mutex);
126 ret = !!find_module(tk->symbol);
127 mutex_unlock(&module_mutex);
133 static bool trace_kprobe_is_busy(struct dyn_event *ev)
135 struct trace_kprobe *tk = to_trace_kprobe(ev);
137 return trace_probe_is_enabled(&tk->tp);
140 static bool trace_kprobe_match(const char *system, const char *event,
141 int argc, const char **argv, struct dyn_event *ev)
143 struct trace_kprobe *tk = to_trace_kprobe(ev);
145 return strcmp(trace_probe_name(&tk->tp), event) == 0 &&
146 (!system || strcmp(trace_probe_group_name(&tk->tp), system) == 0);
149 static nokprobe_inline unsigned long trace_kprobe_nhit(struct trace_kprobe *tk)
151 unsigned long nhit = 0;
154 for_each_possible_cpu(cpu)
155 nhit += *per_cpu_ptr(tk->nhit, cpu);
160 static nokprobe_inline bool trace_kprobe_is_registered(struct trace_kprobe *tk)
162 return !(list_empty(&tk->rp.kp.list) &&
163 hlist_unhashed(&tk->rp.kp.hlist));
166 /* Return 0 if it fails to find the symbol address */
167 static nokprobe_inline
168 unsigned long trace_kprobe_address(struct trace_kprobe *tk)
173 addr = (unsigned long)
174 kallsyms_lookup_name(trace_kprobe_symbol(tk));
176 addr += tk->rp.kp.offset;
178 addr = (unsigned long)tk->rp.kp.addr;
183 static nokprobe_inline struct trace_kprobe *
184 trace_kprobe_primary_from_call(struct trace_event_call *call)
186 struct trace_probe *tp;
188 tp = trace_probe_primary_from_call(call);
189 if (WARN_ON_ONCE(!tp))
192 return container_of(tp, struct trace_kprobe, tp);
195 bool trace_kprobe_on_func_entry(struct trace_event_call *call)
197 struct trace_kprobe *tk = trace_kprobe_primary_from_call(call);
199 return tk ? kprobe_on_func_entry(tk->rp.kp.addr,
200 tk->rp.kp.addr ? NULL : tk->rp.kp.symbol_name,
201 tk->rp.kp.addr ? 0 : tk->rp.kp.offset) : false;
204 bool trace_kprobe_error_injectable(struct trace_event_call *call)
206 struct trace_kprobe *tk = trace_kprobe_primary_from_call(call);
208 return tk ? within_error_injection_list(trace_kprobe_address(tk)) :
212 static int register_kprobe_event(struct trace_kprobe *tk);
213 static int unregister_kprobe_event(struct trace_kprobe *tk);
215 static int kprobe_dispatcher(struct kprobe *kp, struct pt_regs *regs);
216 static int kretprobe_dispatcher(struct kretprobe_instance *ri,
217 struct pt_regs *regs);
219 static void free_trace_kprobe(struct trace_kprobe *tk)
222 trace_probe_cleanup(&tk->tp);
224 free_percpu(tk->nhit);
230 * Allocate new trace_probe and initialize it (including kprobes).
232 static struct trace_kprobe *alloc_trace_kprobe(const char *group,
238 int nargs, bool is_return)
240 struct trace_kprobe *tk;
243 tk = kzalloc(SIZEOF_TRACE_KPROBE(nargs), GFP_KERNEL);
247 tk->nhit = alloc_percpu(unsigned long);
252 tk->symbol = kstrdup(symbol, GFP_KERNEL);
255 tk->rp.kp.symbol_name = tk->symbol;
256 tk->rp.kp.offset = offs;
258 tk->rp.kp.addr = addr;
261 tk->rp.handler = kretprobe_dispatcher;
263 tk->rp.kp.pre_handler = kprobe_dispatcher;
265 tk->rp.maxactive = maxactive;
266 INIT_HLIST_NODE(&tk->rp.kp.hlist);
267 INIT_LIST_HEAD(&tk->rp.kp.list);
269 ret = trace_probe_init(&tk->tp, event, group);
273 dyn_event_init(&tk->devent, &trace_kprobe_ops);
276 free_trace_kprobe(tk);
280 static struct trace_kprobe *find_trace_kprobe(const char *event,
283 struct dyn_event *pos;
284 struct trace_kprobe *tk;
286 for_each_trace_kprobe(tk, pos)
287 if (strcmp(trace_probe_name(&tk->tp), event) == 0 &&
288 strcmp(trace_probe_group_name(&tk->tp), group) == 0)
293 static inline int __enable_trace_kprobe(struct trace_kprobe *tk)
297 if (trace_kprobe_is_registered(tk) && !trace_kprobe_has_gone(tk)) {
298 if (trace_kprobe_is_return(tk))
299 ret = enable_kretprobe(&tk->rp);
301 ret = enable_kprobe(&tk->rp.kp);
307 static void __disable_trace_kprobe(struct trace_probe *tp)
309 struct trace_probe *pos;
310 struct trace_kprobe *tk;
312 list_for_each_entry(pos, trace_probe_probe_list(tp), list) {
313 tk = container_of(pos, struct trace_kprobe, tp);
314 if (!trace_kprobe_is_registered(tk))
316 if (trace_kprobe_is_return(tk))
317 disable_kretprobe(&tk->rp);
319 disable_kprobe(&tk->rp.kp);
325 * if the file is NULL, enable "perf" handler, or enable "trace" handler.
327 static int enable_trace_kprobe(struct trace_event_call *call,
328 struct trace_event_file *file)
330 struct trace_probe *pos, *tp;
331 struct trace_kprobe *tk;
335 tp = trace_probe_primary_from_call(call);
336 if (WARN_ON_ONCE(!tp))
338 enabled = trace_probe_is_enabled(tp);
340 /* This also changes "enabled" state */
342 ret = trace_probe_add_file(tp, file);
346 trace_probe_set_flag(tp, TP_FLAG_PROFILE);
352 list_for_each_entry(pos, trace_probe_probe_list(tp), list) {
353 tk = container_of(pos, struct trace_kprobe, tp);
354 if (trace_kprobe_has_gone(tk))
356 ret = __enable_trace_kprobe(tk);
359 __disable_trace_kprobe(tp);
368 /* No probe is enabled. Roll back */
370 trace_probe_remove_file(tp, file);
372 trace_probe_clear_flag(tp, TP_FLAG_PROFILE);
374 /* Since all probes are gone, this is not available */
375 ret = -EADDRNOTAVAIL;
382 * Disable trace_probe
383 * if the file is NULL, disable "perf" handler, or disable "trace" handler.
385 static int disable_trace_kprobe(struct trace_event_call *call,
386 struct trace_event_file *file)
388 struct trace_probe *tp;
390 tp = trace_probe_primary_from_call(call);
391 if (WARN_ON_ONCE(!tp))
395 if (!trace_probe_get_file_link(tp, file))
397 if (!trace_probe_has_single_file(tp))
399 trace_probe_clear_flag(tp, TP_FLAG_TRACE);
401 trace_probe_clear_flag(tp, TP_FLAG_PROFILE);
403 if (!trace_probe_is_enabled(tp))
404 __disable_trace_kprobe(tp);
409 * Synchronization is done in below function. For perf event,
410 * file == NULL and perf_trace_event_unreg() calls
411 * tracepoint_synchronize_unregister() to ensure synchronize
412 * event. We don't need to care about it.
414 trace_probe_remove_file(tp, file);
419 #if defined(CONFIG_KPROBES_ON_FTRACE) && \
420 !defined(CONFIG_KPROBE_EVENTS_ON_NOTRACE)
421 static bool within_notrace_func(struct trace_kprobe *tk)
423 unsigned long offset, size, addr;
425 addr = trace_kprobe_address(tk);
426 if (!addr || !kallsyms_lookup_size_offset(addr, &size, &offset))
429 /* Get the entry address of the target function */
433 * Since ftrace_location_range() does inclusive range check, we need
434 * to subtract 1 byte from the end address.
436 return !ftrace_location_range(addr, addr + size - 1);
439 #define within_notrace_func(tk) (false)
442 /* Internal register function - just handle k*probes and flags */
443 static int __register_trace_kprobe(struct trace_kprobe *tk)
447 if (trace_kprobe_is_registered(tk))
450 if (within_notrace_func(tk)) {
451 pr_warn("Could not probe notrace function %s\n",
452 trace_kprobe_symbol(tk));
456 for (i = 0; i < tk->tp.nr_args; i++) {
457 ret = traceprobe_update_arg(&tk->tp.args[i]);
462 /* Set/clear disabled flag according to tp->flag */
463 if (trace_probe_is_enabled(&tk->tp))
464 tk->rp.kp.flags &= ~KPROBE_FLAG_DISABLED;
466 tk->rp.kp.flags |= KPROBE_FLAG_DISABLED;
468 if (trace_kprobe_is_return(tk))
469 ret = register_kretprobe(&tk->rp);
471 ret = register_kprobe(&tk->rp.kp);
476 /* Internal unregister function - just handle k*probes and flags */
477 static void __unregister_trace_kprobe(struct trace_kprobe *tk)
479 if (trace_kprobe_is_registered(tk)) {
480 if (trace_kprobe_is_return(tk))
481 unregister_kretprobe(&tk->rp);
483 unregister_kprobe(&tk->rp.kp);
484 /* Cleanup kprobe for reuse and mark it unregistered */
485 INIT_HLIST_NODE(&tk->rp.kp.hlist);
486 INIT_LIST_HEAD(&tk->rp.kp.list);
487 if (tk->rp.kp.symbol_name)
488 tk->rp.kp.addr = NULL;
492 /* Unregister a trace_probe and probe_event */
493 static int unregister_trace_kprobe(struct trace_kprobe *tk)
495 /* If other probes are on the event, just unregister kprobe */
496 if (trace_probe_has_sibling(&tk->tp))
499 /* Enabled event can not be unregistered */
500 if (trace_probe_is_enabled(&tk->tp))
503 /* Will fail if probe is being used by ftrace or perf */
504 if (unregister_kprobe_event(tk))
508 __unregister_trace_kprobe(tk);
509 dyn_event_remove(&tk->devent);
510 trace_probe_unlink(&tk->tp);
515 static int append_trace_kprobe(struct trace_kprobe *tk, struct trace_kprobe *to)
519 /* Append to existing event */
520 ret = trace_probe_append(&tk->tp, &to->tp);
524 /* Register k*probe */
525 ret = __register_trace_kprobe(tk);
526 if (ret == -ENOENT && !trace_kprobe_module_exist(tk)) {
527 pr_warn("This probe might be able to register after target module is loaded. Continue.\n");
532 trace_probe_unlink(&tk->tp);
534 dyn_event_add(&tk->devent);
539 /* Register a trace_probe and probe_event */
540 static int register_trace_kprobe(struct trace_kprobe *tk)
542 struct trace_kprobe *old_tk;
545 mutex_lock(&event_mutex);
547 old_tk = find_trace_kprobe(trace_probe_name(&tk->tp),
548 trace_probe_group_name(&tk->tp));
550 if (trace_kprobe_is_return(tk) != trace_kprobe_is_return(old_tk)) {
551 trace_probe_log_set_index(0);
552 trace_probe_log_err(0, DIFF_PROBE_TYPE);
555 ret = trace_probe_compare_arg_type(&tk->tp, &old_tk->tp);
557 /* Note that argument starts index = 2 */
558 trace_probe_log_set_index(ret + 1);
559 trace_probe_log_err(0, DIFF_ARG_TYPE);
562 ret = append_trace_kprobe(tk, old_tk);
567 /* Register new event */
568 ret = register_kprobe_event(tk);
570 pr_warn("Failed to register probe event(%d)\n", ret);
574 /* Register k*probe */
575 ret = __register_trace_kprobe(tk);
576 if (ret == -ENOENT && !trace_kprobe_module_exist(tk)) {
577 pr_warn("This probe might be able to register after target module is loaded. Continue.\n");
582 unregister_kprobe_event(tk);
584 dyn_event_add(&tk->devent);
587 mutex_unlock(&event_mutex);
591 /* Module notifier call back, checking event on the module */
592 static int trace_kprobe_module_callback(struct notifier_block *nb,
593 unsigned long val, void *data)
595 struct module *mod = data;
596 struct dyn_event *pos;
597 struct trace_kprobe *tk;
600 if (val != MODULE_STATE_COMING)
603 /* Update probes on coming module */
604 mutex_lock(&event_mutex);
605 for_each_trace_kprobe(tk, pos) {
606 if (trace_kprobe_within_module(tk, mod)) {
607 /* Don't need to check busy - this should have gone. */
608 __unregister_trace_kprobe(tk);
609 ret = __register_trace_kprobe(tk);
611 pr_warn("Failed to re-register probe %s on %s: %d\n",
612 trace_probe_name(&tk->tp),
616 mutex_unlock(&event_mutex);
621 static struct notifier_block trace_kprobe_module_nb = {
622 .notifier_call = trace_kprobe_module_callback,
623 .priority = 1 /* Invoked after kprobe module callback */
626 /* Convert certain expected symbols into '_' when generating event names */
627 static inline void sanitize_event_name(char *name)
629 while (*name++ != '\0')
630 if (*name == ':' || *name == '.')
634 static int trace_kprobe_create(int argc, const char *argv[])
639 * p[:[GRP/]EVENT] [MOD:]KSYM[+OFFS]|KADDR [FETCHARGS]
641 * r[MAXACTIVE][:[GRP/]EVENT] [MOD:]KSYM[+0] [FETCHARGS]
643 * $retval : fetch return value
644 * $stack : fetch stack address
645 * $stackN : fetch Nth of stack (N:0-)
646 * $comm : fetch current task comm
647 * @ADDR : fetch memory at ADDR (ADDR should be in kernel)
648 * @SYM[+|-offs] : fetch memory at SYM +|- offs (SYM is a data symbol)
649 * %REG : fetch register REG
650 * Dereferencing memory fetch:
651 * +|-offs(ARG) : fetch memory at ARG +|- offs address.
652 * Alias name of args:
653 * NAME=FETCHARG : set NAME as alias of FETCHARG.
655 * FETCHARG:TYPE : use TYPE instead of unsigned long.
657 struct trace_kprobe *tk = NULL;
659 bool is_return = false;
660 char *symbol = NULL, *tmp = NULL;
661 const char *event = NULL, *group = KPROBE_EVENT_SYSTEM;
665 char buf[MAX_EVENT_NAME_LEN];
666 unsigned int flags = TPARG_FL_KERNEL;
668 switch (argv[0][0]) {
671 flags |= TPARG_FL_RETURN;
681 trace_probe_log_init("trace_kprobe", argc, argv);
683 event = strchr(&argv[0][1], ':');
687 if (isdigit(argv[0][1])) {
689 trace_probe_log_err(1, MAXACT_NO_KPROBE);
693 len = event - &argv[0][1] - 1;
695 len = strlen(&argv[0][1]);
696 if (len > MAX_EVENT_NAME_LEN - 1) {
697 trace_probe_log_err(1, BAD_MAXACT);
700 memcpy(buf, &argv[0][1], len);
702 ret = kstrtouint(buf, 0, &maxactive);
703 if (ret || !maxactive) {
704 trace_probe_log_err(1, BAD_MAXACT);
707 /* kretprobes instances are iterated over via a list. The
708 * maximum should stay reasonable.
710 if (maxactive > KRETPROBE_MAXACTIVE_MAX) {
711 trace_probe_log_err(1, MAXACT_TOO_BIG);
716 /* try to parse an address. if that fails, try to read the
717 * input as a symbol. */
718 if (kstrtoul(argv[1], 0, (unsigned long *)&addr)) {
719 trace_probe_log_set_index(1);
720 /* Check whether uprobe event specified */
721 if (strchr(argv[1], '/') && strchr(argv[1], ':')) {
725 /* a symbol specified */
726 symbol = kstrdup(argv[1], GFP_KERNEL);
729 /* TODO: support .init module functions */
730 ret = traceprobe_split_symbol_offset(symbol, &offset);
731 if (ret || offset < 0 || offset > UINT_MAX) {
732 trace_probe_log_err(0, BAD_PROBE_ADDR);
735 if (kprobe_on_func_entry(NULL, symbol, offset))
736 flags |= TPARG_FL_FENTRY;
737 if (offset && is_return && !(flags & TPARG_FL_FENTRY)) {
738 trace_probe_log_err(0, BAD_RETPROBE);
743 trace_probe_log_set_index(0);
745 ret = traceprobe_parse_event_name(&event, &group, buf,
750 /* Make a new event name */
752 snprintf(buf, MAX_EVENT_NAME_LEN, "%c_%s_%ld",
753 is_return ? 'r' : 'p', symbol, offset);
755 snprintf(buf, MAX_EVENT_NAME_LEN, "%c_0x%p",
756 is_return ? 'r' : 'p', addr);
757 sanitize_event_name(buf);
762 tk = alloc_trace_kprobe(group, event, addr, symbol, offset, maxactive,
763 argc - 2, is_return);
766 /* This must return -ENOMEM, else there is a bug */
767 WARN_ON_ONCE(ret != -ENOMEM);
768 goto out; /* We know tk is not allocated */
770 argc -= 2; argv += 2;
772 /* parse arguments */
773 for (i = 0; i < argc && i < MAX_TRACE_ARGS; i++) {
774 tmp = kstrdup(argv[i], GFP_KERNEL);
780 trace_probe_log_set_index(i + 2);
781 ret = traceprobe_parse_probe_arg(&tk->tp, i, tmp, flags);
784 goto error; /* This can be -ENOMEM */
787 ret = traceprobe_set_print_fmt(&tk->tp, is_return);
791 ret = register_trace_kprobe(tk);
793 trace_probe_log_set_index(1);
795 trace_probe_log_err(0, BAD_INSN_BNDRY);
796 else if (ret == -ENOENT)
797 trace_probe_log_err(0, BAD_PROBE_ADDR);
798 else if (ret != -ENOMEM && ret != -EEXIST)
799 trace_probe_log_err(0, FAIL_REG_PROBE);
804 trace_probe_log_clear();
811 free_trace_kprobe(tk);
815 static int create_or_delete_trace_kprobe(int argc, char **argv)
819 if (argv[0][0] == '-')
820 return dyn_event_release(argc, argv, &trace_kprobe_ops);
822 ret = trace_kprobe_create(argc, (const char **)argv);
823 return ret == -ECANCELED ? -EINVAL : ret;
826 static int trace_kprobe_release(struct dyn_event *ev)
828 struct trace_kprobe *tk = to_trace_kprobe(ev);
829 int ret = unregister_trace_kprobe(tk);
832 free_trace_kprobe(tk);
836 static int trace_kprobe_show(struct seq_file *m, struct dyn_event *ev)
838 struct trace_kprobe *tk = to_trace_kprobe(ev);
841 seq_putc(m, trace_kprobe_is_return(tk) ? 'r' : 'p');
842 seq_printf(m, ":%s/%s", trace_probe_group_name(&tk->tp),
843 trace_probe_name(&tk->tp));
846 seq_printf(m, " 0x%p", tk->rp.kp.addr);
847 else if (tk->rp.kp.offset)
848 seq_printf(m, " %s+%u", trace_kprobe_symbol(tk),
851 seq_printf(m, " %s", trace_kprobe_symbol(tk));
853 for (i = 0; i < tk->tp.nr_args; i++)
854 seq_printf(m, " %s=%s", tk->tp.args[i].name, tk->tp.args[i].comm);
860 static int probes_seq_show(struct seq_file *m, void *v)
862 struct dyn_event *ev = v;
864 if (!is_trace_kprobe(ev))
867 return trace_kprobe_show(m, ev);
870 static const struct seq_operations probes_seq_op = {
871 .start = dyn_event_seq_start,
872 .next = dyn_event_seq_next,
873 .stop = dyn_event_seq_stop,
874 .show = probes_seq_show
877 static int probes_open(struct inode *inode, struct file *file)
881 if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_TRUNC)) {
882 ret = dyn_events_release_all(&trace_kprobe_ops);
887 return seq_open(file, &probes_seq_op);
890 static ssize_t probes_write(struct file *file, const char __user *buffer,
891 size_t count, loff_t *ppos)
893 return trace_parse_run_command(file, buffer, count, ppos,
894 create_or_delete_trace_kprobe);
897 static const struct file_operations kprobe_events_ops = {
898 .owner = THIS_MODULE,
902 .release = seq_release,
903 .write = probes_write,
906 /* Probes profiling interfaces */
907 static int probes_profile_seq_show(struct seq_file *m, void *v)
909 struct dyn_event *ev = v;
910 struct trace_kprobe *tk;
912 if (!is_trace_kprobe(ev))
915 tk = to_trace_kprobe(ev);
916 seq_printf(m, " %-44s %15lu %15lu\n",
917 trace_probe_name(&tk->tp),
918 trace_kprobe_nhit(tk),
924 static const struct seq_operations profile_seq_op = {
925 .start = dyn_event_seq_start,
926 .next = dyn_event_seq_next,
927 .stop = dyn_event_seq_stop,
928 .show = probes_profile_seq_show
931 static int profile_open(struct inode *inode, struct file *file)
933 return seq_open(file, &profile_seq_op);
936 static const struct file_operations kprobe_profile_ops = {
937 .owner = THIS_MODULE,
938 .open = profile_open,
941 .release = seq_release,
944 /* Kprobe specific fetch functions */
946 /* Return the length of string -- including null terminal byte */
947 static nokprobe_inline int
948 fetch_store_strlen(unsigned long addr)
954 ret = probe_kernel_read(&c, (u8 *)addr + len, 1);
956 } while (c && ret == 0 && len < MAX_STRING_SIZE);
958 return (ret < 0) ? ret : len;
961 /* Return the length of string -- including null terminal byte */
962 static nokprobe_inline int
963 fetch_store_strlen_user(unsigned long addr)
965 const void __user *uaddr = (__force const void __user *)addr;
967 return strnlen_unsafe_user(uaddr, MAX_STRING_SIZE);
971 * Fetch a null-terminated string. Caller MUST set *(u32 *)buf with max
972 * length and relative data location.
974 static nokprobe_inline int
975 fetch_store_string(unsigned long addr, void *dest, void *base)
977 int maxlen = get_loc_len(*(u32 *)dest);
981 if (unlikely(!maxlen))
984 __dest = get_loc_data(dest, base);
987 * Try to get string again, since the string can be changed while
990 ret = strncpy_from_unsafe(__dest, (void *)addr, maxlen);
992 *(u32 *)dest = make_data_loc(ret, __dest - base);
998 * Fetch a null-terminated string from user. Caller MUST set *(u32 *)buf
999 * with max length and relative data location.
1001 static nokprobe_inline int
1002 fetch_store_string_user(unsigned long addr, void *dest, void *base)
1004 const void __user *uaddr = (__force const void __user *)addr;
1005 int maxlen = get_loc_len(*(u32 *)dest);
1009 if (unlikely(!maxlen))
1012 __dest = get_loc_data(dest, base);
1014 ret = strncpy_from_unsafe_user(__dest, uaddr, maxlen);
1016 *(u32 *)dest = make_data_loc(ret, __dest - base);
1021 static nokprobe_inline int
1022 probe_mem_read(void *dest, void *src, size_t size)
1024 return probe_kernel_read(dest, src, size);
1027 static nokprobe_inline int
1028 probe_mem_read_user(void *dest, void *src, size_t size)
1030 const void __user *uaddr = (__force const void __user *)src;
1032 return probe_user_read(dest, uaddr, size);
1035 /* Note that we don't verify it, since the code does not come from user space */
1037 process_fetch_insn(struct fetch_insn *code, struct pt_regs *regs, void *dest,
1043 /* 1st stage: get value from context */
1046 val = regs_get_register(regs, code->param);
1048 case FETCH_OP_STACK:
1049 val = regs_get_kernel_stack_nth(regs, code->param);
1051 case FETCH_OP_STACKP:
1052 val = kernel_stack_pointer(regs);
1054 case FETCH_OP_RETVAL:
1055 val = regs_return_value(regs);
1058 val = code->immediate;
1061 val = (unsigned long)current->comm;
1063 #ifdef CONFIG_HAVE_FUNCTION_ARG_ACCESS_API
1065 val = regs_get_kernel_argument(regs, code->param);
1068 case FETCH_NOP_SYMBOL: /* Ignore a place holder */
1076 return process_fetch_insn_bottom(code, val, dest, base);
1078 NOKPROBE_SYMBOL(process_fetch_insn)
1080 /* Kprobe handler */
1081 static nokprobe_inline void
1082 __kprobe_trace_func(struct trace_kprobe *tk, struct pt_regs *regs,
1083 struct trace_event_file *trace_file)
1085 struct kprobe_trace_entry_head *entry;
1086 struct ring_buffer_event *event;
1087 struct ring_buffer *buffer;
1088 int size, dsize, pc;
1089 unsigned long irq_flags;
1090 struct trace_event_call *call = trace_probe_event_call(&tk->tp);
1092 WARN_ON(call != trace_file->event_call);
1094 if (trace_trigger_soft_disabled(trace_file))
1097 local_save_flags(irq_flags);
1098 pc = preempt_count();
1100 dsize = __get_data_size(&tk->tp, regs);
1101 size = sizeof(*entry) + tk->tp.size + dsize;
1103 event = trace_event_buffer_lock_reserve(&buffer, trace_file,
1105 size, irq_flags, pc);
1109 entry = ring_buffer_event_data(event);
1110 entry->ip = (unsigned long)tk->rp.kp.addr;
1111 store_trace_args(&entry[1], &tk->tp, regs, sizeof(*entry), dsize);
1113 event_trigger_unlock_commit_regs(trace_file, buffer, event,
1114 entry, irq_flags, pc, regs);
1118 kprobe_trace_func(struct trace_kprobe *tk, struct pt_regs *regs)
1120 struct event_file_link *link;
1122 trace_probe_for_each_link_rcu(link, &tk->tp)
1123 __kprobe_trace_func(tk, regs, link->file);
1125 NOKPROBE_SYMBOL(kprobe_trace_func);
1127 /* Kretprobe handler */
1128 static nokprobe_inline void
1129 __kretprobe_trace_func(struct trace_kprobe *tk, struct kretprobe_instance *ri,
1130 struct pt_regs *regs,
1131 struct trace_event_file *trace_file)
1133 struct kretprobe_trace_entry_head *entry;
1134 struct ring_buffer_event *event;
1135 struct ring_buffer *buffer;
1136 int size, pc, dsize;
1137 unsigned long irq_flags;
1138 struct trace_event_call *call = trace_probe_event_call(&tk->tp);
1140 WARN_ON(call != trace_file->event_call);
1142 if (trace_trigger_soft_disabled(trace_file))
1145 local_save_flags(irq_flags);
1146 pc = preempt_count();
1148 dsize = __get_data_size(&tk->tp, regs);
1149 size = sizeof(*entry) + tk->tp.size + dsize;
1151 event = trace_event_buffer_lock_reserve(&buffer, trace_file,
1153 size, irq_flags, pc);
1157 entry = ring_buffer_event_data(event);
1158 entry->func = (unsigned long)tk->rp.kp.addr;
1159 entry->ret_ip = (unsigned long)ri->ret_addr;
1160 store_trace_args(&entry[1], &tk->tp, regs, sizeof(*entry), dsize);
1162 event_trigger_unlock_commit_regs(trace_file, buffer, event,
1163 entry, irq_flags, pc, regs);
1167 kretprobe_trace_func(struct trace_kprobe *tk, struct kretprobe_instance *ri,
1168 struct pt_regs *regs)
1170 struct event_file_link *link;
1172 trace_probe_for_each_link_rcu(link, &tk->tp)
1173 __kretprobe_trace_func(tk, ri, regs, link->file);
1175 NOKPROBE_SYMBOL(kretprobe_trace_func);
1177 /* Event entry printers */
1178 static enum print_line_t
1179 print_kprobe_event(struct trace_iterator *iter, int flags,
1180 struct trace_event *event)
1182 struct kprobe_trace_entry_head *field;
1183 struct trace_seq *s = &iter->seq;
1184 struct trace_probe *tp;
1186 field = (struct kprobe_trace_entry_head *)iter->ent;
1187 tp = trace_probe_primary_from_call(
1188 container_of(event, struct trace_event_call, event));
1189 if (WARN_ON_ONCE(!tp))
1192 trace_seq_printf(s, "%s: (", trace_probe_name(tp));
1194 if (!seq_print_ip_sym(s, field->ip, flags | TRACE_ITER_SYM_OFFSET))
1197 trace_seq_putc(s, ')');
1199 if (print_probe_args(s, tp->args, tp->nr_args,
1200 (u8 *)&field[1], field) < 0)
1203 trace_seq_putc(s, '\n');
1205 return trace_handle_return(s);
1208 static enum print_line_t
1209 print_kretprobe_event(struct trace_iterator *iter, int flags,
1210 struct trace_event *event)
1212 struct kretprobe_trace_entry_head *field;
1213 struct trace_seq *s = &iter->seq;
1214 struct trace_probe *tp;
1216 field = (struct kretprobe_trace_entry_head *)iter->ent;
1217 tp = trace_probe_primary_from_call(
1218 container_of(event, struct trace_event_call, event));
1219 if (WARN_ON_ONCE(!tp))
1222 trace_seq_printf(s, "%s: (", trace_probe_name(tp));
1224 if (!seq_print_ip_sym(s, field->ret_ip, flags | TRACE_ITER_SYM_OFFSET))
1227 trace_seq_puts(s, " <- ");
1229 if (!seq_print_ip_sym(s, field->func, flags & ~TRACE_ITER_SYM_OFFSET))
1232 trace_seq_putc(s, ')');
1234 if (print_probe_args(s, tp->args, tp->nr_args,
1235 (u8 *)&field[1], field) < 0)
1238 trace_seq_putc(s, '\n');
1241 return trace_handle_return(s);
1245 static int kprobe_event_define_fields(struct trace_event_call *event_call)
1248 struct kprobe_trace_entry_head field;
1249 struct trace_probe *tp;
1251 tp = trace_probe_primary_from_call(event_call);
1252 if (WARN_ON_ONCE(!tp))
1255 DEFINE_FIELD(unsigned long, ip, FIELD_STRING_IP, 0);
1257 return traceprobe_define_arg_fields(event_call, sizeof(field), tp);
1260 static int kretprobe_event_define_fields(struct trace_event_call *event_call)
1263 struct kretprobe_trace_entry_head field;
1264 struct trace_probe *tp;
1266 tp = trace_probe_primary_from_call(event_call);
1267 if (WARN_ON_ONCE(!tp))
1270 DEFINE_FIELD(unsigned long, func, FIELD_STRING_FUNC, 0);
1271 DEFINE_FIELD(unsigned long, ret_ip, FIELD_STRING_RETIP, 0);
1273 return traceprobe_define_arg_fields(event_call, sizeof(field), tp);
1276 #ifdef CONFIG_PERF_EVENTS
1278 /* Kprobe profile handler */
1280 kprobe_perf_func(struct trace_kprobe *tk, struct pt_regs *regs)
1282 struct trace_event_call *call = trace_probe_event_call(&tk->tp);
1283 struct kprobe_trace_entry_head *entry;
1284 struct hlist_head *head;
1285 int size, __size, dsize;
1288 if (bpf_prog_array_valid(call)) {
1289 unsigned long orig_ip = instruction_pointer(regs);
1292 ret = trace_call_bpf(call, regs);
1295 * We need to check and see if we modified the pc of the
1296 * pt_regs, and if so return 1 so that we don't do the
1299 if (orig_ip != instruction_pointer(regs))
1305 head = this_cpu_ptr(call->perf_events);
1306 if (hlist_empty(head))
1309 dsize = __get_data_size(&tk->tp, regs);
1310 __size = sizeof(*entry) + tk->tp.size + dsize;
1311 size = ALIGN(__size + sizeof(u32), sizeof(u64));
1312 size -= sizeof(u32);
1314 entry = perf_trace_buf_alloc(size, NULL, &rctx);
1318 entry->ip = (unsigned long)tk->rp.kp.addr;
1319 memset(&entry[1], 0, dsize);
1320 store_trace_args(&entry[1], &tk->tp, regs, sizeof(*entry), dsize);
1321 perf_trace_buf_submit(entry, size, rctx, call->event.type, 1, regs,
1325 NOKPROBE_SYMBOL(kprobe_perf_func);
1327 /* Kretprobe profile handler */
1329 kretprobe_perf_func(struct trace_kprobe *tk, struct kretprobe_instance *ri,
1330 struct pt_regs *regs)
1332 struct trace_event_call *call = trace_probe_event_call(&tk->tp);
1333 struct kretprobe_trace_entry_head *entry;
1334 struct hlist_head *head;
1335 int size, __size, dsize;
1338 if (bpf_prog_array_valid(call) && !trace_call_bpf(call, regs))
1341 head = this_cpu_ptr(call->perf_events);
1342 if (hlist_empty(head))
1345 dsize = __get_data_size(&tk->tp, regs);
1346 __size = sizeof(*entry) + tk->tp.size + dsize;
1347 size = ALIGN(__size + sizeof(u32), sizeof(u64));
1348 size -= sizeof(u32);
1350 entry = perf_trace_buf_alloc(size, NULL, &rctx);
1354 entry->func = (unsigned long)tk->rp.kp.addr;
1355 entry->ret_ip = (unsigned long)ri->ret_addr;
1356 store_trace_args(&entry[1], &tk->tp, regs, sizeof(*entry), dsize);
1357 perf_trace_buf_submit(entry, size, rctx, call->event.type, 1, regs,
1360 NOKPROBE_SYMBOL(kretprobe_perf_func);
1362 int bpf_get_kprobe_info(const struct perf_event *event, u32 *fd_type,
1363 const char **symbol, u64 *probe_offset,
1364 u64 *probe_addr, bool perf_type_tracepoint)
1366 const char *pevent = trace_event_name(event->tp_event);
1367 const char *group = event->tp_event->class->system;
1368 struct trace_kprobe *tk;
1370 if (perf_type_tracepoint)
1371 tk = find_trace_kprobe(pevent, group);
1373 tk = event->tp_event->data;
1377 *fd_type = trace_kprobe_is_return(tk) ? BPF_FD_TYPE_KRETPROBE
1378 : BPF_FD_TYPE_KPROBE;
1380 *symbol = tk->symbol;
1381 *probe_offset = tk->rp.kp.offset;
1386 *probe_addr = (unsigned long)tk->rp.kp.addr;
1390 #endif /* CONFIG_PERF_EVENTS */
1393 * called by perf_trace_init() or __ftrace_set_clr_event() under event_mutex.
1395 * kprobe_trace_self_tests_init() does enable_trace_probe/disable_trace_probe
1396 * lockless, but we can't race with this __init function.
1398 static int kprobe_register(struct trace_event_call *event,
1399 enum trace_reg type, void *data)
1401 struct trace_event_file *file = data;
1404 case TRACE_REG_REGISTER:
1405 return enable_trace_kprobe(event, file);
1406 case TRACE_REG_UNREGISTER:
1407 return disable_trace_kprobe(event, file);
1409 #ifdef CONFIG_PERF_EVENTS
1410 case TRACE_REG_PERF_REGISTER:
1411 return enable_trace_kprobe(event, NULL);
1412 case TRACE_REG_PERF_UNREGISTER:
1413 return disable_trace_kprobe(event, NULL);
1414 case TRACE_REG_PERF_OPEN:
1415 case TRACE_REG_PERF_CLOSE:
1416 case TRACE_REG_PERF_ADD:
1417 case TRACE_REG_PERF_DEL:
1424 static int kprobe_dispatcher(struct kprobe *kp, struct pt_regs *regs)
1426 struct trace_kprobe *tk = container_of(kp, struct trace_kprobe, rp.kp);
1429 raw_cpu_inc(*tk->nhit);
1431 if (trace_probe_test_flag(&tk->tp, TP_FLAG_TRACE))
1432 kprobe_trace_func(tk, regs);
1433 #ifdef CONFIG_PERF_EVENTS
1434 if (trace_probe_test_flag(&tk->tp, TP_FLAG_PROFILE))
1435 ret = kprobe_perf_func(tk, regs);
1439 NOKPROBE_SYMBOL(kprobe_dispatcher);
1442 kretprobe_dispatcher(struct kretprobe_instance *ri, struct pt_regs *regs)
1444 struct trace_kprobe *tk = container_of(ri->rp, struct trace_kprobe, rp);
1446 raw_cpu_inc(*tk->nhit);
1448 if (trace_probe_test_flag(&tk->tp, TP_FLAG_TRACE))
1449 kretprobe_trace_func(tk, ri, regs);
1450 #ifdef CONFIG_PERF_EVENTS
1451 if (trace_probe_test_flag(&tk->tp, TP_FLAG_PROFILE))
1452 kretprobe_perf_func(tk, ri, regs);
1454 return 0; /* We don't tweek kernel, so just return 0 */
1456 NOKPROBE_SYMBOL(kretprobe_dispatcher);
1458 static struct trace_event_functions kretprobe_funcs = {
1459 .trace = print_kretprobe_event
1462 static struct trace_event_functions kprobe_funcs = {
1463 .trace = print_kprobe_event
1466 static inline void init_trace_event_call(struct trace_kprobe *tk)
1468 struct trace_event_call *call = trace_probe_event_call(&tk->tp);
1470 if (trace_kprobe_is_return(tk)) {
1471 call->event.funcs = &kretprobe_funcs;
1472 call->class->define_fields = kretprobe_event_define_fields;
1474 call->event.funcs = &kprobe_funcs;
1475 call->class->define_fields = kprobe_event_define_fields;
1478 call->flags = TRACE_EVENT_FL_KPROBE;
1479 call->class->reg = kprobe_register;
1482 static int register_kprobe_event(struct trace_kprobe *tk)
1484 init_trace_event_call(tk);
1486 return trace_probe_register_event_call(&tk->tp);
1489 static int unregister_kprobe_event(struct trace_kprobe *tk)
1491 return trace_probe_unregister_event_call(&tk->tp);
1494 #ifdef CONFIG_PERF_EVENTS
1495 /* create a trace_kprobe, but don't add it to global lists */
1496 struct trace_event_call *
1497 create_local_trace_kprobe(char *func, void *addr, unsigned long offs,
1500 struct trace_kprobe *tk;
1505 * local trace_kprobes are not added to dyn_event, so they are never
1506 * searched in find_trace_kprobe(). Therefore, there is no concern of
1507 * duplicated name here.
1509 event = func ? func : "DUMMY_EVENT";
1511 tk = alloc_trace_kprobe(KPROBE_EVENT_SYSTEM, event, (void *)addr, func,
1512 offs, 0 /* maxactive */, 0 /* nargs */,
1516 pr_info("Failed to allocate trace_probe.(%d)\n",
1518 return ERR_CAST(tk);
1521 init_trace_event_call(tk);
1523 if (traceprobe_set_print_fmt(&tk->tp, trace_kprobe_is_return(tk)) < 0) {
1528 ret = __register_trace_kprobe(tk);
1532 return trace_probe_event_call(&tk->tp);
1534 free_trace_kprobe(tk);
1535 return ERR_PTR(ret);
1538 void destroy_local_trace_kprobe(struct trace_event_call *event_call)
1540 struct trace_kprobe *tk;
1542 tk = trace_kprobe_primary_from_call(event_call);
1546 if (trace_probe_is_enabled(&tk->tp)) {
1551 __unregister_trace_kprobe(tk);
1553 free_trace_kprobe(tk);
1555 #endif /* CONFIG_PERF_EVENTS */
1557 static __init void enable_boot_kprobe_events(void)
1559 struct trace_array *tr = top_trace_array();
1560 struct trace_event_file *file;
1561 struct trace_kprobe *tk;
1562 struct dyn_event *pos;
1564 mutex_lock(&event_mutex);
1565 for_each_trace_kprobe(tk, pos) {
1566 list_for_each_entry(file, &tr->events, list)
1567 if (file->event_call == trace_probe_event_call(&tk->tp))
1568 trace_event_enable_disable(file, 1, 0);
1570 mutex_unlock(&event_mutex);
1573 static __init void setup_boot_kprobe_events(void)
1575 char *p, *cmd = kprobe_boot_events_buf;
1578 strreplace(kprobe_boot_events_buf, ',', ' ');
1580 while (cmd && *cmd != '\0') {
1581 p = strchr(cmd, ';');
1585 ret = trace_run_command(cmd, create_or_delete_trace_kprobe);
1587 pr_warn("Failed to add event(%d): %s\n", ret, cmd);
1589 kprobe_boot_events_enabled = true;
1594 enable_boot_kprobe_events();
1597 /* Make a tracefs interface for controlling probe points */
1598 static __init int init_kprobe_trace(void)
1600 struct dentry *d_tracer;
1601 struct dentry *entry;
1604 ret = dyn_event_register(&trace_kprobe_ops);
1608 if (register_module_notifier(&trace_kprobe_module_nb))
1611 d_tracer = tracing_init_dentry();
1612 if (IS_ERR(d_tracer))
1615 entry = tracefs_create_file("kprobe_events", 0644, d_tracer,
1616 NULL, &kprobe_events_ops);
1618 /* Event list interface */
1620 pr_warn("Could not create tracefs 'kprobe_events' entry\n");
1622 /* Profile interface */
1623 entry = tracefs_create_file("kprobe_profile", 0444, d_tracer,
1624 NULL, &kprobe_profile_ops);
1627 pr_warn("Could not create tracefs 'kprobe_profile' entry\n");
1629 setup_boot_kprobe_events();
1633 fs_initcall(init_kprobe_trace);
1636 #ifdef CONFIG_FTRACE_STARTUP_TEST
1637 static __init struct trace_event_file *
1638 find_trace_probe_file(struct trace_kprobe *tk, struct trace_array *tr)
1640 struct trace_event_file *file;
1642 list_for_each_entry(file, &tr->events, list)
1643 if (file->event_call == trace_probe_event_call(&tk->tp))
1650 * Nobody but us can call enable_trace_kprobe/disable_trace_kprobe at this
1651 * stage, we can do this lockless.
1653 static __init int kprobe_trace_self_tests_init(void)
1656 int (*target)(int, int, int, int, int, int);
1657 struct trace_kprobe *tk;
1658 struct trace_event_file *file;
1660 if (tracing_is_disabled())
1663 if (kprobe_boot_events_enabled) {
1664 pr_info("Skipping kprobe tests due to kprobe_event on cmdline\n");
1668 target = kprobe_trace_selftest_target;
1670 pr_info("Testing kprobe tracing: ");
1672 ret = trace_run_command("p:testprobe kprobe_trace_selftest_target $stack $stack0 +0($stack)",
1673 create_or_delete_trace_kprobe);
1674 if (WARN_ON_ONCE(ret)) {
1675 pr_warn("error on probing function entry.\n");
1678 /* Enable trace point */
1679 tk = find_trace_kprobe("testprobe", KPROBE_EVENT_SYSTEM);
1680 if (WARN_ON_ONCE(tk == NULL)) {
1681 pr_warn("error on getting new probe.\n");
1684 file = find_trace_probe_file(tk, top_trace_array());
1685 if (WARN_ON_ONCE(file == NULL)) {
1686 pr_warn("error on getting probe file.\n");
1689 enable_trace_kprobe(
1690 trace_probe_event_call(&tk->tp), file);
1694 ret = trace_run_command("r:testprobe2 kprobe_trace_selftest_target $retval",
1695 create_or_delete_trace_kprobe);
1696 if (WARN_ON_ONCE(ret)) {
1697 pr_warn("error on probing function return.\n");
1700 /* Enable trace point */
1701 tk = find_trace_kprobe("testprobe2", KPROBE_EVENT_SYSTEM);
1702 if (WARN_ON_ONCE(tk == NULL)) {
1703 pr_warn("error on getting 2nd new probe.\n");
1706 file = find_trace_probe_file(tk, top_trace_array());
1707 if (WARN_ON_ONCE(file == NULL)) {
1708 pr_warn("error on getting probe file.\n");
1711 enable_trace_kprobe(
1712 trace_probe_event_call(&tk->tp), file);
1719 ret = target(1, 2, 3, 4, 5, 6);
1722 * Not expecting an error here, the check is only to prevent the
1723 * optimizer from removing the call to target() as otherwise there
1724 * are no side-effects and the call is never performed.
1729 /* Disable trace points before removing it */
1730 tk = find_trace_kprobe("testprobe", KPROBE_EVENT_SYSTEM);
1731 if (WARN_ON_ONCE(tk == NULL)) {
1732 pr_warn("error on getting test probe.\n");
1735 if (trace_kprobe_nhit(tk) != 1) {
1736 pr_warn("incorrect number of testprobe hits\n");
1740 file = find_trace_probe_file(tk, top_trace_array());
1741 if (WARN_ON_ONCE(file == NULL)) {
1742 pr_warn("error on getting probe file.\n");
1745 disable_trace_kprobe(
1746 trace_probe_event_call(&tk->tp), file);
1749 tk = find_trace_kprobe("testprobe2", KPROBE_EVENT_SYSTEM);
1750 if (WARN_ON_ONCE(tk == NULL)) {
1751 pr_warn("error on getting 2nd test probe.\n");
1754 if (trace_kprobe_nhit(tk) != 1) {
1755 pr_warn("incorrect number of testprobe2 hits\n");
1759 file = find_trace_probe_file(tk, top_trace_array());
1760 if (WARN_ON_ONCE(file == NULL)) {
1761 pr_warn("error on getting probe file.\n");
1764 disable_trace_kprobe(
1765 trace_probe_event_call(&tk->tp), file);
1768 ret = trace_run_command("-:testprobe", create_or_delete_trace_kprobe);
1769 if (WARN_ON_ONCE(ret)) {
1770 pr_warn("error on deleting a probe.\n");
1774 ret = trace_run_command("-:testprobe2", create_or_delete_trace_kprobe);
1775 if (WARN_ON_ONCE(ret)) {
1776 pr_warn("error on deleting a probe.\n");
1781 ret = dyn_events_release_all(&trace_kprobe_ops);
1782 if (WARN_ON_ONCE(ret)) {
1783 pr_warn("error on cleaning up probes.\n");
1787 * Wait for the optimizer work to finish. Otherwise it might fiddle
1788 * with probes in already freed __init text.
1790 wait_for_kprobe_optimizer();
1792 pr_cont("NG: Some tests are failed. Please check them.\n");
1798 late_initcall(kprobe_trace_self_tests_init);