2 * Kprobes-based tracing events
4 * Created by Masami Hiramatsu <mhiramat@redhat.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #define pr_fmt(fmt) "trace_kprobe: " fmt
21 #include <linux/module.h>
22 #include <linux/uaccess.h>
23 #include <linux/rculist.h>
24 #include <linux/error-injection.h>
26 #include "trace_probe.h"
28 #define KPROBE_EVENT_SYSTEM "kprobes"
29 #define KRETPROBE_MAXACTIVE_MAX 4096
32 * Kprobe event core functions
35 struct list_head list
;
36 struct kretprobe rp
; /* Use rp.kp for kprobe use */
37 unsigned long __percpu
*nhit
;
38 const char *symbol
; /* symbol name */
39 struct trace_probe tp
;
42 #define SIZEOF_TRACE_KPROBE(n) \
43 (offsetof(struct trace_kprobe, tp.args) + \
44 (sizeof(struct probe_arg) * (n)))
46 static nokprobe_inline
bool trace_kprobe_is_return(struct trace_kprobe
*tk
)
48 return tk
->rp
.handler
!= NULL
;
51 static nokprobe_inline
const char *trace_kprobe_symbol(struct trace_kprobe
*tk
)
53 return tk
->symbol
? tk
->symbol
: "unknown";
56 static nokprobe_inline
unsigned long trace_kprobe_offset(struct trace_kprobe
*tk
)
58 return tk
->rp
.kp
.offset
;
61 static nokprobe_inline
bool trace_kprobe_has_gone(struct trace_kprobe
*tk
)
63 return !!(kprobe_gone(&tk
->rp
.kp
));
66 static nokprobe_inline
bool trace_kprobe_within_module(struct trace_kprobe
*tk
,
69 int len
= strlen(mod
->name
);
70 const char *name
= trace_kprobe_symbol(tk
);
71 return strncmp(mod
->name
, name
, len
) == 0 && name
[len
] == ':';
74 static nokprobe_inline
bool trace_kprobe_is_on_module(struct trace_kprobe
*tk
)
76 return !!strchr(trace_kprobe_symbol(tk
), ':');
79 static nokprobe_inline
unsigned long trace_kprobe_nhit(struct trace_kprobe
*tk
)
81 unsigned long nhit
= 0;
84 for_each_possible_cpu(cpu
)
85 nhit
+= *per_cpu_ptr(tk
->nhit
, cpu
);
90 bool trace_kprobe_on_func_entry(struct trace_event_call
*call
)
92 struct trace_kprobe
*tk
= (struct trace_kprobe
*)call
->data
;
94 return kprobe_on_func_entry(tk
->rp
.kp
.addr
,
95 tk
->rp
.kp
.addr
? NULL
: tk
->rp
.kp
.symbol_name
,
96 tk
->rp
.kp
.addr
? 0 : tk
->rp
.kp
.offset
);
99 bool trace_kprobe_error_injectable(struct trace_event_call
*call
)
101 struct trace_kprobe
*tk
= (struct trace_kprobe
*)call
->data
;
105 addr
= (unsigned long)
106 kallsyms_lookup_name(trace_kprobe_symbol(tk
));
107 addr
+= tk
->rp
.kp
.offset
;
109 addr
= (unsigned long)tk
->rp
.kp
.addr
;
111 return within_error_injection_list(addr
);
114 static int register_kprobe_event(struct trace_kprobe
*tk
);
115 static int unregister_kprobe_event(struct trace_kprobe
*tk
);
117 static DEFINE_MUTEX(probe_lock
);
118 static LIST_HEAD(probe_list
);
120 static int kprobe_dispatcher(struct kprobe
*kp
, struct pt_regs
*regs
);
121 static int kretprobe_dispatcher(struct kretprobe_instance
*ri
,
122 struct pt_regs
*regs
);
124 /* Memory fetching by symbol */
125 struct symbol_cache
{
131 unsigned long update_symbol_cache(struct symbol_cache
*sc
)
133 sc
->addr
= (unsigned long)kallsyms_lookup_name(sc
->symbol
);
136 sc
->addr
+= sc
->offset
;
141 void free_symbol_cache(struct symbol_cache
*sc
)
147 struct symbol_cache
*alloc_symbol_cache(const char *sym
, long offset
)
149 struct symbol_cache
*sc
;
151 if (!sym
|| strlen(sym
) == 0)
154 sc
= kzalloc(sizeof(struct symbol_cache
), GFP_KERNEL
);
158 sc
->symbol
= kstrdup(sym
, GFP_KERNEL
);
164 update_symbol_cache(sc
);
170 * Kprobes-specific fetch functions
172 #define DEFINE_FETCH_stack(type) \
173 static void FETCH_FUNC_NAME(stack, type)(struct pt_regs *regs, \
174 void *offset, void *dest) \
176 *(type *)dest = (type)regs_get_kernel_stack_nth(regs, \
177 (unsigned int)((unsigned long)offset)); \
179 NOKPROBE_SYMBOL(FETCH_FUNC_NAME(stack, type));
181 DEFINE_BASIC_FETCH_FUNCS(stack
)
182 /* No string on the stack entry */
183 #define fetch_stack_string NULL
184 #define fetch_stack_string_size NULL
186 #define DEFINE_FETCH_memory(type) \
187 static void FETCH_FUNC_NAME(memory, type)(struct pt_regs *regs, \
188 void *addr, void *dest) \
191 if (probe_kernel_address(addr, retval)) \
194 *(type *)dest = retval; \
196 NOKPROBE_SYMBOL(FETCH_FUNC_NAME(memory, type));
198 DEFINE_BASIC_FETCH_FUNCS(memory
)
200 * Fetch a null-terminated string. Caller MUST set *(u32 *)dest with max
201 * length and relative data location.
203 static void FETCH_FUNC_NAME(memory
, string
)(struct pt_regs
*regs
,
204 void *addr
, void *dest
)
206 int maxlen
= get_rloc_len(*(u32
*)dest
);
207 u8
*dst
= get_rloc_data(dest
);
214 * Try to get string again, since the string can be changed while
217 ret
= strncpy_from_unsafe(dst
, addr
, maxlen
);
219 if (ret
< 0) { /* Failed to fetch string */
221 *(u32
*)dest
= make_data_rloc(0, get_rloc_offs(*(u32
*)dest
));
223 *(u32
*)dest
= make_data_rloc(ret
, get_rloc_offs(*(u32
*)dest
));
226 NOKPROBE_SYMBOL(FETCH_FUNC_NAME(memory
, string
));
228 /* Return the length of string -- including null terminal byte */
229 static void FETCH_FUNC_NAME(memory
, string_size
)(struct pt_regs
*regs
,
230 void *addr
, void *dest
)
241 ret
= __copy_from_user_inatomic(&c
, (u8
*)addr
+ len
, 1);
243 } while (c
&& ret
== 0 && len
< MAX_STRING_SIZE
);
248 if (ret
< 0) /* Failed to check the length */
253 NOKPROBE_SYMBOL(FETCH_FUNC_NAME(memory
, string_size
));
255 #define DEFINE_FETCH_symbol(type) \
256 void FETCH_FUNC_NAME(symbol, type)(struct pt_regs *regs, void *data, void *dest)\
258 struct symbol_cache *sc = data; \
260 fetch_memory_##type(regs, (void *)sc->addr, dest); \
264 NOKPROBE_SYMBOL(FETCH_FUNC_NAME(symbol, type));
266 DEFINE_BASIC_FETCH_FUNCS(symbol
)
267 DEFINE_FETCH_symbol(string
)
268 DEFINE_FETCH_symbol(string_size
)
270 /* kprobes don't support file_offset fetch methods */
271 #define fetch_file_offset_u8 NULL
272 #define fetch_file_offset_u16 NULL
273 #define fetch_file_offset_u32 NULL
274 #define fetch_file_offset_u64 NULL
275 #define fetch_file_offset_string NULL
276 #define fetch_file_offset_string_size NULL
278 /* Fetch type information table */
279 static const struct fetch_type kprobes_fetch_type_table
[] = {
281 [FETCH_TYPE_STRING
] = __ASSIGN_FETCH_TYPE("string", string
, string
,
282 sizeof(u32
), 1, "__data_loc char[]"),
283 [FETCH_TYPE_STRSIZE
] = __ASSIGN_FETCH_TYPE("string_size", u32
,
284 string_size
, sizeof(u32
), 0, "u32"),
286 ASSIGN_FETCH_TYPE(u8
, u8
, 0),
287 ASSIGN_FETCH_TYPE(u16
, u16
, 0),
288 ASSIGN_FETCH_TYPE(u32
, u32
, 0),
289 ASSIGN_FETCH_TYPE(u64
, u64
, 0),
290 ASSIGN_FETCH_TYPE(s8
, u8
, 1),
291 ASSIGN_FETCH_TYPE(s16
, u16
, 1),
292 ASSIGN_FETCH_TYPE(s32
, u32
, 1),
293 ASSIGN_FETCH_TYPE(s64
, u64
, 1),
294 ASSIGN_FETCH_TYPE_ALIAS(x8
, u8
, u8
, 0),
295 ASSIGN_FETCH_TYPE_ALIAS(x16
, u16
, u16
, 0),
296 ASSIGN_FETCH_TYPE_ALIAS(x32
, u32
, u32
, 0),
297 ASSIGN_FETCH_TYPE_ALIAS(x64
, u64
, u64
, 0),
299 ASSIGN_FETCH_TYPE_END
303 * Allocate new trace_probe and initialize it (including kprobes).
305 static struct trace_kprobe
*alloc_trace_kprobe(const char *group
,
311 int nargs
, bool is_return
)
313 struct trace_kprobe
*tk
;
316 tk
= kzalloc(SIZEOF_TRACE_KPROBE(nargs
), GFP_KERNEL
);
320 tk
->nhit
= alloc_percpu(unsigned long);
325 tk
->symbol
= kstrdup(symbol
, GFP_KERNEL
);
328 tk
->rp
.kp
.symbol_name
= tk
->symbol
;
329 tk
->rp
.kp
.offset
= offs
;
331 tk
->rp
.kp
.addr
= addr
;
334 tk
->rp
.handler
= kretprobe_dispatcher
;
336 tk
->rp
.kp
.pre_handler
= kprobe_dispatcher
;
338 tk
->rp
.maxactive
= maxactive
;
340 if (!event
|| !is_good_name(event
)) {
345 tk
->tp
.call
.class = &tk
->tp
.class;
346 tk
->tp
.call
.name
= kstrdup(event
, GFP_KERNEL
);
347 if (!tk
->tp
.call
.name
)
350 if (!group
|| !is_good_name(group
)) {
355 tk
->tp
.class.system
= kstrdup(group
, GFP_KERNEL
);
356 if (!tk
->tp
.class.system
)
359 INIT_LIST_HEAD(&tk
->list
);
360 INIT_LIST_HEAD(&tk
->tp
.files
);
363 kfree(tk
->tp
.call
.name
);
365 free_percpu(tk
->nhit
);
370 static void free_trace_kprobe(struct trace_kprobe
*tk
)
374 for (i
= 0; i
< tk
->tp
.nr_args
; i
++)
375 traceprobe_free_probe_arg(&tk
->tp
.args
[i
]);
377 kfree(tk
->tp
.call
.class->system
);
378 kfree(tk
->tp
.call
.name
);
380 free_percpu(tk
->nhit
);
384 static struct trace_kprobe
*find_trace_kprobe(const char *event
,
387 struct trace_kprobe
*tk
;
389 list_for_each_entry(tk
, &probe_list
, list
)
390 if (strcmp(trace_event_name(&tk
->tp
.call
), event
) == 0 &&
391 strcmp(tk
->tp
.call
.class->system
, group
) == 0)
398 * if the file is NULL, enable "perf" handler, or enable "trace" handler.
401 enable_trace_kprobe(struct trace_kprobe
*tk
, struct trace_event_file
*file
)
406 struct event_file_link
*link
;
408 link
= kmalloc(sizeof(*link
), GFP_KERNEL
);
415 list_add_tail_rcu(&link
->list
, &tk
->tp
.files
);
417 tk
->tp
.flags
|= TP_FLAG_TRACE
;
419 tk
->tp
.flags
|= TP_FLAG_PROFILE
;
421 if (trace_probe_is_registered(&tk
->tp
) && !trace_kprobe_has_gone(tk
)) {
422 if (trace_kprobe_is_return(tk
))
423 ret
= enable_kretprobe(&tk
->rp
);
425 ret
= enable_kprobe(&tk
->rp
.kp
);
432 * Disable trace_probe
433 * if the file is NULL, disable "perf" handler, or disable "trace" handler.
436 disable_trace_kprobe(struct trace_kprobe
*tk
, struct trace_event_file
*file
)
438 struct event_file_link
*link
= NULL
;
443 link
= find_event_file_link(&tk
->tp
, file
);
449 list_del_rcu(&link
->list
);
451 if (!list_empty(&tk
->tp
.files
))
454 tk
->tp
.flags
&= ~TP_FLAG_TRACE
;
456 tk
->tp
.flags
&= ~TP_FLAG_PROFILE
;
458 if (!trace_probe_is_enabled(&tk
->tp
) && trace_probe_is_registered(&tk
->tp
)) {
459 if (trace_kprobe_is_return(tk
))
460 disable_kretprobe(&tk
->rp
);
462 disable_kprobe(&tk
->rp
.kp
);
467 * if tk is not added to any list, it must be a local trace_kprobe
468 * created with perf_event_open. We don't need to wait for these
471 if (list_empty(&tk
->list
))
476 * Synchronize with kprobe_trace_func/kretprobe_trace_func
477 * to ensure disabled (all running handlers are finished).
478 * This is not only for kfree(), but also the caller,
479 * trace_remove_event_call() supposes it for releasing
480 * event_call related objects, which will be accessed in
481 * the kprobe_trace_func/kretprobe_trace_func.
484 kfree(link
); /* Ignored if link == NULL */
490 /* Internal register function - just handle k*probes and flags */
491 static int __register_trace_kprobe(struct trace_kprobe
*tk
)
495 if (trace_probe_is_registered(&tk
->tp
))
498 for (i
= 0; i
< tk
->tp
.nr_args
; i
++)
499 traceprobe_update_arg(&tk
->tp
.args
[i
]);
501 /* Set/clear disabled flag according to tp->flag */
502 if (trace_probe_is_enabled(&tk
->tp
))
503 tk
->rp
.kp
.flags
&= ~KPROBE_FLAG_DISABLED
;
505 tk
->rp
.kp
.flags
|= KPROBE_FLAG_DISABLED
;
507 if (trace_kprobe_is_return(tk
))
508 ret
= register_kretprobe(&tk
->rp
);
510 ret
= register_kprobe(&tk
->rp
.kp
);
513 tk
->tp
.flags
|= TP_FLAG_REGISTERED
;
515 if (ret
== -ENOENT
&& trace_kprobe_is_on_module(tk
)) {
516 pr_warn("This probe might be able to register after target module is loaded. Continue.\n");
518 } else if (ret
== -EILSEQ
) {
519 pr_warn("Probing address(0x%p) is not an instruction boundary.\n",
528 /* Internal unregister function - just handle k*probes and flags */
529 static void __unregister_trace_kprobe(struct trace_kprobe
*tk
)
531 if (trace_probe_is_registered(&tk
->tp
)) {
532 if (trace_kprobe_is_return(tk
))
533 unregister_kretprobe(&tk
->rp
);
535 unregister_kprobe(&tk
->rp
.kp
);
536 tk
->tp
.flags
&= ~TP_FLAG_REGISTERED
;
537 /* Cleanup kprobe for reuse */
538 if (tk
->rp
.kp
.symbol_name
)
539 tk
->rp
.kp
.addr
= NULL
;
543 /* Unregister a trace_probe and probe_event: call with locking probe_lock */
544 static int unregister_trace_kprobe(struct trace_kprobe
*tk
)
546 /* Enabled event can not be unregistered */
547 if (trace_probe_is_enabled(&tk
->tp
))
550 /* Will fail if probe is being used by ftrace or perf */
551 if (unregister_kprobe_event(tk
))
554 __unregister_trace_kprobe(tk
);
560 /* Register a trace_probe and probe_event */
561 static int register_trace_kprobe(struct trace_kprobe
*tk
)
563 struct trace_kprobe
*old_tk
;
566 mutex_lock(&probe_lock
);
568 /* Delete old (same name) event if exist */
569 old_tk
= find_trace_kprobe(trace_event_name(&tk
->tp
.call
),
570 tk
->tp
.call
.class->system
);
572 ret
= unregister_trace_kprobe(old_tk
);
575 free_trace_kprobe(old_tk
);
578 /* Register new event */
579 ret
= register_kprobe_event(tk
);
581 pr_warn("Failed to register probe event(%d)\n", ret
);
585 /* Register k*probe */
586 ret
= __register_trace_kprobe(tk
);
588 unregister_kprobe_event(tk
);
590 list_add_tail(&tk
->list
, &probe_list
);
593 mutex_unlock(&probe_lock
);
597 /* Module notifier call back, checking event on the module */
598 static int trace_kprobe_module_callback(struct notifier_block
*nb
,
599 unsigned long val
, void *data
)
601 struct module
*mod
= data
;
602 struct trace_kprobe
*tk
;
605 if (val
!= MODULE_STATE_COMING
)
608 /* Update probes on coming module */
609 mutex_lock(&probe_lock
);
610 list_for_each_entry(tk
, &probe_list
, list
) {
611 if (trace_kprobe_within_module(tk
, mod
)) {
612 /* Don't need to check busy - this should have gone. */
613 __unregister_trace_kprobe(tk
);
614 ret
= __register_trace_kprobe(tk
);
616 pr_warn("Failed to re-register probe %s on %s: %d\n",
617 trace_event_name(&tk
->tp
.call
),
621 mutex_unlock(&probe_lock
);
626 static struct notifier_block trace_kprobe_module_nb
= {
627 .notifier_call
= trace_kprobe_module_callback
,
628 .priority
= 1 /* Invoked after kprobe module callback */
631 /* Convert certain expected symbols into '_' when generating event names */
632 static inline void sanitize_event_name(char *name
)
634 while (*name
++ != '\0')
635 if (*name
== ':' || *name
== '.')
639 static int create_trace_kprobe(int argc
, char **argv
)
644 * p[:[GRP/]EVENT] [MOD:]KSYM[+OFFS]|KADDR [FETCHARGS]
646 * r[MAXACTIVE][:[GRP/]EVENT] [MOD:]KSYM[+0] [FETCHARGS]
648 * $retval : fetch return value
649 * $stack : fetch stack address
650 * $stackN : fetch Nth of stack (N:0-)
651 * $comm : fetch current task comm
652 * @ADDR : fetch memory at ADDR (ADDR should be in kernel)
653 * @SYM[+|-offs] : fetch memory at SYM +|- offs (SYM is a data symbol)
654 * %REG : fetch register REG
655 * Dereferencing memory fetch:
656 * +|-offs(ARG) : fetch memory at ARG +|- offs address.
657 * Alias name of args:
658 * NAME=FETCHARG : set NAME as alias of FETCHARG.
660 * FETCHARG:TYPE : use TYPE instead of unsigned long.
662 struct trace_kprobe
*tk
;
664 bool is_return
= false, is_delete
= false;
665 char *symbol
= NULL
, *event
= NULL
, *group
= NULL
;
670 char buf
[MAX_EVENT_NAME_LEN
];
672 /* argc must be >= 1 */
673 if (argv
[0][0] == 'p')
675 else if (argv
[0][0] == 'r')
677 else if (argv
[0][0] == '-')
680 pr_info("Probe definition must be started with 'p', 'r' or"
685 event
= strchr(&argv
[0][1], ':');
690 if (is_return
&& isdigit(argv
[0][1])) {
691 ret
= kstrtouint(&argv
[0][1], 0, &maxactive
);
693 pr_info("Failed to parse maxactive.\n");
696 /* kretprobes instances are iterated over via a list. The
697 * maximum should stay reasonable.
699 if (maxactive
> KRETPROBE_MAXACTIVE_MAX
) {
700 pr_info("Maxactive is too big (%d > %d).\n",
701 maxactive
, KRETPROBE_MAXACTIVE_MAX
);
707 if (strchr(event
, '/')) {
709 event
= strchr(group
, '/') + 1;
711 if (strlen(group
) == 0) {
712 pr_info("Group name is not specified\n");
716 if (strlen(event
) == 0) {
717 pr_info("Event name is not specified\n");
722 group
= KPROBE_EVENT_SYSTEM
;
726 pr_info("Delete command needs an event name.\n");
729 mutex_lock(&probe_lock
);
730 tk
= find_trace_kprobe(event
, group
);
732 mutex_unlock(&probe_lock
);
733 pr_info("Event %s/%s doesn't exist.\n", group
, event
);
736 /* delete an event */
737 ret
= unregister_trace_kprobe(tk
);
739 free_trace_kprobe(tk
);
740 mutex_unlock(&probe_lock
);
745 pr_info("Probe point is not specified.\n");
749 /* try to parse an address. if that fails, try to read the
750 * input as a symbol. */
751 if (kstrtoul(argv
[1], 0, (unsigned long *)&addr
)) {
752 /* a symbol specified */
754 /* TODO: support .init module functions */
755 ret
= traceprobe_split_symbol_offset(symbol
, &offset
);
756 if (ret
|| offset
< 0 || offset
> UINT_MAX
) {
757 pr_info("Failed to parse either an address or a symbol.\n");
760 if (offset
&& is_return
&&
761 !kprobe_on_func_entry(NULL
, symbol
, offset
)) {
762 pr_info("Given offset is not valid for return probe.\n");
766 argc
-= 2; argv
+= 2;
770 /* Make a new event name */
772 snprintf(buf
, MAX_EVENT_NAME_LEN
, "%c_%s_%ld",
773 is_return
? 'r' : 'p', symbol
, offset
);
775 snprintf(buf
, MAX_EVENT_NAME_LEN
, "%c_0x%p",
776 is_return
? 'r' : 'p', addr
);
777 sanitize_event_name(buf
);
780 tk
= alloc_trace_kprobe(group
, event
, addr
, symbol
, offset
, maxactive
,
783 pr_info("Failed to allocate trace_probe.(%d)\n",
788 /* parse arguments */
790 for (i
= 0; i
< argc
&& i
< MAX_TRACE_ARGS
; i
++) {
791 struct probe_arg
*parg
= &tk
->tp
.args
[i
];
793 /* Increment count for freeing args in error case */
796 /* Parse argument name */
797 arg
= strchr(argv
[i
], '=');
800 parg
->name
= kstrdup(argv
[i
], GFP_KERNEL
);
803 /* If argument name is omitted, set "argN" */
804 snprintf(buf
, MAX_EVENT_NAME_LEN
, "arg%d", i
+ 1);
805 parg
->name
= kstrdup(buf
, GFP_KERNEL
);
809 pr_info("Failed to allocate argument[%d] name.\n", i
);
814 if (!is_good_name(parg
->name
)) {
815 pr_info("Invalid argument[%d] name: %s\n",
821 if (traceprobe_conflict_field_name(parg
->name
,
823 pr_info("Argument[%d] name '%s' conflicts with "
824 "another field.\n", i
, argv
[i
]);
829 /* Parse fetch argument */
830 ret
= traceprobe_parse_probe_arg(arg
, &tk
->tp
.size
, parg
,
832 kprobes_fetch_type_table
);
834 pr_info("Parse error at argument[%d]. (%d)\n", i
, ret
);
839 ret
= register_trace_kprobe(tk
);
845 free_trace_kprobe(tk
);
849 static int release_all_trace_kprobes(void)
851 struct trace_kprobe
*tk
;
854 mutex_lock(&probe_lock
);
855 /* Ensure no probe is in use. */
856 list_for_each_entry(tk
, &probe_list
, list
)
857 if (trace_probe_is_enabled(&tk
->tp
)) {
861 /* TODO: Use batch unregistration */
862 while (!list_empty(&probe_list
)) {
863 tk
= list_entry(probe_list
.next
, struct trace_kprobe
, list
);
864 ret
= unregister_trace_kprobe(tk
);
867 free_trace_kprobe(tk
);
871 mutex_unlock(&probe_lock
);
876 /* Probes listing interfaces */
877 static void *probes_seq_start(struct seq_file
*m
, loff_t
*pos
)
879 mutex_lock(&probe_lock
);
880 return seq_list_start(&probe_list
, *pos
);
883 static void *probes_seq_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
885 return seq_list_next(v
, &probe_list
, pos
);
888 static void probes_seq_stop(struct seq_file
*m
, void *v
)
890 mutex_unlock(&probe_lock
);
893 static int probes_seq_show(struct seq_file
*m
, void *v
)
895 struct trace_kprobe
*tk
= v
;
898 seq_putc(m
, trace_kprobe_is_return(tk
) ? 'r' : 'p');
899 seq_printf(m
, ":%s/%s", tk
->tp
.call
.class->system
,
900 trace_event_name(&tk
->tp
.call
));
903 seq_printf(m
, " 0x%p", tk
->rp
.kp
.addr
);
904 else if (tk
->rp
.kp
.offset
)
905 seq_printf(m
, " %s+%u", trace_kprobe_symbol(tk
),
908 seq_printf(m
, " %s", trace_kprobe_symbol(tk
));
910 for (i
= 0; i
< tk
->tp
.nr_args
; i
++)
911 seq_printf(m
, " %s=%s", tk
->tp
.args
[i
].name
, tk
->tp
.args
[i
].comm
);
917 static const struct seq_operations probes_seq_op
= {
918 .start
= probes_seq_start
,
919 .next
= probes_seq_next
,
920 .stop
= probes_seq_stop
,
921 .show
= probes_seq_show
924 static int probes_open(struct inode
*inode
, struct file
*file
)
928 if ((file
->f_mode
& FMODE_WRITE
) && (file
->f_flags
& O_TRUNC
)) {
929 ret
= release_all_trace_kprobes();
934 return seq_open(file
, &probes_seq_op
);
937 static ssize_t
probes_write(struct file
*file
, const char __user
*buffer
,
938 size_t count
, loff_t
*ppos
)
940 return trace_parse_run_command(file
, buffer
, count
, ppos
,
941 create_trace_kprobe
);
944 static const struct file_operations kprobe_events_ops
= {
945 .owner
= THIS_MODULE
,
949 .release
= seq_release
,
950 .write
= probes_write
,
953 /* Probes profiling interfaces */
954 static int probes_profile_seq_show(struct seq_file
*m
, void *v
)
956 struct trace_kprobe
*tk
= v
;
958 seq_printf(m
, " %-44s %15lu %15lu\n",
959 trace_event_name(&tk
->tp
.call
),
960 trace_kprobe_nhit(tk
),
966 static const struct seq_operations profile_seq_op
= {
967 .start
= probes_seq_start
,
968 .next
= probes_seq_next
,
969 .stop
= probes_seq_stop
,
970 .show
= probes_profile_seq_show
973 static int profile_open(struct inode
*inode
, struct file
*file
)
975 return seq_open(file
, &profile_seq_op
);
978 static const struct file_operations kprobe_profile_ops
= {
979 .owner
= THIS_MODULE
,
980 .open
= profile_open
,
983 .release
= seq_release
,
987 static nokprobe_inline
void
988 __kprobe_trace_func(struct trace_kprobe
*tk
, struct pt_regs
*regs
,
989 struct trace_event_file
*trace_file
)
991 struct kprobe_trace_entry_head
*entry
;
992 struct ring_buffer_event
*event
;
993 struct ring_buffer
*buffer
;
995 unsigned long irq_flags
;
996 struct trace_event_call
*call
= &tk
->tp
.call
;
998 WARN_ON(call
!= trace_file
->event_call
);
1000 if (trace_trigger_soft_disabled(trace_file
))
1003 local_save_flags(irq_flags
);
1004 pc
= preempt_count();
1006 dsize
= __get_data_size(&tk
->tp
, regs
);
1007 size
= sizeof(*entry
) + tk
->tp
.size
+ dsize
;
1009 event
= trace_event_buffer_lock_reserve(&buffer
, trace_file
,
1011 size
, irq_flags
, pc
);
1015 entry
= ring_buffer_event_data(event
);
1016 entry
->ip
= (unsigned long)tk
->rp
.kp
.addr
;
1017 store_trace_args(sizeof(*entry
), &tk
->tp
, regs
, (u8
*)&entry
[1], dsize
);
1019 event_trigger_unlock_commit_regs(trace_file
, buffer
, event
,
1020 entry
, irq_flags
, pc
, regs
);
1024 kprobe_trace_func(struct trace_kprobe
*tk
, struct pt_regs
*regs
)
1026 struct event_file_link
*link
;
1028 list_for_each_entry_rcu(link
, &tk
->tp
.files
, list
)
1029 __kprobe_trace_func(tk
, regs
, link
->file
);
1031 NOKPROBE_SYMBOL(kprobe_trace_func
);
1033 /* Kretprobe handler */
1034 static nokprobe_inline
void
1035 __kretprobe_trace_func(struct trace_kprobe
*tk
, struct kretprobe_instance
*ri
,
1036 struct pt_regs
*regs
,
1037 struct trace_event_file
*trace_file
)
1039 struct kretprobe_trace_entry_head
*entry
;
1040 struct ring_buffer_event
*event
;
1041 struct ring_buffer
*buffer
;
1042 int size
, pc
, dsize
;
1043 unsigned long irq_flags
;
1044 struct trace_event_call
*call
= &tk
->tp
.call
;
1046 WARN_ON(call
!= trace_file
->event_call
);
1048 if (trace_trigger_soft_disabled(trace_file
))
1051 local_save_flags(irq_flags
);
1052 pc
= preempt_count();
1054 dsize
= __get_data_size(&tk
->tp
, regs
);
1055 size
= sizeof(*entry
) + tk
->tp
.size
+ dsize
;
1057 event
= trace_event_buffer_lock_reserve(&buffer
, trace_file
,
1059 size
, irq_flags
, pc
);
1063 entry
= ring_buffer_event_data(event
);
1064 entry
->func
= (unsigned long)tk
->rp
.kp
.addr
;
1065 entry
->ret_ip
= (unsigned long)ri
->ret_addr
;
1066 store_trace_args(sizeof(*entry
), &tk
->tp
, regs
, (u8
*)&entry
[1], dsize
);
1068 event_trigger_unlock_commit_regs(trace_file
, buffer
, event
,
1069 entry
, irq_flags
, pc
, regs
);
1073 kretprobe_trace_func(struct trace_kprobe
*tk
, struct kretprobe_instance
*ri
,
1074 struct pt_regs
*regs
)
1076 struct event_file_link
*link
;
1078 list_for_each_entry_rcu(link
, &tk
->tp
.files
, list
)
1079 __kretprobe_trace_func(tk
, ri
, regs
, link
->file
);
1081 NOKPROBE_SYMBOL(kretprobe_trace_func
);
1083 /* Event entry printers */
1084 static enum print_line_t
1085 print_kprobe_event(struct trace_iterator
*iter
, int flags
,
1086 struct trace_event
*event
)
1088 struct kprobe_trace_entry_head
*field
;
1089 struct trace_seq
*s
= &iter
->seq
;
1090 struct trace_probe
*tp
;
1094 field
= (struct kprobe_trace_entry_head
*)iter
->ent
;
1095 tp
= container_of(event
, struct trace_probe
, call
.event
);
1097 trace_seq_printf(s
, "%s: (", trace_event_name(&tp
->call
));
1099 if (!seq_print_ip_sym(s
, field
->ip
, flags
| TRACE_ITER_SYM_OFFSET
))
1102 trace_seq_putc(s
, ')');
1104 data
= (u8
*)&field
[1];
1105 for (i
= 0; i
< tp
->nr_args
; i
++)
1106 if (!tp
->args
[i
].type
->print(s
, tp
->args
[i
].name
,
1107 data
+ tp
->args
[i
].offset
, field
))
1110 trace_seq_putc(s
, '\n');
1112 return trace_handle_return(s
);
1115 static enum print_line_t
1116 print_kretprobe_event(struct trace_iterator
*iter
, int flags
,
1117 struct trace_event
*event
)
1119 struct kretprobe_trace_entry_head
*field
;
1120 struct trace_seq
*s
= &iter
->seq
;
1121 struct trace_probe
*tp
;
1125 field
= (struct kretprobe_trace_entry_head
*)iter
->ent
;
1126 tp
= container_of(event
, struct trace_probe
, call
.event
);
1128 trace_seq_printf(s
, "%s: (", trace_event_name(&tp
->call
));
1130 if (!seq_print_ip_sym(s
, field
->ret_ip
, flags
| TRACE_ITER_SYM_OFFSET
))
1133 trace_seq_puts(s
, " <- ");
1135 if (!seq_print_ip_sym(s
, field
->func
, flags
& ~TRACE_ITER_SYM_OFFSET
))
1138 trace_seq_putc(s
, ')');
1140 data
= (u8
*)&field
[1];
1141 for (i
= 0; i
< tp
->nr_args
; i
++)
1142 if (!tp
->args
[i
].type
->print(s
, tp
->args
[i
].name
,
1143 data
+ tp
->args
[i
].offset
, field
))
1146 trace_seq_putc(s
, '\n');
1149 return trace_handle_return(s
);
1153 static int kprobe_event_define_fields(struct trace_event_call
*event_call
)
1156 struct kprobe_trace_entry_head field
;
1157 struct trace_kprobe
*tk
= (struct trace_kprobe
*)event_call
->data
;
1159 DEFINE_FIELD(unsigned long, ip
, FIELD_STRING_IP
, 0);
1160 /* Set argument names as fields */
1161 for (i
= 0; i
< tk
->tp
.nr_args
; i
++) {
1162 struct probe_arg
*parg
= &tk
->tp
.args
[i
];
1164 ret
= trace_define_field(event_call
, parg
->type
->fmttype
,
1166 sizeof(field
) + parg
->offset
,
1168 parg
->type
->is_signed
,
1176 static int kretprobe_event_define_fields(struct trace_event_call
*event_call
)
1179 struct kretprobe_trace_entry_head field
;
1180 struct trace_kprobe
*tk
= (struct trace_kprobe
*)event_call
->data
;
1182 DEFINE_FIELD(unsigned long, func
, FIELD_STRING_FUNC
, 0);
1183 DEFINE_FIELD(unsigned long, ret_ip
, FIELD_STRING_RETIP
, 0);
1184 /* Set argument names as fields */
1185 for (i
= 0; i
< tk
->tp
.nr_args
; i
++) {
1186 struct probe_arg
*parg
= &tk
->tp
.args
[i
];
1188 ret
= trace_define_field(event_call
, parg
->type
->fmttype
,
1190 sizeof(field
) + parg
->offset
,
1192 parg
->type
->is_signed
,
1200 #ifdef CONFIG_PERF_EVENTS
1202 /* Kprobe profile handler */
1204 kprobe_perf_func(struct trace_kprobe
*tk
, struct pt_regs
*regs
)
1206 struct trace_event_call
*call
= &tk
->tp
.call
;
1207 struct kprobe_trace_entry_head
*entry
;
1208 struct hlist_head
*head
;
1209 int size
, __size
, dsize
;
1212 if (bpf_prog_array_valid(call
)) {
1213 unsigned long orig_ip
= instruction_pointer(regs
);
1216 ret
= trace_call_bpf(call
, regs
);
1219 * We need to check and see if we modified the pc of the
1220 * pt_regs, and if so clear the kprobe and return 1 so that we
1221 * don't do the single stepping.
1222 * The ftrace kprobe handler leaves it up to us to re-enable
1223 * preemption here before returning if we've modified the ip.
1225 if (orig_ip
!= instruction_pointer(regs
)) {
1226 reset_current_kprobe();
1227 preempt_enable_no_resched();
1234 head
= this_cpu_ptr(call
->perf_events
);
1235 if (hlist_empty(head
))
1238 dsize
= __get_data_size(&tk
->tp
, regs
);
1239 __size
= sizeof(*entry
) + tk
->tp
.size
+ dsize
;
1240 size
= ALIGN(__size
+ sizeof(u32
), sizeof(u64
));
1241 size
-= sizeof(u32
);
1243 entry
= perf_trace_buf_alloc(size
, NULL
, &rctx
);
1247 entry
->ip
= (unsigned long)tk
->rp
.kp
.addr
;
1248 memset(&entry
[1], 0, dsize
);
1249 store_trace_args(sizeof(*entry
), &tk
->tp
, regs
, (u8
*)&entry
[1], dsize
);
1250 perf_trace_buf_submit(entry
, size
, rctx
, call
->event
.type
, 1, regs
,
1254 NOKPROBE_SYMBOL(kprobe_perf_func
);
1256 /* Kretprobe profile handler */
1258 kretprobe_perf_func(struct trace_kprobe
*tk
, struct kretprobe_instance
*ri
,
1259 struct pt_regs
*regs
)
1261 struct trace_event_call
*call
= &tk
->tp
.call
;
1262 struct kretprobe_trace_entry_head
*entry
;
1263 struct hlist_head
*head
;
1264 int size
, __size
, dsize
;
1267 if (bpf_prog_array_valid(call
) && !trace_call_bpf(call
, regs
))
1270 head
= this_cpu_ptr(call
->perf_events
);
1271 if (hlist_empty(head
))
1274 dsize
= __get_data_size(&tk
->tp
, regs
);
1275 __size
= sizeof(*entry
) + tk
->tp
.size
+ dsize
;
1276 size
= ALIGN(__size
+ sizeof(u32
), sizeof(u64
));
1277 size
-= sizeof(u32
);
1279 entry
= perf_trace_buf_alloc(size
, NULL
, &rctx
);
1283 entry
->func
= (unsigned long)tk
->rp
.kp
.addr
;
1284 entry
->ret_ip
= (unsigned long)ri
->ret_addr
;
1285 store_trace_args(sizeof(*entry
), &tk
->tp
, regs
, (u8
*)&entry
[1], dsize
);
1286 perf_trace_buf_submit(entry
, size
, rctx
, call
->event
.type
, 1, regs
,
1289 NOKPROBE_SYMBOL(kretprobe_perf_func
);
1290 #endif /* CONFIG_PERF_EVENTS */
1293 * called by perf_trace_init() or __ftrace_set_clr_event() under event_mutex.
1295 * kprobe_trace_self_tests_init() does enable_trace_probe/disable_trace_probe
1296 * lockless, but we can't race with this __init function.
1298 static int kprobe_register(struct trace_event_call
*event
,
1299 enum trace_reg type
, void *data
)
1301 struct trace_kprobe
*tk
= (struct trace_kprobe
*)event
->data
;
1302 struct trace_event_file
*file
= data
;
1305 case TRACE_REG_REGISTER
:
1306 return enable_trace_kprobe(tk
, file
);
1307 case TRACE_REG_UNREGISTER
:
1308 return disable_trace_kprobe(tk
, file
);
1310 #ifdef CONFIG_PERF_EVENTS
1311 case TRACE_REG_PERF_REGISTER
:
1312 return enable_trace_kprobe(tk
, NULL
);
1313 case TRACE_REG_PERF_UNREGISTER
:
1314 return disable_trace_kprobe(tk
, NULL
);
1315 case TRACE_REG_PERF_OPEN
:
1316 case TRACE_REG_PERF_CLOSE
:
1317 case TRACE_REG_PERF_ADD
:
1318 case TRACE_REG_PERF_DEL
:
1325 static int kprobe_dispatcher(struct kprobe
*kp
, struct pt_regs
*regs
)
1327 struct trace_kprobe
*tk
= container_of(kp
, struct trace_kprobe
, rp
.kp
);
1330 raw_cpu_inc(*tk
->nhit
);
1332 if (tk
->tp
.flags
& TP_FLAG_TRACE
)
1333 kprobe_trace_func(tk
, regs
);
1334 #ifdef CONFIG_PERF_EVENTS
1335 if (tk
->tp
.flags
& TP_FLAG_PROFILE
)
1336 ret
= kprobe_perf_func(tk
, regs
);
1340 NOKPROBE_SYMBOL(kprobe_dispatcher
);
1343 kretprobe_dispatcher(struct kretprobe_instance
*ri
, struct pt_regs
*regs
)
1345 struct trace_kprobe
*tk
= container_of(ri
->rp
, struct trace_kprobe
, rp
);
1347 raw_cpu_inc(*tk
->nhit
);
1349 if (tk
->tp
.flags
& TP_FLAG_TRACE
)
1350 kretprobe_trace_func(tk
, ri
, regs
);
1351 #ifdef CONFIG_PERF_EVENTS
1352 if (tk
->tp
.flags
& TP_FLAG_PROFILE
)
1353 kretprobe_perf_func(tk
, ri
, regs
);
1355 return 0; /* We don't tweek kernel, so just return 0 */
1357 NOKPROBE_SYMBOL(kretprobe_dispatcher
);
1359 static struct trace_event_functions kretprobe_funcs
= {
1360 .trace
= print_kretprobe_event
1363 static struct trace_event_functions kprobe_funcs
= {
1364 .trace
= print_kprobe_event
1367 static inline void init_trace_event_call(struct trace_kprobe
*tk
,
1368 struct trace_event_call
*call
)
1370 INIT_LIST_HEAD(&call
->class->fields
);
1371 if (trace_kprobe_is_return(tk
)) {
1372 call
->event
.funcs
= &kretprobe_funcs
;
1373 call
->class->define_fields
= kretprobe_event_define_fields
;
1375 call
->event
.funcs
= &kprobe_funcs
;
1376 call
->class->define_fields
= kprobe_event_define_fields
;
1379 call
->flags
= TRACE_EVENT_FL_KPROBE
;
1380 call
->class->reg
= kprobe_register
;
1384 static int register_kprobe_event(struct trace_kprobe
*tk
)
1386 struct trace_event_call
*call
= &tk
->tp
.call
;
1389 init_trace_event_call(tk
, call
);
1391 if (set_print_fmt(&tk
->tp
, trace_kprobe_is_return(tk
)) < 0)
1393 ret
= register_trace_event(&call
->event
);
1395 kfree(call
->print_fmt
);
1398 ret
= trace_add_event_call(call
);
1400 pr_info("Failed to register kprobe event: %s\n",
1401 trace_event_name(call
));
1402 kfree(call
->print_fmt
);
1403 unregister_trace_event(&call
->event
);
1408 static int unregister_kprobe_event(struct trace_kprobe
*tk
)
1412 /* tp->event is unregistered in trace_remove_event_call() */
1413 ret
= trace_remove_event_call(&tk
->tp
.call
);
1415 kfree(tk
->tp
.call
.print_fmt
);
1419 #ifdef CONFIG_PERF_EVENTS
1420 /* create a trace_kprobe, but don't add it to global lists */
1421 struct trace_event_call
*
1422 create_local_trace_kprobe(char *func
, void *addr
, unsigned long offs
,
1425 struct trace_kprobe
*tk
;
1430 * local trace_kprobes are not added to probe_list, so they are never
1431 * searched in find_trace_kprobe(). Therefore, there is no concern of
1432 * duplicated name here.
1434 event
= func
? func
: "DUMMY_EVENT";
1436 tk
= alloc_trace_kprobe(KPROBE_EVENT_SYSTEM
, event
, (void *)addr
, func
,
1437 offs
, 0 /* maxactive */, 0 /* nargs */,
1441 pr_info("Failed to allocate trace_probe.(%d)\n",
1443 return ERR_CAST(tk
);
1446 init_trace_event_call(tk
, &tk
->tp
.call
);
1448 if (set_print_fmt(&tk
->tp
, trace_kprobe_is_return(tk
)) < 0) {
1453 ret
= __register_trace_kprobe(tk
);
1457 return &tk
->tp
.call
;
1459 free_trace_kprobe(tk
);
1460 return ERR_PTR(ret
);
1463 void destroy_local_trace_kprobe(struct trace_event_call
*event_call
)
1465 struct trace_kprobe
*tk
;
1467 tk
= container_of(event_call
, struct trace_kprobe
, tp
.call
);
1469 if (trace_probe_is_enabled(&tk
->tp
)) {
1474 __unregister_trace_kprobe(tk
);
1475 free_trace_kprobe(tk
);
1477 #endif /* CONFIG_PERF_EVENTS */
1479 /* Make a tracefs interface for controlling probe points */
1480 static __init
int init_kprobe_trace(void)
1482 struct dentry
*d_tracer
;
1483 struct dentry
*entry
;
1485 if (register_module_notifier(&trace_kprobe_module_nb
))
1488 d_tracer
= tracing_init_dentry();
1489 if (IS_ERR(d_tracer
))
1492 entry
= tracefs_create_file("kprobe_events", 0644, d_tracer
,
1493 NULL
, &kprobe_events_ops
);
1495 /* Event list interface */
1497 pr_warn("Could not create tracefs 'kprobe_events' entry\n");
1499 /* Profile interface */
1500 entry
= tracefs_create_file("kprobe_profile", 0444, d_tracer
,
1501 NULL
, &kprobe_profile_ops
);
1504 pr_warn("Could not create tracefs 'kprobe_profile' entry\n");
1507 fs_initcall(init_kprobe_trace
);
1510 #ifdef CONFIG_FTRACE_STARTUP_TEST
1512 * The "__used" keeps gcc from removing the function symbol
1513 * from the kallsyms table. 'noinline' makes sure that there
1514 * isn't an inlined version used by the test method below
1516 static __used __init noinline
int
1517 kprobe_trace_selftest_target(int a1
, int a2
, int a3
, int a4
, int a5
, int a6
)
1519 return a1
+ a2
+ a3
+ a4
+ a5
+ a6
;
1522 static __init
struct trace_event_file
*
1523 find_trace_probe_file(struct trace_kprobe
*tk
, struct trace_array
*tr
)
1525 struct trace_event_file
*file
;
1527 list_for_each_entry(file
, &tr
->events
, list
)
1528 if (file
->event_call
== &tk
->tp
.call
)
1535 * Nobody but us can call enable_trace_kprobe/disable_trace_kprobe at this
1536 * stage, we can do this lockless.
1538 static __init
int kprobe_trace_self_tests_init(void)
1541 int (*target
)(int, int, int, int, int, int);
1542 struct trace_kprobe
*tk
;
1543 struct trace_event_file
*file
;
1545 if (tracing_is_disabled())
1548 target
= kprobe_trace_selftest_target
;
1550 pr_info("Testing kprobe tracing: ");
1552 ret
= trace_run_command("p:testprobe kprobe_trace_selftest_target "
1553 "$stack $stack0 +0($stack)",
1554 create_trace_kprobe
);
1555 if (WARN_ON_ONCE(ret
)) {
1556 pr_warn("error on probing function entry.\n");
1559 /* Enable trace point */
1560 tk
= find_trace_kprobe("testprobe", KPROBE_EVENT_SYSTEM
);
1561 if (WARN_ON_ONCE(tk
== NULL
)) {
1562 pr_warn("error on getting new probe.\n");
1565 file
= find_trace_probe_file(tk
, top_trace_array());
1566 if (WARN_ON_ONCE(file
== NULL
)) {
1567 pr_warn("error on getting probe file.\n");
1570 enable_trace_kprobe(tk
, file
);
1574 ret
= trace_run_command("r:testprobe2 kprobe_trace_selftest_target "
1575 "$retval", create_trace_kprobe
);
1576 if (WARN_ON_ONCE(ret
)) {
1577 pr_warn("error on probing function return.\n");
1580 /* Enable trace point */
1581 tk
= find_trace_kprobe("testprobe2", KPROBE_EVENT_SYSTEM
);
1582 if (WARN_ON_ONCE(tk
== NULL
)) {
1583 pr_warn("error on getting 2nd new probe.\n");
1586 file
= find_trace_probe_file(tk
, top_trace_array());
1587 if (WARN_ON_ONCE(file
== NULL
)) {
1588 pr_warn("error on getting probe file.\n");
1591 enable_trace_kprobe(tk
, file
);
1598 ret
= target(1, 2, 3, 4, 5, 6);
1601 * Not expecting an error here, the check is only to prevent the
1602 * optimizer from removing the call to target() as otherwise there
1603 * are no side-effects and the call is never performed.
1608 /* Disable trace points before removing it */
1609 tk
= find_trace_kprobe("testprobe", KPROBE_EVENT_SYSTEM
);
1610 if (WARN_ON_ONCE(tk
== NULL
)) {
1611 pr_warn("error on getting test probe.\n");
1614 if (trace_kprobe_nhit(tk
) != 1) {
1615 pr_warn("incorrect number of testprobe hits\n");
1619 file
= find_trace_probe_file(tk
, top_trace_array());
1620 if (WARN_ON_ONCE(file
== NULL
)) {
1621 pr_warn("error on getting probe file.\n");
1624 disable_trace_kprobe(tk
, file
);
1627 tk
= find_trace_kprobe("testprobe2", KPROBE_EVENT_SYSTEM
);
1628 if (WARN_ON_ONCE(tk
== NULL
)) {
1629 pr_warn("error on getting 2nd test probe.\n");
1632 if (trace_kprobe_nhit(tk
) != 1) {
1633 pr_warn("incorrect number of testprobe2 hits\n");
1637 file
= find_trace_probe_file(tk
, top_trace_array());
1638 if (WARN_ON_ONCE(file
== NULL
)) {
1639 pr_warn("error on getting probe file.\n");
1642 disable_trace_kprobe(tk
, file
);
1645 ret
= trace_run_command("-:testprobe", create_trace_kprobe
);
1646 if (WARN_ON_ONCE(ret
)) {
1647 pr_warn("error on deleting a probe.\n");
1651 ret
= trace_run_command("-:testprobe2", create_trace_kprobe
);
1652 if (WARN_ON_ONCE(ret
)) {
1653 pr_warn("error on deleting a probe.\n");
1658 release_all_trace_kprobes();
1660 * Wait for the optimizer work to finish. Otherwise it might fiddle
1661 * with probes in already freed __init text.
1663 wait_for_kprobe_optimizer();
1665 pr_cont("NG: Some tests are failed. Please check them.\n");
1671 late_initcall(kprobe_trace_self_tests_init
);