blob: b233d9cb1216483985fbd3eed8dfe3e3abe9a118 [file] [log] [blame]
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +05301/*
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 Shevchenkob2e902f2012-12-17 16:01:27 -080025#include <linux/string.h>
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +053026
27#include "trace_probe.h"
28
29#define UPROBE_EVENT_SYSTEM "uprobes"
30
Oleg Nesterov457d1772013-03-29 18:26:51 +010031struct 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 Nesterov736288b2013-02-03 20:58:35 +010043struct trace_uprobe_filter {
44 rwlock_t rwlock;
45 int nr_systemwide;
46 struct list_head perf_events;
47};
48
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +053049/*
50 * uprobe event core functions
51 */
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +053052struct trace_uprobe {
53 struct list_head list;
Oleg Nesterov736288b2013-02-03 20:58:35 +010054 struct trace_uprobe_filter filter;
Oleg Nesterova932b732013-01-31 19:47:23 +010055 struct uprobe_consumer consumer;
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +053056 struct inode *inode;
57 char *filename;
58 unsigned long offset;
59 unsigned long nhit;
Namhyung Kim14577c32013-07-03 15:42:53 +090060 struct trace_probe tp;
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +053061};
62
Namhyung Kim14577c32013-07-03 15:42:53 +090063#define SIZEOF_TRACE_UPROBE(n) \
64 (offsetof(struct trace_uprobe, tp.args) + \
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +053065 (sizeof(struct probe_arg) * (n)))
66
67static int register_uprobe_event(struct trace_uprobe *tu);
Steven Rostedt (Red Hat)c6c24012013-07-03 23:33:51 -040068static int unregister_uprobe_event(struct trace_uprobe *tu);
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +053069
70static DEFINE_MUTEX(uprobe_lock);
71static LIST_HEAD(uprobe_list);
72
73static int uprobe_dispatcher(struct uprobe_consumer *con, struct pt_regs *regs);
Oleg Nesterovc1ae5c72013-03-30 18:25:23 +010074static int uretprobe_dispatcher(struct uprobe_consumer *con,
75 unsigned long func, struct pt_regs *regs);
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +053076
Oleg Nesterov736288b2013-02-03 20:58:35 +010077static 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
84static 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 Nesterovc1ae5c72013-03-30 18:25:23 +010089static inline bool is_ret_probe(struct trace_uprobe *tu)
90{
91 return tu->consumer.ret_handler != NULL;
92}
93
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +053094/*
95 * Allocate new trace_uprobe and initialize it (including uprobes).
96 */
97static struct trace_uprobe *
Oleg Nesterovc1ae5c72013-03-30 18:25:23 +010098alloc_trace_uprobe(const char *group, const char *event, int nargs, bool is_ret)
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +053099{
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 Kim14577c32013-07-03 15:42:53 +0900112 tu->tp.call.class = &tu->tp.class;
113 tu->tp.call.name = kstrdup(event, GFP_KERNEL);
114 if (!tu->tp.call.name)
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530115 goto error;
116
Namhyung Kim14577c32013-07-03 15:42:53 +0900117 tu->tp.class.system = kstrdup(group, GFP_KERNEL);
118 if (!tu->tp.class.system)
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530119 goto error;
120
121 INIT_LIST_HEAD(&tu->list);
Oleg Nesterova932b732013-01-31 19:47:23 +0100122 tu->consumer.handler = uprobe_dispatcher;
Oleg Nesterovc1ae5c72013-03-30 18:25:23 +0100123 if (is_ret)
124 tu->consumer.ret_handler = uretprobe_dispatcher;
Oleg Nesterov736288b2013-02-03 20:58:35 +0100125 init_trace_uprobe_filter(&tu->filter);
Namhyung Kim14577c32013-07-03 15:42:53 +0900126 tu->tp.call.flags |= TRACE_EVENT_FL_USE_CALL_FILTER;
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530127 return tu;
128
129error:
Namhyung Kim14577c32013-07-03 15:42:53 +0900130 kfree(tu->tp.call.name);
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530131 kfree(tu);
132
133 return ERR_PTR(-ENOMEM);
134}
135
136static void free_trace_uprobe(struct trace_uprobe *tu)
137{
138 int i;
139
Namhyung Kim14577c32013-07-03 15:42:53 +0900140 for (i = 0; i < tu->tp.nr_args; i++)
141 traceprobe_free_probe_arg(&tu->tp.args[i]);
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530142
143 iput(tu->inode);
Namhyung Kim14577c32013-07-03 15:42:53 +0900144 kfree(tu->tp.call.class->system);
145 kfree(tu->tp.call.name);
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530146 kfree(tu->filename);
147 kfree(tu);
148}
149
150static 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 Kim14577c32013-07-03 15:42:53 +0900155 if (strcmp(tu->tp.call.name, event) == 0 &&
156 strcmp(tu->tp.call.class->system, group) == 0)
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530157 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)c6c24012013-07-03 23:33:51 -0400163static int unregister_trace_uprobe(struct trace_uprobe *tu)
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530164{
Steven Rostedt (Red Hat)c6c24012013-07-03 23:33:51 -0400165 int ret;
166
167 ret = unregister_uprobe_event(tu);
168 if (ret)
169 return ret;
170
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530171 list_del(&tu->list);
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530172 free_trace_uprobe(tu);
Steven Rostedt (Red Hat)c6c24012013-07-03 23:33:51 -0400173 return 0;
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530174}
175
176/* Register a trace_uprobe and probe_event */
177static int register_trace_uprobe(struct trace_uprobe *tu)
178{
Namhyung Kim14577c32013-07-03 15:42:53 +0900179 struct trace_uprobe *old_tu;
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530180 int ret;
181
182 mutex_lock(&uprobe_lock);
183
184 /* register as an event */
Namhyung Kim14577c32013-07-03 15:42:53 +0900185 old_tu = find_probe_event(tu->tp.call.name, tu->tp.call.class->system);
186 if (old_tu) {
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530187 /* delete old event */
Namhyung Kim14577c32013-07-03 15:42:53 +0900188 ret = unregister_trace_uprobe(old_tu);
Steven Rostedt (Red Hat)c6c24012013-07-03 23:33:51 -0400189 if (ret)
190 goto end;
191 }
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530192
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
201end:
202 mutex_unlock(&uprobe_lock);
203
204 return ret;
205}
206
207/*
208 * Argument syntax:
Namhyung Kim306cfe22013-07-03 16:44:46 +0900209 * - Add uprobe: p|r[:[GRP/]EVENT] PATH:OFFSET [FETCHARGS]
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530210 *
211 * - Remove uprobe: -:[GRP/]EVENT
212 */
213static 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 Nesterov4ee5a522013-03-30 20:28:15 +0100221 bool is_delete, is_return;
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530222 int i, ret;
223
224 inode = NULL;
225 ret = 0;
226 is_delete = false;
Oleg Nesterov4ee5a522013-03-30 20:28:15 +0100227 is_return = false;
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530228 event = NULL;
229 group = NULL;
230
231 /* argc must be >= 1 */
232 if (argv[0][0] == '-')
233 is_delete = true;
Oleg Nesterov4ee5a522013-03-30 20:28:15 +0100234 else if (argv[0][0] == 'r')
235 is_return = true;
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530236 else if (argv[0][0] != 'p') {
Oleg Nesterov4ee5a522013-03-30 20:28:15 +0100237 pr_info("Probe definition must be started with 'p', 'r' or '-'.\n");
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530238 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)c6c24012013-07-03 23:33:51 -0400264 int ret;
265
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530266 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)c6c24012013-07-03 23:33:51 -0400279 ret = unregister_trace_uprobe(tu);
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530280 mutex_unlock(&uprobe_lock);
Steven Rostedt (Red Hat)c6c24012013-07-03 23:33:51 -0400281 return ret;
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530282 }
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)fa440632013-06-13 14:21:51 +0800293 if (!arg) {
294 ret = -EINVAL;
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530295 goto fail_address_parse;
zhangwei(Jovi)fa440632013-06-13 14:21:51 +0800296 }
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530297
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 Dronamrajuf3f096c2012-04-11 16:00:43 +0530304 inode = igrab(path.dentry->d_inode);
Oleg Nesterov84d7ed72013-01-27 18:20:45 +0100305 path_put(&path);
306
Oleg Nesterov7e4e28c2013-01-28 17:08:47 +0100307 if (!inode || !S_ISREG(inode->i_mode)) {
Jovi Zhangd24d7db2012-07-18 18:16:44 +0800308 ret = -EINVAL;
309 goto fail_address_parse;
310 }
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530311
Oleg Nesterov84d7ed72013-01-27 18:20:45 +0100312 ret = kstrtoul(arg, 0, &offset);
313 if (ret)
314 goto fail_address_parse;
315
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530316 argc -= 2;
317 argv += 2;
318
319 /* setup a probe */
320 if (!event) {
Andy Shevchenkob2e902f2012-12-17 16:01:27 -0800321 char *tail;
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530322 char *ptr;
323
Andy Shevchenkob2e902f2012-12-17 16:01:27 -0800324 tail = kstrdup(kbasename(filename), GFP_KERNEL);
325 if (!tail) {
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530326 ret = -ENOMEM;
327 goto fail_address_parse;
328 }
329
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530330 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 Nesterov4ee5a522013-03-30 20:28:15 +0100339 tu = alloc_trace_uprobe(group, event, argc, is_return);
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530340 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 Kim14577c32013-07-03 15:42:53 +0900358 struct probe_arg *parg = &tu->tp.args[i];
359
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530360 /* Increment count for freeing args in error case */
Namhyung Kim14577c32013-07-03 15:42:53 +0900361 tu->tp.nr_args++;
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530362
363 /* Parse argument name */
364 arg = strchr(argv[i], '=');
365 if (arg) {
366 *arg++ = '\0';
Namhyung Kim14577c32013-07-03 15:42:53 +0900367 parg->name = kstrdup(argv[i], GFP_KERNEL);
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530368 } 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 Kim14577c32013-07-03 15:42:53 +0900372 parg->name = kstrdup(buf, GFP_KERNEL);
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530373 }
374
Namhyung Kim14577c32013-07-03 15:42:53 +0900375 if (!parg->name) {
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530376 pr_info("Failed to allocate argument[%d] name.\n", i);
377 ret = -ENOMEM;
378 goto error;
379 }
380
Namhyung Kim14577c32013-07-03 15:42:53 +0900381 if (!is_good_name(parg->name)) {
382 pr_info("Invalid argument[%d] name: %s\n", i, parg->name);
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530383 ret = -EINVAL;
384 goto error;
385 }
386
Namhyung Kim14577c32013-07-03 15:42:53 +0900387 if (traceprobe_conflict_field_name(parg->name, tu->tp.args, i)) {
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530388 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 Kim14577c32013-07-03 15:42:53 +0900395 ret = traceprobe_parse_probe_arg(arg, &tu->tp.size, parg,
396 false, false);
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530397 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
408error:
409 free_trace_uprobe(tu);
410 return ret;
411
412fail_address_parse:
413 if (inode)
414 iput(inode);
415
Jovi Zhangd24d7db2012-07-18 18:16:44 +0800416 pr_info("Failed to parse address or file.\n");
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530417
418 return ret;
419}
420
Steven Rostedt (Red Hat)c6c24012013-07-03 23:33:51 -0400421static int cleanup_all_probes(void)
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530422{
423 struct trace_uprobe *tu;
Steven Rostedt (Red Hat)c6c24012013-07-03 23:33:51 -0400424 int ret = 0;
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530425
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)c6c24012013-07-03 23:33:51 -0400429 ret = unregister_trace_uprobe(tu);
430 if (ret)
431 break;
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530432 }
433 mutex_unlock(&uprobe_lock);
Steven Rostedt (Red Hat)c6c24012013-07-03 23:33:51 -0400434 return ret;
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530435}
436
437/* Probes listing interfaces */
438static 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
444static 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
449static void probes_seq_stop(struct seq_file *m, void *v)
450{
451 mutex_unlock(&uprobe_lock);
452}
453
454static int probes_seq_show(struct seq_file *m, void *v)
455{
456 struct trace_uprobe *tu = v;
Oleg Nesterov3ede82d2013-03-30 19:48:09 +0100457 char c = is_ret_probe(tu) ? 'r' : 'p';
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530458 int i;
459
Namhyung Kim14577c32013-07-03 15:42:53 +0900460 seq_printf(m, "%c:%s/%s", c, tu->tp.call.class->system, tu->tp.call.name);
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530461 seq_printf(m, " %s:0x%p", tu->filename, (void *)tu->offset);
462
Namhyung Kim14577c32013-07-03 15:42:53 +0900463 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 Dronamrajuf3f096c2012-04-11 16:00:43 +0530465
466 seq_printf(m, "\n");
467 return 0;
468}
469
470static 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
477static int probes_open(struct inode *inode, struct file *file)
478{
Steven Rostedt (Red Hat)c6c24012013-07-03 23:33:51 -0400479 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 Dronamrajuf3f096c2012-04-11 16:00:43 +0530486
487 return seq_open(file, &probes_seq_op);
488}
489
490static 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
496static 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 */
506static int probes_profile_seq_show(struct seq_file *m, void *v)
507{
508 struct trace_uprobe *tu = v;
509
Namhyung Kim14577c32013-07-03 15:42:53 +0900510 seq_printf(m, " %s %-44s %15lu\n", tu->filename, tu->tp.call.name, tu->nhit);
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530511 return 0;
512}
513
514static 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
521static int profile_open(struct inode *inode, struct file *file)
522{
523 return seq_open(file, &profile_seq_op);
524}
525
526static 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 Nesterova51cc602013-03-30 18:02:12 +0100534static void uprobe_trace_print(struct trace_uprobe *tu,
535 unsigned long func, struct pt_regs *regs)
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530536{
537 struct uprobe_trace_entry_head *entry;
538 struct ring_buffer_event *event;
539 struct ring_buffer *buffer;
Oleg Nesterov457d1772013-03-29 18:26:51 +0100540 void *data;
Oleg Nesterov0e3853d2013-03-28 19:19:11 +0100541 int size, i;
Namhyung Kim14577c32013-07-03 15:42:53 +0900542 struct ftrace_event_call *call = &tu->tp.call;
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530543
Oleg Nesterov393a7362013-03-30 18:46:22 +0100544 size = SIZEOF_TRACE_ENTRY(is_ret_probe(tu));
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530545 event = trace_current_buffer_lock_reserve(&buffer, call->event.type,
Namhyung Kim14577c32013-07-03 15:42:53 +0900546 size + tu->tp.size, 0, 0);
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530547 if (!event)
Oleg Nesterova51cc602013-03-30 18:02:12 +0100548 return;
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530549
550 entry = ring_buffer_event_data(event);
Oleg Nesterov393a7362013-03-30 18:46:22 +0100551 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 Kim14577c32013-07-03 15:42:53 +0900560 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 Dronamrajuf3f096c2012-04-11 16:00:43 +0530564
Tom Zanussif306cc82013-10-24 08:34:17 -0500565 if (!call_filter_check_discard(call, entry, buffer, event))
Oleg Nesterov0e3853d2013-03-28 19:19:11 +0100566 trace_buffer_unlock_commit(buffer, event, 0, 0);
Oleg Nesterova51cc602013-03-30 18:02:12 +0100567}
Oleg Nesterovf42d24a2013-02-04 17:48:34 +0100568
Oleg Nesterova51cc602013-03-30 18:02:12 +0100569/* uprobe handler */
570static int uprobe_trace_func(struct trace_uprobe *tu, struct pt_regs *regs)
571{
Oleg Nesterov393a7362013-03-30 18:46:22 +0100572 if (!is_ret_probe(tu))
573 uprobe_trace_print(tu, 0, regs);
Oleg Nesterovf42d24a2013-02-04 17:48:34 +0100574 return 0;
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530575}
576
Oleg Nesterovc1ae5c72013-03-30 18:25:23 +0100577static 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 Dronamrajuf3f096c2012-04-11 16:00:43 +0530583/* Event entry printers */
584static enum print_line_t
585print_uprobe_event(struct trace_iterator *iter, int flags, struct trace_event *event)
586{
Oleg Nesterov457d1772013-03-29 18:26:51 +0100587 struct uprobe_trace_entry_head *entry;
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530588 struct trace_seq *s = &iter->seq;
589 struct trace_uprobe *tu;
590 u8 *data;
591 int i;
592
Oleg Nesterov457d1772013-03-29 18:26:51 +0100593 entry = (struct uprobe_trace_entry_head *)iter->ent;
Namhyung Kim14577c32013-07-03 15:42:53 +0900594 tu = container_of(event, struct trace_uprobe, tp.call.event);
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530595
Oleg Nesterov3ede82d2013-03-30 19:48:09 +0100596 if (is_ret_probe(tu)) {
Namhyung Kim14577c32013-07-03 15:42:53 +0900597 if (!trace_seq_printf(s, "%s: (0x%lx <- 0x%lx)", tu->tp.call.name,
Oleg Nesterov3ede82d2013-03-30 19:48:09 +0100598 entry->vaddr[1], entry->vaddr[0]))
599 goto partial;
600 data = DATAOF_TRACE_ENTRY(entry, true);
601 } else {
Namhyung Kim14577c32013-07-03 15:42:53 +0900602 if (!trace_seq_printf(s, "%s: (0x%lx)", tu->tp.call.name,
Oleg Nesterov3ede82d2013-03-30 19:48:09 +0100603 entry->vaddr[0]))
604 goto partial;
605 data = DATAOF_TRACE_ENTRY(entry, false);
606 }
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530607
Namhyung Kim14577c32013-07-03 15:42:53 +0900608 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 Dronamrajuf3f096c2012-04-11 16:00:43 +0530612 goto partial;
613 }
614
615 if (trace_seq_puts(s, "\n"))
616 return TRACE_TYPE_HANDLED;
617
618partial:
619 return TRACE_TYPE_PARTIAL_LINE;
620}
621
Oleg Nesterov31ba3342013-02-04 17:11:58 +0100622typedef bool (*filter_func_t)(struct uprobe_consumer *self,
623 enum uprobe_filter_ctx ctx,
624 struct mm_struct *mm);
625
626static int
627probe_event_enable(struct trace_uprobe *tu, int flag, filter_func_t filter)
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530628{
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530629 int ret = 0;
630
Namhyung Kim14577c32013-07-03 15:42:53 +0900631 if (trace_probe_is_enabled(&tu->tp))
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530632 return -EINTR;
633
Oleg Nesterov736288b2013-02-03 20:58:35 +0100634 WARN_ON(!uprobe_filter_is_empty(&tu->filter));
635
Namhyung Kim14577c32013-07-03 15:42:53 +0900636 tu->tp.flags |= flag;
Oleg Nesterov31ba3342013-02-04 17:11:58 +0100637 tu->consumer.filter = filter;
Oleg Nesterova932b732013-01-31 19:47:23 +0100638 ret = uprobe_register(tu->inode, tu->offset, &tu->consumer);
639 if (ret)
Namhyung Kim14577c32013-07-03 15:42:53 +0900640 tu->tp.flags &= ~flag;
Oleg Nesterov41618242013-01-27 18:36:24 +0100641
642 return ret;
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530643}
644
645static void probe_event_disable(struct trace_uprobe *tu, int flag)
646{
Namhyung Kim14577c32013-07-03 15:42:53 +0900647 if (!trace_probe_is_enabled(&tu->tp))
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530648 return;
649
Oleg Nesterov736288b2013-02-03 20:58:35 +0100650 WARN_ON(!uprobe_filter_is_empty(&tu->filter));
651
Oleg Nesterova932b732013-01-31 19:47:23 +0100652 uprobe_unregister(tu->inode, tu->offset, &tu->consumer);
Namhyung Kim14577c32013-07-03 15:42:53 +0900653 tu->tp.flags &= ~flag;
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530654}
655
656static int uprobe_event_define_fields(struct ftrace_event_call *event_call)
657{
Oleg Nesterov457d1772013-03-29 18:26:51 +0100658 int ret, i, size;
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530659 struct uprobe_trace_entry_head field;
Oleg Nesterov457d1772013-03-29 18:26:51 +0100660 struct trace_uprobe *tu = event_call->data;
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530661
Oleg Nesterov4d1298e2013-03-30 19:23:15 +0100662 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 Dronamrajuf3f096c2012-04-11 16:00:43 +0530670 /* Set argument names as fields */
Namhyung Kim14577c32013-07-03 15:42:53 +0900671 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 Dronamrajuf3f096c2012-04-11 16:00:43 +0530677 FILTER_OTHER);
678
679 if (ret)
680 return ret;
681 }
682 return 0;
683}
684
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530685#ifdef CONFIG_PERF_EVENTS
Oleg Nesterov31ba3342013-02-04 17:11:58 +0100686static bool
687__uprobe_perf_filter(struct trace_uprobe_filter *filter, struct mm_struct *mm)
688{
689 struct perf_event *event;
690
691 if (filter->nr_systemwide)
692 return true;
693
694 list_for_each_entry(event, &filter->perf_events, hw.tp_list) {
695 if (event->hw.tp_target->mm == mm)
696 return true;
697 }
698
699 return false;
700}
701
Oleg Nesterovb2fe8ba2013-02-04 19:05:43 +0100702static inline bool
703uprobe_filter_event(struct trace_uprobe *tu, struct perf_event *event)
704{
705 return __uprobe_perf_filter(&tu->filter, event->hw.tp_target->mm);
706}
707
Oleg Nesterov736288b2013-02-03 20:58:35 +0100708static int uprobe_perf_open(struct trace_uprobe *tu, struct perf_event *event)
709{
Oleg Nesterovb2fe8ba2013-02-04 19:05:43 +0100710 bool done;
711
Oleg Nesterov736288b2013-02-03 20:58:35 +0100712 write_lock(&tu->filter.rwlock);
Oleg Nesterovb2fe8ba2013-02-04 19:05:43 +0100713 if (event->hw.tp_target) {
714 /*
715 * event->parent != NULL means copy_process(), we can avoid
716 * uprobe_apply(). current->mm must be probed and we can rely
717 * on dup_mmap() which preserves the already installed bp's.
718 *
719 * attr.enable_on_exec means that exec/mmap will install the
720 * breakpoints we need.
721 */
722 done = tu->filter.nr_systemwide ||
723 event->parent || event->attr.enable_on_exec ||
724 uprobe_filter_event(tu, event);
Oleg Nesterov736288b2013-02-03 20:58:35 +0100725 list_add(&event->hw.tp_list, &tu->filter.perf_events);
Oleg Nesterovb2fe8ba2013-02-04 19:05:43 +0100726 } else {
727 done = tu->filter.nr_systemwide;
Oleg Nesterov736288b2013-02-03 20:58:35 +0100728 tu->filter.nr_systemwide++;
Oleg Nesterovb2fe8ba2013-02-04 19:05:43 +0100729 }
Oleg Nesterov736288b2013-02-03 20:58:35 +0100730 write_unlock(&tu->filter.rwlock);
731
Oleg Nesterovb2fe8ba2013-02-04 19:05:43 +0100732 if (!done)
733 uprobe_apply(tu->inode, tu->offset, &tu->consumer, true);
Oleg Nesterov31ba3342013-02-04 17:11:58 +0100734
Oleg Nesterov736288b2013-02-03 20:58:35 +0100735 return 0;
736}
737
738static int uprobe_perf_close(struct trace_uprobe *tu, struct perf_event *event)
739{
Oleg Nesterovb2fe8ba2013-02-04 19:05:43 +0100740 bool done;
741
Oleg Nesterov736288b2013-02-03 20:58:35 +0100742 write_lock(&tu->filter.rwlock);
Oleg Nesterovb2fe8ba2013-02-04 19:05:43 +0100743 if (event->hw.tp_target) {
Oleg Nesterov736288b2013-02-03 20:58:35 +0100744 list_del(&event->hw.tp_list);
Oleg Nesterovb2fe8ba2013-02-04 19:05:43 +0100745 done = tu->filter.nr_systemwide ||
746 (event->hw.tp_target->flags & PF_EXITING) ||
747 uprobe_filter_event(tu, event);
748 } else {
Oleg Nesterov736288b2013-02-03 20:58:35 +0100749 tu->filter.nr_systemwide--;
Oleg Nesterovb2fe8ba2013-02-04 19:05:43 +0100750 done = tu->filter.nr_systemwide;
751 }
Oleg Nesterov736288b2013-02-03 20:58:35 +0100752 write_unlock(&tu->filter.rwlock);
753
Oleg Nesterovb2fe8ba2013-02-04 19:05:43 +0100754 if (!done)
755 uprobe_apply(tu->inode, tu->offset, &tu->consumer, false);
Oleg Nesterov31ba3342013-02-04 17:11:58 +0100756
Oleg Nesterov736288b2013-02-03 20:58:35 +0100757 return 0;
758}
759
Oleg Nesterov31ba3342013-02-04 17:11:58 +0100760static bool uprobe_perf_filter(struct uprobe_consumer *uc,
761 enum uprobe_filter_ctx ctx, struct mm_struct *mm)
762{
763 struct trace_uprobe *tu;
764 int ret;
765
766 tu = container_of(uc, struct trace_uprobe, consumer);
767 read_lock(&tu->filter.rwlock);
768 ret = __uprobe_perf_filter(&tu->filter, mm);
769 read_unlock(&tu->filter.rwlock);
770
771 return ret;
772}
773
Oleg Nesterova51cc602013-03-30 18:02:12 +0100774static void uprobe_perf_print(struct trace_uprobe *tu,
775 unsigned long func, struct pt_regs *regs)
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530776{
Namhyung Kim14577c32013-07-03 15:42:53 +0900777 struct ftrace_event_call *call = &tu->tp.call;
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530778 struct uprobe_trace_entry_head *entry;
779 struct hlist_head *head;
Oleg Nesterov457d1772013-03-29 18:26:51 +0100780 void *data;
781 int size, rctx, i;
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530782
Oleg Nesterov393a7362013-03-30 18:46:22 +0100783 size = SIZEOF_TRACE_ENTRY(is_ret_probe(tu));
Namhyung Kim14577c32013-07-03 15:42:53 +0900784 size = ALIGN(size + tu->tp.size + sizeof(u32), sizeof(u64)) - sizeof(u32);
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530785
786 preempt_disable();
Oleg Nesterov515619f2013-04-13 15:36:49 +0200787 head = this_cpu_ptr(call->perf_events);
788 if (hlist_empty(head))
789 goto out;
790
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530791 entry = perf_trace_buf_prepare(size, call->event.type, regs, &rctx);
792 if (!entry)
793 goto out;
794
Oleg Nesterov393a7362013-03-30 18:46:22 +0100795 if (is_ret_probe(tu)) {
796 entry->vaddr[0] = func;
Oleg Nesterov32520b22013-04-10 16:25:49 +0200797 entry->vaddr[1] = instruction_pointer(regs);
Oleg Nesterov393a7362013-03-30 18:46:22 +0100798 data = DATAOF_TRACE_ENTRY(entry, true);
799 } else {
Oleg Nesterov32520b22013-04-10 16:25:49 +0200800 entry->vaddr[0] = instruction_pointer(regs);
Oleg Nesterov393a7362013-03-30 18:46:22 +0100801 data = DATAOF_TRACE_ENTRY(entry, false);
802 }
803
Namhyung Kim14577c32013-07-03 15:42:53 +0900804 for (i = 0; i < tu->tp.nr_args; i++) {
805 struct probe_arg *parg = &tu->tp.args[i];
806
807 call_fetch(&parg->fetch, regs, data + parg->offset);
808 }
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530809
Oleg Nesterov32520b22013-04-10 16:25:49 +0200810 perf_trace_buf_submit(entry, size, rctx, 0, 1, regs, head, NULL);
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530811 out:
812 preempt_enable();
Oleg Nesterova51cc602013-03-30 18:02:12 +0100813}
814
815/* uprobe profile handler */
816static int uprobe_perf_func(struct trace_uprobe *tu, struct pt_regs *regs)
817{
818 if (!uprobe_perf_filter(&tu->consumer, 0, current->mm))
819 return UPROBE_HANDLER_REMOVE;
820
Oleg Nesterov393a7362013-03-30 18:46:22 +0100821 if (!is_ret_probe(tu))
822 uprobe_perf_print(tu, 0, regs);
Oleg Nesterovf42d24a2013-02-04 17:48:34 +0100823 return 0;
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530824}
Oleg Nesterovc1ae5c72013-03-30 18:25:23 +0100825
826static void uretprobe_perf_func(struct trace_uprobe *tu, unsigned long func,
827 struct pt_regs *regs)
828{
829 uprobe_perf_print(tu, func, regs);
830}
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530831#endif /* CONFIG_PERF_EVENTS */
832
833static
834int trace_uprobe_register(struct ftrace_event_call *event, enum trace_reg type, void *data)
835{
Oleg Nesterov457d1772013-03-29 18:26:51 +0100836 struct trace_uprobe *tu = event->data;
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530837
838 switch (type) {
839 case TRACE_REG_REGISTER:
Oleg Nesterov31ba3342013-02-04 17:11:58 +0100840 return probe_event_enable(tu, TP_FLAG_TRACE, NULL);
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530841
842 case TRACE_REG_UNREGISTER:
843 probe_event_disable(tu, TP_FLAG_TRACE);
844 return 0;
845
846#ifdef CONFIG_PERF_EVENTS
847 case TRACE_REG_PERF_REGISTER:
Oleg Nesterov31ba3342013-02-04 17:11:58 +0100848 return probe_event_enable(tu, TP_FLAG_PROFILE, uprobe_perf_filter);
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530849
850 case TRACE_REG_PERF_UNREGISTER:
851 probe_event_disable(tu, TP_FLAG_PROFILE);
852 return 0;
Oleg Nesterov736288b2013-02-03 20:58:35 +0100853
854 case TRACE_REG_PERF_OPEN:
855 return uprobe_perf_open(tu, data);
856
857 case TRACE_REG_PERF_CLOSE:
858 return uprobe_perf_close(tu, data);
859
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530860#endif
861 default:
862 return 0;
863 }
864 return 0;
865}
866
867static int uprobe_dispatcher(struct uprobe_consumer *con, struct pt_regs *regs)
868{
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530869 struct trace_uprobe *tu;
Oleg Nesterovf42d24a2013-02-04 17:48:34 +0100870 int ret = 0;
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530871
Oleg Nesterova932b732013-01-31 19:47:23 +0100872 tu = container_of(con, struct trace_uprobe, consumer);
Oleg Nesterov1b47aef2013-01-31 19:55:27 +0100873 tu->nhit++;
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530874
Namhyung Kim14577c32013-07-03 15:42:53 +0900875 if (tu->tp.flags & TP_FLAG_TRACE)
Oleg Nesterovf42d24a2013-02-04 17:48:34 +0100876 ret |= uprobe_trace_func(tu, regs);
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530877
878#ifdef CONFIG_PERF_EVENTS
Namhyung Kim14577c32013-07-03 15:42:53 +0900879 if (tu->tp.flags & TP_FLAG_PROFILE)
Oleg Nesterovf42d24a2013-02-04 17:48:34 +0100880 ret |= uprobe_perf_func(tu, regs);
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530881#endif
Oleg Nesterovf42d24a2013-02-04 17:48:34 +0100882 return ret;
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530883}
884
Oleg Nesterovc1ae5c72013-03-30 18:25:23 +0100885static int uretprobe_dispatcher(struct uprobe_consumer *con,
886 unsigned long func, struct pt_regs *regs)
887{
888 struct trace_uprobe *tu;
889
890 tu = container_of(con, struct trace_uprobe, consumer);
891
Namhyung Kim14577c32013-07-03 15:42:53 +0900892 if (tu->tp.flags & TP_FLAG_TRACE)
Oleg Nesterovc1ae5c72013-03-30 18:25:23 +0100893 uretprobe_trace_func(tu, func, regs);
894
895#ifdef CONFIG_PERF_EVENTS
Namhyung Kim14577c32013-07-03 15:42:53 +0900896 if (tu->tp.flags & TP_FLAG_PROFILE)
Oleg Nesterovc1ae5c72013-03-30 18:25:23 +0100897 uretprobe_perf_func(tu, func, regs);
898#endif
899 return 0;
900}
901
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530902static struct trace_event_functions uprobe_funcs = {
903 .trace = print_uprobe_event
904};
905
906static int register_uprobe_event(struct trace_uprobe *tu)
907{
Namhyung Kim14577c32013-07-03 15:42:53 +0900908 struct ftrace_event_call *call = &tu->tp.call;
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530909 int ret;
910
911 /* Initialize ftrace_event_call */
912 INIT_LIST_HEAD(&call->class->fields);
913 call->event.funcs = &uprobe_funcs;
914 call->class->define_fields = uprobe_event_define_fields;
915
Namhyung Kim5bf652a2013-07-03 16:09:02 +0900916 if (set_print_fmt(&tu->tp, is_ret_probe(tu)) < 0)
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530917 return -ENOMEM;
918
919 ret = register_ftrace_event(&call->event);
920 if (!ret) {
921 kfree(call->print_fmt);
922 return -ENODEV;
923 }
924 call->flags = 0;
925 call->class->reg = trace_uprobe_register;
926 call->data = tu;
927 ret = trace_add_event_call(call);
928
929 if (ret) {
930 pr_info("Failed to register uprobe event: %s\n", call->name);
931 kfree(call->print_fmt);
932 unregister_ftrace_event(&call->event);
933 }
934
935 return ret;
936}
937
Steven Rostedt (Red Hat)c6c24012013-07-03 23:33:51 -0400938static int unregister_uprobe_event(struct trace_uprobe *tu)
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530939{
Steven Rostedt (Red Hat)c6c24012013-07-03 23:33:51 -0400940 int ret;
941
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530942 /* tu->event is unregistered in trace_remove_event_call() */
Namhyung Kim14577c32013-07-03 15:42:53 +0900943 ret = trace_remove_event_call(&tu->tp.call);
Steven Rostedt (Red Hat)c6c24012013-07-03 23:33:51 -0400944 if (ret)
945 return ret;
Namhyung Kim14577c32013-07-03 15:42:53 +0900946 kfree(tu->tp.call.print_fmt);
947 tu->tp.call.print_fmt = NULL;
Steven Rostedt (Red Hat)c6c24012013-07-03 23:33:51 -0400948 return 0;
Srikar Dronamrajuf3f096c2012-04-11 16:00:43 +0530949}
950
951/* Make a trace interface for controling probe points */
952static __init int init_uprobe_trace(void)
953{
954 struct dentry *d_tracer;
955
956 d_tracer = tracing_init_dentry();
957 if (!d_tracer)
958 return 0;
959
960 trace_create_file("uprobe_events", 0644, d_tracer,
961 NULL, &uprobe_events_ops);
962 /* Profile interface */
963 trace_create_file("uprobe_profile", 0444, d_tracer,
964 NULL, &uprobe_profile_ops);
965 return 0;
966}
967
968fs_initcall(init_uprobe_trace);