Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1 | /* |
Masami Hiramatsu | 77b44d1 | 2009-11-03 19:12:47 -0500 | [diff] [blame] | 2 | * Kprobes-based tracing events |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 3 | * |
| 4 | * Created by Masami Hiramatsu <mhiramat@redhat.com> |
| 5 | * |
| 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. |
| 9 | * |
| 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. |
| 14 | * |
| 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 |
| 18 | */ |
Masami Hiramatsu | 7257634 | 2017-02-07 20:21:28 +0900 | [diff] [blame] | 19 | #define pr_fmt(fmt) "trace_kprobe: " fmt |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 20 | |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/uaccess.h> |
Ingo Molnar | b2d0910 | 2017-02-04 01:27:20 +0100 | [diff] [blame] | 23 | #include <linux/rculist.h> |
Masami Hiramatsu | 540adea | 2018-01-13 02:55:03 +0900 | [diff] [blame] | 24 | #include <linux/error-injection.h> |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 25 | |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 26 | #include "trace_probe.h" |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 27 | |
Masami Hiramatsu | f52487e | 2009-09-10 19:53:53 -0400 | [diff] [blame] | 28 | #define KPROBE_EVENT_SYSTEM "kprobes" |
Alban Crequy | 696ced4 | 2017-04-03 12:36:22 +0200 | [diff] [blame] | 29 | #define KRETPROBE_MAXACTIVE_MAX 4096 |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 30 | |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 31 | /** |
Masami Hiramatsu | 77b44d1 | 2009-11-03 19:12:47 -0500 | [diff] [blame] | 32 | * Kprobe event core functions |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 33 | */ |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 34 | struct trace_kprobe { |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 35 | struct list_head list; |
Masami Hiramatsu | 4a846b4 | 2009-09-11 05:31:21 +0200 | [diff] [blame] | 36 | struct kretprobe rp; /* Use rp.kp for kprobe use */ |
Martin KaFai Lau | a7636d9 | 2016-02-03 12:28:28 -0800 | [diff] [blame] | 37 | unsigned long __percpu *nhit; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 38 | const char *symbol; /* symbol name */ |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 39 | struct trace_probe tp; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 40 | }; |
| 41 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 42 | #define SIZEOF_TRACE_KPROBE(n) \ |
| 43 | (offsetof(struct trace_kprobe, tp.args) + \ |
Masami Hiramatsu | eca0d91 | 2009-09-10 19:53:38 -0400 | [diff] [blame] | 44 | (sizeof(struct probe_arg) * (n))) |
Masami Hiramatsu | a82378d | 2009-08-13 16:35:18 -0400 | [diff] [blame] | 45 | |
Masami Hiramatsu | 3da0f18 | 2014-04-17 17:18:28 +0900 | [diff] [blame] | 46 | static nokprobe_inline bool trace_kprobe_is_return(struct trace_kprobe *tk) |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 47 | { |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 48 | return tk->rp.handler != NULL; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 49 | } |
| 50 | |
Masami Hiramatsu | 3da0f18 | 2014-04-17 17:18:28 +0900 | [diff] [blame] | 51 | static nokprobe_inline const char *trace_kprobe_symbol(struct trace_kprobe *tk) |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 52 | { |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 53 | return tk->symbol ? tk->symbol : "unknown"; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 54 | } |
| 55 | |
Masami Hiramatsu | 3da0f18 | 2014-04-17 17:18:28 +0900 | [diff] [blame] | 56 | static nokprobe_inline unsigned long trace_kprobe_offset(struct trace_kprobe *tk) |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 57 | { |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 58 | return tk->rp.kp.offset; |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 59 | } |
| 60 | |
Masami Hiramatsu | 3da0f18 | 2014-04-17 17:18:28 +0900 | [diff] [blame] | 61 | static nokprobe_inline bool trace_kprobe_has_gone(struct trace_kprobe *tk) |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 62 | { |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 63 | return !!(kprobe_gone(&tk->rp.kp)); |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 64 | } |
| 65 | |
Masami Hiramatsu | 3da0f18 | 2014-04-17 17:18:28 +0900 | [diff] [blame] | 66 | static nokprobe_inline bool trace_kprobe_within_module(struct trace_kprobe *tk, |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 67 | struct module *mod) |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 68 | { |
| 69 | int len = strlen(mod->name); |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 70 | const char *name = trace_kprobe_symbol(tk); |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 71 | return strncmp(mod->name, name, len) == 0 && name[len] == ':'; |
| 72 | } |
| 73 | |
Masami Hiramatsu | 3da0f18 | 2014-04-17 17:18:28 +0900 | [diff] [blame] | 74 | static nokprobe_inline bool trace_kprobe_is_on_module(struct trace_kprobe *tk) |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 75 | { |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 76 | return !!strchr(trace_kprobe_symbol(tk), ':'); |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 77 | } |
| 78 | |
Marcin Nowakowski | f18f97a | 2016-12-09 15:19:37 +0100 | [diff] [blame] | 79 | static nokprobe_inline unsigned long trace_kprobe_nhit(struct trace_kprobe *tk) |
| 80 | { |
| 81 | unsigned long nhit = 0; |
| 82 | int cpu; |
| 83 | |
| 84 | for_each_possible_cpu(cpu) |
| 85 | nhit += *per_cpu_ptr(tk->nhit, cpu); |
| 86 | |
| 87 | return nhit; |
| 88 | } |
| 89 | |
Masami Hiramatsu | b4da334 | 2018-01-13 02:54:04 +0900 | [diff] [blame] | 90 | bool trace_kprobe_on_func_entry(struct trace_event_call *call) |
Josef Bacik | 9802d86 | 2017-12-11 11:36:48 -0500 | [diff] [blame] | 91 | { |
| 92 | struct trace_kprobe *tk = (struct trace_kprobe *)call->data; |
Masami Hiramatsu | b4da334 | 2018-01-13 02:54:04 +0900 | [diff] [blame] | 93 | |
| 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); |
Josef Bacik | 9802d86 | 2017-12-11 11:36:48 -0500 | [diff] [blame] | 97 | } |
| 98 | |
Masami Hiramatsu | b4da334 | 2018-01-13 02:54:04 +0900 | [diff] [blame] | 99 | bool trace_kprobe_error_injectable(struct trace_event_call *call) |
Josef Bacik | 9802d86 | 2017-12-11 11:36:48 -0500 | [diff] [blame] | 100 | { |
| 101 | struct trace_kprobe *tk = (struct trace_kprobe *)call->data; |
| 102 | unsigned long addr; |
| 103 | |
| 104 | if (tk->symbol) { |
| 105 | addr = (unsigned long) |
| 106 | kallsyms_lookup_name(trace_kprobe_symbol(tk)); |
| 107 | addr += tk->rp.kp.offset; |
| 108 | } else { |
| 109 | addr = (unsigned long)tk->rp.kp.addr; |
| 110 | } |
Masami Hiramatsu | 540adea | 2018-01-13 02:55:03 +0900 | [diff] [blame] | 111 | return within_error_injection_list(addr); |
Josef Bacik | 9802d86 | 2017-12-11 11:36:48 -0500 | [diff] [blame] | 112 | } |
| 113 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 114 | static int register_kprobe_event(struct trace_kprobe *tk); |
| 115 | static int unregister_kprobe_event(struct trace_kprobe *tk); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 116 | |
| 117 | static DEFINE_MUTEX(probe_lock); |
| 118 | static LIST_HEAD(probe_list); |
| 119 | |
Masami Hiramatsu | 50d7805 | 2009-09-14 16:49:20 -0400 | [diff] [blame] | 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); |
| 123 | |
Namhyung Kim | 1301a44 | 2013-11-26 15:21:04 +0900 | [diff] [blame] | 124 | /* Memory fetching by symbol */ |
| 125 | struct symbol_cache { |
| 126 | char *symbol; |
| 127 | long offset; |
| 128 | unsigned long addr; |
| 129 | }; |
| 130 | |
| 131 | unsigned long update_symbol_cache(struct symbol_cache *sc) |
| 132 | { |
| 133 | sc->addr = (unsigned long)kallsyms_lookup_name(sc->symbol); |
| 134 | |
| 135 | if (sc->addr) |
| 136 | sc->addr += sc->offset; |
| 137 | |
| 138 | return sc->addr; |
| 139 | } |
| 140 | |
| 141 | void free_symbol_cache(struct symbol_cache *sc) |
| 142 | { |
| 143 | kfree(sc->symbol); |
| 144 | kfree(sc); |
| 145 | } |
| 146 | |
| 147 | struct symbol_cache *alloc_symbol_cache(const char *sym, long offset) |
| 148 | { |
| 149 | struct symbol_cache *sc; |
| 150 | |
| 151 | if (!sym || strlen(sym) == 0) |
| 152 | return NULL; |
| 153 | |
| 154 | sc = kzalloc(sizeof(struct symbol_cache), GFP_KERNEL); |
| 155 | if (!sc) |
| 156 | return NULL; |
| 157 | |
| 158 | sc->symbol = kstrdup(sym, GFP_KERNEL); |
| 159 | if (!sc->symbol) { |
| 160 | kfree(sc); |
| 161 | return NULL; |
| 162 | } |
| 163 | sc->offset = offset; |
| 164 | update_symbol_cache(sc); |
| 165 | |
| 166 | return sc; |
| 167 | } |
| 168 | |
Namhyung Kim | 3fd996a | 2013-11-26 15:21:04 +0900 | [diff] [blame] | 169 | /* |
| 170 | * Kprobes-specific fetch functions |
| 171 | */ |
| 172 | #define DEFINE_FETCH_stack(type) \ |
Masami Hiramatsu | 3da0f18 | 2014-04-17 17:18:28 +0900 | [diff] [blame] | 173 | static void FETCH_FUNC_NAME(stack, type)(struct pt_regs *regs, \ |
Namhyung Kim | 3fd996a | 2013-11-26 15:21:04 +0900 | [diff] [blame] | 174 | void *offset, void *dest) \ |
| 175 | { \ |
| 176 | *(type *)dest = (type)regs_get_kernel_stack_nth(regs, \ |
| 177 | (unsigned int)((unsigned long)offset)); \ |
Masami Hiramatsu | 3da0f18 | 2014-04-17 17:18:28 +0900 | [diff] [blame] | 178 | } \ |
| 179 | NOKPROBE_SYMBOL(FETCH_FUNC_NAME(stack, type)); |
| 180 | |
Namhyung Kim | 3fd996a | 2013-11-26 15:21:04 +0900 | [diff] [blame] | 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 |
| 185 | |
Namhyung Kim | 5baaa59 | 2013-11-26 15:21:04 +0900 | [diff] [blame] | 186 | #define DEFINE_FETCH_memory(type) \ |
Masami Hiramatsu | 3da0f18 | 2014-04-17 17:18:28 +0900 | [diff] [blame] | 187 | static void FETCH_FUNC_NAME(memory, type)(struct pt_regs *regs, \ |
Namhyung Kim | 5baaa59 | 2013-11-26 15:21:04 +0900 | [diff] [blame] | 188 | void *addr, void *dest) \ |
| 189 | { \ |
| 190 | type retval; \ |
| 191 | if (probe_kernel_address(addr, retval)) \ |
| 192 | *(type *)dest = 0; \ |
| 193 | else \ |
| 194 | *(type *)dest = retval; \ |
Masami Hiramatsu | 3da0f18 | 2014-04-17 17:18:28 +0900 | [diff] [blame] | 195 | } \ |
| 196 | NOKPROBE_SYMBOL(FETCH_FUNC_NAME(memory, type)); |
| 197 | |
Namhyung Kim | 5baaa59 | 2013-11-26 15:21:04 +0900 | [diff] [blame] | 198 | DEFINE_BASIC_FETCH_FUNCS(memory) |
| 199 | /* |
| 200 | * Fetch a null-terminated string. Caller MUST set *(u32 *)dest with max |
| 201 | * length and relative data location. |
| 202 | */ |
Masami Hiramatsu | 3da0f18 | 2014-04-17 17:18:28 +0900 | [diff] [blame] | 203 | static void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs, |
| 204 | void *addr, void *dest) |
Namhyung Kim | 5baaa59 | 2013-11-26 15:21:04 +0900 | [diff] [blame] | 205 | { |
Namhyung Kim | 5baaa59 | 2013-11-26 15:21:04 +0900 | [diff] [blame] | 206 | int maxlen = get_rloc_len(*(u32 *)dest); |
| 207 | u8 *dst = get_rloc_data(dest); |
Alexei Starovoitov | 1a6877b | 2015-08-28 15:56:22 -0700 | [diff] [blame] | 208 | long ret; |
Namhyung Kim | 5baaa59 | 2013-11-26 15:21:04 +0900 | [diff] [blame] | 209 | |
| 210 | if (!maxlen) |
| 211 | return; |
| 212 | |
| 213 | /* |
| 214 | * Try to get string again, since the string can be changed while |
| 215 | * probing. |
| 216 | */ |
Alexei Starovoitov | 1a6877b | 2015-08-28 15:56:22 -0700 | [diff] [blame] | 217 | ret = strncpy_from_unsafe(dst, addr, maxlen); |
Namhyung Kim | 5baaa59 | 2013-11-26 15:21:04 +0900 | [diff] [blame] | 218 | |
| 219 | if (ret < 0) { /* Failed to fetch string */ |
Alexei Starovoitov | 1a6877b | 2015-08-28 15:56:22 -0700 | [diff] [blame] | 220 | dst[0] = '\0'; |
Namhyung Kim | 5baaa59 | 2013-11-26 15:21:04 +0900 | [diff] [blame] | 221 | *(u32 *)dest = make_data_rloc(0, get_rloc_offs(*(u32 *)dest)); |
| 222 | } else { |
Alexei Starovoitov | 1a6877b | 2015-08-28 15:56:22 -0700 | [diff] [blame] | 223 | *(u32 *)dest = make_data_rloc(ret, get_rloc_offs(*(u32 *)dest)); |
Namhyung Kim | 5baaa59 | 2013-11-26 15:21:04 +0900 | [diff] [blame] | 224 | } |
| 225 | } |
Masami Hiramatsu | 3da0f18 | 2014-04-17 17:18:28 +0900 | [diff] [blame] | 226 | NOKPROBE_SYMBOL(FETCH_FUNC_NAME(memory, string)); |
Namhyung Kim | 5baaa59 | 2013-11-26 15:21:04 +0900 | [diff] [blame] | 227 | |
| 228 | /* Return the length of string -- including null terminal byte */ |
Masami Hiramatsu | 3da0f18 | 2014-04-17 17:18:28 +0900 | [diff] [blame] | 229 | static void FETCH_FUNC_NAME(memory, string_size)(struct pt_regs *regs, |
| 230 | void *addr, void *dest) |
Namhyung Kim | 5baaa59 | 2013-11-26 15:21:04 +0900 | [diff] [blame] | 231 | { |
| 232 | mm_segment_t old_fs; |
| 233 | int ret, len = 0; |
| 234 | u8 c; |
| 235 | |
| 236 | old_fs = get_fs(); |
| 237 | set_fs(KERNEL_DS); |
| 238 | pagefault_disable(); |
| 239 | |
| 240 | do { |
| 241 | ret = __copy_from_user_inatomic(&c, (u8 *)addr + len, 1); |
| 242 | len++; |
| 243 | } while (c && ret == 0 && len < MAX_STRING_SIZE); |
| 244 | |
| 245 | pagefault_enable(); |
| 246 | set_fs(old_fs); |
| 247 | |
| 248 | if (ret < 0) /* Failed to check the length */ |
| 249 | *(u32 *)dest = 0; |
| 250 | else |
| 251 | *(u32 *)dest = len; |
| 252 | } |
Masami Hiramatsu | 3da0f18 | 2014-04-17 17:18:28 +0900 | [diff] [blame] | 253 | NOKPROBE_SYMBOL(FETCH_FUNC_NAME(memory, string_size)); |
Namhyung Kim | 5baaa59 | 2013-11-26 15:21:04 +0900 | [diff] [blame] | 254 | |
Namhyung Kim | 1301a44 | 2013-11-26 15:21:04 +0900 | [diff] [blame] | 255 | #define DEFINE_FETCH_symbol(type) \ |
Masami Hiramatsu | 3da0f18 | 2014-04-17 17:18:28 +0900 | [diff] [blame] | 256 | void FETCH_FUNC_NAME(symbol, type)(struct pt_regs *regs, void *data, void *dest)\ |
Namhyung Kim | 1301a44 | 2013-11-26 15:21:04 +0900 | [diff] [blame] | 257 | { \ |
| 258 | struct symbol_cache *sc = data; \ |
| 259 | if (sc->addr) \ |
| 260 | fetch_memory_##type(regs, (void *)sc->addr, dest); \ |
| 261 | else \ |
| 262 | *(type *)dest = 0; \ |
Masami Hiramatsu | 3da0f18 | 2014-04-17 17:18:28 +0900 | [diff] [blame] | 263 | } \ |
| 264 | NOKPROBE_SYMBOL(FETCH_FUNC_NAME(symbol, type)); |
| 265 | |
Namhyung Kim | 1301a44 | 2013-11-26 15:21:04 +0900 | [diff] [blame] | 266 | DEFINE_BASIC_FETCH_FUNCS(symbol) |
| 267 | DEFINE_FETCH_symbol(string) |
| 268 | DEFINE_FETCH_symbol(string_size) |
| 269 | |
Namhyung Kim | b7e0bf3 | 2013-11-25 13:42:47 +0900 | [diff] [blame] | 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 |
| 277 | |
Namhyung Kim | 34fee3a | 2013-11-26 14:56:28 +0900 | [diff] [blame] | 278 | /* Fetch type information table */ |
Stephen Rothwell | d9a16d3 | 2015-03-12 16:58:34 +1100 | [diff] [blame] | 279 | static const struct fetch_type kprobes_fetch_type_table[] = { |
Namhyung Kim | 34fee3a | 2013-11-26 14:56:28 +0900 | [diff] [blame] | 280 | /* Special types */ |
| 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"), |
| 285 | /* Basic types */ |
| 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), |
Masami Hiramatsu | 17ce3dc | 2016-08-18 17:57:50 +0900 | [diff] [blame] | 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), |
Namhyung Kim | 34fee3a | 2013-11-26 14:56:28 +0900 | [diff] [blame] | 298 | |
| 299 | ASSIGN_FETCH_TYPE_END |
| 300 | }; |
| 301 | |
Masami Hiramatsu | 4a846b4 | 2009-09-11 05:31:21 +0200 | [diff] [blame] | 302 | /* |
| 303 | * Allocate new trace_probe and initialize it (including kprobes). |
| 304 | */ |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 305 | static struct trace_kprobe *alloc_trace_kprobe(const char *group, |
Masami Hiramatsu | f52487e | 2009-09-10 19:53:53 -0400 | [diff] [blame] | 306 | const char *event, |
Masami Hiramatsu | 4a846b4 | 2009-09-11 05:31:21 +0200 | [diff] [blame] | 307 | void *addr, |
| 308 | const char *symbol, |
| 309 | unsigned long offs, |
Alban Crequy | 696ced4 | 2017-04-03 12:36:22 +0200 | [diff] [blame] | 310 | int maxactive, |
Srikar Dronamraju | 3a6b766 | 2012-04-09 14:41:33 +0530 | [diff] [blame] | 311 | int nargs, bool is_return) |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 312 | { |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 313 | struct trace_kprobe *tk; |
Masami Hiramatsu | 6f3cf44 | 2009-12-16 17:24:08 -0500 | [diff] [blame] | 314 | int ret = -ENOMEM; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 315 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 316 | tk = kzalloc(SIZEOF_TRACE_KPROBE(nargs), GFP_KERNEL); |
| 317 | if (!tk) |
Masami Hiramatsu | 6f3cf44 | 2009-12-16 17:24:08 -0500 | [diff] [blame] | 318 | return ERR_PTR(ret); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 319 | |
Martin KaFai Lau | a7636d9 | 2016-02-03 12:28:28 -0800 | [diff] [blame] | 320 | tk->nhit = alloc_percpu(unsigned long); |
| 321 | if (!tk->nhit) |
| 322 | goto error; |
| 323 | |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 324 | if (symbol) { |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 325 | tk->symbol = kstrdup(symbol, GFP_KERNEL); |
| 326 | if (!tk->symbol) |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 327 | goto error; |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 328 | tk->rp.kp.symbol_name = tk->symbol; |
| 329 | tk->rp.kp.offset = offs; |
Masami Hiramatsu | 4a846b4 | 2009-09-11 05:31:21 +0200 | [diff] [blame] | 330 | } else |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 331 | tk->rp.kp.addr = addr; |
Masami Hiramatsu | 4a846b4 | 2009-09-11 05:31:21 +0200 | [diff] [blame] | 332 | |
| 333 | if (is_return) |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 334 | tk->rp.handler = kretprobe_dispatcher; |
Masami Hiramatsu | 4a846b4 | 2009-09-11 05:31:21 +0200 | [diff] [blame] | 335 | else |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 336 | tk->rp.kp.pre_handler = kprobe_dispatcher; |
Masami Hiramatsu | 4a846b4 | 2009-09-11 05:31:21 +0200 | [diff] [blame] | 337 | |
Alban Crequy | 696ced4 | 2017-04-03 12:36:22 +0200 | [diff] [blame] | 338 | tk->rp.maxactive = maxactive; |
| 339 | |
Masami Hiramatsu | da34634 | 2010-08-27 20:39:12 +0900 | [diff] [blame] | 340 | if (!event || !is_good_name(event)) { |
Masami Hiramatsu | 6f3cf44 | 2009-12-16 17:24:08 -0500 | [diff] [blame] | 341 | ret = -EINVAL; |
Masami Hiramatsu | 4263565 | 2009-08-13 16:35:26 -0400 | [diff] [blame] | 342 | goto error; |
Masami Hiramatsu | 6f3cf44 | 2009-12-16 17:24:08 -0500 | [diff] [blame] | 343 | } |
| 344 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 345 | tk->tp.call.class = &tk->tp.class; |
| 346 | tk->tp.call.name = kstrdup(event, GFP_KERNEL); |
| 347 | if (!tk->tp.call.name) |
Masami Hiramatsu | 4263565 | 2009-08-13 16:35:26 -0400 | [diff] [blame] | 348 | goto error; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 349 | |
Masami Hiramatsu | da34634 | 2010-08-27 20:39:12 +0900 | [diff] [blame] | 350 | if (!group || !is_good_name(group)) { |
Masami Hiramatsu | 6f3cf44 | 2009-12-16 17:24:08 -0500 | [diff] [blame] | 351 | ret = -EINVAL; |
Masami Hiramatsu | f52487e | 2009-09-10 19:53:53 -0400 | [diff] [blame] | 352 | goto error; |
Masami Hiramatsu | 6f3cf44 | 2009-12-16 17:24:08 -0500 | [diff] [blame] | 353 | } |
| 354 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 355 | tk->tp.class.system = kstrdup(group, GFP_KERNEL); |
| 356 | if (!tk->tp.class.system) |
Masami Hiramatsu | f52487e | 2009-09-10 19:53:53 -0400 | [diff] [blame] | 357 | goto error; |
| 358 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 359 | INIT_LIST_HEAD(&tk->list); |
| 360 | INIT_LIST_HEAD(&tk->tp.files); |
| 361 | return tk; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 362 | error: |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 363 | kfree(tk->tp.call.name); |
| 364 | kfree(tk->symbol); |
Martin KaFai Lau | a7636d9 | 2016-02-03 12:28:28 -0800 | [diff] [blame] | 365 | free_percpu(tk->nhit); |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 366 | kfree(tk); |
Masami Hiramatsu | 6f3cf44 | 2009-12-16 17:24:08 -0500 | [diff] [blame] | 367 | return ERR_PTR(ret); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 368 | } |
| 369 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 370 | static void free_trace_kprobe(struct trace_kprobe *tk) |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 371 | { |
| 372 | int i; |
| 373 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 374 | for (i = 0; i < tk->tp.nr_args; i++) |
| 375 | traceprobe_free_probe_arg(&tk->tp.args[i]); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 376 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 377 | kfree(tk->tp.call.class->system); |
| 378 | kfree(tk->tp.call.name); |
| 379 | kfree(tk->symbol); |
Martin KaFai Lau | a7636d9 | 2016-02-03 12:28:28 -0800 | [diff] [blame] | 380 | free_percpu(tk->nhit); |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 381 | kfree(tk); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 382 | } |
| 383 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 384 | static struct trace_kprobe *find_trace_kprobe(const char *event, |
| 385 | const char *group) |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 386 | { |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 387 | struct trace_kprobe *tk; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 388 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 389 | list_for_each_entry(tk, &probe_list, list) |
Steven Rostedt (Red Hat) | 687fcc4 | 2015-05-13 14:20:14 -0400 | [diff] [blame] | 390 | if (strcmp(trace_event_name(&tk->tp.call), event) == 0 && |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 391 | strcmp(tk->tp.call.class->system, group) == 0) |
| 392 | return tk; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 393 | return NULL; |
| 394 | } |
| 395 | |
Oleg Nesterov | 3fe3d61 | 2013-06-20 19:38:09 +0200 | [diff] [blame] | 396 | /* |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 397 | * Enable trace_probe |
| 398 | * if the file is NULL, enable "perf" handler, or enable "trace" handler. |
| 399 | */ |
| 400 | static int |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 401 | enable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file) |
Masami Hiramatsu | 1538f88 | 2011-06-27 16:26:44 +0900 | [diff] [blame] | 402 | { |
| 403 | int ret = 0; |
| 404 | |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 405 | if (file) { |
Oleg Nesterov | b04d52e | 2013-06-20 19:38:14 +0200 | [diff] [blame] | 406 | struct event_file_link *link; |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 407 | |
Oleg Nesterov | b04d52e | 2013-06-20 19:38:14 +0200 | [diff] [blame] | 408 | link = kmalloc(sizeof(*link), GFP_KERNEL); |
| 409 | if (!link) { |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 410 | ret = -ENOMEM; |
Oleg Nesterov | 3fe3d61 | 2013-06-20 19:38:09 +0200 | [diff] [blame] | 411 | goto out; |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 412 | } |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 413 | |
Oleg Nesterov | b04d52e | 2013-06-20 19:38:14 +0200 | [diff] [blame] | 414 | link->file = file; |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 415 | list_add_tail_rcu(&link->list, &tk->tp.files); |
Oleg Nesterov | b04d52e | 2013-06-20 19:38:14 +0200 | [diff] [blame] | 416 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 417 | tk->tp.flags |= TP_FLAG_TRACE; |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 418 | } else |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 419 | tk->tp.flags |= TP_FLAG_PROFILE; |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 420 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 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); |
Masami Hiramatsu | 1538f88 | 2011-06-27 16:26:44 +0900 | [diff] [blame] | 424 | else |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 425 | ret = enable_kprobe(&tk->rp.kp); |
Masami Hiramatsu | 1538f88 | 2011-06-27 16:26:44 +0900 | [diff] [blame] | 426 | } |
Oleg Nesterov | 3fe3d61 | 2013-06-20 19:38:09 +0200 | [diff] [blame] | 427 | out: |
Masami Hiramatsu | 1538f88 | 2011-06-27 16:26:44 +0900 | [diff] [blame] | 428 | return ret; |
| 429 | } |
| 430 | |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 431 | /* |
| 432 | * Disable trace_probe |
| 433 | * if the file is NULL, disable "perf" handler, or disable "trace" handler. |
| 434 | */ |
| 435 | static int |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 436 | disable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file) |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 437 | { |
Masami Hiramatsu | a232e27 | 2013-07-09 18:35:26 +0900 | [diff] [blame] | 438 | struct event_file_link *link = NULL; |
| 439 | int wait = 0; |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 440 | int ret = 0; |
| 441 | |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 442 | if (file) { |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 443 | link = find_event_file_link(&tk->tp, file); |
Oleg Nesterov | b04d52e | 2013-06-20 19:38:14 +0200 | [diff] [blame] | 444 | if (!link) { |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 445 | ret = -EINVAL; |
Oleg Nesterov | 3fe3d61 | 2013-06-20 19:38:09 +0200 | [diff] [blame] | 446 | goto out; |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 447 | } |
| 448 | |
Oleg Nesterov | b04d52e | 2013-06-20 19:38:14 +0200 | [diff] [blame] | 449 | list_del_rcu(&link->list); |
Masami Hiramatsu | a232e27 | 2013-07-09 18:35:26 +0900 | [diff] [blame] | 450 | wait = 1; |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 451 | if (!list_empty(&tk->tp.files)) |
Oleg Nesterov | b04d52e | 2013-06-20 19:38:14 +0200 | [diff] [blame] | 452 | goto out; |
| 453 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 454 | tk->tp.flags &= ~TP_FLAG_TRACE; |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 455 | } else |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 456 | tk->tp.flags &= ~TP_FLAG_PROFILE; |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 457 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 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); |
Masami Hiramatsu | 1538f88 | 2011-06-27 16:26:44 +0900 | [diff] [blame] | 461 | else |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 462 | disable_kprobe(&tk->rp.kp); |
Masami Hiramatsu | a232e27 | 2013-07-09 18:35:26 +0900 | [diff] [blame] | 463 | wait = 1; |
Masami Hiramatsu | 1538f88 | 2011-06-27 16:26:44 +0900 | [diff] [blame] | 464 | } |
Song Liu | e12f03d | 2017-12-06 14:45:15 -0800 | [diff] [blame] | 465 | |
| 466 | /* |
| 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 |
| 469 | * trace_kprobes |
| 470 | */ |
| 471 | if (list_empty(&tk->list)) |
| 472 | wait = 0; |
Oleg Nesterov | 3fe3d61 | 2013-06-20 19:38:09 +0200 | [diff] [blame] | 473 | out: |
Masami Hiramatsu | a232e27 | 2013-07-09 18:35:26 +0900 | [diff] [blame] | 474 | if (wait) { |
| 475 | /* |
| 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. |
| 482 | */ |
| 483 | synchronize_sched(); |
| 484 | kfree(link); /* Ignored if link == NULL */ |
| 485 | } |
| 486 | |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 487 | return ret; |
Masami Hiramatsu | 1538f88 | 2011-06-27 16:26:44 +0900 | [diff] [blame] | 488 | } |
| 489 | |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 490 | /* Internal register function - just handle k*probes and flags */ |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 491 | static int __register_trace_kprobe(struct trace_kprobe *tk) |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 492 | { |
Masami Hiramatsu | 7f6878a | 2011-06-27 16:27:03 +0900 | [diff] [blame] | 493 | int i, ret; |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 494 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 495 | if (trace_probe_is_registered(&tk->tp)) |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 496 | return -EINVAL; |
| 497 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 498 | for (i = 0; i < tk->tp.nr_args; i++) |
| 499 | traceprobe_update_arg(&tk->tp.args[i]); |
Masami Hiramatsu | 7f6878a | 2011-06-27 16:27:03 +0900 | [diff] [blame] | 500 | |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 501 | /* Set/clear disabled flag according to tp->flag */ |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 502 | if (trace_probe_is_enabled(&tk->tp)) |
| 503 | tk->rp.kp.flags &= ~KPROBE_FLAG_DISABLED; |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 504 | else |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 505 | tk->rp.kp.flags |= KPROBE_FLAG_DISABLED; |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 506 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 507 | if (trace_kprobe_is_return(tk)) |
| 508 | ret = register_kretprobe(&tk->rp); |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 509 | else |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 510 | ret = register_kprobe(&tk->rp.kp); |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 511 | |
| 512 | if (ret == 0) |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 513 | tk->tp.flags |= TP_FLAG_REGISTERED; |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 514 | else { |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 515 | if (ret == -ENOENT && trace_kprobe_is_on_module(tk)) { |
Joe Perches | a395d6a | 2016-03-22 14:28:09 -0700 | [diff] [blame] | 516 | pr_warn("This probe might be able to register after target module is loaded. Continue.\n"); |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 517 | ret = 0; |
| 518 | } else if (ret == -EILSEQ) { |
Joe Perches | a395d6a | 2016-03-22 14:28:09 -0700 | [diff] [blame] | 519 | pr_warn("Probing address(0x%p) is not an instruction boundary.\n", |
| 520 | tk->rp.kp.addr); |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 521 | ret = -EINVAL; |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | return ret; |
| 526 | } |
| 527 | |
| 528 | /* Internal unregister function - just handle k*probes and flags */ |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 529 | static void __unregister_trace_kprobe(struct trace_kprobe *tk) |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 530 | { |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 531 | if (trace_probe_is_registered(&tk->tp)) { |
| 532 | if (trace_kprobe_is_return(tk)) |
| 533 | unregister_kretprobe(&tk->rp); |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 534 | else |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 535 | unregister_kprobe(&tk->rp.kp); |
| 536 | tk->tp.flags &= ~TP_FLAG_REGISTERED; |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 537 | /* Cleanup kprobe for reuse */ |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 538 | if (tk->rp.kp.symbol_name) |
| 539 | tk->rp.kp.addr = NULL; |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 540 | } |
| 541 | } |
| 542 | |
Masami Hiramatsu | 2d5e067 | 2009-09-14 16:48:56 -0400 | [diff] [blame] | 543 | /* Unregister a trace_probe and probe_event: call with locking probe_lock */ |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 544 | static int unregister_trace_kprobe(struct trace_kprobe *tk) |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 545 | { |
Masami Hiramatsu | 02ca152 | 2011-10-04 19:44:38 +0900 | [diff] [blame] | 546 | /* Enabled event can not be unregistered */ |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 547 | if (trace_probe_is_enabled(&tk->tp)) |
Masami Hiramatsu | 02ca152 | 2011-10-04 19:44:38 +0900 | [diff] [blame] | 548 | return -EBUSY; |
| 549 | |
Steven Rostedt (Red Hat) | 40c3259 | 2013-07-03 23:33:50 -0400 | [diff] [blame] | 550 | /* Will fail if probe is being used by ftrace or perf */ |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 551 | if (unregister_kprobe_event(tk)) |
Steven Rostedt (Red Hat) | 40c3259 | 2013-07-03 23:33:50 -0400 | [diff] [blame] | 552 | return -EBUSY; |
| 553 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 554 | __unregister_trace_kprobe(tk); |
| 555 | list_del(&tk->list); |
Masami Hiramatsu | 02ca152 | 2011-10-04 19:44:38 +0900 | [diff] [blame] | 556 | |
| 557 | return 0; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | /* Register a trace_probe and probe_event */ |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 561 | static int register_trace_kprobe(struct trace_kprobe *tk) |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 562 | { |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 563 | struct trace_kprobe *old_tk; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 564 | int ret; |
| 565 | |
| 566 | mutex_lock(&probe_lock); |
| 567 | |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 568 | /* Delete old (same name) event if exist */ |
Steven Rostedt (Red Hat) | 687fcc4 | 2015-05-13 14:20:14 -0400 | [diff] [blame] | 569 | old_tk = find_trace_kprobe(trace_event_name(&tk->tp.call), |
Mathieu Desnoyers | de7b297 | 2014-04-08 17:26:21 -0400 | [diff] [blame] | 570 | tk->tp.call.class->system); |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 571 | if (old_tk) { |
| 572 | ret = unregister_trace_kprobe(old_tk); |
Masami Hiramatsu | 02ca152 | 2011-10-04 19:44:38 +0900 | [diff] [blame] | 573 | if (ret < 0) |
| 574 | goto end; |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 575 | free_trace_kprobe(old_tk); |
Masami Hiramatsu | 2d5e067 | 2009-09-14 16:48:56 -0400 | [diff] [blame] | 576 | } |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 577 | |
| 578 | /* Register new event */ |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 579 | ret = register_kprobe_event(tk); |
Masami Hiramatsu | 2d5e067 | 2009-09-14 16:48:56 -0400 | [diff] [blame] | 580 | if (ret) { |
Joe Perches | a395d6a | 2016-03-22 14:28:09 -0700 | [diff] [blame] | 581 | pr_warn("Failed to register probe event(%d)\n", ret); |
Masami Hiramatsu | 2d5e067 | 2009-09-14 16:48:56 -0400 | [diff] [blame] | 582 | goto end; |
| 583 | } |
| 584 | |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 585 | /* Register k*probe */ |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 586 | ret = __register_trace_kprobe(tk); |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 587 | if (ret < 0) |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 588 | unregister_kprobe_event(tk); |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 589 | else |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 590 | list_add_tail(&tk->list, &probe_list); |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 591 | |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 592 | end: |
| 593 | mutex_unlock(&probe_lock); |
| 594 | return ret; |
| 595 | } |
| 596 | |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 597 | /* Module notifier call back, checking event on the module */ |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 598 | static int trace_kprobe_module_callback(struct notifier_block *nb, |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 599 | unsigned long val, void *data) |
| 600 | { |
| 601 | struct module *mod = data; |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 602 | struct trace_kprobe *tk; |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 603 | int ret; |
| 604 | |
| 605 | if (val != MODULE_STATE_COMING) |
| 606 | return NOTIFY_DONE; |
| 607 | |
| 608 | /* Update probes on coming module */ |
| 609 | mutex_lock(&probe_lock); |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 610 | list_for_each_entry(tk, &probe_list, list) { |
| 611 | if (trace_kprobe_within_module(tk, mod)) { |
Masami Hiramatsu | 02ca152 | 2011-10-04 19:44:38 +0900 | [diff] [blame] | 612 | /* Don't need to check busy - this should have gone. */ |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 613 | __unregister_trace_kprobe(tk); |
| 614 | ret = __register_trace_kprobe(tk); |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 615 | if (ret) |
Joe Perches | a395d6a | 2016-03-22 14:28:09 -0700 | [diff] [blame] | 616 | pr_warn("Failed to re-register probe %s on %s: %d\n", |
| 617 | trace_event_name(&tk->tp.call), |
| 618 | mod->name, ret); |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 619 | } |
| 620 | } |
| 621 | mutex_unlock(&probe_lock); |
| 622 | |
| 623 | return NOTIFY_DONE; |
| 624 | } |
| 625 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 626 | static struct notifier_block trace_kprobe_module_nb = { |
| 627 | .notifier_call = trace_kprobe_module_callback, |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 628 | .priority = 1 /* Invoked after kprobe module callback */ |
| 629 | }; |
| 630 | |
Naveen N. Rao | fca18a4 | 2017-07-08 00:27:30 +0530 | [diff] [blame] | 631 | /* Convert certain expected symbols into '_' when generating event names */ |
| 632 | static inline void sanitize_event_name(char *name) |
| 633 | { |
| 634 | while (*name++ != '\0') |
| 635 | if (*name == ':' || *name == '.') |
| 636 | *name = '_'; |
| 637 | } |
| 638 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 639 | static int create_trace_kprobe(int argc, char **argv) |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 640 | { |
| 641 | /* |
| 642 | * Argument syntax: |
Alban Crequy | 696ced4 | 2017-04-03 12:36:22 +0200 | [diff] [blame] | 643 | * - Add kprobe: |
| 644 | * p[:[GRP/]EVENT] [MOD:]KSYM[+OFFS]|KADDR [FETCHARGS] |
| 645 | * - Add kretprobe: |
| 646 | * r[MAXACTIVE][:[GRP/]EVENT] [MOD:]KSYM[+0] [FETCHARGS] |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 647 | * Fetch args: |
Masami Hiramatsu | 2e06ff6 | 2009-10-07 18:27:59 -0400 | [diff] [blame] | 648 | * $retval : fetch return value |
| 649 | * $stack : fetch stack address |
| 650 | * $stackN : fetch Nth of stack (N:0-) |
Omar Sandoval | 35abb67 | 2016-06-08 18:38:02 -0700 | [diff] [blame] | 651 | * $comm : fetch current task comm |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 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 |
Masami Hiramatsu | 93ccae7 | 2010-04-12 13:17:08 -0400 | [diff] [blame] | 655 | * Dereferencing memory fetch: |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 656 | * +|-offs(ARG) : fetch memory at ARG +|- offs address. |
Masami Hiramatsu | eca0d91 | 2009-09-10 19:53:38 -0400 | [diff] [blame] | 657 | * Alias name of args: |
| 658 | * NAME=FETCHARG : set NAME as alias of FETCHARG. |
Masami Hiramatsu | 93ccae7 | 2010-04-12 13:17:08 -0400 | [diff] [blame] | 659 | * Type of args: |
| 660 | * FETCHARG:TYPE : use TYPE instead of unsigned long. |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 661 | */ |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 662 | struct trace_kprobe *tk; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 663 | int i, ret = 0; |
Srikar Dronamraju | 3a6b766 | 2012-04-09 14:41:33 +0530 | [diff] [blame] | 664 | bool is_return = false, is_delete = false; |
Masami Hiramatsu | 93ccae7 | 2010-04-12 13:17:08 -0400 | [diff] [blame] | 665 | char *symbol = NULL, *event = NULL, *group = NULL; |
Alban Crequy | 696ced4 | 2017-04-03 12:36:22 +0200 | [diff] [blame] | 666 | int maxactive = 0; |
Masami Hiramatsu | da34634 | 2010-08-27 20:39:12 +0900 | [diff] [blame] | 667 | char *arg; |
Masami Hiramatsu | c5d343b | 2018-03-17 21:38:10 +0900 | [diff] [blame] | 668 | long offset = 0; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 669 | void *addr = NULL; |
Masami Hiramatsu | 4a846b4 | 2009-09-11 05:31:21 +0200 | [diff] [blame] | 670 | char buf[MAX_EVENT_NAME_LEN]; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 671 | |
Masami Hiramatsu | a7c312b | 2009-12-08 17:03:16 -0500 | [diff] [blame] | 672 | /* argc must be >= 1 */ |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 673 | if (argv[0][0] == 'p') |
Srikar Dronamraju | 3a6b766 | 2012-04-09 14:41:33 +0530 | [diff] [blame] | 674 | is_return = false; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 675 | else if (argv[0][0] == 'r') |
Srikar Dronamraju | 3a6b766 | 2012-04-09 14:41:33 +0530 | [diff] [blame] | 676 | is_return = true; |
Masami Hiramatsu | a7c312b | 2009-12-08 17:03:16 -0500 | [diff] [blame] | 677 | else if (argv[0][0] == '-') |
Srikar Dronamraju | 3a6b766 | 2012-04-09 14:41:33 +0530 | [diff] [blame] | 678 | is_delete = true; |
Masami Hiramatsu | e63cc23 | 2009-10-16 20:07:28 -0400 | [diff] [blame] | 679 | else { |
Masami Hiramatsu | a7c312b | 2009-12-08 17:03:16 -0500 | [diff] [blame] | 680 | pr_info("Probe definition must be started with 'p', 'r' or" |
| 681 | " '-'.\n"); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 682 | return -EINVAL; |
Masami Hiramatsu | e63cc23 | 2009-10-16 20:07:28 -0400 | [diff] [blame] | 683 | } |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 684 | |
Alban Crequy | 696ced4 | 2017-04-03 12:36:22 +0200 | [diff] [blame] | 685 | event = strchr(&argv[0][1], ':'); |
| 686 | if (event) { |
| 687 | event[0] = '\0'; |
| 688 | event++; |
| 689 | } |
| 690 | if (is_return && isdigit(argv[0][1])) { |
| 691 | ret = kstrtouint(&argv[0][1], 0, &maxactive); |
| 692 | if (ret) { |
| 693 | pr_info("Failed to parse maxactive.\n"); |
| 694 | return ret; |
| 695 | } |
| 696 | /* kretprobes instances are iterated over via a list. The |
| 697 | * maximum should stay reasonable. |
| 698 | */ |
| 699 | if (maxactive > KRETPROBE_MAXACTIVE_MAX) { |
| 700 | pr_info("Maxactive is too big (%d > %d).\n", |
| 701 | maxactive, KRETPROBE_MAXACTIVE_MAX); |
| 702 | return -E2BIG; |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | if (event) { |
Masami Hiramatsu | f52487e | 2009-09-10 19:53:53 -0400 | [diff] [blame] | 707 | if (strchr(event, '/')) { |
| 708 | group = event; |
| 709 | event = strchr(group, '/') + 1; |
| 710 | event[-1] = '\0'; |
| 711 | if (strlen(group) == 0) { |
Wenji Huang | a5efd92 | 2010-02-24 15:40:23 +0800 | [diff] [blame] | 712 | pr_info("Group name is not specified\n"); |
Masami Hiramatsu | f52487e | 2009-09-10 19:53:53 -0400 | [diff] [blame] | 713 | return -EINVAL; |
| 714 | } |
| 715 | } |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 716 | if (strlen(event) == 0) { |
Wenji Huang | a5efd92 | 2010-02-24 15:40:23 +0800 | [diff] [blame] | 717 | pr_info("Event name is not specified\n"); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 718 | return -EINVAL; |
| 719 | } |
| 720 | } |
Masami Hiramatsu | a7c312b | 2009-12-08 17:03:16 -0500 | [diff] [blame] | 721 | if (!group) |
| 722 | group = KPROBE_EVENT_SYSTEM; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 723 | |
Masami Hiramatsu | a7c312b | 2009-12-08 17:03:16 -0500 | [diff] [blame] | 724 | if (is_delete) { |
| 725 | if (!event) { |
| 726 | pr_info("Delete command needs an event name.\n"); |
| 727 | return -EINVAL; |
| 728 | } |
Srikar Dronamraju | 9da79ab | 2010-06-30 14:15:48 +0530 | [diff] [blame] | 729 | mutex_lock(&probe_lock); |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 730 | tk = find_trace_kprobe(event, group); |
| 731 | if (!tk) { |
Srikar Dronamraju | 9da79ab | 2010-06-30 14:15:48 +0530 | [diff] [blame] | 732 | mutex_unlock(&probe_lock); |
Masami Hiramatsu | a7c312b | 2009-12-08 17:03:16 -0500 | [diff] [blame] | 733 | pr_info("Event %s/%s doesn't exist.\n", group, event); |
| 734 | return -ENOENT; |
| 735 | } |
| 736 | /* delete an event */ |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 737 | ret = unregister_trace_kprobe(tk); |
Masami Hiramatsu | 02ca152 | 2011-10-04 19:44:38 +0900 | [diff] [blame] | 738 | if (ret == 0) |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 739 | free_trace_kprobe(tk); |
Srikar Dronamraju | 9da79ab | 2010-06-30 14:15:48 +0530 | [diff] [blame] | 740 | mutex_unlock(&probe_lock); |
Masami Hiramatsu | 02ca152 | 2011-10-04 19:44:38 +0900 | [diff] [blame] | 741 | return ret; |
Masami Hiramatsu | a7c312b | 2009-12-08 17:03:16 -0500 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | if (argc < 2) { |
| 745 | pr_info("Probe point is not specified.\n"); |
| 746 | return -EINVAL; |
| 747 | } |
Sabrina Dubroca | 9e52b32 | 2017-06-22 11:24:42 +0200 | [diff] [blame] | 748 | |
| 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)) { |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 752 | /* a symbol specified */ |
| 753 | symbol = argv[1]; |
| 754 | /* TODO: support .init module functions */ |
Srikar Dronamraju | 8ab83f5 | 2012-04-09 14:41:44 +0530 | [diff] [blame] | 755 | ret = traceprobe_split_symbol_offset(symbol, &offset); |
Masami Hiramatsu | c5d343b | 2018-03-17 21:38:10 +0900 | [diff] [blame] | 756 | if (ret || offset < 0 || offset > UINT_MAX) { |
Sabrina Dubroca | 9e52b32 | 2017-06-22 11:24:42 +0200 | [diff] [blame] | 757 | pr_info("Failed to parse either an address or a symbol.\n"); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 758 | return ret; |
Masami Hiramatsu | e63cc23 | 2009-10-16 20:07:28 -0400 | [diff] [blame] | 759 | } |
Steven Rostedt (VMware) | d0e0257 | 2017-02-27 11:52:04 -0500 | [diff] [blame] | 760 | if (offset && is_return && |
Naveen N. Rao | 659b957 | 2017-07-07 22:37:24 +0530 | [diff] [blame] | 761 | !kprobe_on_func_entry(NULL, symbol, offset)) { |
Steven Rostedt (VMware) | d0e0257 | 2017-02-27 11:52:04 -0500 | [diff] [blame] | 762 | pr_info("Given offset is not valid for return probe.\n"); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 763 | return -EINVAL; |
Masami Hiramatsu | e63cc23 | 2009-10-16 20:07:28 -0400 | [diff] [blame] | 764 | } |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 765 | } |
Masami Hiramatsu | a82378d | 2009-08-13 16:35:18 -0400 | [diff] [blame] | 766 | argc -= 2; argv += 2; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 767 | |
| 768 | /* setup a probe */ |
Masami Hiramatsu | 4263565 | 2009-08-13 16:35:26 -0400 | [diff] [blame] | 769 | if (!event) { |
| 770 | /* Make a new event name */ |
Masami Hiramatsu | 4263565 | 2009-08-13 16:35:26 -0400 | [diff] [blame] | 771 | if (symbol) |
Masami Hiramatsu | 6f3cf44 | 2009-12-16 17:24:08 -0500 | [diff] [blame] | 772 | snprintf(buf, MAX_EVENT_NAME_LEN, "%c_%s_%ld", |
Masami Hiramatsu | 4263565 | 2009-08-13 16:35:26 -0400 | [diff] [blame] | 773 | is_return ? 'r' : 'p', symbol, offset); |
| 774 | else |
Masami Hiramatsu | 6f3cf44 | 2009-12-16 17:24:08 -0500 | [diff] [blame] | 775 | snprintf(buf, MAX_EVENT_NAME_LEN, "%c_0x%p", |
Masami Hiramatsu | 4263565 | 2009-08-13 16:35:26 -0400 | [diff] [blame] | 776 | is_return ? 'r' : 'p', addr); |
Naveen N. Rao | fca18a4 | 2017-07-08 00:27:30 +0530 | [diff] [blame] | 777 | sanitize_event_name(buf); |
Masami Hiramatsu | 4a846b4 | 2009-09-11 05:31:21 +0200 | [diff] [blame] | 778 | event = buf; |
| 779 | } |
Alban Crequy | 696ced4 | 2017-04-03 12:36:22 +0200 | [diff] [blame] | 780 | tk = alloc_trace_kprobe(group, event, addr, symbol, offset, maxactive, |
| 781 | argc, is_return); |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 782 | if (IS_ERR(tk)) { |
Masami Hiramatsu | e63cc23 | 2009-10-16 20:07:28 -0400 | [diff] [blame] | 783 | pr_info("Failed to allocate trace_probe.(%d)\n", |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 784 | (int)PTR_ERR(tk)); |
| 785 | return PTR_ERR(tk); |
Masami Hiramatsu | e63cc23 | 2009-10-16 20:07:28 -0400 | [diff] [blame] | 786 | } |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 787 | |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 788 | /* parse arguments */ |
Masami Hiramatsu | a82378d | 2009-08-13 16:35:18 -0400 | [diff] [blame] | 789 | ret = 0; |
| 790 | for (i = 0; i < argc && i < MAX_TRACE_ARGS; i++) { |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 791 | struct probe_arg *parg = &tk->tp.args[i]; |
| 792 | |
Masami Hiramatsu | 61a5273 | 2010-08-27 20:38:46 +0900 | [diff] [blame] | 793 | /* Increment count for freeing args in error case */ |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 794 | tk->tp.nr_args++; |
Masami Hiramatsu | 61a5273 | 2010-08-27 20:38:46 +0900 | [diff] [blame] | 795 | |
Masami Hiramatsu | eca0d91 | 2009-09-10 19:53:38 -0400 | [diff] [blame] | 796 | /* Parse argument name */ |
| 797 | arg = strchr(argv[i], '='); |
Masami Hiramatsu | aba9159 | 2010-08-27 20:39:06 +0900 | [diff] [blame] | 798 | if (arg) { |
Masami Hiramatsu | eca0d91 | 2009-09-10 19:53:38 -0400 | [diff] [blame] | 799 | *arg++ = '\0'; |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 800 | parg->name = kstrdup(argv[i], GFP_KERNEL); |
Masami Hiramatsu | aba9159 | 2010-08-27 20:39:06 +0900 | [diff] [blame] | 801 | } else { |
Masami Hiramatsu | eca0d91 | 2009-09-10 19:53:38 -0400 | [diff] [blame] | 802 | arg = argv[i]; |
Masami Hiramatsu | aba9159 | 2010-08-27 20:39:06 +0900 | [diff] [blame] | 803 | /* If argument name is omitted, set "argN" */ |
| 804 | snprintf(buf, MAX_EVENT_NAME_LEN, "arg%d", i + 1); |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 805 | parg->name = kstrdup(buf, GFP_KERNEL); |
Masami Hiramatsu | aba9159 | 2010-08-27 20:39:06 +0900 | [diff] [blame] | 806 | } |
Masami Hiramatsu | a703d94 | 2009-10-07 18:28:07 -0400 | [diff] [blame] | 807 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 808 | if (!parg->name) { |
Masami Hiramatsu | aba9159 | 2010-08-27 20:39:06 +0900 | [diff] [blame] | 809 | pr_info("Failed to allocate argument[%d] name.\n", i); |
Masami Hiramatsu | ba8665d | 2009-11-30 19:19:20 -0500 | [diff] [blame] | 810 | ret = -ENOMEM; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 811 | goto error; |
| 812 | } |
Masami Hiramatsu | da34634 | 2010-08-27 20:39:12 +0900 | [diff] [blame] | 813 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 814 | if (!is_good_name(parg->name)) { |
Masami Hiramatsu | da34634 | 2010-08-27 20:39:12 +0900 | [diff] [blame] | 815 | pr_info("Invalid argument[%d] name: %s\n", |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 816 | i, parg->name); |
Masami Hiramatsu | da34634 | 2010-08-27 20:39:12 +0900 | [diff] [blame] | 817 | ret = -EINVAL; |
| 818 | goto error; |
| 819 | } |
Masami Hiramatsu | 93ccae7 | 2010-04-12 13:17:08 -0400 | [diff] [blame] | 820 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 821 | if (traceprobe_conflict_field_name(parg->name, |
| 822 | tk->tp.args, i)) { |
Masami Hiramatsu | aba9159 | 2010-08-27 20:39:06 +0900 | [diff] [blame] | 823 | pr_info("Argument[%d] name '%s' conflicts with " |
Masami Hiramatsu | 93ccae7 | 2010-04-12 13:17:08 -0400 | [diff] [blame] | 824 | "another field.\n", i, argv[i]); |
| 825 | ret = -EINVAL; |
| 826 | goto error; |
| 827 | } |
Masami Hiramatsu | ba8665d | 2009-11-30 19:19:20 -0500 | [diff] [blame] | 828 | |
| 829 | /* Parse fetch argument */ |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 830 | ret = traceprobe_parse_probe_arg(arg, &tk->tp.size, parg, |
Stephen Rothwell | d9a16d3 | 2015-03-12 16:58:34 +1100 | [diff] [blame] | 831 | is_return, true, |
| 832 | kprobes_fetch_type_table); |
Masami Hiramatsu | e63cc23 | 2009-10-16 20:07:28 -0400 | [diff] [blame] | 833 | if (ret) { |
Masami Hiramatsu | aba9159 | 2010-08-27 20:39:06 +0900 | [diff] [blame] | 834 | pr_info("Parse error at argument[%d]. (%d)\n", i, ret); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 835 | goto error; |
Masami Hiramatsu | e63cc23 | 2009-10-16 20:07:28 -0400 | [diff] [blame] | 836 | } |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 837 | } |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 838 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 839 | ret = register_trace_kprobe(tk); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 840 | if (ret) |
| 841 | goto error; |
| 842 | return 0; |
| 843 | |
| 844 | error: |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 845 | free_trace_kprobe(tk); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 846 | return ret; |
| 847 | } |
| 848 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 849 | static int release_all_trace_kprobes(void) |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 850 | { |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 851 | struct trace_kprobe *tk; |
Masami Hiramatsu | 02ca152 | 2011-10-04 19:44:38 +0900 | [diff] [blame] | 852 | int ret = 0; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 853 | |
| 854 | mutex_lock(&probe_lock); |
Masami Hiramatsu | 02ca152 | 2011-10-04 19:44:38 +0900 | [diff] [blame] | 855 | /* Ensure no probe is in use. */ |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 856 | list_for_each_entry(tk, &probe_list, list) |
| 857 | if (trace_probe_is_enabled(&tk->tp)) { |
Masami Hiramatsu | 02ca152 | 2011-10-04 19:44:38 +0900 | [diff] [blame] | 858 | ret = -EBUSY; |
| 859 | goto end; |
| 860 | } |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 861 | /* TODO: Use batch unregistration */ |
| 862 | while (!list_empty(&probe_list)) { |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 863 | tk = list_entry(probe_list.next, struct trace_kprobe, list); |
| 864 | ret = unregister_trace_kprobe(tk); |
Steven Rostedt (Red Hat) | 40c3259 | 2013-07-03 23:33:50 -0400 | [diff] [blame] | 865 | if (ret) |
| 866 | goto end; |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 867 | free_trace_kprobe(tk); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 868 | } |
Masami Hiramatsu | 02ca152 | 2011-10-04 19:44:38 +0900 | [diff] [blame] | 869 | |
| 870 | end: |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 871 | mutex_unlock(&probe_lock); |
Masami Hiramatsu | 02ca152 | 2011-10-04 19:44:38 +0900 | [diff] [blame] | 872 | |
| 873 | return ret; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 874 | } |
| 875 | |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 876 | /* Probes listing interfaces */ |
| 877 | static void *probes_seq_start(struct seq_file *m, loff_t *pos) |
| 878 | { |
| 879 | mutex_lock(&probe_lock); |
| 880 | return seq_list_start(&probe_list, *pos); |
| 881 | } |
| 882 | |
| 883 | static void *probes_seq_next(struct seq_file *m, void *v, loff_t *pos) |
| 884 | { |
| 885 | return seq_list_next(v, &probe_list, pos); |
| 886 | } |
| 887 | |
| 888 | static void probes_seq_stop(struct seq_file *m, void *v) |
| 889 | { |
| 890 | mutex_unlock(&probe_lock); |
| 891 | } |
| 892 | |
| 893 | static int probes_seq_show(struct seq_file *m, void *v) |
| 894 | { |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 895 | struct trace_kprobe *tk = v; |
Masami Hiramatsu | 93ccae7 | 2010-04-12 13:17:08 -0400 | [diff] [blame] | 896 | int i; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 897 | |
Rasmus Villemoes | fa6f0cc | 2014-11-08 21:42:10 +0100 | [diff] [blame] | 898 | seq_putc(m, trace_kprobe_is_return(tk) ? 'r' : 'p'); |
Mathieu Desnoyers | de7b297 | 2014-04-08 17:26:21 -0400 | [diff] [blame] | 899 | seq_printf(m, ":%s/%s", tk->tp.call.class->system, |
Steven Rostedt (Red Hat) | 687fcc4 | 2015-05-13 14:20:14 -0400 | [diff] [blame] | 900 | trace_event_name(&tk->tp.call)); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 901 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 902 | if (!tk->symbol) |
| 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), |
| 906 | tk->rp.kp.offset); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 907 | else |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 908 | seq_printf(m, " %s", trace_kprobe_symbol(tk)); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 909 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 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); |
Rasmus Villemoes | fa6f0cc | 2014-11-08 21:42:10 +0100 | [diff] [blame] | 912 | seq_putc(m, '\n'); |
Masami Hiramatsu | 93ccae7 | 2010-04-12 13:17:08 -0400 | [diff] [blame] | 913 | |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 914 | return 0; |
| 915 | } |
| 916 | |
| 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 |
| 922 | }; |
| 923 | |
| 924 | static int probes_open(struct inode *inode, struct file *file) |
| 925 | { |
Masami Hiramatsu | 02ca152 | 2011-10-04 19:44:38 +0900 | [diff] [blame] | 926 | int ret; |
| 927 | |
| 928 | if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_TRUNC)) { |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 929 | ret = release_all_trace_kprobes(); |
Masami Hiramatsu | 02ca152 | 2011-10-04 19:44:38 +0900 | [diff] [blame] | 930 | if (ret < 0) |
| 931 | return ret; |
| 932 | } |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 933 | |
| 934 | return seq_open(file, &probes_seq_op); |
| 935 | } |
| 936 | |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 937 | static ssize_t probes_write(struct file *file, const char __user *buffer, |
| 938 | size_t count, loff_t *ppos) |
| 939 | { |
Tom Zanussi | 7e465ba | 2017-09-22 14:58:20 -0500 | [diff] [blame] | 940 | return trace_parse_run_command(file, buffer, count, ppos, |
| 941 | create_trace_kprobe); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | static const struct file_operations kprobe_events_ops = { |
| 945 | .owner = THIS_MODULE, |
| 946 | .open = probes_open, |
| 947 | .read = seq_read, |
| 948 | .llseek = seq_lseek, |
| 949 | .release = seq_release, |
| 950 | .write = probes_write, |
| 951 | }; |
| 952 | |
Masami Hiramatsu | cd7e7bd | 2009-08-13 16:35:42 -0400 | [diff] [blame] | 953 | /* Probes profiling interfaces */ |
| 954 | static int probes_profile_seq_show(struct seq_file *m, void *v) |
| 955 | { |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 956 | struct trace_kprobe *tk = v; |
Masami Hiramatsu | cd7e7bd | 2009-08-13 16:35:42 -0400 | [diff] [blame] | 957 | |
Mathieu Desnoyers | de7b297 | 2014-04-08 17:26:21 -0400 | [diff] [blame] | 958 | seq_printf(m, " %-44s %15lu %15lu\n", |
Marcin Nowakowski | f18f97a | 2016-12-09 15:19:37 +0100 | [diff] [blame] | 959 | trace_event_name(&tk->tp.call), |
| 960 | trace_kprobe_nhit(tk), |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 961 | tk->rp.kp.nmissed); |
Masami Hiramatsu | cd7e7bd | 2009-08-13 16:35:42 -0400 | [diff] [blame] | 962 | |
| 963 | return 0; |
| 964 | } |
| 965 | |
| 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 |
| 971 | }; |
| 972 | |
| 973 | static int profile_open(struct inode *inode, struct file *file) |
| 974 | { |
| 975 | return seq_open(file, &profile_seq_op); |
| 976 | } |
| 977 | |
| 978 | static const struct file_operations kprobe_profile_ops = { |
| 979 | .owner = THIS_MODULE, |
| 980 | .open = profile_open, |
| 981 | .read = seq_read, |
| 982 | .llseek = seq_lseek, |
| 983 | .release = seq_release, |
| 984 | }; |
| 985 | |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 986 | /* Kprobe handler */ |
Masami Hiramatsu | 3da0f18 | 2014-04-17 17:18:28 +0900 | [diff] [blame] | 987 | static nokprobe_inline void |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 988 | __kprobe_trace_func(struct trace_kprobe *tk, struct pt_regs *regs, |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 989 | struct trace_event_file *trace_file) |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 990 | { |
Masami Hiramatsu | 93ccae7 | 2010-04-12 13:17:08 -0400 | [diff] [blame] | 991 | struct kprobe_trace_entry_head *entry; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 992 | struct ring_buffer_event *event; |
Frederic Weisbecker | 8f8ffe2 | 2009-09-11 01:09:23 +0200 | [diff] [blame] | 993 | struct ring_buffer *buffer; |
Masami Hiramatsu | e09c861 | 2010-07-05 15:54:45 -0300 | [diff] [blame] | 994 | int size, dsize, pc; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 995 | unsigned long irq_flags; |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 996 | struct trace_event_call *call = &tk->tp.call; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 997 | |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 998 | WARN_ON(call != trace_file->event_call); |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 999 | |
Steven Rostedt (Red Hat) | 09a5059 | 2015-05-13 15:21:25 -0400 | [diff] [blame] | 1000 | if (trace_trigger_soft_disabled(trace_file)) |
Steven Rostedt (Red Hat) | 13a1e4a | 2014-01-06 21:32:10 -0500 | [diff] [blame] | 1001 | return; |
Masami Hiramatsu | b882008 | 2013-05-09 14:44:54 +0900 | [diff] [blame] | 1002 | |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1003 | local_save_flags(irq_flags); |
| 1004 | pc = preempt_count(); |
| 1005 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1006 | dsize = __get_data_size(&tk->tp, regs); |
| 1007 | size = sizeof(*entry) + tk->tp.size + dsize; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1008 | |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 1009 | event = trace_event_buffer_lock_reserve(&buffer, trace_file, |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1010 | call->event.type, |
| 1011 | size, irq_flags, pc); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1012 | if (!event) |
Xiao Guangrong | 1e12a4a | 2010-01-28 09:34:27 +0800 | [diff] [blame] | 1013 | return; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1014 | |
| 1015 | entry = ring_buffer_event_data(event); |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1016 | entry->ip = (unsigned long)tk->rp.kp.addr; |
| 1017 | store_trace_args(sizeof(*entry), &tk->tp, regs, (u8 *)&entry[1], dsize); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1018 | |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 1019 | event_trigger_unlock_commit_regs(trace_file, buffer, event, |
Steven Rostedt (Red Hat) | 13a1e4a | 2014-01-06 21:32:10 -0500 | [diff] [blame] | 1020 | entry, irq_flags, pc, regs); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1021 | } |
| 1022 | |
Masami Hiramatsu | 3da0f18 | 2014-04-17 17:18:28 +0900 | [diff] [blame] | 1023 | static void |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1024 | kprobe_trace_func(struct trace_kprobe *tk, struct pt_regs *regs) |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1025 | { |
Oleg Nesterov | b04d52e | 2013-06-20 19:38:14 +0200 | [diff] [blame] | 1026 | struct event_file_link *link; |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1027 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1028 | list_for_each_entry_rcu(link, &tk->tp.files, list) |
| 1029 | __kprobe_trace_func(tk, regs, link->file); |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1030 | } |
Masami Hiramatsu | 3da0f18 | 2014-04-17 17:18:28 +0900 | [diff] [blame] | 1031 | NOKPROBE_SYMBOL(kprobe_trace_func); |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1032 | |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1033 | /* Kretprobe handler */ |
Masami Hiramatsu | 3da0f18 | 2014-04-17 17:18:28 +0900 | [diff] [blame] | 1034 | static nokprobe_inline void |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1035 | __kretprobe_trace_func(struct trace_kprobe *tk, struct kretprobe_instance *ri, |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1036 | struct pt_regs *regs, |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 1037 | struct trace_event_file *trace_file) |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1038 | { |
Masami Hiramatsu | 93ccae7 | 2010-04-12 13:17:08 -0400 | [diff] [blame] | 1039 | struct kretprobe_trace_entry_head *entry; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1040 | struct ring_buffer_event *event; |
Frederic Weisbecker | 8f8ffe2 | 2009-09-11 01:09:23 +0200 | [diff] [blame] | 1041 | struct ring_buffer *buffer; |
Masami Hiramatsu | e09c861 | 2010-07-05 15:54:45 -0300 | [diff] [blame] | 1042 | int size, pc, dsize; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1043 | unsigned long irq_flags; |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 1044 | struct trace_event_call *call = &tk->tp.call; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1045 | |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 1046 | WARN_ON(call != trace_file->event_call); |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1047 | |
Steven Rostedt (Red Hat) | 09a5059 | 2015-05-13 15:21:25 -0400 | [diff] [blame] | 1048 | if (trace_trigger_soft_disabled(trace_file)) |
Steven Rostedt (Red Hat) | 13a1e4a | 2014-01-06 21:32:10 -0500 | [diff] [blame] | 1049 | return; |
Masami Hiramatsu | b882008 | 2013-05-09 14:44:54 +0900 | [diff] [blame] | 1050 | |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1051 | local_save_flags(irq_flags); |
| 1052 | pc = preempt_count(); |
| 1053 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1054 | dsize = __get_data_size(&tk->tp, regs); |
| 1055 | size = sizeof(*entry) + tk->tp.size + dsize; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1056 | |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 1057 | event = trace_event_buffer_lock_reserve(&buffer, trace_file, |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1058 | call->event.type, |
| 1059 | size, irq_flags, pc); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1060 | if (!event) |
Xiao Guangrong | 1e12a4a | 2010-01-28 09:34:27 +0800 | [diff] [blame] | 1061 | return; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1062 | |
| 1063 | entry = ring_buffer_event_data(event); |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1064 | entry->func = (unsigned long)tk->rp.kp.addr; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1065 | entry->ret_ip = (unsigned long)ri->ret_addr; |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1066 | store_trace_args(sizeof(*entry), &tk->tp, regs, (u8 *)&entry[1], dsize); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1067 | |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 1068 | event_trigger_unlock_commit_regs(trace_file, buffer, event, |
Steven Rostedt (Red Hat) | 13a1e4a | 2014-01-06 21:32:10 -0500 | [diff] [blame] | 1069 | entry, irq_flags, pc, regs); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1070 | } |
| 1071 | |
Masami Hiramatsu | 3da0f18 | 2014-04-17 17:18:28 +0900 | [diff] [blame] | 1072 | static void |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1073 | kretprobe_trace_func(struct trace_kprobe *tk, struct kretprobe_instance *ri, |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1074 | struct pt_regs *regs) |
| 1075 | { |
Oleg Nesterov | b04d52e | 2013-06-20 19:38:14 +0200 | [diff] [blame] | 1076 | struct event_file_link *link; |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1077 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1078 | list_for_each_entry_rcu(link, &tk->tp.files, list) |
| 1079 | __kretprobe_trace_func(tk, ri, regs, link->file); |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1080 | } |
Masami Hiramatsu | 3da0f18 | 2014-04-17 17:18:28 +0900 | [diff] [blame] | 1081 | NOKPROBE_SYMBOL(kretprobe_trace_func); |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1082 | |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1083 | /* Event entry printers */ |
Masami Hiramatsu | b62fdd9 | 2013-05-13 20:58:39 +0900 | [diff] [blame] | 1084 | static enum print_line_t |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 1085 | print_kprobe_event(struct trace_iterator *iter, int flags, |
| 1086 | struct trace_event *event) |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1087 | { |
Masami Hiramatsu | 93ccae7 | 2010-04-12 13:17:08 -0400 | [diff] [blame] | 1088 | struct kprobe_trace_entry_head *field; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1089 | struct trace_seq *s = &iter->seq; |
Masami Hiramatsu | eca0d91 | 2009-09-10 19:53:38 -0400 | [diff] [blame] | 1090 | struct trace_probe *tp; |
Masami Hiramatsu | 93ccae7 | 2010-04-12 13:17:08 -0400 | [diff] [blame] | 1091 | u8 *data; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1092 | int i; |
| 1093 | |
Masami Hiramatsu | 93ccae7 | 2010-04-12 13:17:08 -0400 | [diff] [blame] | 1094 | field = (struct kprobe_trace_entry_head *)iter->ent; |
Steven Rostedt | 80decc7 | 2010-04-23 10:00:22 -0400 | [diff] [blame] | 1095 | tp = container_of(event, struct trace_probe, call.event); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1096 | |
Steven Rostedt (Red Hat) | 687fcc4 | 2015-05-13 14:20:14 -0400 | [diff] [blame] | 1097 | trace_seq_printf(s, "%s: (", trace_event_name(&tp->call)); |
Masami Hiramatsu | 6e9f23d | 2009-09-10 19:53:45 -0400 | [diff] [blame] | 1098 | |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1099 | if (!seq_print_ip_sym(s, field->ip, flags | TRACE_ITER_SYM_OFFSET)) |
Steven Rostedt (Red Hat) | 85224da | 2014-11-12 15:18:16 -0500 | [diff] [blame] | 1100 | goto out; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1101 | |
Steven Rostedt (Red Hat) | 85224da | 2014-11-12 15:18:16 -0500 | [diff] [blame] | 1102 | trace_seq_putc(s, ')'); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1103 | |
Masami Hiramatsu | 93ccae7 | 2010-04-12 13:17:08 -0400 | [diff] [blame] | 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, |
Masami Hiramatsu | e09c861 | 2010-07-05 15:54:45 -0300 | [diff] [blame] | 1107 | data + tp->args[i].offset, field)) |
Steven Rostedt (Red Hat) | 85224da | 2014-11-12 15:18:16 -0500 | [diff] [blame] | 1108 | goto out; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1109 | |
Steven Rostedt (Red Hat) | 85224da | 2014-11-12 15:18:16 -0500 | [diff] [blame] | 1110 | trace_seq_putc(s, '\n'); |
| 1111 | out: |
| 1112 | return trace_handle_return(s); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1113 | } |
| 1114 | |
Masami Hiramatsu | b62fdd9 | 2013-05-13 20:58:39 +0900 | [diff] [blame] | 1115 | static enum print_line_t |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 1116 | print_kretprobe_event(struct trace_iterator *iter, int flags, |
| 1117 | struct trace_event *event) |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1118 | { |
Masami Hiramatsu | 93ccae7 | 2010-04-12 13:17:08 -0400 | [diff] [blame] | 1119 | struct kretprobe_trace_entry_head *field; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1120 | struct trace_seq *s = &iter->seq; |
Masami Hiramatsu | eca0d91 | 2009-09-10 19:53:38 -0400 | [diff] [blame] | 1121 | struct trace_probe *tp; |
Masami Hiramatsu | 93ccae7 | 2010-04-12 13:17:08 -0400 | [diff] [blame] | 1122 | u8 *data; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1123 | int i; |
| 1124 | |
Masami Hiramatsu | 93ccae7 | 2010-04-12 13:17:08 -0400 | [diff] [blame] | 1125 | field = (struct kretprobe_trace_entry_head *)iter->ent; |
Steven Rostedt | 80decc7 | 2010-04-23 10:00:22 -0400 | [diff] [blame] | 1126 | tp = container_of(event, struct trace_probe, call.event); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1127 | |
Steven Rostedt (Red Hat) | 687fcc4 | 2015-05-13 14:20:14 -0400 | [diff] [blame] | 1128 | trace_seq_printf(s, "%s: (", trace_event_name(&tp->call)); |
Masami Hiramatsu | 6e9f23d | 2009-09-10 19:53:45 -0400 | [diff] [blame] | 1129 | |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1130 | if (!seq_print_ip_sym(s, field->ret_ip, flags | TRACE_ITER_SYM_OFFSET)) |
Steven Rostedt (Red Hat) | 85224da | 2014-11-12 15:18:16 -0500 | [diff] [blame] | 1131 | goto out; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1132 | |
Steven Rostedt (Red Hat) | 85224da | 2014-11-12 15:18:16 -0500 | [diff] [blame] | 1133 | trace_seq_puts(s, " <- "); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1134 | |
| 1135 | if (!seq_print_ip_sym(s, field->func, flags & ~TRACE_ITER_SYM_OFFSET)) |
Steven Rostedt (Red Hat) | 85224da | 2014-11-12 15:18:16 -0500 | [diff] [blame] | 1136 | goto out; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1137 | |
Steven Rostedt (Red Hat) | 85224da | 2014-11-12 15:18:16 -0500 | [diff] [blame] | 1138 | trace_seq_putc(s, ')'); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1139 | |
Masami Hiramatsu | 93ccae7 | 2010-04-12 13:17:08 -0400 | [diff] [blame] | 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, |
Masami Hiramatsu | e09c861 | 2010-07-05 15:54:45 -0300 | [diff] [blame] | 1143 | data + tp->args[i].offset, field)) |
Steven Rostedt (Red Hat) | 85224da | 2014-11-12 15:18:16 -0500 | [diff] [blame] | 1144 | goto out; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1145 | |
Steven Rostedt (Red Hat) | 85224da | 2014-11-12 15:18:16 -0500 | [diff] [blame] | 1146 | trace_seq_putc(s, '\n'); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1147 | |
Steven Rostedt (Red Hat) | 85224da | 2014-11-12 15:18:16 -0500 | [diff] [blame] | 1148 | out: |
| 1149 | return trace_handle_return(s); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1150 | } |
| 1151 | |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1152 | |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 1153 | static int kprobe_event_define_fields(struct trace_event_call *event_call) |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1154 | { |
| 1155 | int ret, i; |
Masami Hiramatsu | 93ccae7 | 2010-04-12 13:17:08 -0400 | [diff] [blame] | 1156 | struct kprobe_trace_entry_head field; |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1157 | struct trace_kprobe *tk = (struct trace_kprobe *)event_call->data; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1158 | |
Masami Hiramatsu | a703d94 | 2009-10-07 18:28:07 -0400 | [diff] [blame] | 1159 | DEFINE_FIELD(unsigned long, ip, FIELD_STRING_IP, 0); |
Masami Hiramatsu | eca0d91 | 2009-09-10 19:53:38 -0400 | [diff] [blame] | 1160 | /* Set argument names as fields */ |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1161 | for (i = 0; i < tk->tp.nr_args; i++) { |
| 1162 | struct probe_arg *parg = &tk->tp.args[i]; |
| 1163 | |
| 1164 | ret = trace_define_field(event_call, parg->type->fmttype, |
| 1165 | parg->name, |
| 1166 | sizeof(field) + parg->offset, |
| 1167 | parg->type->size, |
| 1168 | parg->type->is_signed, |
Masami Hiramatsu | 93ccae7 | 2010-04-12 13:17:08 -0400 | [diff] [blame] | 1169 | FILTER_OTHER); |
| 1170 | if (ret) |
| 1171 | return ret; |
| 1172 | } |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1173 | return 0; |
| 1174 | } |
| 1175 | |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 1176 | static int kretprobe_event_define_fields(struct trace_event_call *event_call) |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1177 | { |
| 1178 | int ret, i; |
Masami Hiramatsu | 93ccae7 | 2010-04-12 13:17:08 -0400 | [diff] [blame] | 1179 | struct kretprobe_trace_entry_head field; |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1180 | struct trace_kprobe *tk = (struct trace_kprobe *)event_call->data; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1181 | |
Masami Hiramatsu | a703d94 | 2009-10-07 18:28:07 -0400 | [diff] [blame] | 1182 | DEFINE_FIELD(unsigned long, func, FIELD_STRING_FUNC, 0); |
| 1183 | DEFINE_FIELD(unsigned long, ret_ip, FIELD_STRING_RETIP, 0); |
Masami Hiramatsu | eca0d91 | 2009-09-10 19:53:38 -0400 | [diff] [blame] | 1184 | /* Set argument names as fields */ |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1185 | for (i = 0; i < tk->tp.nr_args; i++) { |
| 1186 | struct probe_arg *parg = &tk->tp.args[i]; |
| 1187 | |
| 1188 | ret = trace_define_field(event_call, parg->type->fmttype, |
| 1189 | parg->name, |
| 1190 | sizeof(field) + parg->offset, |
| 1191 | parg->type->size, |
| 1192 | parg->type->is_signed, |
Masami Hiramatsu | 93ccae7 | 2010-04-12 13:17:08 -0400 | [diff] [blame] | 1193 | FILTER_OTHER); |
| 1194 | if (ret) |
| 1195 | return ret; |
| 1196 | } |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1197 | return 0; |
| 1198 | } |
| 1199 | |
Li Zefan | 07b139c | 2009-12-21 14:27:35 +0800 | [diff] [blame] | 1200 | #ifdef CONFIG_PERF_EVENTS |
Masami Hiramatsu | e08d1c6 | 2009-09-10 19:53:30 -0400 | [diff] [blame] | 1201 | |
| 1202 | /* Kprobe profile handler */ |
Josef Bacik | 9802d86 | 2017-12-11 11:36:48 -0500 | [diff] [blame] | 1203 | static int |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1204 | kprobe_perf_func(struct trace_kprobe *tk, struct pt_regs *regs) |
Masami Hiramatsu | e08d1c6 | 2009-09-10 19:53:30 -0400 | [diff] [blame] | 1205 | { |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 1206 | struct trace_event_call *call = &tk->tp.call; |
Masami Hiramatsu | 93ccae7 | 2010-04-12 13:17:08 -0400 | [diff] [blame] | 1207 | struct kprobe_trace_entry_head *entry; |
Peter Zijlstra | 1c024eca | 2010-05-19 14:02:22 +0200 | [diff] [blame] | 1208 | struct hlist_head *head; |
Masami Hiramatsu | e09c861 | 2010-07-05 15:54:45 -0300 | [diff] [blame] | 1209 | int size, __size, dsize; |
Peter Zijlstra | 4ed7c92 | 2009-11-23 11:37:29 +0100 | [diff] [blame] | 1210 | int rctx; |
Masami Hiramatsu | e08d1c6 | 2009-09-10 19:53:30 -0400 | [diff] [blame] | 1211 | |
Josef Bacik | 9802d86 | 2017-12-11 11:36:48 -0500 | [diff] [blame] | 1212 | if (bpf_prog_array_valid(call)) { |
Masami Hiramatsu | 66665ad | 2018-01-13 02:54:33 +0900 | [diff] [blame] | 1213 | unsigned long orig_ip = instruction_pointer(regs); |
Josef Bacik | 9802d86 | 2017-12-11 11:36:48 -0500 | [diff] [blame] | 1214 | int ret; |
| 1215 | |
| 1216 | ret = trace_call_bpf(call, regs); |
| 1217 | |
| 1218 | /* |
| 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 |
Masami Hiramatsu | 66665ad | 2018-01-13 02:54:33 +0900 | [diff] [blame] | 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. |
Josef Bacik | 9802d86 | 2017-12-11 11:36:48 -0500 | [diff] [blame] | 1224 | */ |
Masami Hiramatsu | 66665ad | 2018-01-13 02:54:33 +0900 | [diff] [blame] | 1225 | if (orig_ip != instruction_pointer(regs)) { |
Josef Bacik | 9802d86 | 2017-12-11 11:36:48 -0500 | [diff] [blame] | 1226 | reset_current_kprobe(); |
Masami Hiramatsu | 66665ad | 2018-01-13 02:54:33 +0900 | [diff] [blame] | 1227 | preempt_enable_no_resched(); |
Josef Bacik | 9802d86 | 2017-12-11 11:36:48 -0500 | [diff] [blame] | 1228 | return 1; |
| 1229 | } |
| 1230 | if (!ret) |
| 1231 | return 0; |
| 1232 | } |
Alexei Starovoitov | 2541517 | 2015-03-25 12:49:20 -0700 | [diff] [blame] | 1233 | |
Oleg Nesterov | 288e984 | 2013-06-20 19:38:06 +0200 | [diff] [blame] | 1234 | head = this_cpu_ptr(call->perf_events); |
| 1235 | if (hlist_empty(head)) |
Josef Bacik | 9802d86 | 2017-12-11 11:36:48 -0500 | [diff] [blame] | 1236 | return 0; |
Oleg Nesterov | 288e984 | 2013-06-20 19:38:06 +0200 | [diff] [blame] | 1237 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1238 | dsize = __get_data_size(&tk->tp, regs); |
| 1239 | __size = sizeof(*entry) + tk->tp.size + dsize; |
Masami Hiramatsu | 74ebb63 | 2009-09-14 16:49:28 -0400 | [diff] [blame] | 1240 | size = ALIGN(__size + sizeof(u32), sizeof(u64)); |
| 1241 | size -= sizeof(u32); |
Masami Hiramatsu | e08d1c6 | 2009-09-10 19:53:30 -0400 | [diff] [blame] | 1242 | |
Alexei Starovoitov | 1e1dcd9 | 2016-04-06 18:43:24 -0700 | [diff] [blame] | 1243 | entry = perf_trace_buf_alloc(size, NULL, &rctx); |
Xiao Guangrong | 430ad5a | 2010-01-28 09:32:29 +0800 | [diff] [blame] | 1244 | if (!entry) |
Josef Bacik | 9802d86 | 2017-12-11 11:36:48 -0500 | [diff] [blame] | 1245 | return 0; |
Frederic Weisbecker | ce71b9d | 2009-11-22 05:26:55 +0100 | [diff] [blame] | 1246 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1247 | entry->ip = (unsigned long)tk->rp.kp.addr; |
Masami Hiramatsu | e09c861 | 2010-07-05 15:54:45 -0300 | [diff] [blame] | 1248 | memset(&entry[1], 0, dsize); |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1249 | store_trace_args(sizeof(*entry), &tk->tp, regs, (u8 *)&entry[1], dsize); |
Alexei Starovoitov | 1e1dcd9 | 2016-04-06 18:43:24 -0700 | [diff] [blame] | 1250 | perf_trace_buf_submit(entry, size, rctx, call->event.type, 1, regs, |
Peter Zijlstra | 8fd0fbb | 2017-10-11 09:45:29 +0200 | [diff] [blame] | 1251 | head, NULL); |
Josef Bacik | 9802d86 | 2017-12-11 11:36:48 -0500 | [diff] [blame] | 1252 | return 0; |
Masami Hiramatsu | e08d1c6 | 2009-09-10 19:53:30 -0400 | [diff] [blame] | 1253 | } |
Masami Hiramatsu | 3da0f18 | 2014-04-17 17:18:28 +0900 | [diff] [blame] | 1254 | NOKPROBE_SYMBOL(kprobe_perf_func); |
Masami Hiramatsu | e08d1c6 | 2009-09-10 19:53:30 -0400 | [diff] [blame] | 1255 | |
| 1256 | /* Kretprobe profile handler */ |
Masami Hiramatsu | 3da0f18 | 2014-04-17 17:18:28 +0900 | [diff] [blame] | 1257 | static void |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1258 | kretprobe_perf_func(struct trace_kprobe *tk, struct kretprobe_instance *ri, |
Masami Hiramatsu | 2b106aa | 2013-05-09 14:44:41 +0900 | [diff] [blame] | 1259 | struct pt_regs *regs) |
Masami Hiramatsu | e08d1c6 | 2009-09-10 19:53:30 -0400 | [diff] [blame] | 1260 | { |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 1261 | struct trace_event_call *call = &tk->tp.call; |
Masami Hiramatsu | 93ccae7 | 2010-04-12 13:17:08 -0400 | [diff] [blame] | 1262 | struct kretprobe_trace_entry_head *entry; |
Peter Zijlstra | 1c024eca | 2010-05-19 14:02:22 +0200 | [diff] [blame] | 1263 | struct hlist_head *head; |
Masami Hiramatsu | e09c861 | 2010-07-05 15:54:45 -0300 | [diff] [blame] | 1264 | int size, __size, dsize; |
Peter Zijlstra | 4ed7c92 | 2009-11-23 11:37:29 +0100 | [diff] [blame] | 1265 | int rctx; |
Masami Hiramatsu | e08d1c6 | 2009-09-10 19:53:30 -0400 | [diff] [blame] | 1266 | |
Yonghong Song | e87c6bc | 2017-10-23 23:53:08 -0700 | [diff] [blame] | 1267 | if (bpf_prog_array_valid(call) && !trace_call_bpf(call, regs)) |
Alexei Starovoitov | 2541517 | 2015-03-25 12:49:20 -0700 | [diff] [blame] | 1268 | return; |
| 1269 | |
Oleg Nesterov | 288e984 | 2013-06-20 19:38:06 +0200 | [diff] [blame] | 1270 | head = this_cpu_ptr(call->perf_events); |
| 1271 | if (hlist_empty(head)) |
| 1272 | return; |
| 1273 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1274 | dsize = __get_data_size(&tk->tp, regs); |
| 1275 | __size = sizeof(*entry) + tk->tp.size + dsize; |
Masami Hiramatsu | 74ebb63 | 2009-09-14 16:49:28 -0400 | [diff] [blame] | 1276 | size = ALIGN(__size + sizeof(u32), sizeof(u64)); |
| 1277 | size -= sizeof(u32); |
Masami Hiramatsu | e08d1c6 | 2009-09-10 19:53:30 -0400 | [diff] [blame] | 1278 | |
Alexei Starovoitov | 1e1dcd9 | 2016-04-06 18:43:24 -0700 | [diff] [blame] | 1279 | entry = perf_trace_buf_alloc(size, NULL, &rctx); |
Xiao Guangrong | 430ad5a | 2010-01-28 09:32:29 +0800 | [diff] [blame] | 1280 | if (!entry) |
Xiao Guangrong | 1e12a4a | 2010-01-28 09:34:27 +0800 | [diff] [blame] | 1281 | return; |
Frederic Weisbecker | ce71b9d | 2009-11-22 05:26:55 +0100 | [diff] [blame] | 1282 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1283 | entry->func = (unsigned long)tk->rp.kp.addr; |
Masami Hiramatsu | a1a138d | 2009-09-25 11:20:12 -0700 | [diff] [blame] | 1284 | entry->ret_ip = (unsigned long)ri->ret_addr; |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1285 | store_trace_args(sizeof(*entry), &tk->tp, regs, (u8 *)&entry[1], dsize); |
Alexei Starovoitov | 1e1dcd9 | 2016-04-06 18:43:24 -0700 | [diff] [blame] | 1286 | perf_trace_buf_submit(entry, size, rctx, call->event.type, 1, regs, |
Peter Zijlstra | 8fd0fbb | 2017-10-11 09:45:29 +0200 | [diff] [blame] | 1287 | head, NULL); |
Masami Hiramatsu | e08d1c6 | 2009-09-10 19:53:30 -0400 | [diff] [blame] | 1288 | } |
Masami Hiramatsu | 3da0f18 | 2014-04-17 17:18:28 +0900 | [diff] [blame] | 1289 | NOKPROBE_SYMBOL(kretprobe_perf_func); |
Yonghong Song | 41bdc4b | 2018-05-24 11:21:09 -0700 | [diff] [blame] | 1290 | |
| 1291 | int bpf_get_kprobe_info(const struct perf_event *event, u32 *fd_type, |
| 1292 | const char **symbol, u64 *probe_offset, |
| 1293 | u64 *probe_addr, bool perf_type_tracepoint) |
| 1294 | { |
| 1295 | const char *pevent = trace_event_name(event->tp_event); |
| 1296 | const char *group = event->tp_event->class->system; |
| 1297 | struct trace_kprobe *tk; |
| 1298 | |
| 1299 | if (perf_type_tracepoint) |
| 1300 | tk = find_trace_kprobe(pevent, group); |
| 1301 | else |
| 1302 | tk = event->tp_event->data; |
| 1303 | if (!tk) |
| 1304 | return -EINVAL; |
| 1305 | |
| 1306 | *fd_type = trace_kprobe_is_return(tk) ? BPF_FD_TYPE_KRETPROBE |
| 1307 | : BPF_FD_TYPE_KPROBE; |
| 1308 | if (tk->symbol) { |
| 1309 | *symbol = tk->symbol; |
| 1310 | *probe_offset = tk->rp.kp.offset; |
| 1311 | *probe_addr = 0; |
| 1312 | } else { |
| 1313 | *symbol = NULL; |
| 1314 | *probe_offset = 0; |
| 1315 | *probe_addr = (unsigned long)tk->rp.kp.addr; |
| 1316 | } |
| 1317 | return 0; |
| 1318 | } |
Li Zefan | 07b139c | 2009-12-21 14:27:35 +0800 | [diff] [blame] | 1319 | #endif /* CONFIG_PERF_EVENTS */ |
Masami Hiramatsu | 50d7805 | 2009-09-14 16:49:20 -0400 | [diff] [blame] | 1320 | |
Oleg Nesterov | 3fe3d61 | 2013-06-20 19:38:09 +0200 | [diff] [blame] | 1321 | /* |
| 1322 | * called by perf_trace_init() or __ftrace_set_clr_event() under event_mutex. |
| 1323 | * |
| 1324 | * kprobe_trace_self_tests_init() does enable_trace_probe/disable_trace_probe |
| 1325 | * lockless, but we can't race with this __init function. |
| 1326 | */ |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 1327 | static int kprobe_register(struct trace_event_call *event, |
Masami Hiramatsu | fbc1963 | 2014-04-17 17:18:00 +0900 | [diff] [blame] | 1328 | enum trace_reg type, void *data) |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 1329 | { |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1330 | struct trace_kprobe *tk = (struct trace_kprobe *)event->data; |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 1331 | struct trace_event_file *file = data; |
Masami Hiramatsu | 1538f88 | 2011-06-27 16:26:44 +0900 | [diff] [blame] | 1332 | |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 1333 | switch (type) { |
| 1334 | case TRACE_REG_REGISTER: |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1335 | return enable_trace_kprobe(tk, file); |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 1336 | case TRACE_REG_UNREGISTER: |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1337 | return disable_trace_kprobe(tk, file); |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 1338 | |
| 1339 | #ifdef CONFIG_PERF_EVENTS |
| 1340 | case TRACE_REG_PERF_REGISTER: |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1341 | return enable_trace_kprobe(tk, NULL); |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 1342 | case TRACE_REG_PERF_UNREGISTER: |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1343 | return disable_trace_kprobe(tk, NULL); |
Jiri Olsa | ceec0b6 | 2012-02-15 15:51:49 +0100 | [diff] [blame] | 1344 | case TRACE_REG_PERF_OPEN: |
| 1345 | case TRACE_REG_PERF_CLOSE: |
Jiri Olsa | 489c75c | 2012-02-15 15:51:50 +0100 | [diff] [blame] | 1346 | case TRACE_REG_PERF_ADD: |
| 1347 | case TRACE_REG_PERF_DEL: |
Jiri Olsa | ceec0b6 | 2012-02-15 15:51:49 +0100 | [diff] [blame] | 1348 | return 0; |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 1349 | #endif |
| 1350 | } |
| 1351 | return 0; |
| 1352 | } |
Masami Hiramatsu | 50d7805 | 2009-09-14 16:49:20 -0400 | [diff] [blame] | 1353 | |
Masami Hiramatsu | 3da0f18 | 2014-04-17 17:18:28 +0900 | [diff] [blame] | 1354 | static int kprobe_dispatcher(struct kprobe *kp, struct pt_regs *regs) |
Masami Hiramatsu | 50d7805 | 2009-09-14 16:49:20 -0400 | [diff] [blame] | 1355 | { |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1356 | struct trace_kprobe *tk = container_of(kp, struct trace_kprobe, rp.kp); |
Josef Bacik | 9802d86 | 2017-12-11 11:36:48 -0500 | [diff] [blame] | 1357 | int ret = 0; |
Masami Hiramatsu | 50d7805 | 2009-09-14 16:49:20 -0400 | [diff] [blame] | 1358 | |
Martin KaFai Lau | a7636d9 | 2016-02-03 12:28:28 -0800 | [diff] [blame] | 1359 | raw_cpu_inc(*tk->nhit); |
Masami Hiramatsu | 48182bd | 2013-05-09 14:44:36 +0900 | [diff] [blame] | 1360 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1361 | if (tk->tp.flags & TP_FLAG_TRACE) |
| 1362 | kprobe_trace_func(tk, regs); |
Li Zefan | 07b139c | 2009-12-21 14:27:35 +0800 | [diff] [blame] | 1363 | #ifdef CONFIG_PERF_EVENTS |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1364 | if (tk->tp.flags & TP_FLAG_PROFILE) |
Josef Bacik | 9802d86 | 2017-12-11 11:36:48 -0500 | [diff] [blame] | 1365 | ret = kprobe_perf_func(tk, regs); |
Li Zefan | 07b139c | 2009-12-21 14:27:35 +0800 | [diff] [blame] | 1366 | #endif |
Josef Bacik | 9802d86 | 2017-12-11 11:36:48 -0500 | [diff] [blame] | 1367 | return ret; |
Masami Hiramatsu | e08d1c6 | 2009-09-10 19:53:30 -0400 | [diff] [blame] | 1368 | } |
Masami Hiramatsu | 3da0f18 | 2014-04-17 17:18:28 +0900 | [diff] [blame] | 1369 | NOKPROBE_SYMBOL(kprobe_dispatcher); |
Masami Hiramatsu | e08d1c6 | 2009-09-10 19:53:30 -0400 | [diff] [blame] | 1370 | |
Masami Hiramatsu | 3da0f18 | 2014-04-17 17:18:28 +0900 | [diff] [blame] | 1371 | static int |
| 1372 | kretprobe_dispatcher(struct kretprobe_instance *ri, struct pt_regs *regs) |
Masami Hiramatsu | 50d7805 | 2009-09-14 16:49:20 -0400 | [diff] [blame] | 1373 | { |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1374 | struct trace_kprobe *tk = container_of(ri->rp, struct trace_kprobe, rp); |
Masami Hiramatsu | 50d7805 | 2009-09-14 16:49:20 -0400 | [diff] [blame] | 1375 | |
Martin KaFai Lau | a7636d9 | 2016-02-03 12:28:28 -0800 | [diff] [blame] | 1376 | raw_cpu_inc(*tk->nhit); |
Masami Hiramatsu | 48182bd | 2013-05-09 14:44:36 +0900 | [diff] [blame] | 1377 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1378 | if (tk->tp.flags & TP_FLAG_TRACE) |
| 1379 | kretprobe_trace_func(tk, ri, regs); |
Li Zefan | 07b139c | 2009-12-21 14:27:35 +0800 | [diff] [blame] | 1380 | #ifdef CONFIG_PERF_EVENTS |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1381 | if (tk->tp.flags & TP_FLAG_PROFILE) |
| 1382 | kretprobe_perf_func(tk, ri, regs); |
Li Zefan | 07b139c | 2009-12-21 14:27:35 +0800 | [diff] [blame] | 1383 | #endif |
Masami Hiramatsu | 50d7805 | 2009-09-14 16:49:20 -0400 | [diff] [blame] | 1384 | return 0; /* We don't tweek kernel, so just return 0 */ |
| 1385 | } |
Masami Hiramatsu | 3da0f18 | 2014-04-17 17:18:28 +0900 | [diff] [blame] | 1386 | NOKPROBE_SYMBOL(kretprobe_dispatcher); |
Masami Hiramatsu | e08d1c6 | 2009-09-10 19:53:30 -0400 | [diff] [blame] | 1387 | |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 1388 | static struct trace_event_functions kretprobe_funcs = { |
| 1389 | .trace = print_kretprobe_event |
| 1390 | }; |
| 1391 | |
| 1392 | static struct trace_event_functions kprobe_funcs = { |
| 1393 | .trace = print_kprobe_event |
| 1394 | }; |
| 1395 | |
Song Liu | e12f03d | 2017-12-06 14:45:15 -0800 | [diff] [blame] | 1396 | static inline void init_trace_event_call(struct trace_kprobe *tk, |
| 1397 | struct trace_event_call *call) |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1398 | { |
Li Zefan | ffb9f99 | 2010-05-24 16:24:52 +0800 | [diff] [blame] | 1399 | INIT_LIST_HEAD(&call->class->fields); |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1400 | if (trace_kprobe_is_return(tk)) { |
Steven Rostedt | 80decc7 | 2010-04-23 10:00:22 -0400 | [diff] [blame] | 1401 | call->event.funcs = &kretprobe_funcs; |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame] | 1402 | call->class->define_fields = kretprobe_event_define_fields; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1403 | } else { |
Steven Rostedt | 80decc7 | 2010-04-23 10:00:22 -0400 | [diff] [blame] | 1404 | call->event.funcs = &kprobe_funcs; |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame] | 1405 | call->class->define_fields = kprobe_event_define_fields; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1406 | } |
Song Liu | e12f03d | 2017-12-06 14:45:15 -0800 | [diff] [blame] | 1407 | |
| 1408 | call->flags = TRACE_EVENT_FL_KPROBE; |
| 1409 | call->class->reg = kprobe_register; |
| 1410 | call->data = tk; |
| 1411 | } |
| 1412 | |
| 1413 | static int register_kprobe_event(struct trace_kprobe *tk) |
| 1414 | { |
| 1415 | struct trace_event_call *call = &tk->tp.call; |
| 1416 | int ret = 0; |
| 1417 | |
| 1418 | init_trace_event_call(tk, call); |
| 1419 | |
Namhyung Kim | 5bf652a | 2013-07-03 16:09:02 +0900 | [diff] [blame] | 1420 | if (set_print_fmt(&tk->tp, trace_kprobe_is_return(tk)) < 0) |
Lai Jiangshan | a342a028 | 2009-12-15 15:39:49 +0800 | [diff] [blame] | 1421 | return -ENOMEM; |
Steven Rostedt (Red Hat) | 9023c93 | 2015-05-05 09:39:12 -0400 | [diff] [blame] | 1422 | ret = register_trace_event(&call->event); |
Steven Rostedt | 32c0eda | 2010-04-23 10:38:03 -0400 | [diff] [blame] | 1423 | if (!ret) { |
Lai Jiangshan | a342a028 | 2009-12-15 15:39:49 +0800 | [diff] [blame] | 1424 | kfree(call->print_fmt); |
Masami Hiramatsu | ff50d99 | 2009-08-13 16:35:34 -0400 | [diff] [blame] | 1425 | return -ENODEV; |
Lai Jiangshan | a342a028 | 2009-12-15 15:39:49 +0800 | [diff] [blame] | 1426 | } |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1427 | ret = trace_add_event_call(call); |
Masami Hiramatsu | ff50d99 | 2009-08-13 16:35:34 -0400 | [diff] [blame] | 1428 | if (ret) { |
Mathieu Desnoyers | de7b297 | 2014-04-08 17:26:21 -0400 | [diff] [blame] | 1429 | pr_info("Failed to register kprobe event: %s\n", |
Steven Rostedt (Red Hat) | 687fcc4 | 2015-05-13 14:20:14 -0400 | [diff] [blame] | 1430 | trace_event_name(call)); |
Lai Jiangshan | a342a028 | 2009-12-15 15:39:49 +0800 | [diff] [blame] | 1431 | kfree(call->print_fmt); |
Steven Rostedt (Red Hat) | 9023c93 | 2015-05-05 09:39:12 -0400 | [diff] [blame] | 1432 | unregister_trace_event(&call->event); |
Masami Hiramatsu | ff50d99 | 2009-08-13 16:35:34 -0400 | [diff] [blame] | 1433 | } |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1434 | return ret; |
| 1435 | } |
| 1436 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1437 | static int unregister_kprobe_event(struct trace_kprobe *tk) |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1438 | { |
Steven Rostedt (Red Hat) | 40c3259 | 2013-07-03 23:33:50 -0400 | [diff] [blame] | 1439 | int ret; |
| 1440 | |
Masami Hiramatsu | ff50d99 | 2009-08-13 16:35:34 -0400 | [diff] [blame] | 1441 | /* tp->event is unregistered in trace_remove_event_call() */ |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1442 | ret = trace_remove_event_call(&tk->tp.call); |
Steven Rostedt (Red Hat) | 40c3259 | 2013-07-03 23:33:50 -0400 | [diff] [blame] | 1443 | if (!ret) |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1444 | kfree(tk->tp.call.print_fmt); |
Steven Rostedt (Red Hat) | 40c3259 | 2013-07-03 23:33:50 -0400 | [diff] [blame] | 1445 | return ret; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1446 | } |
| 1447 | |
Song Liu | e12f03d | 2017-12-06 14:45:15 -0800 | [diff] [blame] | 1448 | #ifdef CONFIG_PERF_EVENTS |
| 1449 | /* create a trace_kprobe, but don't add it to global lists */ |
| 1450 | struct trace_event_call * |
| 1451 | create_local_trace_kprobe(char *func, void *addr, unsigned long offs, |
| 1452 | bool is_return) |
| 1453 | { |
| 1454 | struct trace_kprobe *tk; |
| 1455 | int ret; |
| 1456 | char *event; |
| 1457 | |
| 1458 | /* |
| 1459 | * local trace_kprobes are not added to probe_list, so they are never |
| 1460 | * searched in find_trace_kprobe(). Therefore, there is no concern of |
| 1461 | * duplicated name here. |
| 1462 | */ |
| 1463 | event = func ? func : "DUMMY_EVENT"; |
| 1464 | |
| 1465 | tk = alloc_trace_kprobe(KPROBE_EVENT_SYSTEM, event, (void *)addr, func, |
| 1466 | offs, 0 /* maxactive */, 0 /* nargs */, |
| 1467 | is_return); |
| 1468 | |
| 1469 | if (IS_ERR(tk)) { |
| 1470 | pr_info("Failed to allocate trace_probe.(%d)\n", |
| 1471 | (int)PTR_ERR(tk)); |
| 1472 | return ERR_CAST(tk); |
| 1473 | } |
| 1474 | |
| 1475 | init_trace_event_call(tk, &tk->tp.call); |
| 1476 | |
| 1477 | if (set_print_fmt(&tk->tp, trace_kprobe_is_return(tk)) < 0) { |
| 1478 | ret = -ENOMEM; |
| 1479 | goto error; |
| 1480 | } |
| 1481 | |
| 1482 | ret = __register_trace_kprobe(tk); |
| 1483 | if (ret < 0) |
| 1484 | goto error; |
| 1485 | |
| 1486 | return &tk->tp.call; |
| 1487 | error: |
| 1488 | free_trace_kprobe(tk); |
| 1489 | return ERR_PTR(ret); |
| 1490 | } |
| 1491 | |
| 1492 | void destroy_local_trace_kprobe(struct trace_event_call *event_call) |
| 1493 | { |
| 1494 | struct trace_kprobe *tk; |
| 1495 | |
| 1496 | tk = container_of(event_call, struct trace_kprobe, tp.call); |
| 1497 | |
| 1498 | if (trace_probe_is_enabled(&tk->tp)) { |
| 1499 | WARN_ON(1); |
| 1500 | return; |
| 1501 | } |
| 1502 | |
| 1503 | __unregister_trace_kprobe(tk); |
| 1504 | free_trace_kprobe(tk); |
| 1505 | } |
| 1506 | #endif /* CONFIG_PERF_EVENTS */ |
| 1507 | |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 1508 | /* Make a tracefs interface for controlling probe points */ |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1509 | static __init int init_kprobe_trace(void) |
| 1510 | { |
| 1511 | struct dentry *d_tracer; |
| 1512 | struct dentry *entry; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1513 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1514 | if (register_module_notifier(&trace_kprobe_module_nb)) |
Masami Hiramatsu | 6142431 | 2011-06-27 16:26:56 +0900 | [diff] [blame] | 1515 | return -EINVAL; |
| 1516 | |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1517 | d_tracer = tracing_init_dentry(); |
Steven Rostedt (Red Hat) | 14a5ae4 | 2015-01-20 11:14:16 -0500 | [diff] [blame] | 1518 | if (IS_ERR(d_tracer)) |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1519 | return 0; |
| 1520 | |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 1521 | entry = tracefs_create_file("kprobe_events", 0644, d_tracer, |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1522 | NULL, &kprobe_events_ops); |
| 1523 | |
Masami Hiramatsu | cd7e7bd | 2009-08-13 16:35:42 -0400 | [diff] [blame] | 1524 | /* Event list interface */ |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1525 | if (!entry) |
Joe Perches | a395d6a | 2016-03-22 14:28:09 -0700 | [diff] [blame] | 1526 | pr_warn("Could not create tracefs 'kprobe_events' entry\n"); |
Masami Hiramatsu | cd7e7bd | 2009-08-13 16:35:42 -0400 | [diff] [blame] | 1527 | |
| 1528 | /* Profile interface */ |
Steven Rostedt (Red Hat) | 8434dc9 | 2015-01-20 12:13:40 -0500 | [diff] [blame] | 1529 | entry = tracefs_create_file("kprobe_profile", 0444, d_tracer, |
Masami Hiramatsu | cd7e7bd | 2009-08-13 16:35:42 -0400 | [diff] [blame] | 1530 | NULL, &kprobe_profile_ops); |
| 1531 | |
| 1532 | if (!entry) |
Joe Perches | a395d6a | 2016-03-22 14:28:09 -0700 | [diff] [blame] | 1533 | pr_warn("Could not create tracefs 'kprobe_profile' entry\n"); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1534 | return 0; |
| 1535 | } |
| 1536 | fs_initcall(init_kprobe_trace); |
| 1537 | |
| 1538 | |
| 1539 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
Steven Rostedt | 265a5b7 | 2011-06-06 22:35:13 -0400 | [diff] [blame] | 1540 | /* |
| 1541 | * The "__used" keeps gcc from removing the function symbol |
Marcin Nowakowski | d4d7ccc | 2016-12-09 15:19:38 +0100 | [diff] [blame] | 1542 | * from the kallsyms table. 'noinline' makes sure that there |
| 1543 | * isn't an inlined version used by the test method below |
Steven Rostedt | 265a5b7 | 2011-06-06 22:35:13 -0400 | [diff] [blame] | 1544 | */ |
Marcin Nowakowski | d4d7ccc | 2016-12-09 15:19:38 +0100 | [diff] [blame] | 1545 | static __used __init noinline int |
| 1546 | kprobe_trace_selftest_target(int a1, int a2, int a3, int a4, int a5, int a6) |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1547 | { |
| 1548 | return a1 + a2 + a3 + a4 + a5 + a6; |
| 1549 | } |
| 1550 | |
Arnd Bergmann | 26a346f | 2017-02-01 17:57:56 +0100 | [diff] [blame] | 1551 | static __init struct trace_event_file * |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1552 | find_trace_probe_file(struct trace_kprobe *tk, struct trace_array *tr) |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1553 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 1554 | struct trace_event_file *file; |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1555 | |
| 1556 | list_for_each_entry(file, &tr->events, list) |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1557 | if (file->event_call == &tk->tp.call) |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1558 | return file; |
| 1559 | |
| 1560 | return NULL; |
| 1561 | } |
| 1562 | |
Oleg Nesterov | 3fe3d61 | 2013-06-20 19:38:09 +0200 | [diff] [blame] | 1563 | /* |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1564 | * Nobody but us can call enable_trace_kprobe/disable_trace_kprobe at this |
Oleg Nesterov | 3fe3d61 | 2013-06-20 19:38:09 +0200 | [diff] [blame] | 1565 | * stage, we can do this lockless. |
| 1566 | */ |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1567 | static __init int kprobe_trace_self_tests_init(void) |
| 1568 | { |
Masami Hiramatsu | 231e36f | 2010-01-14 00:12:12 -0500 | [diff] [blame] | 1569 | int ret, warn = 0; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1570 | int (*target)(int, int, int, int, int, int); |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1571 | struct trace_kprobe *tk; |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 1572 | struct trace_event_file *file; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1573 | |
Yoshihiro YUNOMAE | 748ec3a | 2014-06-06 07:35:20 +0900 | [diff] [blame] | 1574 | if (tracing_is_disabled()) |
| 1575 | return -ENODEV; |
| 1576 | |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1577 | target = kprobe_trace_selftest_target; |
| 1578 | |
| 1579 | pr_info("Testing kprobe tracing: "); |
| 1580 | |
Tom Zanussi | 7e465ba | 2017-09-22 14:58:20 -0500 | [diff] [blame] | 1581 | ret = trace_run_command("p:testprobe kprobe_trace_selftest_target " |
| 1582 | "$stack $stack0 +0($stack)", |
| 1583 | create_trace_kprobe); |
Masami Hiramatsu | 231e36f | 2010-01-14 00:12:12 -0500 | [diff] [blame] | 1584 | if (WARN_ON_ONCE(ret)) { |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1585 | pr_warn("error on probing function entry.\n"); |
Masami Hiramatsu | 231e36f | 2010-01-14 00:12:12 -0500 | [diff] [blame] | 1586 | warn++; |
| 1587 | } else { |
| 1588 | /* Enable trace point */ |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1589 | tk = find_trace_kprobe("testprobe", KPROBE_EVENT_SYSTEM); |
| 1590 | if (WARN_ON_ONCE(tk == NULL)) { |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1591 | pr_warn("error on getting new probe.\n"); |
Masami Hiramatsu | 231e36f | 2010-01-14 00:12:12 -0500 | [diff] [blame] | 1592 | warn++; |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1593 | } else { |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1594 | file = find_trace_probe_file(tk, top_trace_array()); |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1595 | if (WARN_ON_ONCE(file == NULL)) { |
| 1596 | pr_warn("error on getting probe file.\n"); |
| 1597 | warn++; |
| 1598 | } else |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1599 | enable_trace_kprobe(tk, file); |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1600 | } |
Masami Hiramatsu | 231e36f | 2010-01-14 00:12:12 -0500 | [diff] [blame] | 1601 | } |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1602 | |
Tom Zanussi | 7e465ba | 2017-09-22 14:58:20 -0500 | [diff] [blame] | 1603 | ret = trace_run_command("r:testprobe2 kprobe_trace_selftest_target " |
| 1604 | "$retval", create_trace_kprobe); |
Masami Hiramatsu | 231e36f | 2010-01-14 00:12:12 -0500 | [diff] [blame] | 1605 | if (WARN_ON_ONCE(ret)) { |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1606 | pr_warn("error on probing function return.\n"); |
Masami Hiramatsu | 231e36f | 2010-01-14 00:12:12 -0500 | [diff] [blame] | 1607 | warn++; |
| 1608 | } else { |
| 1609 | /* Enable trace point */ |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1610 | tk = find_trace_kprobe("testprobe2", KPROBE_EVENT_SYSTEM); |
| 1611 | if (WARN_ON_ONCE(tk == NULL)) { |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1612 | pr_warn("error on getting 2nd new probe.\n"); |
Masami Hiramatsu | 231e36f | 2010-01-14 00:12:12 -0500 | [diff] [blame] | 1613 | warn++; |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1614 | } else { |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1615 | file = find_trace_probe_file(tk, top_trace_array()); |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1616 | if (WARN_ON_ONCE(file == NULL)) { |
| 1617 | pr_warn("error on getting probe file.\n"); |
| 1618 | warn++; |
| 1619 | } else |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1620 | enable_trace_kprobe(tk, file); |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1621 | } |
Masami Hiramatsu | 231e36f | 2010-01-14 00:12:12 -0500 | [diff] [blame] | 1622 | } |
| 1623 | |
| 1624 | if (warn) |
| 1625 | goto end; |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1626 | |
| 1627 | ret = target(1, 2, 3, 4, 5, 6); |
| 1628 | |
Marcin Nowakowski | d4d7ccc | 2016-12-09 15:19:38 +0100 | [diff] [blame] | 1629 | /* |
| 1630 | * Not expecting an error here, the check is only to prevent the |
| 1631 | * optimizer from removing the call to target() as otherwise there |
| 1632 | * are no side-effects and the call is never performed. |
| 1633 | */ |
| 1634 | if (ret != 21) |
| 1635 | warn++; |
| 1636 | |
Masami Hiramatsu | 02ca152 | 2011-10-04 19:44:38 +0900 | [diff] [blame] | 1637 | /* Disable trace points before removing it */ |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1638 | tk = find_trace_kprobe("testprobe", KPROBE_EVENT_SYSTEM); |
| 1639 | if (WARN_ON_ONCE(tk == NULL)) { |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1640 | pr_warn("error on getting test probe.\n"); |
Masami Hiramatsu | 02ca152 | 2011-10-04 19:44:38 +0900 | [diff] [blame] | 1641 | warn++; |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1642 | } else { |
Marcin Nowakowski | d4d7ccc | 2016-12-09 15:19:38 +0100 | [diff] [blame] | 1643 | if (trace_kprobe_nhit(tk) != 1) { |
| 1644 | pr_warn("incorrect number of testprobe hits\n"); |
| 1645 | warn++; |
| 1646 | } |
| 1647 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1648 | file = find_trace_probe_file(tk, top_trace_array()); |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1649 | if (WARN_ON_ONCE(file == NULL)) { |
| 1650 | pr_warn("error on getting probe file.\n"); |
| 1651 | warn++; |
| 1652 | } else |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1653 | disable_trace_kprobe(tk, file); |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1654 | } |
Masami Hiramatsu | 02ca152 | 2011-10-04 19:44:38 +0900 | [diff] [blame] | 1655 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1656 | tk = find_trace_kprobe("testprobe2", KPROBE_EVENT_SYSTEM); |
| 1657 | if (WARN_ON_ONCE(tk == NULL)) { |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1658 | pr_warn("error on getting 2nd test probe.\n"); |
Masami Hiramatsu | 02ca152 | 2011-10-04 19:44:38 +0900 | [diff] [blame] | 1659 | warn++; |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1660 | } else { |
Marcin Nowakowski | d4d7ccc | 2016-12-09 15:19:38 +0100 | [diff] [blame] | 1661 | if (trace_kprobe_nhit(tk) != 1) { |
| 1662 | pr_warn("incorrect number of testprobe2 hits\n"); |
| 1663 | warn++; |
| 1664 | } |
| 1665 | |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1666 | file = find_trace_probe_file(tk, top_trace_array()); |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1667 | if (WARN_ON_ONCE(file == NULL)) { |
| 1668 | pr_warn("error on getting probe file.\n"); |
| 1669 | warn++; |
| 1670 | } else |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1671 | disable_trace_kprobe(tk, file); |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1672 | } |
Masami Hiramatsu | 02ca152 | 2011-10-04 19:44:38 +0900 | [diff] [blame] | 1673 | |
Tom Zanussi | 7e465ba | 2017-09-22 14:58:20 -0500 | [diff] [blame] | 1674 | ret = trace_run_command("-:testprobe", create_trace_kprobe); |
Masami Hiramatsu | 231e36f | 2010-01-14 00:12:12 -0500 | [diff] [blame] | 1675 | if (WARN_ON_ONCE(ret)) { |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1676 | pr_warn("error on deleting a probe.\n"); |
Masami Hiramatsu | 231e36f | 2010-01-14 00:12:12 -0500 | [diff] [blame] | 1677 | warn++; |
| 1678 | } |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1679 | |
Tom Zanussi | 7e465ba | 2017-09-22 14:58:20 -0500 | [diff] [blame] | 1680 | ret = trace_run_command("-:testprobe2", create_trace_kprobe); |
Masami Hiramatsu | 231e36f | 2010-01-14 00:12:12 -0500 | [diff] [blame] | 1681 | if (WARN_ON_ONCE(ret)) { |
Masami Hiramatsu | 41a7dd4 | 2013-05-09 14:44:49 +0900 | [diff] [blame] | 1682 | pr_warn("error on deleting a probe.\n"); |
Masami Hiramatsu | 231e36f | 2010-01-14 00:12:12 -0500 | [diff] [blame] | 1683 | warn++; |
| 1684 | } |
| 1685 | |
| 1686 | end: |
Namhyung Kim | c31ffb3 | 2013-07-03 13:50:51 +0900 | [diff] [blame] | 1687 | release_all_trace_kprobes(); |
Thomas Gleixner | 30e7d894 | 2017-05-17 10:19:49 +0200 | [diff] [blame] | 1688 | /* |
| 1689 | * Wait for the optimizer work to finish. Otherwise it might fiddle |
| 1690 | * with probes in already freed __init text. |
| 1691 | */ |
| 1692 | wait_for_kprobe_optimizer(); |
Masami Hiramatsu | 231e36f | 2010-01-14 00:12:12 -0500 | [diff] [blame] | 1693 | if (warn) |
| 1694 | pr_cont("NG: Some tests are failed. Please check them.\n"); |
| 1695 | else |
| 1696 | pr_cont("OK\n"); |
Masami Hiramatsu | 413d37d | 2009-08-13 16:35:11 -0400 | [diff] [blame] | 1697 | return 0; |
| 1698 | } |
| 1699 | |
| 1700 | late_initcall(kprobe_trace_self_tests_init); |
| 1701 | |
| 1702 | #endif |