Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1 | /* |
| 2 | * uprobes-based tracing events |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 16 | * |
| 17 | * Copyright (C) IBM Corporation, 2010-2012 |
| 18 | * Author: Srikar Dronamraju <srikar@linux.vnet.ibm.com> |
| 19 | */ |
| 20 | |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/uaccess.h> |
| 23 | #include <linux/uprobes.h> |
| 24 | #include <linux/namei.h> |
Andy Shevchenko | b2e902f | 2012-12-17 16:01:27 -0800 | [diff] [blame] | 25 | #include <linux/string.h> |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 26 | |
| 27 | #include "trace_probe.h" |
| 28 | |
| 29 | #define UPROBE_EVENT_SYSTEM "uprobes" |
| 30 | |
Oleg Nesterov | 457d177 | 2013-03-29 18:26:51 +0100 | [diff] [blame] | 31 | struct uprobe_trace_entry_head { |
| 32 | struct trace_entry ent; |
| 33 | unsigned long vaddr[]; |
| 34 | }; |
| 35 | |
| 36 | #define SIZEOF_TRACE_ENTRY(is_return) \ |
| 37 | (sizeof(struct uprobe_trace_entry_head) + \ |
| 38 | sizeof(unsigned long) * (is_return ? 2 : 1)) |
| 39 | |
| 40 | #define DATAOF_TRACE_ENTRY(entry, is_return) \ |
| 41 | ((void*)(entry) + SIZEOF_TRACE_ENTRY(is_return)) |
| 42 | |
Oleg Nesterov | 736288b | 2013-02-03 20:58:35 +0100 | [diff] [blame] | 43 | struct trace_uprobe_filter { |
| 44 | rwlock_t rwlock; |
| 45 | int nr_systemwide; |
| 46 | struct list_head perf_events; |
| 47 | }; |
| 48 | |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 49 | /* |
| 50 | * uprobe event core functions |
| 51 | */ |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 52 | struct trace_uprobe { |
| 53 | struct list_head list; |
Oleg Nesterov | 736288b | 2013-02-03 20:58:35 +0100 | [diff] [blame] | 54 | struct trace_uprobe_filter filter; |
Oleg Nesterov | a932b73 | 2013-01-31 19:47:23 +0100 | [diff] [blame] | 55 | struct uprobe_consumer consumer; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 56 | struct inode *inode; |
| 57 | char *filename; |
| 58 | unsigned long offset; |
| 59 | unsigned long nhit; |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 60 | struct trace_probe tp; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 61 | }; |
| 62 | |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 63 | #define SIZEOF_TRACE_UPROBE(n) \ |
| 64 | (offsetof(struct trace_uprobe, tp.args) + \ |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 65 | (sizeof(struct probe_arg) * (n))) |
| 66 | |
| 67 | static int register_uprobe_event(struct trace_uprobe *tu); |
Steven Rostedt (Red Hat) | c6c2401 | 2013-07-03 23:33:51 -0400 | [diff] [blame] | 68 | static int unregister_uprobe_event(struct trace_uprobe *tu); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 69 | |
| 70 | static DEFINE_MUTEX(uprobe_lock); |
| 71 | static LIST_HEAD(uprobe_list); |
| 72 | |
| 73 | static int uprobe_dispatcher(struct uprobe_consumer *con, struct pt_regs *regs); |
Oleg Nesterov | c1ae5c7 | 2013-03-30 18:25:23 +0100 | [diff] [blame] | 74 | static int uretprobe_dispatcher(struct uprobe_consumer *con, |
| 75 | unsigned long func, struct pt_regs *regs); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 76 | |
Oleg Nesterov | 736288b | 2013-02-03 20:58:35 +0100 | [diff] [blame] | 77 | static inline void init_trace_uprobe_filter(struct trace_uprobe_filter *filter) |
| 78 | { |
| 79 | rwlock_init(&filter->rwlock); |
| 80 | filter->nr_systemwide = 0; |
| 81 | INIT_LIST_HEAD(&filter->perf_events); |
| 82 | } |
| 83 | |
| 84 | static inline bool uprobe_filter_is_empty(struct trace_uprobe_filter *filter) |
| 85 | { |
| 86 | return !filter->nr_systemwide && list_empty(&filter->perf_events); |
| 87 | } |
| 88 | |
Oleg Nesterov | c1ae5c7 | 2013-03-30 18:25:23 +0100 | [diff] [blame] | 89 | static inline bool is_ret_probe(struct trace_uprobe *tu) |
| 90 | { |
| 91 | return tu->consumer.ret_handler != NULL; |
| 92 | } |
| 93 | |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 94 | /* |
| 95 | * Allocate new trace_uprobe and initialize it (including uprobes). |
| 96 | */ |
| 97 | static struct trace_uprobe * |
Oleg Nesterov | c1ae5c7 | 2013-03-30 18:25:23 +0100 | [diff] [blame] | 98 | 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] | 99 | { |
| 100 | struct trace_uprobe *tu; |
| 101 | |
| 102 | if (!event || !is_good_name(event)) |
| 103 | return ERR_PTR(-EINVAL); |
| 104 | |
| 105 | if (!group || !is_good_name(group)) |
| 106 | return ERR_PTR(-EINVAL); |
| 107 | |
| 108 | tu = kzalloc(SIZEOF_TRACE_UPROBE(nargs), GFP_KERNEL); |
| 109 | if (!tu) |
| 110 | return ERR_PTR(-ENOMEM); |
| 111 | |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 112 | tu->tp.call.class = &tu->tp.class; |
| 113 | tu->tp.call.name = kstrdup(event, GFP_KERNEL); |
| 114 | if (!tu->tp.call.name) |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 115 | goto error; |
| 116 | |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 117 | tu->tp.class.system = kstrdup(group, GFP_KERNEL); |
| 118 | if (!tu->tp.class.system) |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 119 | goto error; |
| 120 | |
| 121 | INIT_LIST_HEAD(&tu->list); |
Oleg Nesterov | a932b73 | 2013-01-31 19:47:23 +0100 | [diff] [blame] | 122 | tu->consumer.handler = uprobe_dispatcher; |
Oleg Nesterov | c1ae5c7 | 2013-03-30 18:25:23 +0100 | [diff] [blame] | 123 | if (is_ret) |
| 124 | tu->consumer.ret_handler = uretprobe_dispatcher; |
Oleg Nesterov | 736288b | 2013-02-03 20:58:35 +0100 | [diff] [blame] | 125 | init_trace_uprobe_filter(&tu->filter); |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 126 | tu->tp.call.flags |= TRACE_EVENT_FL_USE_CALL_FILTER; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 127 | return tu; |
| 128 | |
| 129 | error: |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 130 | kfree(tu->tp.call.name); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 131 | kfree(tu); |
| 132 | |
| 133 | return ERR_PTR(-ENOMEM); |
| 134 | } |
| 135 | |
| 136 | static void free_trace_uprobe(struct trace_uprobe *tu) |
| 137 | { |
| 138 | int i; |
| 139 | |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 140 | for (i = 0; i < tu->tp.nr_args; i++) |
| 141 | traceprobe_free_probe_arg(&tu->tp.args[i]); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 142 | |
| 143 | iput(tu->inode); |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 144 | kfree(tu->tp.call.class->system); |
| 145 | kfree(tu->tp.call.name); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 146 | kfree(tu->filename); |
| 147 | kfree(tu); |
| 148 | } |
| 149 | |
| 150 | static struct trace_uprobe *find_probe_event(const char *event, const char *group) |
| 151 | { |
| 152 | struct trace_uprobe *tu; |
| 153 | |
| 154 | list_for_each_entry(tu, &uprobe_list, list) |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 155 | if (strcmp(tu->tp.call.name, event) == 0 && |
| 156 | strcmp(tu->tp.call.class->system, group) == 0) |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 157 | return tu; |
| 158 | |
| 159 | return NULL; |
| 160 | } |
| 161 | |
| 162 | /* Unregister a trace_uprobe and probe_event: call with locking uprobe_lock */ |
Steven Rostedt (Red Hat) | c6c2401 | 2013-07-03 23:33:51 -0400 | [diff] [blame] | 163 | static int unregister_trace_uprobe(struct trace_uprobe *tu) |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 164 | { |
Steven Rostedt (Red Hat) | c6c2401 | 2013-07-03 23:33:51 -0400 | [diff] [blame] | 165 | int ret; |
| 166 | |
| 167 | ret = unregister_uprobe_event(tu); |
| 168 | if (ret) |
| 169 | return ret; |
| 170 | |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 171 | list_del(&tu->list); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 172 | free_trace_uprobe(tu); |
Steven Rostedt (Red Hat) | c6c2401 | 2013-07-03 23:33:51 -0400 | [diff] [blame] | 173 | return 0; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | /* Register a trace_uprobe and probe_event */ |
| 177 | static int register_trace_uprobe(struct trace_uprobe *tu) |
| 178 | { |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 179 | struct trace_uprobe *old_tu; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 180 | int ret; |
| 181 | |
| 182 | mutex_lock(&uprobe_lock); |
| 183 | |
| 184 | /* register as an event */ |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 185 | old_tu = find_probe_event(tu->tp.call.name, tu->tp.call.class->system); |
| 186 | if (old_tu) { |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 187 | /* delete old event */ |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 188 | ret = unregister_trace_uprobe(old_tu); |
Steven Rostedt (Red Hat) | c6c2401 | 2013-07-03 23:33:51 -0400 | [diff] [blame] | 189 | if (ret) |
| 190 | goto end; |
| 191 | } |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 192 | |
| 193 | ret = register_uprobe_event(tu); |
| 194 | if (ret) { |
| 195 | pr_warning("Failed to register probe event(%d)\n", ret); |
| 196 | goto end; |
| 197 | } |
| 198 | |
| 199 | list_add_tail(&tu->list, &uprobe_list); |
| 200 | |
| 201 | end: |
| 202 | mutex_unlock(&uprobe_lock); |
| 203 | |
| 204 | return ret; |
| 205 | } |
| 206 | |
| 207 | /* |
| 208 | * Argument syntax: |
Namhyung Kim | 306cfe2 | 2013-07-03 16:44:46 +0900 | [diff] [blame] | 209 | * - Add uprobe: p|r[:[GRP/]EVENT] PATH:OFFSET [FETCHARGS] |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 210 | * |
| 211 | * - Remove uprobe: -:[GRP/]EVENT |
| 212 | */ |
| 213 | static int create_trace_uprobe(int argc, char **argv) |
| 214 | { |
| 215 | struct trace_uprobe *tu; |
| 216 | struct inode *inode; |
| 217 | char *arg, *event, *group, *filename; |
| 218 | char buf[MAX_EVENT_NAME_LEN]; |
| 219 | struct path path; |
| 220 | unsigned long offset; |
Oleg Nesterov | 4ee5a52 | 2013-03-30 20:28:15 +0100 | [diff] [blame] | 221 | bool is_delete, is_return; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 222 | int i, ret; |
| 223 | |
| 224 | inode = NULL; |
| 225 | ret = 0; |
| 226 | is_delete = false; |
Oleg Nesterov | 4ee5a52 | 2013-03-30 20:28:15 +0100 | [diff] [blame] | 227 | is_return = false; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 228 | event = NULL; |
| 229 | group = NULL; |
| 230 | |
| 231 | /* argc must be >= 1 */ |
| 232 | if (argv[0][0] == '-') |
| 233 | is_delete = true; |
Oleg Nesterov | 4ee5a52 | 2013-03-30 20:28:15 +0100 | [diff] [blame] | 234 | else if (argv[0][0] == 'r') |
| 235 | is_return = true; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 236 | else if (argv[0][0] != 'p') { |
Oleg Nesterov | 4ee5a52 | 2013-03-30 20:28:15 +0100 | [diff] [blame] | 237 | pr_info("Probe definition must be started with 'p', 'r' or '-'.\n"); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 238 | return -EINVAL; |
| 239 | } |
| 240 | |
| 241 | if (argv[0][1] == ':') { |
| 242 | event = &argv[0][2]; |
| 243 | arg = strchr(event, '/'); |
| 244 | |
| 245 | if (arg) { |
| 246 | group = event; |
| 247 | event = arg + 1; |
| 248 | event[-1] = '\0'; |
| 249 | |
| 250 | if (strlen(group) == 0) { |
| 251 | pr_info("Group name is not specified\n"); |
| 252 | return -EINVAL; |
| 253 | } |
| 254 | } |
| 255 | if (strlen(event) == 0) { |
| 256 | pr_info("Event name is not specified\n"); |
| 257 | return -EINVAL; |
| 258 | } |
| 259 | } |
| 260 | if (!group) |
| 261 | group = UPROBE_EVENT_SYSTEM; |
| 262 | |
| 263 | if (is_delete) { |
Steven Rostedt (Red Hat) | c6c2401 | 2013-07-03 23:33:51 -0400 | [diff] [blame] | 264 | int ret; |
| 265 | |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 266 | if (!event) { |
| 267 | pr_info("Delete command needs an event name.\n"); |
| 268 | return -EINVAL; |
| 269 | } |
| 270 | mutex_lock(&uprobe_lock); |
| 271 | tu = find_probe_event(event, group); |
| 272 | |
| 273 | if (!tu) { |
| 274 | mutex_unlock(&uprobe_lock); |
| 275 | pr_info("Event %s/%s doesn't exist.\n", group, event); |
| 276 | return -ENOENT; |
| 277 | } |
| 278 | /* delete an event */ |
Steven Rostedt (Red Hat) | c6c2401 | 2013-07-03 23:33:51 -0400 | [diff] [blame] | 279 | ret = unregister_trace_uprobe(tu); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 280 | mutex_unlock(&uprobe_lock); |
Steven Rostedt (Red Hat) | c6c2401 | 2013-07-03 23:33:51 -0400 | [diff] [blame] | 281 | return ret; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | if (argc < 2) { |
| 285 | pr_info("Probe point is not specified.\n"); |
| 286 | return -EINVAL; |
| 287 | } |
| 288 | if (isdigit(argv[1][0])) { |
| 289 | pr_info("probe point must be have a filename.\n"); |
| 290 | return -EINVAL; |
| 291 | } |
| 292 | arg = strchr(argv[1], ':'); |
zhangwei(Jovi) | fa44063 | 2013-06-13 14:21:51 +0800 | [diff] [blame] | 293 | if (!arg) { |
| 294 | ret = -EINVAL; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 295 | goto fail_address_parse; |
zhangwei(Jovi) | fa44063 | 2013-06-13 14:21:51 +0800 | [diff] [blame] | 296 | } |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 297 | |
| 298 | *arg++ = '\0'; |
| 299 | filename = argv[1]; |
| 300 | ret = kern_path(filename, LOOKUP_FOLLOW, &path); |
| 301 | if (ret) |
| 302 | goto fail_address_parse; |
| 303 | |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 304 | inode = igrab(path.dentry->d_inode); |
Oleg Nesterov | 84d7ed7 | 2013-01-27 18:20:45 +0100 | [diff] [blame] | 305 | path_put(&path); |
| 306 | |
Oleg Nesterov | 7e4e28c | 2013-01-28 17:08:47 +0100 | [diff] [blame] | 307 | if (!inode || !S_ISREG(inode->i_mode)) { |
Jovi Zhang | d24d7db | 2012-07-18 18:16:44 +0800 | [diff] [blame] | 308 | ret = -EINVAL; |
| 309 | goto fail_address_parse; |
| 310 | } |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 311 | |
Oleg Nesterov | 84d7ed7 | 2013-01-27 18:20:45 +0100 | [diff] [blame] | 312 | ret = kstrtoul(arg, 0, &offset); |
| 313 | if (ret) |
| 314 | goto fail_address_parse; |
| 315 | |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 316 | argc -= 2; |
| 317 | argv += 2; |
| 318 | |
| 319 | /* setup a probe */ |
| 320 | if (!event) { |
Andy Shevchenko | b2e902f | 2012-12-17 16:01:27 -0800 | [diff] [blame] | 321 | char *tail; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 322 | char *ptr; |
| 323 | |
Andy Shevchenko | b2e902f | 2012-12-17 16:01:27 -0800 | [diff] [blame] | 324 | tail = kstrdup(kbasename(filename), GFP_KERNEL); |
| 325 | if (!tail) { |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 326 | ret = -ENOMEM; |
| 327 | goto fail_address_parse; |
| 328 | } |
| 329 | |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 330 | ptr = strpbrk(tail, ".-_"); |
| 331 | if (ptr) |
| 332 | *ptr = '\0'; |
| 333 | |
| 334 | snprintf(buf, MAX_EVENT_NAME_LEN, "%c_%s_0x%lx", 'p', tail, offset); |
| 335 | event = buf; |
| 336 | kfree(tail); |
| 337 | } |
| 338 | |
Oleg Nesterov | 4ee5a52 | 2013-03-30 20:28:15 +0100 | [diff] [blame] | 339 | tu = alloc_trace_uprobe(group, event, argc, is_return); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 340 | if (IS_ERR(tu)) { |
| 341 | pr_info("Failed to allocate trace_uprobe.(%d)\n", (int)PTR_ERR(tu)); |
| 342 | ret = PTR_ERR(tu); |
| 343 | goto fail_address_parse; |
| 344 | } |
| 345 | tu->offset = offset; |
| 346 | tu->inode = inode; |
| 347 | tu->filename = kstrdup(filename, GFP_KERNEL); |
| 348 | |
| 349 | if (!tu->filename) { |
| 350 | pr_info("Failed to allocate filename.\n"); |
| 351 | ret = -ENOMEM; |
| 352 | goto error; |
| 353 | } |
| 354 | |
| 355 | /* parse arguments */ |
| 356 | ret = 0; |
| 357 | for (i = 0; i < argc && i < MAX_TRACE_ARGS; i++) { |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 358 | struct probe_arg *parg = &tu->tp.args[i]; |
| 359 | |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 360 | /* Increment count for freeing args in error case */ |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 361 | tu->tp.nr_args++; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 362 | |
| 363 | /* Parse argument name */ |
| 364 | arg = strchr(argv[i], '='); |
| 365 | if (arg) { |
| 366 | *arg++ = '\0'; |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 367 | parg->name = kstrdup(argv[i], GFP_KERNEL); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 368 | } else { |
| 369 | arg = argv[i]; |
| 370 | /* If argument name is omitted, set "argN" */ |
| 371 | snprintf(buf, MAX_EVENT_NAME_LEN, "arg%d", i + 1); |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 372 | parg->name = kstrdup(buf, GFP_KERNEL); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 373 | } |
| 374 | |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 375 | if (!parg->name) { |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 376 | pr_info("Failed to allocate argument[%d] name.\n", i); |
| 377 | ret = -ENOMEM; |
| 378 | goto error; |
| 379 | } |
| 380 | |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 381 | if (!is_good_name(parg->name)) { |
| 382 | pr_info("Invalid argument[%d] name: %s\n", i, parg->name); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 383 | ret = -EINVAL; |
| 384 | goto error; |
| 385 | } |
| 386 | |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 387 | if (traceprobe_conflict_field_name(parg->name, tu->tp.args, i)) { |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 388 | pr_info("Argument[%d] name '%s' conflicts with " |
| 389 | "another field.\n", i, argv[i]); |
| 390 | ret = -EINVAL; |
| 391 | goto error; |
| 392 | } |
| 393 | |
| 394 | /* Parse fetch argument */ |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 395 | ret = traceprobe_parse_probe_arg(arg, &tu->tp.size, parg, |
| 396 | false, false); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 397 | if (ret) { |
| 398 | pr_info("Parse error at argument[%d]. (%d)\n", i, ret); |
| 399 | goto error; |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | ret = register_trace_uprobe(tu); |
| 404 | if (ret) |
| 405 | goto error; |
| 406 | return 0; |
| 407 | |
| 408 | error: |
| 409 | free_trace_uprobe(tu); |
| 410 | return ret; |
| 411 | |
| 412 | fail_address_parse: |
| 413 | if (inode) |
| 414 | iput(inode); |
| 415 | |
Jovi Zhang | d24d7db | 2012-07-18 18:16:44 +0800 | [diff] [blame] | 416 | pr_info("Failed to parse address or file.\n"); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 417 | |
| 418 | return ret; |
| 419 | } |
| 420 | |
Steven Rostedt (Red Hat) | c6c2401 | 2013-07-03 23:33:51 -0400 | [diff] [blame] | 421 | static int cleanup_all_probes(void) |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 422 | { |
| 423 | struct trace_uprobe *tu; |
Steven Rostedt (Red Hat) | c6c2401 | 2013-07-03 23:33:51 -0400 | [diff] [blame] | 424 | int ret = 0; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 425 | |
| 426 | mutex_lock(&uprobe_lock); |
| 427 | while (!list_empty(&uprobe_list)) { |
| 428 | tu = list_entry(uprobe_list.next, struct trace_uprobe, list); |
Steven Rostedt (Red Hat) | c6c2401 | 2013-07-03 23:33:51 -0400 | [diff] [blame] | 429 | ret = unregister_trace_uprobe(tu); |
| 430 | if (ret) |
| 431 | break; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 432 | } |
| 433 | mutex_unlock(&uprobe_lock); |
Steven Rostedt (Red Hat) | c6c2401 | 2013-07-03 23:33:51 -0400 | [diff] [blame] | 434 | return ret; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | /* Probes listing interfaces */ |
| 438 | static void *probes_seq_start(struct seq_file *m, loff_t *pos) |
| 439 | { |
| 440 | mutex_lock(&uprobe_lock); |
| 441 | return seq_list_start(&uprobe_list, *pos); |
| 442 | } |
| 443 | |
| 444 | static void *probes_seq_next(struct seq_file *m, void *v, loff_t *pos) |
| 445 | { |
| 446 | return seq_list_next(v, &uprobe_list, pos); |
| 447 | } |
| 448 | |
| 449 | static void probes_seq_stop(struct seq_file *m, void *v) |
| 450 | { |
| 451 | mutex_unlock(&uprobe_lock); |
| 452 | } |
| 453 | |
| 454 | static int probes_seq_show(struct seq_file *m, void *v) |
| 455 | { |
| 456 | struct trace_uprobe *tu = v; |
Oleg Nesterov | 3ede82d | 2013-03-30 19:48:09 +0100 | [diff] [blame] | 457 | char c = is_ret_probe(tu) ? 'r' : 'p'; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 458 | int i; |
| 459 | |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 460 | seq_printf(m, "%c:%s/%s", c, tu->tp.call.class->system, tu->tp.call.name); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 461 | seq_printf(m, " %s:0x%p", tu->filename, (void *)tu->offset); |
| 462 | |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 463 | for (i = 0; i < tu->tp.nr_args; i++) |
| 464 | 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] | 465 | |
| 466 | seq_printf(m, "\n"); |
| 467 | return 0; |
| 468 | } |
| 469 | |
| 470 | static const struct seq_operations probes_seq_op = { |
| 471 | .start = probes_seq_start, |
| 472 | .next = probes_seq_next, |
| 473 | .stop = probes_seq_stop, |
| 474 | .show = probes_seq_show |
| 475 | }; |
| 476 | |
| 477 | static int probes_open(struct inode *inode, struct file *file) |
| 478 | { |
Steven Rostedt (Red Hat) | c6c2401 | 2013-07-03 23:33:51 -0400 | [diff] [blame] | 479 | int ret; |
| 480 | |
| 481 | if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_TRUNC)) { |
| 482 | ret = cleanup_all_probes(); |
| 483 | if (ret) |
| 484 | return ret; |
| 485 | } |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 486 | |
| 487 | return seq_open(file, &probes_seq_op); |
| 488 | } |
| 489 | |
| 490 | static ssize_t probes_write(struct file *file, const char __user *buffer, |
| 491 | size_t count, loff_t *ppos) |
| 492 | { |
| 493 | return traceprobe_probes_write(file, buffer, count, ppos, create_trace_uprobe); |
| 494 | } |
| 495 | |
| 496 | static const struct file_operations uprobe_events_ops = { |
| 497 | .owner = THIS_MODULE, |
| 498 | .open = probes_open, |
| 499 | .read = seq_read, |
| 500 | .llseek = seq_lseek, |
| 501 | .release = seq_release, |
| 502 | .write = probes_write, |
| 503 | }; |
| 504 | |
| 505 | /* Probes profiling interfaces */ |
| 506 | static int probes_profile_seq_show(struct seq_file *m, void *v) |
| 507 | { |
| 508 | struct trace_uprobe *tu = v; |
| 509 | |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 510 | seq_printf(m, " %s %-44s %15lu\n", tu->filename, tu->tp.call.name, tu->nhit); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 511 | return 0; |
| 512 | } |
| 513 | |
| 514 | static const struct seq_operations profile_seq_op = { |
| 515 | .start = probes_seq_start, |
| 516 | .next = probes_seq_next, |
| 517 | .stop = probes_seq_stop, |
| 518 | .show = probes_profile_seq_show |
| 519 | }; |
| 520 | |
| 521 | static int profile_open(struct inode *inode, struct file *file) |
| 522 | { |
| 523 | return seq_open(file, &profile_seq_op); |
| 524 | } |
| 525 | |
| 526 | static const struct file_operations uprobe_profile_ops = { |
| 527 | .owner = THIS_MODULE, |
| 528 | .open = profile_open, |
| 529 | .read = seq_read, |
| 530 | .llseek = seq_lseek, |
| 531 | .release = seq_release, |
| 532 | }; |
| 533 | |
Oleg Nesterov | a51cc60 | 2013-03-30 18:02:12 +0100 | [diff] [blame] | 534 | static void uprobe_trace_print(struct trace_uprobe *tu, |
| 535 | unsigned long func, struct pt_regs *regs) |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 536 | { |
| 537 | struct uprobe_trace_entry_head *entry; |
| 538 | struct ring_buffer_event *event; |
| 539 | struct ring_buffer *buffer; |
Oleg Nesterov | 457d177 | 2013-03-29 18:26:51 +0100 | [diff] [blame] | 540 | void *data; |
Oleg Nesterov | 0e3853d | 2013-03-28 19:19:11 +0100 | [diff] [blame] | 541 | int size, i; |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 542 | struct ftrace_event_call *call = &tu->tp.call; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 543 | |
Oleg Nesterov | 393a736 | 2013-03-30 18:46:22 +0100 | [diff] [blame] | 544 | size = SIZEOF_TRACE_ENTRY(is_ret_probe(tu)); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 545 | event = trace_current_buffer_lock_reserve(&buffer, call->event.type, |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 546 | size + tu->tp.size, 0, 0); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 547 | if (!event) |
Oleg Nesterov | a51cc60 | 2013-03-30 18:02:12 +0100 | [diff] [blame] | 548 | return; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 549 | |
| 550 | entry = ring_buffer_event_data(event); |
Oleg Nesterov | 393a736 | 2013-03-30 18:46:22 +0100 | [diff] [blame] | 551 | if (is_ret_probe(tu)) { |
| 552 | entry->vaddr[0] = func; |
| 553 | entry->vaddr[1] = instruction_pointer(regs); |
| 554 | data = DATAOF_TRACE_ENTRY(entry, true); |
| 555 | } else { |
| 556 | entry->vaddr[0] = instruction_pointer(regs); |
| 557 | data = DATAOF_TRACE_ENTRY(entry, false); |
| 558 | } |
| 559 | |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 560 | for (i = 0; i < tu->tp.nr_args; i++) { |
| 561 | call_fetch(&tu->tp.args[i].fetch, regs, |
| 562 | data + tu->tp.args[i].offset); |
| 563 | } |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 564 | |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 565 | if (!call_filter_check_discard(call, entry, buffer, event)) |
Oleg Nesterov | 0e3853d | 2013-03-28 19:19:11 +0100 | [diff] [blame] | 566 | trace_buffer_unlock_commit(buffer, event, 0, 0); |
Oleg Nesterov | a51cc60 | 2013-03-30 18:02:12 +0100 | [diff] [blame] | 567 | } |
Oleg Nesterov | f42d24a | 2013-02-04 17:48:34 +0100 | [diff] [blame] | 568 | |
Oleg Nesterov | a51cc60 | 2013-03-30 18:02:12 +0100 | [diff] [blame] | 569 | /* uprobe handler */ |
| 570 | static int uprobe_trace_func(struct trace_uprobe *tu, struct pt_regs *regs) |
| 571 | { |
Oleg Nesterov | 393a736 | 2013-03-30 18:46:22 +0100 | [diff] [blame] | 572 | if (!is_ret_probe(tu)) |
| 573 | uprobe_trace_print(tu, 0, regs); |
Oleg Nesterov | f42d24a | 2013-02-04 17:48:34 +0100 | [diff] [blame] | 574 | return 0; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 575 | } |
| 576 | |
Oleg Nesterov | c1ae5c7 | 2013-03-30 18:25:23 +0100 | [diff] [blame] | 577 | static void uretprobe_trace_func(struct trace_uprobe *tu, unsigned long func, |
| 578 | struct pt_regs *regs) |
| 579 | { |
| 580 | uprobe_trace_print(tu, func, regs); |
| 581 | } |
| 582 | |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 583 | /* Event entry printers */ |
| 584 | static enum print_line_t |
| 585 | print_uprobe_event(struct trace_iterator *iter, int flags, struct trace_event *event) |
| 586 | { |
Oleg Nesterov | 457d177 | 2013-03-29 18:26:51 +0100 | [diff] [blame] | 587 | struct uprobe_trace_entry_head *entry; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 588 | struct trace_seq *s = &iter->seq; |
| 589 | struct trace_uprobe *tu; |
| 590 | u8 *data; |
| 591 | int i; |
| 592 | |
Oleg Nesterov | 457d177 | 2013-03-29 18:26:51 +0100 | [diff] [blame] | 593 | entry = (struct uprobe_trace_entry_head *)iter->ent; |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 594 | tu = container_of(event, struct trace_uprobe, tp.call.event); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 595 | |
Oleg Nesterov | 3ede82d | 2013-03-30 19:48:09 +0100 | [diff] [blame] | 596 | if (is_ret_probe(tu)) { |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 597 | if (!trace_seq_printf(s, "%s: (0x%lx <- 0x%lx)", tu->tp.call.name, |
Oleg Nesterov | 3ede82d | 2013-03-30 19:48:09 +0100 | [diff] [blame] | 598 | entry->vaddr[1], entry->vaddr[0])) |
| 599 | goto partial; |
| 600 | data = DATAOF_TRACE_ENTRY(entry, true); |
| 601 | } else { |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 602 | if (!trace_seq_printf(s, "%s: (0x%lx)", tu->tp.call.name, |
Oleg Nesterov | 3ede82d | 2013-03-30 19:48:09 +0100 | [diff] [blame] | 603 | entry->vaddr[0])) |
| 604 | goto partial; |
| 605 | data = DATAOF_TRACE_ENTRY(entry, false); |
| 606 | } |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 607 | |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 608 | for (i = 0; i < tu->tp.nr_args; i++) { |
| 609 | struct probe_arg *parg = &tu->tp.args[i]; |
| 610 | |
| 611 | if (!parg->type->print(s, parg->name, data + parg->offset, entry)) |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 612 | goto partial; |
| 613 | } |
| 614 | |
| 615 | if (trace_seq_puts(s, "\n")) |
| 616 | return TRACE_TYPE_HANDLED; |
| 617 | |
| 618 | partial: |
| 619 | return TRACE_TYPE_PARTIAL_LINE; |
| 620 | } |
| 621 | |
Oleg Nesterov | 31ba334 | 2013-02-04 17:11:58 +0100 | [diff] [blame] | 622 | typedef bool (*filter_func_t)(struct uprobe_consumer *self, |
| 623 | enum uprobe_filter_ctx ctx, |
| 624 | struct mm_struct *mm); |
| 625 | |
| 626 | static int |
| 627 | probe_event_enable(struct trace_uprobe *tu, int flag, filter_func_t filter) |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 628 | { |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 629 | int ret = 0; |
| 630 | |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 631 | if (trace_probe_is_enabled(&tu->tp)) |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 632 | return -EINTR; |
| 633 | |
Oleg Nesterov | 736288b | 2013-02-03 20:58:35 +0100 | [diff] [blame] | 634 | WARN_ON(!uprobe_filter_is_empty(&tu->filter)); |
| 635 | |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 636 | tu->tp.flags |= flag; |
Oleg Nesterov | 31ba334 | 2013-02-04 17:11:58 +0100 | [diff] [blame] | 637 | tu->consumer.filter = filter; |
Oleg Nesterov | a932b73 | 2013-01-31 19:47:23 +0100 | [diff] [blame] | 638 | ret = uprobe_register(tu->inode, tu->offset, &tu->consumer); |
| 639 | if (ret) |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 640 | tu->tp.flags &= ~flag; |
Oleg Nesterov | 4161824 | 2013-01-27 18:36:24 +0100 | [diff] [blame] | 641 | |
| 642 | return ret; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | static void probe_event_disable(struct trace_uprobe *tu, int flag) |
| 646 | { |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 647 | if (!trace_probe_is_enabled(&tu->tp)) |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 648 | return; |
| 649 | |
Oleg Nesterov | 736288b | 2013-02-03 20:58:35 +0100 | [diff] [blame] | 650 | WARN_ON(!uprobe_filter_is_empty(&tu->filter)); |
| 651 | |
Oleg Nesterov | a932b73 | 2013-01-31 19:47:23 +0100 | [diff] [blame] | 652 | uprobe_unregister(tu->inode, tu->offset, &tu->consumer); |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 653 | tu->tp.flags &= ~flag; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | static int uprobe_event_define_fields(struct ftrace_event_call *event_call) |
| 657 | { |
Oleg Nesterov | 457d177 | 2013-03-29 18:26:51 +0100 | [diff] [blame] | 658 | int ret, i, size; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 659 | struct uprobe_trace_entry_head field; |
Oleg Nesterov | 457d177 | 2013-03-29 18:26:51 +0100 | [diff] [blame] | 660 | struct trace_uprobe *tu = event_call->data; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 661 | |
Oleg Nesterov | 4d1298e | 2013-03-30 19:23:15 +0100 | [diff] [blame] | 662 | if (is_ret_probe(tu)) { |
| 663 | DEFINE_FIELD(unsigned long, vaddr[0], FIELD_STRING_FUNC, 0); |
| 664 | DEFINE_FIELD(unsigned long, vaddr[1], FIELD_STRING_RETIP, 0); |
| 665 | size = SIZEOF_TRACE_ENTRY(true); |
| 666 | } else { |
| 667 | DEFINE_FIELD(unsigned long, vaddr[0], FIELD_STRING_IP, 0); |
| 668 | size = SIZEOF_TRACE_ENTRY(false); |
| 669 | } |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 670 | /* Set argument names as fields */ |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 671 | for (i = 0; i < tu->tp.nr_args; i++) { |
| 672 | struct probe_arg *parg = &tu->tp.args[i]; |
| 673 | |
| 674 | ret = trace_define_field(event_call, parg->type->fmttype, |
| 675 | parg->name, size + parg->offset, |
| 676 | parg->type->size, parg->type->is_signed, |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 677 | FILTER_OTHER); |
| 678 | |
| 679 | if (ret) |
| 680 | return ret; |
| 681 | } |
| 682 | return 0; |
| 683 | } |
| 684 | |
| 685 | #define LEN_OR_ZERO (len ? len - pos : 0) |
| 686 | static int __set_print_fmt(struct trace_uprobe *tu, char *buf, int len) |
| 687 | { |
| 688 | const char *fmt, *arg; |
| 689 | int i; |
| 690 | int pos = 0; |
| 691 | |
Oleg Nesterov | 4d1298e | 2013-03-30 19:23:15 +0100 | [diff] [blame] | 692 | if (is_ret_probe(tu)) { |
| 693 | fmt = "(%lx <- %lx)"; |
| 694 | arg = "REC->" FIELD_STRING_FUNC ", REC->" FIELD_STRING_RETIP; |
| 695 | } else { |
| 696 | fmt = "(%lx)"; |
| 697 | arg = "REC->" FIELD_STRING_IP; |
| 698 | } |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 699 | |
| 700 | /* When len=0, we just calculate the needed length */ |
| 701 | |
| 702 | pos += snprintf(buf + pos, LEN_OR_ZERO, "\"%s", fmt); |
| 703 | |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 704 | for (i = 0; i < tu->tp.nr_args; i++) { |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 705 | pos += snprintf(buf + pos, LEN_OR_ZERO, " %s=%s", |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 706 | tu->tp.args[i].name, tu->tp.args[i].type->fmt); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | pos += snprintf(buf + pos, LEN_OR_ZERO, "\", %s", arg); |
| 710 | |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 711 | for (i = 0; i < tu->tp.nr_args; i++) { |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 712 | pos += snprintf(buf + pos, LEN_OR_ZERO, ", REC->%s", |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 713 | tu->tp.args[i].name); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | return pos; /* return the length of print_fmt */ |
| 717 | } |
| 718 | #undef LEN_OR_ZERO |
| 719 | |
| 720 | static int set_print_fmt(struct trace_uprobe *tu) |
| 721 | { |
| 722 | char *print_fmt; |
| 723 | int len; |
| 724 | |
| 725 | /* First: called with 0 length to calculate the needed length */ |
| 726 | len = __set_print_fmt(tu, NULL, 0); |
| 727 | print_fmt = kmalloc(len + 1, GFP_KERNEL); |
| 728 | if (!print_fmt) |
| 729 | return -ENOMEM; |
| 730 | |
| 731 | /* Second: actually write the @print_fmt */ |
| 732 | __set_print_fmt(tu, print_fmt, len + 1); |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 733 | tu->tp.call.print_fmt = print_fmt; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 734 | |
| 735 | return 0; |
| 736 | } |
| 737 | |
| 738 | #ifdef CONFIG_PERF_EVENTS |
Oleg Nesterov | 31ba334 | 2013-02-04 17:11:58 +0100 | [diff] [blame] | 739 | static bool |
| 740 | __uprobe_perf_filter(struct trace_uprobe_filter *filter, struct mm_struct *mm) |
| 741 | { |
| 742 | struct perf_event *event; |
| 743 | |
| 744 | if (filter->nr_systemwide) |
| 745 | return true; |
| 746 | |
| 747 | list_for_each_entry(event, &filter->perf_events, hw.tp_list) { |
| 748 | if (event->hw.tp_target->mm == mm) |
| 749 | return true; |
| 750 | } |
| 751 | |
| 752 | return false; |
| 753 | } |
| 754 | |
Oleg Nesterov | b2fe8ba | 2013-02-04 19:05:43 +0100 | [diff] [blame] | 755 | static inline bool |
| 756 | uprobe_filter_event(struct trace_uprobe *tu, struct perf_event *event) |
| 757 | { |
| 758 | return __uprobe_perf_filter(&tu->filter, event->hw.tp_target->mm); |
| 759 | } |
| 760 | |
Oleg Nesterov | 736288b | 2013-02-03 20:58:35 +0100 | [diff] [blame] | 761 | static int uprobe_perf_open(struct trace_uprobe *tu, struct perf_event *event) |
| 762 | { |
Oleg Nesterov | b2fe8ba | 2013-02-04 19:05:43 +0100 | [diff] [blame] | 763 | bool done; |
| 764 | |
Oleg Nesterov | 736288b | 2013-02-03 20:58:35 +0100 | [diff] [blame] | 765 | write_lock(&tu->filter.rwlock); |
Oleg Nesterov | b2fe8ba | 2013-02-04 19:05:43 +0100 | [diff] [blame] | 766 | if (event->hw.tp_target) { |
| 767 | /* |
| 768 | * event->parent != NULL means copy_process(), we can avoid |
| 769 | * uprobe_apply(). current->mm must be probed and we can rely |
| 770 | * on dup_mmap() which preserves the already installed bp's. |
| 771 | * |
| 772 | * attr.enable_on_exec means that exec/mmap will install the |
| 773 | * breakpoints we need. |
| 774 | */ |
| 775 | done = tu->filter.nr_systemwide || |
| 776 | event->parent || event->attr.enable_on_exec || |
| 777 | uprobe_filter_event(tu, event); |
Oleg Nesterov | 736288b | 2013-02-03 20:58:35 +0100 | [diff] [blame] | 778 | list_add(&event->hw.tp_list, &tu->filter.perf_events); |
Oleg Nesterov | b2fe8ba | 2013-02-04 19:05:43 +0100 | [diff] [blame] | 779 | } else { |
| 780 | done = tu->filter.nr_systemwide; |
Oleg Nesterov | 736288b | 2013-02-03 20:58:35 +0100 | [diff] [blame] | 781 | tu->filter.nr_systemwide++; |
Oleg Nesterov | b2fe8ba | 2013-02-04 19:05:43 +0100 | [diff] [blame] | 782 | } |
Oleg Nesterov | 736288b | 2013-02-03 20:58:35 +0100 | [diff] [blame] | 783 | write_unlock(&tu->filter.rwlock); |
| 784 | |
Oleg Nesterov | b2fe8ba | 2013-02-04 19:05:43 +0100 | [diff] [blame] | 785 | if (!done) |
| 786 | uprobe_apply(tu->inode, tu->offset, &tu->consumer, true); |
Oleg Nesterov | 31ba334 | 2013-02-04 17:11:58 +0100 | [diff] [blame] | 787 | |
Oleg Nesterov | 736288b | 2013-02-03 20:58:35 +0100 | [diff] [blame] | 788 | return 0; |
| 789 | } |
| 790 | |
| 791 | static int uprobe_perf_close(struct trace_uprobe *tu, struct perf_event *event) |
| 792 | { |
Oleg Nesterov | b2fe8ba | 2013-02-04 19:05:43 +0100 | [diff] [blame] | 793 | bool done; |
| 794 | |
Oleg Nesterov | 736288b | 2013-02-03 20:58:35 +0100 | [diff] [blame] | 795 | write_lock(&tu->filter.rwlock); |
Oleg Nesterov | b2fe8ba | 2013-02-04 19:05:43 +0100 | [diff] [blame] | 796 | if (event->hw.tp_target) { |
Oleg Nesterov | 736288b | 2013-02-03 20:58:35 +0100 | [diff] [blame] | 797 | list_del(&event->hw.tp_list); |
Oleg Nesterov | b2fe8ba | 2013-02-04 19:05:43 +0100 | [diff] [blame] | 798 | done = tu->filter.nr_systemwide || |
| 799 | (event->hw.tp_target->flags & PF_EXITING) || |
| 800 | uprobe_filter_event(tu, event); |
| 801 | } else { |
Oleg Nesterov | 736288b | 2013-02-03 20:58:35 +0100 | [diff] [blame] | 802 | tu->filter.nr_systemwide--; |
Oleg Nesterov | b2fe8ba | 2013-02-04 19:05:43 +0100 | [diff] [blame] | 803 | done = tu->filter.nr_systemwide; |
| 804 | } |
Oleg Nesterov | 736288b | 2013-02-03 20:58:35 +0100 | [diff] [blame] | 805 | write_unlock(&tu->filter.rwlock); |
| 806 | |
Oleg Nesterov | b2fe8ba | 2013-02-04 19:05:43 +0100 | [diff] [blame] | 807 | if (!done) |
| 808 | uprobe_apply(tu->inode, tu->offset, &tu->consumer, false); |
Oleg Nesterov | 31ba334 | 2013-02-04 17:11:58 +0100 | [diff] [blame] | 809 | |
Oleg Nesterov | 736288b | 2013-02-03 20:58:35 +0100 | [diff] [blame] | 810 | return 0; |
| 811 | } |
| 812 | |
Oleg Nesterov | 31ba334 | 2013-02-04 17:11:58 +0100 | [diff] [blame] | 813 | static bool uprobe_perf_filter(struct uprobe_consumer *uc, |
| 814 | enum uprobe_filter_ctx ctx, struct mm_struct *mm) |
| 815 | { |
| 816 | struct trace_uprobe *tu; |
| 817 | int ret; |
| 818 | |
| 819 | tu = container_of(uc, struct trace_uprobe, consumer); |
| 820 | read_lock(&tu->filter.rwlock); |
| 821 | ret = __uprobe_perf_filter(&tu->filter, mm); |
| 822 | read_unlock(&tu->filter.rwlock); |
| 823 | |
| 824 | return ret; |
| 825 | } |
| 826 | |
Oleg Nesterov | a51cc60 | 2013-03-30 18:02:12 +0100 | [diff] [blame] | 827 | static void uprobe_perf_print(struct trace_uprobe *tu, |
| 828 | unsigned long func, struct pt_regs *regs) |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 829 | { |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 830 | struct ftrace_event_call *call = &tu->tp.call; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 831 | struct uprobe_trace_entry_head *entry; |
| 832 | struct hlist_head *head; |
Oleg Nesterov | 457d177 | 2013-03-29 18:26:51 +0100 | [diff] [blame] | 833 | void *data; |
| 834 | int size, rctx, i; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 835 | |
Oleg Nesterov | 393a736 | 2013-03-30 18:46:22 +0100 | [diff] [blame] | 836 | size = SIZEOF_TRACE_ENTRY(is_ret_probe(tu)); |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 837 | size = ALIGN(size + tu->tp.size + sizeof(u32), sizeof(u64)) - sizeof(u32); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 838 | |
| 839 | preempt_disable(); |
Oleg Nesterov | 515619f | 2013-04-13 15:36:49 +0200 | [diff] [blame] | 840 | head = this_cpu_ptr(call->perf_events); |
| 841 | if (hlist_empty(head)) |
| 842 | goto out; |
| 843 | |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 844 | entry = perf_trace_buf_prepare(size, call->event.type, regs, &rctx); |
| 845 | if (!entry) |
| 846 | goto out; |
| 847 | |
Oleg Nesterov | 393a736 | 2013-03-30 18:46:22 +0100 | [diff] [blame] | 848 | if (is_ret_probe(tu)) { |
| 849 | entry->vaddr[0] = func; |
Oleg Nesterov | 32520b2 | 2013-04-10 16:25:49 +0200 | [diff] [blame] | 850 | entry->vaddr[1] = instruction_pointer(regs); |
Oleg Nesterov | 393a736 | 2013-03-30 18:46:22 +0100 | [diff] [blame] | 851 | data = DATAOF_TRACE_ENTRY(entry, true); |
| 852 | } else { |
Oleg Nesterov | 32520b2 | 2013-04-10 16:25:49 +0200 | [diff] [blame] | 853 | entry->vaddr[0] = instruction_pointer(regs); |
Oleg Nesterov | 393a736 | 2013-03-30 18:46:22 +0100 | [diff] [blame] | 854 | data = DATAOF_TRACE_ENTRY(entry, false); |
| 855 | } |
| 856 | |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 857 | for (i = 0; i < tu->tp.nr_args; i++) { |
| 858 | struct probe_arg *parg = &tu->tp.args[i]; |
| 859 | |
| 860 | call_fetch(&parg->fetch, regs, data + parg->offset); |
| 861 | } |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 862 | |
Oleg Nesterov | 32520b2 | 2013-04-10 16:25:49 +0200 | [diff] [blame] | 863 | perf_trace_buf_submit(entry, size, rctx, 0, 1, regs, head, NULL); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 864 | out: |
| 865 | preempt_enable(); |
Oleg Nesterov | a51cc60 | 2013-03-30 18:02:12 +0100 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | /* uprobe profile handler */ |
| 869 | static int uprobe_perf_func(struct trace_uprobe *tu, struct pt_regs *regs) |
| 870 | { |
| 871 | if (!uprobe_perf_filter(&tu->consumer, 0, current->mm)) |
| 872 | return UPROBE_HANDLER_REMOVE; |
| 873 | |
Oleg Nesterov | 393a736 | 2013-03-30 18:46:22 +0100 | [diff] [blame] | 874 | if (!is_ret_probe(tu)) |
| 875 | uprobe_perf_print(tu, 0, regs); |
Oleg Nesterov | f42d24a | 2013-02-04 17:48:34 +0100 | [diff] [blame] | 876 | return 0; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 877 | } |
Oleg Nesterov | c1ae5c7 | 2013-03-30 18:25:23 +0100 | [diff] [blame] | 878 | |
| 879 | static void uretprobe_perf_func(struct trace_uprobe *tu, unsigned long func, |
| 880 | struct pt_regs *regs) |
| 881 | { |
| 882 | uprobe_perf_print(tu, func, regs); |
| 883 | } |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 884 | #endif /* CONFIG_PERF_EVENTS */ |
| 885 | |
| 886 | static |
| 887 | int trace_uprobe_register(struct ftrace_event_call *event, enum trace_reg type, void *data) |
| 888 | { |
Oleg Nesterov | 457d177 | 2013-03-29 18:26:51 +0100 | [diff] [blame] | 889 | struct trace_uprobe *tu = event->data; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 890 | |
| 891 | switch (type) { |
| 892 | case TRACE_REG_REGISTER: |
Oleg Nesterov | 31ba334 | 2013-02-04 17:11:58 +0100 | [diff] [blame] | 893 | return probe_event_enable(tu, TP_FLAG_TRACE, NULL); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 894 | |
| 895 | case TRACE_REG_UNREGISTER: |
| 896 | probe_event_disable(tu, TP_FLAG_TRACE); |
| 897 | return 0; |
| 898 | |
| 899 | #ifdef CONFIG_PERF_EVENTS |
| 900 | case TRACE_REG_PERF_REGISTER: |
Oleg Nesterov | 31ba334 | 2013-02-04 17:11:58 +0100 | [diff] [blame] | 901 | return probe_event_enable(tu, TP_FLAG_PROFILE, uprobe_perf_filter); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 902 | |
| 903 | case TRACE_REG_PERF_UNREGISTER: |
| 904 | probe_event_disable(tu, TP_FLAG_PROFILE); |
| 905 | return 0; |
Oleg Nesterov | 736288b | 2013-02-03 20:58:35 +0100 | [diff] [blame] | 906 | |
| 907 | case TRACE_REG_PERF_OPEN: |
| 908 | return uprobe_perf_open(tu, data); |
| 909 | |
| 910 | case TRACE_REG_PERF_CLOSE: |
| 911 | return uprobe_perf_close(tu, data); |
| 912 | |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 913 | #endif |
| 914 | default: |
| 915 | return 0; |
| 916 | } |
| 917 | return 0; |
| 918 | } |
| 919 | |
| 920 | static int uprobe_dispatcher(struct uprobe_consumer *con, struct pt_regs *regs) |
| 921 | { |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 922 | struct trace_uprobe *tu; |
Oleg Nesterov | f42d24a | 2013-02-04 17:48:34 +0100 | [diff] [blame] | 923 | int ret = 0; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 924 | |
Oleg Nesterov | a932b73 | 2013-01-31 19:47:23 +0100 | [diff] [blame] | 925 | tu = container_of(con, struct trace_uprobe, consumer); |
Oleg Nesterov | 1b47aef | 2013-01-31 19:55:27 +0100 | [diff] [blame] | 926 | tu->nhit++; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 927 | |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 928 | if (tu->tp.flags & TP_FLAG_TRACE) |
Oleg Nesterov | f42d24a | 2013-02-04 17:48:34 +0100 | [diff] [blame] | 929 | ret |= uprobe_trace_func(tu, regs); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 930 | |
| 931 | #ifdef CONFIG_PERF_EVENTS |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 932 | if (tu->tp.flags & TP_FLAG_PROFILE) |
Oleg Nesterov | f42d24a | 2013-02-04 17:48:34 +0100 | [diff] [blame] | 933 | ret |= uprobe_perf_func(tu, regs); |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 934 | #endif |
Oleg Nesterov | f42d24a | 2013-02-04 17:48:34 +0100 | [diff] [blame] | 935 | return ret; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 936 | } |
| 937 | |
Oleg Nesterov | c1ae5c7 | 2013-03-30 18:25:23 +0100 | [diff] [blame] | 938 | static int uretprobe_dispatcher(struct uprobe_consumer *con, |
| 939 | unsigned long func, struct pt_regs *regs) |
| 940 | { |
| 941 | struct trace_uprobe *tu; |
| 942 | |
| 943 | tu = container_of(con, struct trace_uprobe, consumer); |
| 944 | |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 945 | if (tu->tp.flags & TP_FLAG_TRACE) |
Oleg Nesterov | c1ae5c7 | 2013-03-30 18:25:23 +0100 | [diff] [blame] | 946 | uretprobe_trace_func(tu, func, regs); |
| 947 | |
| 948 | #ifdef CONFIG_PERF_EVENTS |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 949 | if (tu->tp.flags & TP_FLAG_PROFILE) |
Oleg Nesterov | c1ae5c7 | 2013-03-30 18:25:23 +0100 | [diff] [blame] | 950 | uretprobe_perf_func(tu, func, regs); |
| 951 | #endif |
| 952 | return 0; |
| 953 | } |
| 954 | |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 955 | static struct trace_event_functions uprobe_funcs = { |
| 956 | .trace = print_uprobe_event |
| 957 | }; |
| 958 | |
| 959 | static int register_uprobe_event(struct trace_uprobe *tu) |
| 960 | { |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 961 | struct ftrace_event_call *call = &tu->tp.call; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 962 | int ret; |
| 963 | |
| 964 | /* Initialize ftrace_event_call */ |
| 965 | INIT_LIST_HEAD(&call->class->fields); |
| 966 | call->event.funcs = &uprobe_funcs; |
| 967 | call->class->define_fields = uprobe_event_define_fields; |
| 968 | |
| 969 | if (set_print_fmt(tu) < 0) |
| 970 | return -ENOMEM; |
| 971 | |
| 972 | ret = register_ftrace_event(&call->event); |
| 973 | if (!ret) { |
| 974 | kfree(call->print_fmt); |
| 975 | return -ENODEV; |
| 976 | } |
| 977 | call->flags = 0; |
| 978 | call->class->reg = trace_uprobe_register; |
| 979 | call->data = tu; |
| 980 | ret = trace_add_event_call(call); |
| 981 | |
| 982 | if (ret) { |
| 983 | pr_info("Failed to register uprobe event: %s\n", call->name); |
| 984 | kfree(call->print_fmt); |
| 985 | unregister_ftrace_event(&call->event); |
| 986 | } |
| 987 | |
| 988 | return ret; |
| 989 | } |
| 990 | |
Steven Rostedt (Red Hat) | c6c2401 | 2013-07-03 23:33:51 -0400 | [diff] [blame] | 991 | static int unregister_uprobe_event(struct trace_uprobe *tu) |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 992 | { |
Steven Rostedt (Red Hat) | c6c2401 | 2013-07-03 23:33:51 -0400 | [diff] [blame] | 993 | int ret; |
| 994 | |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 995 | /* tu->event is unregistered in trace_remove_event_call() */ |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 996 | ret = trace_remove_event_call(&tu->tp.call); |
Steven Rostedt (Red Hat) | c6c2401 | 2013-07-03 23:33:51 -0400 | [diff] [blame] | 997 | if (ret) |
| 998 | return ret; |
Namhyung Kim | 14577c3 | 2013-07-03 15:42:53 +0900 | [diff] [blame^] | 999 | kfree(tu->tp.call.print_fmt); |
| 1000 | tu->tp.call.print_fmt = NULL; |
Steven Rostedt (Red Hat) | c6c2401 | 2013-07-03 23:33:51 -0400 | [diff] [blame] | 1001 | return 0; |
Srikar Dronamraju | f3f096c | 2012-04-11 16:00:43 +0530 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | /* Make a trace interface for controling probe points */ |
| 1005 | static __init int init_uprobe_trace(void) |
| 1006 | { |
| 1007 | struct dentry *d_tracer; |
| 1008 | |
| 1009 | d_tracer = tracing_init_dentry(); |
| 1010 | if (!d_tracer) |
| 1011 | return 0; |
| 1012 | |
| 1013 | trace_create_file("uprobe_events", 0644, d_tracer, |
| 1014 | NULL, &uprobe_events_ops); |
| 1015 | /* Profile interface */ |
| 1016 | trace_create_file("uprobe_profile", 0444, d_tracer, |
| 1017 | NULL, &uprobe_profile_ops); |
| 1018 | return 0; |
| 1019 | } |
| 1020 | |
| 1021 | fs_initcall(init_uprobe_trace); |