Steven Rostedt (VMware) | bcea3f9 | 2018-08-16 11:23:53 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 2 | /* |
| 3 | * uprobes-based tracing events |
| 4 | * |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 5 | * Copyright (C) IBM Corporation, 2010-2012 |
| 6 | * Author: Srikar Dronamraju <srikar@linux.vnet.ibm.com> |
| 7 | */ |
Andreas Ziegler | ea6eb5e | 2019-01-17 14:30:23 +0100 | [diff] [blame] | 8 | #define pr_fmt(fmt) "trace_uprobe: " fmt |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 9 | |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 10 | #include <linux/ctype.h> |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 11 | #include <linux/module.h> |
| 12 | #include <linux/uaccess.h> |
| 13 | #include <linux/uprobes.h> |
| 14 | #include <linux/namei.h> |
Andy Shevchenko | b2e902f | 2012-12-17 16:01:27 -0800 | [diff] [blame] | 15 | #include <linux/string.h> |
Ingo Molnar | b2d0910 | 2017-02-04 01:27:20 +0100 | [diff] [blame] | 16 | #include <linux/rculist.h> |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 17 | |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 18 | #include "trace_dynevent.h" |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 19 | #include "trace_probe.h" |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 20 | #include "trace_probe_tmpl.h" |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 21 | |
| 22 | #define UPROBE_EVENT_SYSTEM "uprobes" |
| 23 | |
Oleg Nesterov | 457d177 | 2013-03-29 18:26:51 +0100 | [diff] [blame] | 24 | struct uprobe_trace_entry_head { |
| 25 | struct trace_entry ent; |
| 26 | unsigned long vaddr[]; |
| 27 | }; |
| 28 | |
| 29 | #define SIZEOF_TRACE_ENTRY(is_return) \ |
| 30 | (sizeof(struct uprobe_trace_entry_head) + \ |
| 31 | sizeof(unsigned long) * (is_return ? 2 : 1)) |
| 32 | |
| 33 | #define DATAOF_TRACE_ENTRY(entry, is_return) \ |
| 34 | ((void*)(entry) + SIZEOF_TRACE_ENTRY(is_return)) |
| 35 | |
Oleg Nesterov | 736288b | 2013-02-03 20:58:35 +0100 | [diff] [blame] | 36 | struct trace_uprobe_filter { |
| 37 | rwlock_t rwlock; |
| 38 | int nr_systemwide; |
| 39 | struct list_head perf_events; |
| 40 | }; |
| 41 | |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 42 | static int trace_uprobe_create(int argc, const char **argv); |
| 43 | static int trace_uprobe_show(struct seq_file *m, struct dyn_event *ev); |
| 44 | static int trace_uprobe_release(struct dyn_event *ev); |
| 45 | static bool trace_uprobe_is_busy(struct dyn_event *ev); |
| 46 | static bool trace_uprobe_match(const char *system, const char *event, |
| 47 | struct dyn_event *ev); |
| 48 | |
| 49 | static struct dyn_event_operations trace_uprobe_ops = { |
| 50 | .create = trace_uprobe_create, |
| 51 | .show = trace_uprobe_show, |
| 52 | .is_busy = trace_uprobe_is_busy, |
| 53 | .free = trace_uprobe_release, |
| 54 | .match = trace_uprobe_match, |
| 55 | }; |
| 56 | |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 57 | /* |
| 58 | * uprobe event core functions |
| 59 | */ |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 60 | struct trace_uprobe { |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 61 | struct dyn_event devent; |
Oleg Nesterov | 736288b | 2013-02-03 20:58:35 +0100 | [diff] [blame] | 62 | struct trace_uprobe_filter filter; |
Oleg Nesterov | a932b73 | 2013-01-31 19:47:23 +0100 | [diff] [blame] | 63 | struct uprobe_consumer consumer; |
Song Liu | 0c92c7a | 2018-04-23 10:21:34 -0700 | [diff] [blame] | 64 | struct path path; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 65 | struct inode *inode; |
| 66 | char *filename; |
| 67 | unsigned long offset; |
Ravi Bangoria | 1cc3316 | 2018-08-20 10:12:47 +0530 | [diff] [blame] | 68 | unsigned long ref_ctr_offset; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 69 | unsigned long nhit; |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame] | 70 | struct trace_probe tp; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 71 | }; |
| 72 | |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 73 | static bool is_trace_uprobe(struct dyn_event *ev) |
| 74 | { |
| 75 | return ev->ops == &trace_uprobe_ops; |
| 76 | } |
| 77 | |
| 78 | static struct trace_uprobe *to_trace_uprobe(struct dyn_event *ev) |
| 79 | { |
| 80 | return container_of(ev, struct trace_uprobe, devent); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * for_each_trace_uprobe - iterate over the trace_uprobe list |
| 85 | * @pos: the struct trace_uprobe * for each entry |
| 86 | * @dpos: the struct dyn_event * to use as a loop cursor |
| 87 | */ |
| 88 | #define for_each_trace_uprobe(pos, dpos) \ |
| 89 | for_each_dyn_event(dpos) \ |
| 90 | if (is_trace_uprobe(dpos) && (pos = to_trace_uprobe(dpos))) |
| 91 | |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame] | 92 | #define SIZEOF_TRACE_UPROBE(n) \ |
| 93 | (offsetof(struct trace_uprobe, tp.args) + \ |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 94 | (sizeof(struct probe_arg) * (n))) |
| 95 | |
| 96 | static int register_uprobe_event(struct trace_uprobe *tu); |
Steven Rostedt (Red Hat) | c6c2401 | 2013-07-03 23:33:51 -0400 | [diff] [blame] | 97 | static int unregister_uprobe_event(struct trace_uprobe *tu); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 98 | |
Namhyung Kim | b7e0bf3 | 2013-11-25 13:42:47 +0900 | [diff] [blame] | 99 | struct uprobe_dispatch_data { |
| 100 | struct trace_uprobe *tu; |
| 101 | unsigned long bp_addr; |
| 102 | }; |
| 103 | |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 104 | static int uprobe_dispatcher(struct uprobe_consumer *con, struct pt_regs *regs); |
Oleg Nesterov | c1ae5c7 | 2013-03-30 18:25:23 +0100 | [diff] [blame] | 105 | static int uretprobe_dispatcher(struct uprobe_consumer *con, |
| 106 | unsigned long func, struct pt_regs *regs); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 107 | |
Namhyung Kim | 3fd996a | 2013-11-26 15:21:04 +0900 | [diff] [blame] | 108 | #ifdef CONFIG_STACK_GROWSUP |
| 109 | static unsigned long adjust_stack_addr(unsigned long addr, unsigned int n) |
| 110 | { |
| 111 | return addr - (n * sizeof(long)); |
| 112 | } |
| 113 | #else |
| 114 | static unsigned long adjust_stack_addr(unsigned long addr, unsigned int n) |
| 115 | { |
| 116 | return addr + (n * sizeof(long)); |
| 117 | } |
| 118 | #endif |
| 119 | |
| 120 | static unsigned long get_user_stack_nth(struct pt_regs *regs, unsigned int n) |
| 121 | { |
| 122 | unsigned long ret; |
| 123 | unsigned long addr = user_stack_pointer(regs); |
| 124 | |
| 125 | addr = adjust_stack_addr(addr, n); |
| 126 | |
| 127 | if (copy_from_user(&ret, (void __force __user *) addr, sizeof(ret))) |
| 128 | return 0; |
| 129 | |
| 130 | return ret; |
| 131 | } |
| 132 | |
| 133 | /* |
| 134 | * Uprobes-specific fetch functions |
| 135 | */ |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 136 | static nokprobe_inline int |
Masami Hiramatsu | 9b960a3 | 2018-04-25 21:19:59 +0900 | [diff] [blame] | 137 | probe_mem_read(void *dest, void *src, size_t size) |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 138 | { |
| 139 | void __user *vaddr = (void __force __user *)src; |
Namhyung Kim | 3fd996a | 2013-11-26 15:21:04 +0900 | [diff] [blame] | 140 | |
Masami Hiramatsu | f3f5893 | 2018-08-29 01:17:47 +0900 | [diff] [blame] | 141 | return copy_from_user(dest, vaddr, size) ? -EFAULT : 0; |
Namhyung Kim | 5baaa59 | 2013-11-26 15:21:04 +0900 | [diff] [blame] | 142 | } |
Masami Hiramatsu | e65f7ae | 2019-05-15 14:38:42 +0900 | [diff] [blame] | 143 | |
| 144 | static nokprobe_inline int |
| 145 | probe_mem_read_user(void *dest, void *src, size_t size) |
| 146 | { |
| 147 | return probe_mem_read(dest, src, size); |
| 148 | } |
| 149 | |
Namhyung Kim | 5baaa59 | 2013-11-26 15:21:04 +0900 | [diff] [blame] | 150 | /* |
| 151 | * Fetch a null-terminated string. Caller MUST set *(u32 *)dest with max |
| 152 | * length and relative data location. |
| 153 | */ |
Masami Hiramatsu | 9178412 | 2018-04-25 21:19:01 +0900 | [diff] [blame] | 154 | static nokprobe_inline int |
| 155 | fetch_store_string(unsigned long addr, void *dest, void *base) |
Namhyung Kim | 5baaa59 | 2013-11-26 15:21:04 +0900 | [diff] [blame] | 156 | { |
| 157 | long ret; |
Masami Hiramatsu | 9178412 | 2018-04-25 21:19:01 +0900 | [diff] [blame] | 158 | u32 loc = *(u32 *)dest; |
| 159 | int maxlen = get_loc_len(loc); |
| 160 | u8 *dst = get_loc_data(dest, base); |
Namhyung Kim | 5baaa59 | 2013-11-26 15:21:04 +0900 | [diff] [blame] | 161 | void __user *src = (void __force __user *) addr; |
| 162 | |
Masami Hiramatsu | 9178412 | 2018-04-25 21:19:01 +0900 | [diff] [blame] | 163 | if (unlikely(!maxlen)) |
| 164 | return -ENOMEM; |
Namhyung Kim | 5baaa59 | 2013-11-26 15:21:04 +0900 | [diff] [blame] | 165 | |
Masami Hiramatsu | 4dd537a | 2019-05-07 22:55:41 +0900 | [diff] [blame] | 166 | if (addr == FETCH_TOKEN_COMM) |
| 167 | ret = strlcpy(dst, current->comm, maxlen); |
| 168 | else |
| 169 | ret = strncpy_from_user(dst, src, maxlen); |
Masami Hiramatsu | 9178412 | 2018-04-25 21:19:01 +0900 | [diff] [blame] | 170 | if (ret >= 0) { |
| 171 | if (ret == maxlen) |
| 172 | dst[ret - 1] = '\0'; |
Andreas Ziegler | 0722069 | 2019-01-16 15:16:29 +0100 | [diff] [blame] | 173 | else |
| 174 | /* |
| 175 | * Include the terminating null byte. In this case it |
| 176 | * was copied by strncpy_from_user but not accounted |
| 177 | * for in ret. |
| 178 | */ |
| 179 | ret++; |
Masami Hiramatsu | 9178412 | 2018-04-25 21:19:01 +0900 | [diff] [blame] | 180 | *(u32 *)dest = make_data_loc(ret, (void *)dst - base); |
Namhyung Kim | 5baaa59 | 2013-11-26 15:21:04 +0900 | [diff] [blame] | 181 | } |
Masami Hiramatsu | 9178412 | 2018-04-25 21:19:01 +0900 | [diff] [blame] | 182 | |
| 183 | return ret; |
Namhyung Kim | 5baaa59 | 2013-11-26 15:21:04 +0900 | [diff] [blame] | 184 | } |
| 185 | |
Masami Hiramatsu | 88903c4 | 2019-05-15 14:38:30 +0900 | [diff] [blame] | 186 | static nokprobe_inline int |
| 187 | fetch_store_string_user(unsigned long addr, void *dest, void *base) |
| 188 | { |
| 189 | return fetch_store_string(addr, dest, base); |
| 190 | } |
| 191 | |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 192 | /* Return the length of string -- including null terminal byte */ |
Masami Hiramatsu | 9178412 | 2018-04-25 21:19:01 +0900 | [diff] [blame] | 193 | static nokprobe_inline int |
| 194 | fetch_store_strlen(unsigned long addr) |
Namhyung Kim | 5baaa59 | 2013-11-26 15:21:04 +0900 | [diff] [blame] | 195 | { |
| 196 | int len; |
| 197 | void __user *vaddr = (void __force __user *) addr; |
| 198 | |
Masami Hiramatsu | 4dd537a | 2019-05-07 22:55:41 +0900 | [diff] [blame] | 199 | if (addr == FETCH_TOKEN_COMM) |
| 200 | len = strlen(current->comm) + 1; |
| 201 | else |
| 202 | len = strnlen_user(vaddr, MAX_STRING_SIZE); |
Namhyung Kim | 5baaa59 | 2013-11-26 15:21:04 +0900 | [diff] [blame] | 203 | |
Masami Hiramatsu | 9178412 | 2018-04-25 21:19:01 +0900 | [diff] [blame] | 204 | return (len > MAX_STRING_SIZE) ? 0 : len; |
Namhyung Kim | 5baaa59 | 2013-11-26 15:21:04 +0900 | [diff] [blame] | 205 | } |
Namhyung Kim | 3fd996a | 2013-11-26 15:21:04 +0900 | [diff] [blame] | 206 | |
Masami Hiramatsu | 88903c4 | 2019-05-15 14:38:30 +0900 | [diff] [blame] | 207 | static nokprobe_inline int |
| 208 | fetch_store_strlen_user(unsigned long addr) |
| 209 | { |
| 210 | return fetch_store_strlen(addr); |
| 211 | } |
| 212 | |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 213 | static unsigned long translate_user_vaddr(unsigned long file_offset) |
Namhyung Kim | b7e0bf3 | 2013-11-25 13:42:47 +0900 | [diff] [blame] | 214 | { |
| 215 | unsigned long base_addr; |
| 216 | struct uprobe_dispatch_data *udd; |
| 217 | |
| 218 | udd = (void *) current->utask->vaddr; |
| 219 | |
| 220 | base_addr = udd->bp_addr - udd->tu->offset; |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 221 | return base_addr + file_offset; |
Namhyung Kim | b7e0bf3 | 2013-11-25 13:42:47 +0900 | [diff] [blame] | 222 | } |
| 223 | |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 224 | /* Note that we don't verify it, since the code does not come from user space */ |
| 225 | static int |
| 226 | process_fetch_insn(struct fetch_insn *code, struct pt_regs *regs, void *dest, |
Masami Hiramatsu | 9178412 | 2018-04-25 21:19:01 +0900 | [diff] [blame] | 227 | void *base) |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 228 | { |
| 229 | unsigned long val; |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 230 | |
| 231 | /* 1st stage: get value from context */ |
| 232 | switch (code->op) { |
| 233 | case FETCH_OP_REG: |
| 234 | val = regs_get_register(regs, code->param); |
| 235 | break; |
| 236 | case FETCH_OP_STACK: |
| 237 | val = get_user_stack_nth(regs, code->param); |
| 238 | break; |
| 239 | case FETCH_OP_STACKP: |
| 240 | val = user_stack_pointer(regs); |
| 241 | break; |
| 242 | case FETCH_OP_RETVAL: |
| 243 | val = regs_return_value(regs); |
| 244 | break; |
| 245 | case FETCH_OP_IMM: |
| 246 | val = code->immediate; |
| 247 | break; |
Masami Hiramatsu | 4dd537a | 2019-05-07 22:55:41 +0900 | [diff] [blame] | 248 | case FETCH_OP_COMM: |
| 249 | val = FETCH_TOKEN_COMM; |
| 250 | break; |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 251 | case FETCH_OP_FOFFS: |
| 252 | val = translate_user_vaddr(code->immediate); |
| 253 | break; |
| 254 | default: |
| 255 | return -EILSEQ; |
| 256 | } |
| 257 | code++; |
| 258 | |
Masami Hiramatsu | 9b960a3 | 2018-04-25 21:19:59 +0900 | [diff] [blame] | 259 | return process_fetch_insn_bottom(code, val, dest, base); |
Masami Hiramatsu | 5330592 | 2018-04-25 21:18:03 +0900 | [diff] [blame] | 260 | } |
| 261 | NOKPROBE_SYMBOL(process_fetch_insn) |
| 262 | |
Oleg Nesterov | 736288b | 2013-02-03 20:58:35 +0100 | [diff] [blame] | 263 | static inline void init_trace_uprobe_filter(struct trace_uprobe_filter *filter) |
| 264 | { |
| 265 | rwlock_init(&filter->rwlock); |
| 266 | filter->nr_systemwide = 0; |
| 267 | INIT_LIST_HEAD(&filter->perf_events); |
| 268 | } |
| 269 | |
| 270 | static inline bool uprobe_filter_is_empty(struct trace_uprobe_filter *filter) |
| 271 | { |
| 272 | return !filter->nr_systemwide && list_empty(&filter->perf_events); |
| 273 | } |
| 274 | |
Oleg Nesterov | c1ae5c7 | 2013-03-30 18:25:23 +0100 | [diff] [blame] | 275 | static inline bool is_ret_probe(struct trace_uprobe *tu) |
| 276 | { |
| 277 | return tu->consumer.ret_handler != NULL; |
| 278 | } |
| 279 | |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 280 | static bool trace_uprobe_is_busy(struct dyn_event *ev) |
| 281 | { |
| 282 | struct trace_uprobe *tu = to_trace_uprobe(ev); |
| 283 | |
| 284 | return trace_probe_is_enabled(&tu->tp); |
| 285 | } |
| 286 | |
| 287 | static bool trace_uprobe_match(const char *system, const char *event, |
| 288 | struct dyn_event *ev) |
| 289 | { |
| 290 | struct trace_uprobe *tu = to_trace_uprobe(ev); |
| 291 | |
Masami Hiramatsu | b55ce203 | 2019-06-01 00:17:47 +0900 | [diff] [blame] | 292 | return strcmp(trace_probe_name(&tu->tp), event) == 0 && |
| 293 | (!system || strcmp(trace_probe_group_name(&tu->tp), system) == 0); |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 294 | } |
| 295 | |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 296 | /* |
| 297 | * Allocate new trace_uprobe and initialize it (including uprobes). |
| 298 | */ |
| 299 | static struct trace_uprobe * |
Oleg Nesterov | c1ae5c7 | 2013-03-30 18:25:23 +0100 | [diff] [blame] | 300 | alloc_trace_uprobe(const char *group, const char *event, int nargs, bool is_ret) |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 301 | { |
| 302 | struct trace_uprobe *tu; |
Masami Hiramatsu | 455b289 | 2019-06-01 00:17:06 +0900 | [diff] [blame] | 303 | int ret; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 304 | |
| 305 | tu = kzalloc(SIZEOF_TRACE_UPROBE(nargs), GFP_KERNEL); |
| 306 | if (!tu) |
| 307 | return ERR_PTR(-ENOMEM); |
| 308 | |
Masami Hiramatsu | 455b289 | 2019-06-01 00:17:06 +0900 | [diff] [blame] | 309 | ret = trace_probe_init(&tu->tp, event, group); |
| 310 | if (ret < 0) |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 311 | goto error; |
| 312 | |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 313 | dyn_event_init(&tu->devent, &trace_uprobe_ops); |
Oleg Nesterov | a932b73 | 2013-01-31 19:47:23 +0100 | [diff] [blame] | 314 | tu->consumer.handler = uprobe_dispatcher; |
Oleg Nesterov | c1ae5c7 | 2013-03-30 18:25:23 +0100 | [diff] [blame] | 315 | if (is_ret) |
| 316 | tu->consumer.ret_handler = uretprobe_dispatcher; |
Oleg Nesterov | 736288b | 2013-02-03 20:58:35 +0100 | [diff] [blame] | 317 | init_trace_uprobe_filter(&tu->filter); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 318 | return tu; |
| 319 | |
| 320 | error: |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 321 | kfree(tu); |
| 322 | |
Masami Hiramatsu | 455b289 | 2019-06-01 00:17:06 +0900 | [diff] [blame] | 323 | return ERR_PTR(ret); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | static void free_trace_uprobe(struct trace_uprobe *tu) |
| 327 | { |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 328 | if (!tu) |
| 329 | return; |
| 330 | |
Song Liu | 0c92c7a | 2018-04-23 10:21:34 -0700 | [diff] [blame] | 331 | path_put(&tu->path); |
Masami Hiramatsu | 455b289 | 2019-06-01 00:17:06 +0900 | [diff] [blame] | 332 | trace_probe_cleanup(&tu->tp); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 333 | kfree(tu->filename); |
| 334 | kfree(tu); |
| 335 | } |
| 336 | |
| 337 | static struct trace_uprobe *find_probe_event(const char *event, const char *group) |
| 338 | { |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 339 | struct dyn_event *pos; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 340 | struct trace_uprobe *tu; |
| 341 | |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 342 | for_each_trace_uprobe(tu, pos) |
Masami Hiramatsu | b55ce203 | 2019-06-01 00:17:47 +0900 | [diff] [blame] | 343 | if (strcmp(trace_probe_name(&tu->tp), event) == 0 && |
| 344 | strcmp(trace_probe_group_name(&tu->tp), group) == 0) |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 345 | return tu; |
| 346 | |
| 347 | return NULL; |
| 348 | } |
| 349 | |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 350 | /* Unregister a trace_uprobe and probe_event */ |
Steven Rostedt (Red Hat) | c6c2401 | 2013-07-03 23:33:51 -0400 | [diff] [blame] | 351 | static int unregister_trace_uprobe(struct trace_uprobe *tu) |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 352 | { |
Steven Rostedt (Red Hat) | c6c2401 | 2013-07-03 23:33:51 -0400 | [diff] [blame] | 353 | int ret; |
| 354 | |
| 355 | ret = unregister_uprobe_event(tu); |
| 356 | if (ret) |
| 357 | return ret; |
| 358 | |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 359 | dyn_event_remove(&tu->devent); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 360 | free_trace_uprobe(tu); |
Steven Rostedt (Red Hat) | c6c2401 | 2013-07-03 23:33:51 -0400 | [diff] [blame] | 361 | return 0; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 362 | } |
| 363 | |
Ravi Bangoria | ccea872 | 2018-08-20 10:12:49 +0530 | [diff] [blame] | 364 | /* |
| 365 | * Uprobe with multiple reference counter is not allowed. i.e. |
| 366 | * If inode and offset matches, reference counter offset *must* |
| 367 | * match as well. Though, there is one exception: If user is |
| 368 | * replacing old trace_uprobe with new one(same group/event), |
| 369 | * then we allow same uprobe with new reference counter as far |
| 370 | * as the new one does not conflict with any other existing |
| 371 | * ones. |
| 372 | */ |
| 373 | static struct trace_uprobe *find_old_trace_uprobe(struct trace_uprobe *new) |
| 374 | { |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 375 | struct dyn_event *pos; |
Ravi Bangoria | ccea872 | 2018-08-20 10:12:49 +0530 | [diff] [blame] | 376 | struct trace_uprobe *tmp, *old = NULL; |
| 377 | struct inode *new_inode = d_real_inode(new->path.dentry); |
| 378 | |
Masami Hiramatsu | b55ce203 | 2019-06-01 00:17:47 +0900 | [diff] [blame] | 379 | old = find_probe_event(trace_probe_name(&new->tp), |
| 380 | trace_probe_group_name(&new->tp)); |
Ravi Bangoria | ccea872 | 2018-08-20 10:12:49 +0530 | [diff] [blame] | 381 | |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 382 | for_each_trace_uprobe(tmp, pos) { |
Ravi Bangoria | ccea872 | 2018-08-20 10:12:49 +0530 | [diff] [blame] | 383 | if ((old ? old != tmp : true) && |
| 384 | new_inode == d_real_inode(tmp->path.dentry) && |
| 385 | new->offset == tmp->offset && |
| 386 | new->ref_ctr_offset != tmp->ref_ctr_offset) { |
| 387 | pr_warn("Reference counter offset mismatch."); |
| 388 | return ERR_PTR(-EINVAL); |
| 389 | } |
| 390 | } |
| 391 | return old; |
| 392 | } |
| 393 | |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 394 | /* Register a trace_uprobe and probe_event */ |
| 395 | static int register_trace_uprobe(struct trace_uprobe *tu) |
| 396 | { |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame] | 397 | struct trace_uprobe *old_tu; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 398 | int ret; |
| 399 | |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 400 | mutex_lock(&event_mutex); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 401 | |
| 402 | /* register as an event */ |
Ravi Bangoria | ccea872 | 2018-08-20 10:12:49 +0530 | [diff] [blame] | 403 | old_tu = find_old_trace_uprobe(tu); |
| 404 | if (IS_ERR(old_tu)) { |
| 405 | ret = PTR_ERR(old_tu); |
| 406 | goto end; |
| 407 | } |
| 408 | |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame] | 409 | if (old_tu) { |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 410 | /* delete old event */ |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame] | 411 | ret = unregister_trace_uprobe(old_tu); |
Steven Rostedt (Red Hat) | c6c2401 | 2013-07-03 23:33:51 -0400 | [diff] [blame] | 412 | if (ret) |
| 413 | goto end; |
| 414 | } |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 415 | |
| 416 | ret = register_uprobe_event(tu); |
| 417 | if (ret) { |
Joe Perches | a395d6a | 2016-03-22 14:28:09 -0700 | [diff] [blame] | 418 | pr_warn("Failed to register probe event(%d)\n", ret); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 419 | goto end; |
| 420 | } |
| 421 | |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 422 | dyn_event_add(&tu->devent); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 423 | |
| 424 | end: |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 425 | mutex_unlock(&event_mutex); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 426 | |
| 427 | return ret; |
| 428 | } |
| 429 | |
| 430 | /* |
| 431 | * Argument syntax: |
Namhyung Kim | 306cfe2 | 2013-07-03 16:44:46 +0900 | [diff] [blame] | 432 | * - Add uprobe: p|r[:[GRP/]EVENT] PATH:OFFSET [FETCHARGS] |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 433 | */ |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 434 | static int trace_uprobe_create(int argc, const char **argv) |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 435 | { |
| 436 | struct trace_uprobe *tu; |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 437 | const char *event = NULL, *group = UPROBE_EVENT_SYSTEM; |
| 438 | char *arg, *filename, *rctr, *rctr_end, *tmp; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 439 | char buf[MAX_EVENT_NAME_LEN]; |
| 440 | struct path path; |
Ravi Bangoria | 1cc3316 | 2018-08-20 10:12:47 +0530 | [diff] [blame] | 441 | unsigned long offset, ref_ctr_offset; |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 442 | bool is_return = false; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 443 | int i, ret; |
| 444 | |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 445 | ret = 0; |
Ravi Bangoria | 1cc3316 | 2018-08-20 10:12:47 +0530 | [diff] [blame] | 446 | ref_ctr_offset = 0; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 447 | |
Eiichi Tsukata | f01098c | 2019-06-14 16:40:25 +0900 | [diff] [blame] | 448 | switch (argv[0][0]) { |
| 449 | case 'r': |
Oleg Nesterov | 4ee5a52 | 2013-03-30 20:28:15 +0100 | [diff] [blame] | 450 | is_return = true; |
Eiichi Tsukata | f01098c | 2019-06-14 16:40:25 +0900 | [diff] [blame] | 451 | break; |
| 452 | case 'p': |
| 453 | break; |
| 454 | default: |
| 455 | return -ECANCELED; |
| 456 | } |
| 457 | |
| 458 | if (argc < 2) |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 459 | return -ECANCELED; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 460 | |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 461 | if (argv[0][1] == ':') |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 462 | event = &argv[0][2]; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 463 | |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 464 | if (!strchr(argv[1], '/')) |
| 465 | return -ECANCELED; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 466 | |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 467 | filename = kstrdup(argv[1], GFP_KERNEL); |
| 468 | if (!filename) |
| 469 | return -ENOMEM; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 470 | |
Kenny Yu | 6496bb7 | 2017-01-13 08:58:34 -0800 | [diff] [blame] | 471 | /* Find the last occurrence, in case the path contains ':' too. */ |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 472 | arg = strrchr(filename, ':'); |
| 473 | if (!arg || !isdigit(arg[1])) { |
| 474 | kfree(filename); |
| 475 | return -ECANCELED; |
| 476 | } |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 477 | |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 478 | trace_probe_log_init("trace_uprobe", argc, argv); |
| 479 | trace_probe_log_set_index(1); /* filename is the 2nd argument */ |
| 480 | |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 481 | *arg++ = '\0'; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 482 | ret = kern_path(filename, LOOKUP_FOLLOW, &path); |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 483 | if (ret) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 484 | trace_probe_log_err(0, FILE_NOT_FOUND); |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 485 | kfree(filename); |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 486 | trace_probe_log_clear(); |
Song Liu | 0c92c7a | 2018-04-23 10:21:34 -0700 | [diff] [blame] | 487 | return ret; |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 488 | } |
Song Liu | 0c92c7a | 2018-04-23 10:21:34 -0700 | [diff] [blame] | 489 | if (!d_is_reg(path.dentry)) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 490 | trace_probe_log_err(0, NO_REGULAR_FILE); |
Jovi Zhang | d24d7db | 2012-07-18 18:16:44 +0800 | [diff] [blame] | 491 | ret = -EINVAL; |
| 492 | goto fail_address_parse; |
| 493 | } |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 494 | |
Ravi Bangoria | 1cc3316 | 2018-08-20 10:12:47 +0530 | [diff] [blame] | 495 | /* Parse reference counter offset if specified. */ |
| 496 | rctr = strchr(arg, '('); |
| 497 | if (rctr) { |
| 498 | rctr_end = strchr(rctr, ')'); |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 499 | if (!rctr_end) { |
Ravi Bangoria | 1cc3316 | 2018-08-20 10:12:47 +0530 | [diff] [blame] | 500 | ret = -EINVAL; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 501 | rctr_end = rctr + strlen(rctr); |
| 502 | trace_probe_log_err(rctr_end - filename, |
| 503 | REFCNT_OPEN_BRACE); |
| 504 | goto fail_address_parse; |
| 505 | } else if (rctr_end[1] != '\0') { |
| 506 | ret = -EINVAL; |
| 507 | trace_probe_log_err(rctr_end + 1 - filename, |
| 508 | BAD_REFCNT_SUFFIX); |
Ravi Bangoria | 1cc3316 | 2018-08-20 10:12:47 +0530 | [diff] [blame] | 509 | goto fail_address_parse; |
| 510 | } |
| 511 | |
| 512 | *rctr++ = '\0'; |
| 513 | *rctr_end = '\0'; |
| 514 | ret = kstrtoul(rctr, 0, &ref_ctr_offset); |
| 515 | if (ret) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 516 | trace_probe_log_err(rctr - filename, BAD_REFCNT); |
Ravi Bangoria | 1cc3316 | 2018-08-20 10:12:47 +0530 | [diff] [blame] | 517 | goto fail_address_parse; |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | /* Parse uprobe offset. */ |
Oleg Nesterov | 84d7ed7 | 2013-01-27 18:20:45 +0100 | [diff] [blame] | 522 | ret = kstrtoul(arg, 0, &offset); |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 523 | if (ret) { |
| 524 | trace_probe_log_err(arg - filename, BAD_UPROBE_OFFS); |
Oleg Nesterov | 84d7ed7 | 2013-01-27 18:20:45 +0100 | [diff] [blame] | 525 | goto fail_address_parse; |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 526 | } |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 527 | |
| 528 | /* setup a probe */ |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 529 | trace_probe_log_set_index(0); |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 530 | if (event) { |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 531 | ret = traceprobe_parse_event_name(&event, &group, buf, |
| 532 | event - argv[0]); |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 533 | if (ret) |
| 534 | goto fail_address_parse; |
| 535 | } else { |
Andy Shevchenko | b2e902f | 2012-12-17 16:01:27 -0800 | [diff] [blame] | 536 | char *tail; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 537 | char *ptr; |
| 538 | |
Andy Shevchenko | b2e902f | 2012-12-17 16:01:27 -0800 | [diff] [blame] | 539 | tail = kstrdup(kbasename(filename), GFP_KERNEL); |
| 540 | if (!tail) { |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 541 | ret = -ENOMEM; |
| 542 | goto fail_address_parse; |
| 543 | } |
| 544 | |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 545 | ptr = strpbrk(tail, ".-_"); |
| 546 | if (ptr) |
| 547 | *ptr = '\0'; |
| 548 | |
| 549 | snprintf(buf, MAX_EVENT_NAME_LEN, "%c_%s_0x%lx", 'p', tail, offset); |
| 550 | event = buf; |
| 551 | kfree(tail); |
| 552 | } |
| 553 | |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 554 | argc -= 2; |
| 555 | argv += 2; |
| 556 | |
Oleg Nesterov | 4ee5a52 | 2013-03-30 20:28:15 +0100 | [diff] [blame] | 557 | tu = alloc_trace_uprobe(group, event, argc, is_return); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 558 | if (IS_ERR(tu)) { |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 559 | ret = PTR_ERR(tu); |
Masami Hiramatsu | a039480 | 2019-03-14 13:30:50 +0900 | [diff] [blame] | 560 | /* This must return -ENOMEM otherwise there is a bug */ |
| 561 | WARN_ON_ONCE(ret != -ENOMEM); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 562 | goto fail_address_parse; |
| 563 | } |
| 564 | tu->offset = offset; |
Ravi Bangoria | 1cc3316 | 2018-08-20 10:12:47 +0530 | [diff] [blame] | 565 | tu->ref_ctr_offset = ref_ctr_offset; |
Song Liu | 0c92c7a | 2018-04-23 10:21:34 -0700 | [diff] [blame] | 566 | tu->path = path; |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 567 | tu->filename = filename; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 568 | |
| 569 | /* parse arguments */ |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 570 | for (i = 0; i < argc && i < MAX_TRACE_ARGS; i++) { |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 571 | tmp = kstrdup(argv[i], GFP_KERNEL); |
| 572 | if (!tmp) { |
| 573 | ret = -ENOMEM; |
| 574 | goto error; |
| 575 | } |
| 576 | |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 577 | trace_probe_log_set_index(i + 2); |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 578 | ret = traceprobe_parse_probe_arg(&tu->tp, i, tmp, |
Masami Hiramatsu | a1303af | 2018-04-25 21:21:26 +0900 | [diff] [blame] | 579 | is_return ? TPARG_FL_RETURN : 0); |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 580 | kfree(tmp); |
Masami Hiramatsu | d00bbea9 | 2018-11-05 18:01:40 +0900 | [diff] [blame] | 581 | if (ret) |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 582 | goto error; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 583 | } |
| 584 | |
Masami Hiramatsu | b4d4b96 | 2019-06-01 00:16:56 +0900 | [diff] [blame] | 585 | ret = traceprobe_set_print_fmt(&tu->tp, is_ret_probe(tu)); |
| 586 | if (ret < 0) |
| 587 | goto error; |
| 588 | |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 589 | ret = register_trace_uprobe(tu); |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 590 | if (!ret) |
| 591 | goto out; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 592 | |
| 593 | error: |
| 594 | free_trace_uprobe(tu); |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 595 | out: |
| 596 | trace_probe_log_clear(); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 597 | return ret; |
| 598 | |
| 599 | fail_address_parse: |
Masami Hiramatsu | ab105a4 | 2019-03-31 18:48:19 -0500 | [diff] [blame] | 600 | trace_probe_log_clear(); |
Song Liu | 0c92c7a | 2018-04-23 10:21:34 -0700 | [diff] [blame] | 601 | path_put(&path); |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 602 | kfree(filename); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 603 | |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 604 | return ret; |
| 605 | } |
| 606 | |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 607 | static int create_or_delete_trace_uprobe(int argc, char **argv) |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 608 | { |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 609 | int ret; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 610 | |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 611 | if (argv[0][0] == '-') |
| 612 | return dyn_event_release(argc, argv, &trace_uprobe_ops); |
| 613 | |
| 614 | ret = trace_uprobe_create(argc, (const char **)argv); |
| 615 | return ret == -ECANCELED ? -EINVAL : ret; |
| 616 | } |
| 617 | |
| 618 | static int trace_uprobe_release(struct dyn_event *ev) |
| 619 | { |
| 620 | struct trace_uprobe *tu = to_trace_uprobe(ev); |
| 621 | |
| 622 | return unregister_trace_uprobe(tu); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | /* Probes listing interfaces */ |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 626 | static int trace_uprobe_show(struct seq_file *m, struct dyn_event *ev) |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 627 | { |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 628 | struct trace_uprobe *tu = to_trace_uprobe(ev); |
Oleg Nesterov | 3ede82d | 2013-03-30 19:48:09 +0100 | [diff] [blame] | 629 | char c = is_ret_probe(tu) ? 'r' : 'p'; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 630 | int i; |
| 631 | |
Masami Hiramatsu | b55ce203 | 2019-06-01 00:17:47 +0900 | [diff] [blame] | 632 | seq_printf(m, "%c:%s/%s %s:0x%0*lx", c, trace_probe_group_name(&tu->tp), |
| 633 | trace_probe_name(&tu->tp), tu->filename, |
Ravi Bangoria | a64b2c0 | 2018-03-15 13:57:56 +0530 | [diff] [blame] | 634 | (int)(sizeof(void *) * 2), tu->offset); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 635 | |
Ravi Bangoria | 1cc3316 | 2018-08-20 10:12:47 +0530 | [diff] [blame] | 636 | if (tu->ref_ctr_offset) |
| 637 | seq_printf(m, "(0x%lx)", tu->ref_ctr_offset); |
| 638 | |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame] | 639 | for (i = 0; i < tu->tp.nr_args; i++) |
| 640 | seq_printf(m, " %s=%s", tu->tp.args[i].name, tu->tp.args[i].comm); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 641 | |
Rasmus Villemoes | fa6f0cc | 2014-11-08 21:42:10 +0100 | [diff] [blame] | 642 | seq_putc(m, '\n'); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 643 | return 0; |
| 644 | } |
| 645 | |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 646 | static int probes_seq_show(struct seq_file *m, void *v) |
| 647 | { |
| 648 | struct dyn_event *ev = v; |
| 649 | |
| 650 | if (!is_trace_uprobe(ev)) |
| 651 | return 0; |
| 652 | |
| 653 | return trace_uprobe_show(m, ev); |
| 654 | } |
| 655 | |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 656 | static const struct seq_operations probes_seq_op = { |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 657 | .start = dyn_event_seq_start, |
| 658 | .next = dyn_event_seq_next, |
| 659 | .stop = dyn_event_seq_stop, |
| 660 | .show = probes_seq_show |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 661 | }; |
| 662 | |
| 663 | static int probes_open(struct inode *inode, struct file *file) |
| 664 | { |
Steven Rostedt (Red Hat) | c6c2401 | 2013-07-03 23:33:51 -0400 | [diff] [blame] | 665 | int ret; |
| 666 | |
| 667 | if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_TRUNC)) { |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 668 | ret = dyn_events_release_all(&trace_uprobe_ops); |
Steven Rostedt (Red Hat) | c6c2401 | 2013-07-03 23:33:51 -0400 | [diff] [blame] | 669 | if (ret) |
| 670 | return ret; |
| 671 | } |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 672 | |
| 673 | return seq_open(file, &probes_seq_op); |
| 674 | } |
| 675 | |
| 676 | static ssize_t probes_write(struct file *file, const char __user *buffer, |
| 677 | size_t count, loff_t *ppos) |
| 678 | { |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 679 | return trace_parse_run_command(file, buffer, count, ppos, |
| 680 | create_or_delete_trace_uprobe); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | static const struct file_operations uprobe_events_ops = { |
| 684 | .owner = THIS_MODULE, |
| 685 | .open = probes_open, |
| 686 | .read = seq_read, |
| 687 | .llseek = seq_lseek, |
| 688 | .release = seq_release, |
| 689 | .write = probes_write, |
| 690 | }; |
| 691 | |
| 692 | /* Probes profiling interfaces */ |
| 693 | static int probes_profile_seq_show(struct seq_file *m, void *v) |
| 694 | { |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 695 | struct dyn_event *ev = v; |
| 696 | struct trace_uprobe *tu; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 697 | |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 698 | if (!is_trace_uprobe(ev)) |
| 699 | return 0; |
| 700 | |
| 701 | tu = to_trace_uprobe(ev); |
Mathieu Desnoyers | de7b297 | 2014-04-08 17:26:21 -0400 | [diff] [blame] | 702 | seq_printf(m, " %s %-44s %15lu\n", tu->filename, |
Masami Hiramatsu | b55ce203 | 2019-06-01 00:17:47 +0900 | [diff] [blame] | 703 | trace_probe_name(&tu->tp), tu->nhit); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 704 | return 0; |
| 705 | } |
| 706 | |
| 707 | static const struct seq_operations profile_seq_op = { |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 708 | .start = dyn_event_seq_start, |
| 709 | .next = dyn_event_seq_next, |
| 710 | .stop = dyn_event_seq_stop, |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 711 | .show = probes_profile_seq_show |
| 712 | }; |
| 713 | |
| 714 | static int profile_open(struct inode *inode, struct file *file) |
| 715 | { |
| 716 | return seq_open(file, &profile_seq_op); |
| 717 | } |
| 718 | |
| 719 | static const struct file_operations uprobe_profile_ops = { |
| 720 | .owner = THIS_MODULE, |
| 721 | .open = profile_open, |
| 722 | .read = seq_read, |
| 723 | .llseek = seq_lseek, |
| 724 | .release = seq_release, |
| 725 | }; |
| 726 | |
Namhyung Kim | dcad1a2 | 2013-07-03 16:40:28 +0900 | [diff] [blame] | 727 | struct uprobe_cpu_buffer { |
| 728 | struct mutex mutex; |
| 729 | void *buf; |
| 730 | }; |
| 731 | static struct uprobe_cpu_buffer __percpu *uprobe_cpu_buffer; |
| 732 | static int uprobe_buffer_refcnt; |
| 733 | |
| 734 | static int uprobe_buffer_init(void) |
| 735 | { |
| 736 | int cpu, err_cpu; |
| 737 | |
| 738 | uprobe_cpu_buffer = alloc_percpu(struct uprobe_cpu_buffer); |
| 739 | if (uprobe_cpu_buffer == NULL) |
| 740 | return -ENOMEM; |
| 741 | |
| 742 | for_each_possible_cpu(cpu) { |
| 743 | struct page *p = alloc_pages_node(cpu_to_node(cpu), |
| 744 | GFP_KERNEL, 0); |
| 745 | if (p == NULL) { |
| 746 | err_cpu = cpu; |
| 747 | goto err; |
| 748 | } |
| 749 | per_cpu_ptr(uprobe_cpu_buffer, cpu)->buf = page_address(p); |
| 750 | mutex_init(&per_cpu_ptr(uprobe_cpu_buffer, cpu)->mutex); |
| 751 | } |
| 752 | |
| 753 | return 0; |
| 754 | |
| 755 | err: |
| 756 | for_each_possible_cpu(cpu) { |
| 757 | if (cpu == err_cpu) |
| 758 | break; |
| 759 | free_page((unsigned long)per_cpu_ptr(uprobe_cpu_buffer, cpu)->buf); |
| 760 | } |
| 761 | |
| 762 | free_percpu(uprobe_cpu_buffer); |
| 763 | return -ENOMEM; |
| 764 | } |
| 765 | |
| 766 | static int uprobe_buffer_enable(void) |
| 767 | { |
| 768 | int ret = 0; |
| 769 | |
| 770 | BUG_ON(!mutex_is_locked(&event_mutex)); |
| 771 | |
| 772 | if (uprobe_buffer_refcnt++ == 0) { |
| 773 | ret = uprobe_buffer_init(); |
| 774 | if (ret < 0) |
| 775 | uprobe_buffer_refcnt--; |
| 776 | } |
| 777 | |
| 778 | return ret; |
| 779 | } |
| 780 | |
| 781 | static void uprobe_buffer_disable(void) |
| 782 | { |
zhangwei(Jovi) | 6ea6215 | 2014-04-17 16:05:19 +0800 | [diff] [blame] | 783 | int cpu; |
| 784 | |
Namhyung Kim | dcad1a2 | 2013-07-03 16:40:28 +0900 | [diff] [blame] | 785 | BUG_ON(!mutex_is_locked(&event_mutex)); |
| 786 | |
| 787 | if (--uprobe_buffer_refcnt == 0) { |
zhangwei(Jovi) | 6ea6215 | 2014-04-17 16:05:19 +0800 | [diff] [blame] | 788 | for_each_possible_cpu(cpu) |
| 789 | free_page((unsigned long)per_cpu_ptr(uprobe_cpu_buffer, |
| 790 | cpu)->buf); |
| 791 | |
Namhyung Kim | dcad1a2 | 2013-07-03 16:40:28 +0900 | [diff] [blame] | 792 | free_percpu(uprobe_cpu_buffer); |
| 793 | uprobe_cpu_buffer = NULL; |
| 794 | } |
| 795 | } |
| 796 | |
| 797 | static struct uprobe_cpu_buffer *uprobe_buffer_get(void) |
| 798 | { |
| 799 | struct uprobe_cpu_buffer *ucb; |
| 800 | int cpu; |
| 801 | |
| 802 | cpu = raw_smp_processor_id(); |
| 803 | ucb = per_cpu_ptr(uprobe_cpu_buffer, cpu); |
| 804 | |
| 805 | /* |
| 806 | * Use per-cpu buffers for fastest access, but we might migrate |
| 807 | * so the mutex makes sure we have sole access to it. |
| 808 | */ |
| 809 | mutex_lock(&ucb->mutex); |
| 810 | |
| 811 | return ucb; |
| 812 | } |
| 813 | |
| 814 | static void uprobe_buffer_put(struct uprobe_cpu_buffer *ucb) |
| 815 | { |
| 816 | mutex_unlock(&ucb->mutex); |
| 817 | } |
| 818 | |
Namhyung Kim | a43b970 | 2014-01-17 17:08:36 +0900 | [diff] [blame] | 819 | static void __uprobe_trace_func(struct trace_uprobe *tu, |
Namhyung Kim | dd9fa55 | 2014-01-17 17:08:37 +0900 | [diff] [blame] | 820 | unsigned long func, struct pt_regs *regs, |
zhangwei(Jovi) | 70ed91c | 2014-01-17 17:08:38 +0900 | [diff] [blame] | 821 | struct uprobe_cpu_buffer *ucb, int dsize, |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 822 | struct trace_event_file *trace_file) |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 823 | { |
| 824 | struct uprobe_trace_entry_head *entry; |
| 825 | struct ring_buffer_event *event; |
| 826 | struct ring_buffer *buffer; |
Oleg Nesterov | 457d177 | 2013-03-29 18:26:51 +0100 | [diff] [blame] | 827 | void *data; |
Namhyung Kim | dd9fa55 | 2014-01-17 17:08:37 +0900 | [diff] [blame] | 828 | int size, esize; |
Masami Hiramatsu | e3dc9f8 | 2019-06-01 00:17:57 +0900 | [diff] [blame] | 829 | struct trace_event_call *call = trace_probe_event_call(&tu->tp); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 830 | |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 831 | WARN_ON(call != trace_file->event_call); |
zhangwei(Jovi) | 70ed91c | 2014-01-17 17:08:38 +0900 | [diff] [blame] | 832 | |
Namhyung Kim | dd9fa55 | 2014-01-17 17:08:37 +0900 | [diff] [blame] | 833 | if (WARN_ON_ONCE(tu->tp.size + dsize > PAGE_SIZE)) |
Oleg Nesterov | a51cc60 | 2013-03-30 18:02:12 +0100 | [diff] [blame] | 834 | return; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 835 | |
Steven Rostedt (Red Hat) | 09a5059 | 2015-05-13 15:21:25 -0400 | [diff] [blame] | 836 | if (trace_trigger_soft_disabled(trace_file)) |
Namhyung Kim | ca3b162 | 2014-01-17 17:08:39 +0900 | [diff] [blame] | 837 | return; |
| 838 | |
Namhyung Kim | dd9fa55 | 2014-01-17 17:08:37 +0900 | [diff] [blame] | 839 | esize = SIZEOF_TRACE_ENTRY(is_ret_probe(tu)); |
Namhyung Kim | dcad1a2 | 2013-07-03 16:40:28 +0900 | [diff] [blame] | 840 | size = esize + tu->tp.size + dsize; |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 841 | event = trace_event_buffer_lock_reserve(&buffer, trace_file, |
zhangwei(Jovi) | 70ed91c | 2014-01-17 17:08:38 +0900 | [diff] [blame] | 842 | call->event.type, size, 0, 0); |
Namhyung Kim | dcad1a2 | 2013-07-03 16:40:28 +0900 | [diff] [blame] | 843 | if (!event) |
Namhyung Kim | dd9fa55 | 2014-01-17 17:08:37 +0900 | [diff] [blame] | 844 | return; |
Namhyung Kim | dcad1a2 | 2013-07-03 16:40:28 +0900 | [diff] [blame] | 845 | |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 846 | entry = ring_buffer_event_data(event); |
Oleg Nesterov | 393a736 | 2013-03-30 18:46:22 +0100 | [diff] [blame] | 847 | if (is_ret_probe(tu)) { |
| 848 | entry->vaddr[0] = func; |
| 849 | entry->vaddr[1] = instruction_pointer(regs); |
| 850 | data = DATAOF_TRACE_ENTRY(entry, true); |
| 851 | } else { |
| 852 | entry->vaddr[0] = instruction_pointer(regs); |
| 853 | data = DATAOF_TRACE_ENTRY(entry, false); |
| 854 | } |
| 855 | |
Namhyung Kim | dcad1a2 | 2013-07-03 16:40:28 +0900 | [diff] [blame] | 856 | memcpy(data, ucb->buf, tu->tp.size + dsize); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 857 | |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 858 | event_trigger_unlock_commit(trace_file, buffer, event, entry, 0, 0); |
Oleg Nesterov | a51cc60 | 2013-03-30 18:02:12 +0100 | [diff] [blame] | 859 | } |
Oleg Nesterov | f42d24a | 2013-02-04 17:48:34 +0100 | [diff] [blame] | 860 | |
Oleg Nesterov | a51cc60 | 2013-03-30 18:02:12 +0100 | [diff] [blame] | 861 | /* uprobe handler */ |
Namhyung Kim | dd9fa55 | 2014-01-17 17:08:37 +0900 | [diff] [blame] | 862 | static int uprobe_trace_func(struct trace_uprobe *tu, struct pt_regs *regs, |
| 863 | struct uprobe_cpu_buffer *ucb, int dsize) |
Oleg Nesterov | a51cc60 | 2013-03-30 18:02:12 +0100 | [diff] [blame] | 864 | { |
zhangwei(Jovi) | 70ed91c | 2014-01-17 17:08:38 +0900 | [diff] [blame] | 865 | struct event_file_link *link; |
| 866 | |
| 867 | if (is_ret_probe(tu)) |
| 868 | return 0; |
| 869 | |
| 870 | rcu_read_lock(); |
Masami Hiramatsu | b5f935e | 2019-06-01 00:17:26 +0900 | [diff] [blame] | 871 | trace_probe_for_each_link_rcu(link, &tu->tp) |
zhangwei(Jovi) | 70ed91c | 2014-01-17 17:08:38 +0900 | [diff] [blame] | 872 | __uprobe_trace_func(tu, 0, regs, ucb, dsize, link->file); |
| 873 | rcu_read_unlock(); |
| 874 | |
Oleg Nesterov | f42d24a | 2013-02-04 17:48:34 +0100 | [diff] [blame] | 875 | return 0; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 876 | } |
| 877 | |
Oleg Nesterov | c1ae5c7 | 2013-03-30 18:25:23 +0100 | [diff] [blame] | 878 | static void uretprobe_trace_func(struct trace_uprobe *tu, unsigned long func, |
Namhyung Kim | dd9fa55 | 2014-01-17 17:08:37 +0900 | [diff] [blame] | 879 | struct pt_regs *regs, |
| 880 | struct uprobe_cpu_buffer *ucb, int dsize) |
Oleg Nesterov | c1ae5c7 | 2013-03-30 18:25:23 +0100 | [diff] [blame] | 881 | { |
zhangwei(Jovi) | 70ed91c | 2014-01-17 17:08:38 +0900 | [diff] [blame] | 882 | struct event_file_link *link; |
| 883 | |
| 884 | rcu_read_lock(); |
Masami Hiramatsu | b5f935e | 2019-06-01 00:17:26 +0900 | [diff] [blame] | 885 | trace_probe_for_each_link_rcu(link, &tu->tp) |
zhangwei(Jovi) | 70ed91c | 2014-01-17 17:08:38 +0900 | [diff] [blame] | 886 | __uprobe_trace_func(tu, func, regs, ucb, dsize, link->file); |
| 887 | rcu_read_unlock(); |
Oleg Nesterov | c1ae5c7 | 2013-03-30 18:25:23 +0100 | [diff] [blame] | 888 | } |
| 889 | |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 890 | /* Event entry printers */ |
| 891 | static enum print_line_t |
| 892 | print_uprobe_event(struct trace_iterator *iter, int flags, struct trace_event *event) |
| 893 | { |
Oleg Nesterov | 457d177 | 2013-03-29 18:26:51 +0100 | [diff] [blame] | 894 | struct uprobe_trace_entry_head *entry; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 895 | struct trace_seq *s = &iter->seq; |
| 896 | struct trace_uprobe *tu; |
| 897 | u8 *data; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 898 | |
Oleg Nesterov | 457d177 | 2013-03-29 18:26:51 +0100 | [diff] [blame] | 899 | entry = (struct uprobe_trace_entry_head *)iter->ent; |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame] | 900 | tu = container_of(event, struct trace_uprobe, tp.call.event); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 901 | |
Oleg Nesterov | 3ede82d | 2013-03-30 19:48:09 +0100 | [diff] [blame] | 902 | if (is_ret_probe(tu)) { |
Steven Rostedt (Red Hat) | 8579a10 | 2014-11-12 17:26:57 -0500 | [diff] [blame] | 903 | trace_seq_printf(s, "%s: (0x%lx <- 0x%lx)", |
Masami Hiramatsu | b55ce203 | 2019-06-01 00:17:47 +0900 | [diff] [blame] | 904 | trace_probe_name(&tu->tp), |
Steven Rostedt (Red Hat) | 8579a10 | 2014-11-12 17:26:57 -0500 | [diff] [blame] | 905 | entry->vaddr[1], entry->vaddr[0]); |
Oleg Nesterov | 3ede82d | 2013-03-30 19:48:09 +0100 | [diff] [blame] | 906 | data = DATAOF_TRACE_ENTRY(entry, true); |
| 907 | } else { |
Steven Rostedt (Red Hat) | 8579a10 | 2014-11-12 17:26:57 -0500 | [diff] [blame] | 908 | trace_seq_printf(s, "%s: (0x%lx)", |
Masami Hiramatsu | b55ce203 | 2019-06-01 00:17:47 +0900 | [diff] [blame] | 909 | trace_probe_name(&tu->tp), |
Steven Rostedt (Red Hat) | 8579a10 | 2014-11-12 17:26:57 -0500 | [diff] [blame] | 910 | entry->vaddr[0]); |
Oleg Nesterov | 3ede82d | 2013-03-30 19:48:09 +0100 | [diff] [blame] | 911 | data = DATAOF_TRACE_ENTRY(entry, false); |
| 912 | } |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 913 | |
Masami Hiramatsu | 56de763 | 2018-04-25 21:16:36 +0900 | [diff] [blame] | 914 | if (print_probe_args(s, tu->tp.args, tu->tp.nr_args, data, entry) < 0) |
| 915 | goto out; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 916 | |
Steven Rostedt (Red Hat) | 8579a10 | 2014-11-12 17:26:57 -0500 | [diff] [blame] | 917 | trace_seq_putc(s, '\n'); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 918 | |
Steven Rostedt (Red Hat) | 8579a10 | 2014-11-12 17:26:57 -0500 | [diff] [blame] | 919 | out: |
| 920 | return trace_handle_return(s); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 921 | } |
| 922 | |
Oleg Nesterov | 31ba334 | 2013-02-04 17:11:58 +0100 | [diff] [blame] | 923 | typedef bool (*filter_func_t)(struct uprobe_consumer *self, |
| 924 | enum uprobe_filter_ctx ctx, |
| 925 | struct mm_struct *mm); |
| 926 | |
| 927 | static int |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 928 | probe_event_enable(struct trace_uprobe *tu, struct trace_event_file *file, |
zhangwei(Jovi) | 70ed91c | 2014-01-17 17:08:38 +0900 | [diff] [blame] | 929 | filter_func_t filter) |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 930 | { |
zhangwei(Jovi) | 70ed91c | 2014-01-17 17:08:38 +0900 | [diff] [blame] | 931 | bool enabled = trace_probe_is_enabled(&tu->tp); |
zhangwei(Jovi) | 70ed91c | 2014-01-17 17:08:38 +0900 | [diff] [blame] | 932 | int ret; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 933 | |
zhangwei(Jovi) | 70ed91c | 2014-01-17 17:08:38 +0900 | [diff] [blame] | 934 | if (file) { |
Masami Hiramatsu | 747774d | 2019-06-01 00:17:37 +0900 | [diff] [blame] | 935 | if (trace_probe_test_flag(&tu->tp, TP_FLAG_PROFILE)) |
Oleg Nesterov | 4821254 | 2014-06-27 19:01:36 +0200 | [diff] [blame] | 936 | return -EINTR; |
| 937 | |
Masami Hiramatsu | b5f935e | 2019-06-01 00:17:26 +0900 | [diff] [blame] | 938 | ret = trace_probe_add_file(&tu->tp, file); |
| 939 | if (ret < 0) |
| 940 | return ret; |
Oleg Nesterov | 4821254 | 2014-06-27 19:01:36 +0200 | [diff] [blame] | 941 | } else { |
Masami Hiramatsu | 747774d | 2019-06-01 00:17:37 +0900 | [diff] [blame] | 942 | if (trace_probe_test_flag(&tu->tp, TP_FLAG_TRACE)) |
Oleg Nesterov | 4821254 | 2014-06-27 19:01:36 +0200 | [diff] [blame] | 943 | return -EINTR; |
| 944 | |
Masami Hiramatsu | 747774d | 2019-06-01 00:17:37 +0900 | [diff] [blame] | 945 | trace_probe_set_flag(&tu->tp, TP_FLAG_PROFILE); |
Oleg Nesterov | 4821254 | 2014-06-27 19:01:36 +0200 | [diff] [blame] | 946 | } |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 947 | |
Oleg Nesterov | 736288b | 2013-02-03 20:58:35 +0100 | [diff] [blame] | 948 | WARN_ON(!uprobe_filter_is_empty(&tu->filter)); |
| 949 | |
zhangwei(Jovi) | 70ed91c | 2014-01-17 17:08:38 +0900 | [diff] [blame] | 950 | if (enabled) |
| 951 | return 0; |
| 952 | |
Oleg Nesterov | fb6bab6 | 2014-06-27 19:01:46 +0200 | [diff] [blame] | 953 | ret = uprobe_buffer_enable(); |
| 954 | if (ret) |
| 955 | goto err_flags; |
| 956 | |
Oleg Nesterov | 31ba334 | 2013-02-04 17:11:58 +0100 | [diff] [blame] | 957 | tu->consumer.filter = filter; |
Song Liu | 0c92c7a | 2018-04-23 10:21:34 -0700 | [diff] [blame] | 958 | tu->inode = d_real_inode(tu->path.dentry); |
Ravi Bangoria | 1cc3316 | 2018-08-20 10:12:47 +0530 | [diff] [blame] | 959 | if (tu->ref_ctr_offset) { |
| 960 | ret = uprobe_register_refctr(tu->inode, tu->offset, |
| 961 | tu->ref_ctr_offset, &tu->consumer); |
| 962 | } else { |
| 963 | ret = uprobe_register(tu->inode, tu->offset, &tu->consumer); |
| 964 | } |
| 965 | |
Oleg Nesterov | fb6bab6 | 2014-06-27 19:01:46 +0200 | [diff] [blame] | 966 | if (ret) |
| 967 | goto err_buffer; |
Oleg Nesterov | 4161824 | 2013-01-27 18:36:24 +0100 | [diff] [blame] | 968 | |
Oleg Nesterov | fb6bab6 | 2014-06-27 19:01:46 +0200 | [diff] [blame] | 969 | return 0; |
| 970 | |
| 971 | err_buffer: |
| 972 | uprobe_buffer_disable(); |
| 973 | |
| 974 | err_flags: |
Masami Hiramatsu | b5f935e | 2019-06-01 00:17:26 +0900 | [diff] [blame] | 975 | if (file) |
| 976 | trace_probe_remove_file(&tu->tp, file); |
| 977 | else |
Masami Hiramatsu | 747774d | 2019-06-01 00:17:37 +0900 | [diff] [blame] | 978 | trace_probe_clear_flag(&tu->tp, TP_FLAG_PROFILE); |
Masami Hiramatsu | b5f935e | 2019-06-01 00:17:26 +0900 | [diff] [blame] | 979 | |
Oleg Nesterov | 4161824 | 2013-01-27 18:36:24 +0100 | [diff] [blame] | 980 | return ret; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 981 | } |
| 982 | |
zhangwei(Jovi) | 70ed91c | 2014-01-17 17:08:38 +0900 | [diff] [blame] | 983 | static void |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 984 | probe_event_disable(struct trace_uprobe *tu, struct trace_event_file *file) |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 985 | { |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame] | 986 | if (!trace_probe_is_enabled(&tu->tp)) |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 987 | return; |
| 988 | |
zhangwei(Jovi) | 70ed91c | 2014-01-17 17:08:38 +0900 | [diff] [blame] | 989 | if (file) { |
Masami Hiramatsu | b5f935e | 2019-06-01 00:17:26 +0900 | [diff] [blame] | 990 | if (trace_probe_remove_file(&tu->tp, file) < 0) |
zhangwei(Jovi) | 70ed91c | 2014-01-17 17:08:38 +0900 | [diff] [blame] | 991 | return; |
| 992 | |
Masami Hiramatsu | b5f935e | 2019-06-01 00:17:26 +0900 | [diff] [blame] | 993 | if (trace_probe_is_enabled(&tu->tp)) |
zhangwei(Jovi) | 70ed91c | 2014-01-17 17:08:38 +0900 | [diff] [blame] | 994 | return; |
Masami Hiramatsu | b5f935e | 2019-06-01 00:17:26 +0900 | [diff] [blame] | 995 | } else |
Masami Hiramatsu | 747774d | 2019-06-01 00:17:37 +0900 | [diff] [blame] | 996 | trace_probe_clear_flag(&tu->tp, TP_FLAG_PROFILE); |
zhangwei(Jovi) | 70ed91c | 2014-01-17 17:08:38 +0900 | [diff] [blame] | 997 | |
Oleg Nesterov | 736288b | 2013-02-03 20:58:35 +0100 | [diff] [blame] | 998 | WARN_ON(!uprobe_filter_is_empty(&tu->filter)); |
| 999 | |
Oleg Nesterov | a932b73 | 2013-01-31 19:47:23 +0100 | [diff] [blame] | 1000 | uprobe_unregister(tu->inode, tu->offset, &tu->consumer); |
Song Liu | 0c92c7a | 2018-04-23 10:21:34 -0700 | [diff] [blame] | 1001 | tu->inode = NULL; |
Namhyung Kim | dcad1a2 | 2013-07-03 16:40:28 +0900 | [diff] [blame] | 1002 | |
| 1003 | uprobe_buffer_disable(); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1004 | } |
| 1005 | |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 1006 | static int uprobe_event_define_fields(struct trace_event_call *event_call) |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1007 | { |
Masami Hiramatsu | eeb07b0 | 2018-04-25 21:17:05 +0900 | [diff] [blame] | 1008 | int ret, size; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1009 | struct uprobe_trace_entry_head field; |
Oleg Nesterov | 457d177 | 2013-03-29 18:26:51 +0100 | [diff] [blame] | 1010 | struct trace_uprobe *tu = event_call->data; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1011 | |
Oleg Nesterov | 4d1298e | 2013-03-30 19:23:15 +0100 | [diff] [blame] | 1012 | if (is_ret_probe(tu)) { |
| 1013 | DEFINE_FIELD(unsigned long, vaddr[0], FIELD_STRING_FUNC, 0); |
| 1014 | DEFINE_FIELD(unsigned long, vaddr[1], FIELD_STRING_RETIP, 0); |
| 1015 | size = SIZEOF_TRACE_ENTRY(true); |
| 1016 | } else { |
| 1017 | DEFINE_FIELD(unsigned long, vaddr[0], FIELD_STRING_IP, 0); |
| 1018 | size = SIZEOF_TRACE_ENTRY(false); |
| 1019 | } |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame] | 1020 | |
Masami Hiramatsu | eeb07b0 | 2018-04-25 21:17:05 +0900 | [diff] [blame] | 1021 | return traceprobe_define_arg_fields(event_call, size, &tu->tp); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1022 | } |
| 1023 | |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1024 | #ifdef CONFIG_PERF_EVENTS |
Oleg Nesterov | 31ba334 | 2013-02-04 17:11:58 +0100 | [diff] [blame] | 1025 | static bool |
| 1026 | __uprobe_perf_filter(struct trace_uprobe_filter *filter, struct mm_struct *mm) |
| 1027 | { |
| 1028 | struct perf_event *event; |
| 1029 | |
| 1030 | if (filter->nr_systemwide) |
| 1031 | return true; |
| 1032 | |
| 1033 | list_for_each_entry(event, &filter->perf_events, hw.tp_list) { |
Peter Zijlstra | 50f16a8 | 2015-03-05 22:10:19 +0100 | [diff] [blame] | 1034 | if (event->hw.target->mm == mm) |
Oleg Nesterov | 31ba334 | 2013-02-04 17:11:58 +0100 | [diff] [blame] | 1035 | return true; |
| 1036 | } |
| 1037 | |
| 1038 | return false; |
| 1039 | } |
| 1040 | |
Oleg Nesterov | b2fe8ba | 2013-02-04 19:05:43 +0100 | [diff] [blame] | 1041 | static inline bool |
| 1042 | uprobe_filter_event(struct trace_uprobe *tu, struct perf_event *event) |
| 1043 | { |
Peter Zijlstra | 50f16a8 | 2015-03-05 22:10:19 +0100 | [diff] [blame] | 1044 | return __uprobe_perf_filter(&tu->filter, event->hw.target->mm); |
Oleg Nesterov | b2fe8ba | 2013-02-04 19:05:43 +0100 | [diff] [blame] | 1045 | } |
| 1046 | |
Oleg Nesterov | ce5f36a | 2014-04-24 13:26:01 +0200 | [diff] [blame] | 1047 | static int uprobe_perf_close(struct trace_uprobe *tu, struct perf_event *event) |
| 1048 | { |
| 1049 | bool done; |
| 1050 | |
| 1051 | write_lock(&tu->filter.rwlock); |
Peter Zijlstra | 50f16a8 | 2015-03-05 22:10:19 +0100 | [diff] [blame] | 1052 | if (event->hw.target) { |
Oleg Nesterov | ce5f36a | 2014-04-24 13:26:01 +0200 | [diff] [blame] | 1053 | list_del(&event->hw.tp_list); |
| 1054 | done = tu->filter.nr_systemwide || |
Peter Zijlstra | 50f16a8 | 2015-03-05 22:10:19 +0100 | [diff] [blame] | 1055 | (event->hw.target->flags & PF_EXITING) || |
Oleg Nesterov | ce5f36a | 2014-04-24 13:26:01 +0200 | [diff] [blame] | 1056 | uprobe_filter_event(tu, event); |
| 1057 | } else { |
| 1058 | tu->filter.nr_systemwide--; |
| 1059 | done = tu->filter.nr_systemwide; |
| 1060 | } |
| 1061 | write_unlock(&tu->filter.rwlock); |
| 1062 | |
| 1063 | if (!done) |
Oleg Nesterov | 927d687 | 2014-04-24 13:33:31 +0200 | [diff] [blame] | 1064 | return uprobe_apply(tu->inode, tu->offset, &tu->consumer, false); |
Oleg Nesterov | ce5f36a | 2014-04-24 13:26:01 +0200 | [diff] [blame] | 1065 | |
| 1066 | return 0; |
| 1067 | } |
| 1068 | |
Oleg Nesterov | 736288b | 2013-02-03 20:58:35 +0100 | [diff] [blame] | 1069 | static int uprobe_perf_open(struct trace_uprobe *tu, struct perf_event *event) |
| 1070 | { |
Oleg Nesterov | b2fe8ba | 2013-02-04 19:05:43 +0100 | [diff] [blame] | 1071 | bool done; |
Oleg Nesterov | 927d687 | 2014-04-24 13:33:31 +0200 | [diff] [blame] | 1072 | int err; |
Oleg Nesterov | b2fe8ba | 2013-02-04 19:05:43 +0100 | [diff] [blame] | 1073 | |
Oleg Nesterov | 736288b | 2013-02-03 20:58:35 +0100 | [diff] [blame] | 1074 | write_lock(&tu->filter.rwlock); |
Peter Zijlstra | 50f16a8 | 2015-03-05 22:10:19 +0100 | [diff] [blame] | 1075 | if (event->hw.target) { |
Oleg Nesterov | b2fe8ba | 2013-02-04 19:05:43 +0100 | [diff] [blame] | 1076 | /* |
| 1077 | * event->parent != NULL means copy_process(), we can avoid |
| 1078 | * uprobe_apply(). current->mm must be probed and we can rely |
| 1079 | * on dup_mmap() which preserves the already installed bp's. |
| 1080 | * |
| 1081 | * attr.enable_on_exec means that exec/mmap will install the |
| 1082 | * breakpoints we need. |
| 1083 | */ |
| 1084 | done = tu->filter.nr_systemwide || |
| 1085 | event->parent || event->attr.enable_on_exec || |
| 1086 | uprobe_filter_event(tu, event); |
Oleg Nesterov | 736288b | 2013-02-03 20:58:35 +0100 | [diff] [blame] | 1087 | list_add(&event->hw.tp_list, &tu->filter.perf_events); |
Oleg Nesterov | b2fe8ba | 2013-02-04 19:05:43 +0100 | [diff] [blame] | 1088 | } else { |
| 1089 | done = tu->filter.nr_systemwide; |
Oleg Nesterov | 736288b | 2013-02-03 20:58:35 +0100 | [diff] [blame] | 1090 | tu->filter.nr_systemwide++; |
Oleg Nesterov | b2fe8ba | 2013-02-04 19:05:43 +0100 | [diff] [blame] | 1091 | } |
Oleg Nesterov | 736288b | 2013-02-03 20:58:35 +0100 | [diff] [blame] | 1092 | write_unlock(&tu->filter.rwlock); |
| 1093 | |
Oleg Nesterov | 927d687 | 2014-04-24 13:33:31 +0200 | [diff] [blame] | 1094 | err = 0; |
| 1095 | if (!done) { |
| 1096 | err = uprobe_apply(tu->inode, tu->offset, &tu->consumer, true); |
| 1097 | if (err) |
| 1098 | uprobe_perf_close(tu, event); |
| 1099 | } |
| 1100 | return err; |
Oleg Nesterov | 736288b | 2013-02-03 20:58:35 +0100 | [diff] [blame] | 1101 | } |
| 1102 | |
Oleg Nesterov | 31ba334 | 2013-02-04 17:11:58 +0100 | [diff] [blame] | 1103 | static bool uprobe_perf_filter(struct uprobe_consumer *uc, |
| 1104 | enum uprobe_filter_ctx ctx, struct mm_struct *mm) |
| 1105 | { |
| 1106 | struct trace_uprobe *tu; |
| 1107 | int ret; |
| 1108 | |
| 1109 | tu = container_of(uc, struct trace_uprobe, consumer); |
| 1110 | read_lock(&tu->filter.rwlock); |
| 1111 | ret = __uprobe_perf_filter(&tu->filter, mm); |
| 1112 | read_unlock(&tu->filter.rwlock); |
| 1113 | |
| 1114 | return ret; |
| 1115 | } |
| 1116 | |
Namhyung Kim | a43b970 | 2014-01-17 17:08:36 +0900 | [diff] [blame] | 1117 | static void __uprobe_perf_func(struct trace_uprobe *tu, |
Namhyung Kim | dd9fa55 | 2014-01-17 17:08:37 +0900 | [diff] [blame] | 1118 | unsigned long func, struct pt_regs *regs, |
| 1119 | struct uprobe_cpu_buffer *ucb, int dsize) |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1120 | { |
Masami Hiramatsu | e3dc9f8 | 2019-06-01 00:17:57 +0900 | [diff] [blame] | 1121 | struct trace_event_call *call = trace_probe_event_call(&tu->tp); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1122 | struct uprobe_trace_entry_head *entry; |
| 1123 | struct hlist_head *head; |
Oleg Nesterov | 457d177 | 2013-03-29 18:26:51 +0100 | [diff] [blame] | 1124 | void *data; |
Namhyung Kim | dd9fa55 | 2014-01-17 17:08:37 +0900 | [diff] [blame] | 1125 | int size, esize; |
Namhyung Kim | dcad1a2 | 2013-07-03 16:40:28 +0900 | [diff] [blame] | 1126 | int rctx; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1127 | |
Yonghong Song | e87c6bc | 2017-10-23 23:53:08 -0700 | [diff] [blame] | 1128 | if (bpf_prog_array_valid(call) && !trace_call_bpf(call, regs)) |
Wang Nan | 04a22fa | 2015-07-01 02:13:50 +0000 | [diff] [blame] | 1129 | return; |
| 1130 | |
Namhyung Kim | dcad1a2 | 2013-07-03 16:40:28 +0900 | [diff] [blame] | 1131 | esize = SIZEOF_TRACE_ENTRY(is_ret_probe(tu)); |
| 1132 | |
Namhyung Kim | dcad1a2 | 2013-07-03 16:40:28 +0900 | [diff] [blame] | 1133 | size = esize + tu->tp.size + dsize; |
| 1134 | size = ALIGN(size + sizeof(u32), sizeof(u64)) - sizeof(u32); |
| 1135 | if (WARN_ONCE(size > PERF_MAX_TRACE_SIZE, "profile buffer not large enough")) |
| 1136 | return; |
| 1137 | |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1138 | preempt_disable(); |
Oleg Nesterov | 515619f | 2013-04-13 15:36:49 +0200 | [diff] [blame] | 1139 | head = this_cpu_ptr(call->perf_events); |
| 1140 | if (hlist_empty(head)) |
| 1141 | goto out; |
| 1142 | |
Alexei Starovoitov | 1e1dcd9 | 2016-04-06 18:43:24 -0700 | [diff] [blame] | 1143 | entry = perf_trace_buf_alloc(size, NULL, &rctx); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1144 | if (!entry) |
| 1145 | goto out; |
| 1146 | |
Oleg Nesterov | 393a736 | 2013-03-30 18:46:22 +0100 | [diff] [blame] | 1147 | if (is_ret_probe(tu)) { |
| 1148 | entry->vaddr[0] = func; |
Oleg Nesterov | 32520b2 | 2013-04-10 16:25:49 +0200 | [diff] [blame] | 1149 | entry->vaddr[1] = instruction_pointer(regs); |
Oleg Nesterov | 393a736 | 2013-03-30 18:46:22 +0100 | [diff] [blame] | 1150 | data = DATAOF_TRACE_ENTRY(entry, true); |
| 1151 | } else { |
Oleg Nesterov | 32520b2 | 2013-04-10 16:25:49 +0200 | [diff] [blame] | 1152 | entry->vaddr[0] = instruction_pointer(regs); |
Oleg Nesterov | 393a736 | 2013-03-30 18:46:22 +0100 | [diff] [blame] | 1153 | data = DATAOF_TRACE_ENTRY(entry, false); |
| 1154 | } |
| 1155 | |
Namhyung Kim | dcad1a2 | 2013-07-03 16:40:28 +0900 | [diff] [blame] | 1156 | memcpy(data, ucb->buf, tu->tp.size + dsize); |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame] | 1157 | |
Namhyung Kim | dcad1a2 | 2013-07-03 16:40:28 +0900 | [diff] [blame] | 1158 | if (size - esize > tu->tp.size + dsize) { |
| 1159 | int len = tu->tp.size + dsize; |
| 1160 | |
| 1161 | memset(data + len, 0, size - esize - len); |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame] | 1162 | } |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1163 | |
Alexei Starovoitov | 1e1dcd9 | 2016-04-06 18:43:24 -0700 | [diff] [blame] | 1164 | perf_trace_buf_submit(entry, size, rctx, call->event.type, 1, regs, |
Peter Zijlstra | 8fd0fbb | 2017-10-11 09:45:29 +0200 | [diff] [blame] | 1165 | head, NULL); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1166 | out: |
| 1167 | preempt_enable(); |
Oleg Nesterov | a51cc60 | 2013-03-30 18:02:12 +0100 | [diff] [blame] | 1168 | } |
| 1169 | |
| 1170 | /* uprobe profile handler */ |
Namhyung Kim | dd9fa55 | 2014-01-17 17:08:37 +0900 | [diff] [blame] | 1171 | static int uprobe_perf_func(struct trace_uprobe *tu, struct pt_regs *regs, |
| 1172 | struct uprobe_cpu_buffer *ucb, int dsize) |
Oleg Nesterov | a51cc60 | 2013-03-30 18:02:12 +0100 | [diff] [blame] | 1173 | { |
| 1174 | if (!uprobe_perf_filter(&tu->consumer, 0, current->mm)) |
| 1175 | return UPROBE_HANDLER_REMOVE; |
| 1176 | |
Oleg Nesterov | 393a736 | 2013-03-30 18:46:22 +0100 | [diff] [blame] | 1177 | if (!is_ret_probe(tu)) |
Namhyung Kim | dd9fa55 | 2014-01-17 17:08:37 +0900 | [diff] [blame] | 1178 | __uprobe_perf_func(tu, 0, regs, ucb, dsize); |
Oleg Nesterov | f42d24a | 2013-02-04 17:48:34 +0100 | [diff] [blame] | 1179 | return 0; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1180 | } |
Oleg Nesterov | c1ae5c7 | 2013-03-30 18:25:23 +0100 | [diff] [blame] | 1181 | |
| 1182 | static void uretprobe_perf_func(struct trace_uprobe *tu, unsigned long func, |
Namhyung Kim | dd9fa55 | 2014-01-17 17:08:37 +0900 | [diff] [blame] | 1183 | struct pt_regs *regs, |
| 1184 | struct uprobe_cpu_buffer *ucb, int dsize) |
Oleg Nesterov | c1ae5c7 | 2013-03-30 18:25:23 +0100 | [diff] [blame] | 1185 | { |
Namhyung Kim | dd9fa55 | 2014-01-17 17:08:37 +0900 | [diff] [blame] | 1186 | __uprobe_perf_func(tu, func, regs, ucb, dsize); |
Oleg Nesterov | c1ae5c7 | 2013-03-30 18:25:23 +0100 | [diff] [blame] | 1187 | } |
Yonghong Song | 41bdc4b | 2018-05-24 11:21:09 -0700 | [diff] [blame] | 1188 | |
| 1189 | int bpf_get_uprobe_info(const struct perf_event *event, u32 *fd_type, |
| 1190 | const char **filename, u64 *probe_offset, |
| 1191 | bool perf_type_tracepoint) |
| 1192 | { |
| 1193 | const char *pevent = trace_event_name(event->tp_event); |
| 1194 | const char *group = event->tp_event->class->system; |
| 1195 | struct trace_uprobe *tu; |
| 1196 | |
| 1197 | if (perf_type_tracepoint) |
| 1198 | tu = find_probe_event(pevent, group); |
| 1199 | else |
| 1200 | tu = event->tp_event->data; |
| 1201 | if (!tu) |
| 1202 | return -EINVAL; |
| 1203 | |
| 1204 | *fd_type = is_ret_probe(tu) ? BPF_FD_TYPE_URETPROBE |
| 1205 | : BPF_FD_TYPE_UPROBE; |
| 1206 | *filename = tu->filename; |
| 1207 | *probe_offset = tu->offset; |
| 1208 | return 0; |
| 1209 | } |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1210 | #endif /* CONFIG_PERF_EVENTS */ |
| 1211 | |
zhangwei(Jovi) | 70ed91c | 2014-01-17 17:08:38 +0900 | [diff] [blame] | 1212 | static int |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 1213 | trace_uprobe_register(struct trace_event_call *event, enum trace_reg type, |
zhangwei(Jovi) | 70ed91c | 2014-01-17 17:08:38 +0900 | [diff] [blame] | 1214 | void *data) |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1215 | { |
Oleg Nesterov | 457d177 | 2013-03-29 18:26:51 +0100 | [diff] [blame] | 1216 | struct trace_uprobe *tu = event->data; |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 1217 | struct trace_event_file *file = data; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1218 | |
| 1219 | switch (type) { |
| 1220 | case TRACE_REG_REGISTER: |
zhangwei(Jovi) | 70ed91c | 2014-01-17 17:08:38 +0900 | [diff] [blame] | 1221 | return probe_event_enable(tu, file, NULL); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1222 | |
| 1223 | case TRACE_REG_UNREGISTER: |
zhangwei(Jovi) | 70ed91c | 2014-01-17 17:08:38 +0900 | [diff] [blame] | 1224 | probe_event_disable(tu, file); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1225 | return 0; |
| 1226 | |
| 1227 | #ifdef CONFIG_PERF_EVENTS |
| 1228 | case TRACE_REG_PERF_REGISTER: |
zhangwei(Jovi) | 70ed91c | 2014-01-17 17:08:38 +0900 | [diff] [blame] | 1229 | return probe_event_enable(tu, NULL, uprobe_perf_filter); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1230 | |
| 1231 | case TRACE_REG_PERF_UNREGISTER: |
zhangwei(Jovi) | 70ed91c | 2014-01-17 17:08:38 +0900 | [diff] [blame] | 1232 | probe_event_disable(tu, NULL); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1233 | return 0; |
Oleg Nesterov | 736288b | 2013-02-03 20:58:35 +0100 | [diff] [blame] | 1234 | |
| 1235 | case TRACE_REG_PERF_OPEN: |
| 1236 | return uprobe_perf_open(tu, data); |
| 1237 | |
| 1238 | case TRACE_REG_PERF_CLOSE: |
| 1239 | return uprobe_perf_close(tu, data); |
| 1240 | |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1241 | #endif |
| 1242 | default: |
| 1243 | return 0; |
| 1244 | } |
| 1245 | return 0; |
| 1246 | } |
| 1247 | |
| 1248 | static int uprobe_dispatcher(struct uprobe_consumer *con, struct pt_regs *regs) |
| 1249 | { |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1250 | struct trace_uprobe *tu; |
Namhyung Kim | b7e0bf3 | 2013-11-25 13:42:47 +0900 | [diff] [blame] | 1251 | struct uprobe_dispatch_data udd; |
Namhyung Kim | dd9fa55 | 2014-01-17 17:08:37 +0900 | [diff] [blame] | 1252 | struct uprobe_cpu_buffer *ucb; |
| 1253 | int dsize, esize; |
Oleg Nesterov | f42d24a | 2013-02-04 17:48:34 +0100 | [diff] [blame] | 1254 | int ret = 0; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1255 | |
Namhyung Kim | dd9fa55 | 2014-01-17 17:08:37 +0900 | [diff] [blame] | 1256 | |
Oleg Nesterov | a932b73 | 2013-01-31 19:47:23 +0100 | [diff] [blame] | 1257 | tu = container_of(con, struct trace_uprobe, consumer); |
Oleg Nesterov | 1b47aef | 2013-01-31 19:55:27 +0100 | [diff] [blame] | 1258 | tu->nhit++; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1259 | |
Namhyung Kim | b7e0bf3 | 2013-11-25 13:42:47 +0900 | [diff] [blame] | 1260 | udd.tu = tu; |
| 1261 | udd.bp_addr = instruction_pointer(regs); |
| 1262 | |
| 1263 | current->utask->vaddr = (unsigned long) &udd; |
| 1264 | |
Namhyung Kim | dd9fa55 | 2014-01-17 17:08:37 +0900 | [diff] [blame] | 1265 | if (WARN_ON_ONCE(!uprobe_cpu_buffer)) |
| 1266 | return 0; |
| 1267 | |
| 1268 | dsize = __get_data_size(&tu->tp, regs); |
| 1269 | esize = SIZEOF_TRACE_ENTRY(is_ret_probe(tu)); |
| 1270 | |
| 1271 | ucb = uprobe_buffer_get(); |
Masami Hiramatsu | 9178412 | 2018-04-25 21:19:01 +0900 | [diff] [blame] | 1272 | store_trace_args(ucb->buf, &tu->tp, regs, esize, dsize); |
Namhyung Kim | dd9fa55 | 2014-01-17 17:08:37 +0900 | [diff] [blame] | 1273 | |
Masami Hiramatsu | 747774d | 2019-06-01 00:17:37 +0900 | [diff] [blame] | 1274 | if (trace_probe_test_flag(&tu->tp, TP_FLAG_TRACE)) |
Namhyung Kim | dd9fa55 | 2014-01-17 17:08:37 +0900 | [diff] [blame] | 1275 | ret |= uprobe_trace_func(tu, regs, ucb, dsize); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1276 | |
| 1277 | #ifdef CONFIG_PERF_EVENTS |
Masami Hiramatsu | 747774d | 2019-06-01 00:17:37 +0900 | [diff] [blame] | 1278 | if (trace_probe_test_flag(&tu->tp, TP_FLAG_PROFILE)) |
Namhyung Kim | dd9fa55 | 2014-01-17 17:08:37 +0900 | [diff] [blame] | 1279 | ret |= uprobe_perf_func(tu, regs, ucb, dsize); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1280 | #endif |
Namhyung Kim | dd9fa55 | 2014-01-17 17:08:37 +0900 | [diff] [blame] | 1281 | uprobe_buffer_put(ucb); |
Oleg Nesterov | f42d24a | 2013-02-04 17:48:34 +0100 | [diff] [blame] | 1282 | return ret; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1283 | } |
| 1284 | |
Oleg Nesterov | c1ae5c7 | 2013-03-30 18:25:23 +0100 | [diff] [blame] | 1285 | static int uretprobe_dispatcher(struct uprobe_consumer *con, |
| 1286 | unsigned long func, struct pt_regs *regs) |
| 1287 | { |
| 1288 | struct trace_uprobe *tu; |
Namhyung Kim | b7e0bf3 | 2013-11-25 13:42:47 +0900 | [diff] [blame] | 1289 | struct uprobe_dispatch_data udd; |
Namhyung Kim | dd9fa55 | 2014-01-17 17:08:37 +0900 | [diff] [blame] | 1290 | struct uprobe_cpu_buffer *ucb; |
| 1291 | int dsize, esize; |
Oleg Nesterov | c1ae5c7 | 2013-03-30 18:25:23 +0100 | [diff] [blame] | 1292 | |
| 1293 | tu = container_of(con, struct trace_uprobe, consumer); |
| 1294 | |
Namhyung Kim | b7e0bf3 | 2013-11-25 13:42:47 +0900 | [diff] [blame] | 1295 | udd.tu = tu; |
| 1296 | udd.bp_addr = func; |
| 1297 | |
| 1298 | current->utask->vaddr = (unsigned long) &udd; |
| 1299 | |
Namhyung Kim | dd9fa55 | 2014-01-17 17:08:37 +0900 | [diff] [blame] | 1300 | if (WARN_ON_ONCE(!uprobe_cpu_buffer)) |
| 1301 | return 0; |
| 1302 | |
| 1303 | dsize = __get_data_size(&tu->tp, regs); |
| 1304 | esize = SIZEOF_TRACE_ENTRY(is_ret_probe(tu)); |
| 1305 | |
| 1306 | ucb = uprobe_buffer_get(); |
Masami Hiramatsu | 9178412 | 2018-04-25 21:19:01 +0900 | [diff] [blame] | 1307 | store_trace_args(ucb->buf, &tu->tp, regs, esize, dsize); |
Namhyung Kim | dd9fa55 | 2014-01-17 17:08:37 +0900 | [diff] [blame] | 1308 | |
Masami Hiramatsu | 747774d | 2019-06-01 00:17:37 +0900 | [diff] [blame] | 1309 | if (trace_probe_test_flag(&tu->tp, TP_FLAG_TRACE)) |
Namhyung Kim | dd9fa55 | 2014-01-17 17:08:37 +0900 | [diff] [blame] | 1310 | uretprobe_trace_func(tu, func, regs, ucb, dsize); |
Oleg Nesterov | c1ae5c7 | 2013-03-30 18:25:23 +0100 | [diff] [blame] | 1311 | |
| 1312 | #ifdef CONFIG_PERF_EVENTS |
Masami Hiramatsu | 747774d | 2019-06-01 00:17:37 +0900 | [diff] [blame] | 1313 | if (trace_probe_test_flag(&tu->tp, TP_FLAG_PROFILE)) |
Namhyung Kim | dd9fa55 | 2014-01-17 17:08:37 +0900 | [diff] [blame] | 1314 | uretprobe_perf_func(tu, func, regs, ucb, dsize); |
Oleg Nesterov | c1ae5c7 | 2013-03-30 18:25:23 +0100 | [diff] [blame] | 1315 | #endif |
Namhyung Kim | dd9fa55 | 2014-01-17 17:08:37 +0900 | [diff] [blame] | 1316 | uprobe_buffer_put(ucb); |
Oleg Nesterov | c1ae5c7 | 2013-03-30 18:25:23 +0100 | [diff] [blame] | 1317 | return 0; |
| 1318 | } |
| 1319 | |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1320 | static struct trace_event_functions uprobe_funcs = { |
| 1321 | .trace = print_uprobe_event |
| 1322 | }; |
| 1323 | |
Masami Hiramatsu | e3dc9f8 | 2019-06-01 00:17:57 +0900 | [diff] [blame] | 1324 | static inline void init_trace_event_call(struct trace_uprobe *tu) |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1325 | { |
Masami Hiramatsu | e3dc9f8 | 2019-06-01 00:17:57 +0900 | [diff] [blame] | 1326 | struct trace_event_call *call = trace_probe_event_call(&tu->tp); |
| 1327 | |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1328 | call->event.funcs = &uprobe_funcs; |
| 1329 | call->class->define_fields = uprobe_event_define_fields; |
| 1330 | |
Song Liu | 9fd2e48 | 2019-05-07 09:15:45 -0700 | [diff] [blame] | 1331 | call->flags = TRACE_EVENT_FL_UPROBE | TRACE_EVENT_FL_CAP_ANY; |
Song Liu | 33ea4b2 | 2017-12-06 14:45:16 -0800 | [diff] [blame] | 1332 | call->class->reg = trace_uprobe_register; |
| 1333 | call->data = tu; |
| 1334 | } |
| 1335 | |
| 1336 | static int register_uprobe_event(struct trace_uprobe *tu) |
| 1337 | { |
Masami Hiramatsu | e3dc9f8 | 2019-06-01 00:17:57 +0900 | [diff] [blame] | 1338 | init_trace_event_call(tu); |
Song Liu | 33ea4b2 | 2017-12-06 14:45:16 -0800 | [diff] [blame] | 1339 | |
Masami Hiramatsu | 46e5376 | 2019-06-01 00:17:16 +0900 | [diff] [blame] | 1340 | return trace_probe_register_event_call(&tu->tp); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1341 | } |
| 1342 | |
Steven Rostedt (Red Hat) | c6c2401 | 2013-07-03 23:33:51 -0400 | [diff] [blame] | 1343 | static int unregister_uprobe_event(struct trace_uprobe *tu) |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1344 | { |
Masami Hiramatsu | 46e5376 | 2019-06-01 00:17:16 +0900 | [diff] [blame] | 1345 | return trace_probe_unregister_event_call(&tu->tp); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1346 | } |
| 1347 | |
Song Liu | 33ea4b2 | 2017-12-06 14:45:16 -0800 | [diff] [blame] | 1348 | #ifdef CONFIG_PERF_EVENTS |
| 1349 | struct trace_event_call * |
Song Liu | a6ca88b | 2018-10-01 22:36:36 -0700 | [diff] [blame] | 1350 | create_local_trace_uprobe(char *name, unsigned long offs, |
| 1351 | unsigned long ref_ctr_offset, bool is_return) |
Song Liu | 33ea4b2 | 2017-12-06 14:45:16 -0800 | [diff] [blame] | 1352 | { |
| 1353 | struct trace_uprobe *tu; |
Song Liu | 33ea4b2 | 2017-12-06 14:45:16 -0800 | [diff] [blame] | 1354 | struct path path; |
| 1355 | int ret; |
| 1356 | |
| 1357 | ret = kern_path(name, LOOKUP_FOLLOW, &path); |
| 1358 | if (ret) |
| 1359 | return ERR_PTR(ret); |
| 1360 | |
Song Liu | 0c92c7a | 2018-04-23 10:21:34 -0700 | [diff] [blame] | 1361 | if (!d_is_reg(path.dentry)) { |
| 1362 | path_put(&path); |
Song Liu | 33ea4b2 | 2017-12-06 14:45:16 -0800 | [diff] [blame] | 1363 | return ERR_PTR(-EINVAL); |
| 1364 | } |
| 1365 | |
| 1366 | /* |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 1367 | * local trace_kprobes are not added to dyn_event, so they are never |
Song Liu | 33ea4b2 | 2017-12-06 14:45:16 -0800 | [diff] [blame] | 1368 | * searched in find_trace_kprobe(). Therefore, there is no concern of |
| 1369 | * duplicated name "DUMMY_EVENT" here. |
| 1370 | */ |
| 1371 | tu = alloc_trace_uprobe(UPROBE_EVENT_SYSTEM, "DUMMY_EVENT", 0, |
| 1372 | is_return); |
| 1373 | |
| 1374 | if (IS_ERR(tu)) { |
| 1375 | pr_info("Failed to allocate trace_uprobe.(%d)\n", |
| 1376 | (int)PTR_ERR(tu)); |
Song Liu | 0c92c7a | 2018-04-23 10:21:34 -0700 | [diff] [blame] | 1377 | path_put(&path); |
Song Liu | 33ea4b2 | 2017-12-06 14:45:16 -0800 | [diff] [blame] | 1378 | return ERR_CAST(tu); |
| 1379 | } |
| 1380 | |
| 1381 | tu->offset = offs; |
Song Liu | 0c92c7a | 2018-04-23 10:21:34 -0700 | [diff] [blame] | 1382 | tu->path = path; |
Song Liu | a6ca88b | 2018-10-01 22:36:36 -0700 | [diff] [blame] | 1383 | tu->ref_ctr_offset = ref_ctr_offset; |
Song Liu | 33ea4b2 | 2017-12-06 14:45:16 -0800 | [diff] [blame] | 1384 | tu->filename = kstrdup(name, GFP_KERNEL); |
Masami Hiramatsu | e3dc9f8 | 2019-06-01 00:17:57 +0900 | [diff] [blame] | 1385 | init_trace_event_call(tu); |
Song Liu | 33ea4b2 | 2017-12-06 14:45:16 -0800 | [diff] [blame] | 1386 | |
Masami Hiramatsu | 0a46c85 | 2018-04-25 21:19:30 +0900 | [diff] [blame] | 1387 | if (traceprobe_set_print_fmt(&tu->tp, is_ret_probe(tu)) < 0) { |
Song Liu | 33ea4b2 | 2017-12-06 14:45:16 -0800 | [diff] [blame] | 1388 | ret = -ENOMEM; |
| 1389 | goto error; |
| 1390 | } |
| 1391 | |
Masami Hiramatsu | e3dc9f8 | 2019-06-01 00:17:57 +0900 | [diff] [blame] | 1392 | return trace_probe_event_call(&tu->tp); |
Song Liu | 33ea4b2 | 2017-12-06 14:45:16 -0800 | [diff] [blame] | 1393 | error: |
| 1394 | free_trace_uprobe(tu); |
| 1395 | return ERR_PTR(ret); |
| 1396 | } |
| 1397 | |
| 1398 | void destroy_local_trace_uprobe(struct trace_event_call *event_call) |
| 1399 | { |
| 1400 | struct trace_uprobe *tu; |
| 1401 | |
| 1402 | tu = container_of(event_call, struct trace_uprobe, tp.call); |
| 1403 | |
Song Liu | 33ea4b2 | 2017-12-06 14:45:16 -0800 | [diff] [blame] | 1404 | free_trace_uprobe(tu); |
| 1405 | } |
| 1406 | #endif /* CONFIG_PERF_EVENTS */ |
| 1407 | |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1408 | /* Make a trace interface for controling probe points */ |
| 1409 | static __init int init_uprobe_trace(void) |
| 1410 | { |
| 1411 | struct dentry *d_tracer; |
Masami Hiramatsu | 0597c49 | 2018-11-05 18:03:04 +0900 | [diff] [blame] | 1412 | int ret; |
| 1413 | |
| 1414 | ret = dyn_event_register(&trace_uprobe_ops); |
| 1415 | if (ret) |
| 1416 | return ret; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1417 | |
| 1418 | d_tracer = tracing_init_dentry(); |
Steven Rostedt (Red Hat) | 14a5ae4 | 2015-01-20 11:14:16 -0500 | [diff] [blame] | 1419 | if (IS_ERR(d_tracer)) |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1420 | return 0; |
| 1421 | |
| 1422 | trace_create_file("uprobe_events", 0644, d_tracer, |
| 1423 | NULL, &uprobe_events_ops); |
| 1424 | /* Profile interface */ |
| 1425 | trace_create_file("uprobe_profile", 0444, d_tracer, |
| 1426 | NULL, &uprobe_profile_ops); |
| 1427 | return 0; |
| 1428 | } |
| 1429 | |
| 1430 | fs_initcall(init_uprobe_trace); |