tracing/probe: Add trace_probe init and free functions
[linux-2.6-block.git] / kernel / trace / trace_uprobe.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * uprobes-based tracing events
4  *
5  * Copyright (C) IBM Corporation, 2010-2012
6  * Author:      Srikar Dronamraju <srikar@linux.vnet.ibm.com>
7  */
8 #define pr_fmt(fmt)     "trace_uprobe: " fmt
9
10 #include <linux/ctype.h>
11 #include <linux/module.h>
12 #include <linux/uaccess.h>
13 #include <linux/uprobes.h>
14 #include <linux/namei.h>
15 #include <linux/string.h>
16 #include <linux/rculist.h>
17
18 #include "trace_dynevent.h"
19 #include "trace_probe.h"
20 #include "trace_probe_tmpl.h"
21
22 #define UPROBE_EVENT_SYSTEM     "uprobes"
23
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
36 struct trace_uprobe_filter {
37         rwlock_t                rwlock;
38         int                     nr_systemwide;
39         struct list_head        perf_events;
40 };
41
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
57 /*
58  * uprobe event core functions
59  */
60 struct trace_uprobe {
61         struct dyn_event                devent;
62         struct trace_uprobe_filter      filter;
63         struct uprobe_consumer          consumer;
64         struct path                     path;
65         struct inode                    *inode;
66         char                            *filename;
67         unsigned long                   offset;
68         unsigned long                   ref_ctr_offset;
69         unsigned long                   nhit;
70         struct trace_probe              tp;
71 };
72
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
92 #define SIZEOF_TRACE_UPROBE(n)                          \
93         (offsetof(struct trace_uprobe, tp.args) +       \
94         (sizeof(struct probe_arg) * (n)))
95
96 static int register_uprobe_event(struct trace_uprobe *tu);
97 static int unregister_uprobe_event(struct trace_uprobe *tu);
98
99 struct uprobe_dispatch_data {
100         struct trace_uprobe     *tu;
101         unsigned long           bp_addr;
102 };
103
104 static int uprobe_dispatcher(struct uprobe_consumer *con, struct pt_regs *regs);
105 static int uretprobe_dispatcher(struct uprobe_consumer *con,
106                                 unsigned long func, struct pt_regs *regs);
107
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  */
136 static nokprobe_inline int
137 probe_mem_read(void *dest, void *src, size_t size)
138 {
139         void __user *vaddr = (void __force __user *)src;
140
141         return copy_from_user(dest, vaddr, size) ? -EFAULT : 0;
142 }
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
150 /*
151  * Fetch a null-terminated string. Caller MUST set *(u32 *)dest with max
152  * length and relative data location.
153  */
154 static nokprobe_inline int
155 fetch_store_string(unsigned long addr, void *dest, void *base)
156 {
157         long ret;
158         u32 loc = *(u32 *)dest;
159         int maxlen  = get_loc_len(loc);
160         u8 *dst = get_loc_data(dest, base);
161         void __user *src = (void __force __user *) addr;
162
163         if (unlikely(!maxlen))
164                 return -ENOMEM;
165
166         if (addr == FETCH_TOKEN_COMM)
167                 ret = strlcpy(dst, current->comm, maxlen);
168         else
169                 ret = strncpy_from_user(dst, src, maxlen);
170         if (ret >= 0) {
171                 if (ret == maxlen)
172                         dst[ret - 1] = '\0';
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++;
180                 *(u32 *)dest = make_data_loc(ret, (void *)dst - base);
181         }
182
183         return ret;
184 }
185
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
192 /* Return the length of string -- including null terminal byte */
193 static nokprobe_inline int
194 fetch_store_strlen(unsigned long addr)
195 {
196         int len;
197         void __user *vaddr = (void __force __user *) addr;
198
199         if (addr == FETCH_TOKEN_COMM)
200                 len = strlen(current->comm) + 1;
201         else
202                 len = strnlen_user(vaddr, MAX_STRING_SIZE);
203
204         return (len > MAX_STRING_SIZE) ? 0 : len;
205 }
206
207 static nokprobe_inline int
208 fetch_store_strlen_user(unsigned long addr)
209 {
210         return fetch_store_strlen(addr);
211 }
212
213 static unsigned long translate_user_vaddr(unsigned long file_offset)
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;
221         return base_addr + file_offset;
222 }
223
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,
227                    void *base)
228 {
229         unsigned long val;
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;
248         case FETCH_OP_COMM:
249                 val = FETCH_TOKEN_COMM;
250                 break;
251         case FETCH_OP_FOFFS:
252                 val = translate_user_vaddr(code->immediate);
253                 break;
254         default:
255                 return -EILSEQ;
256         }
257         code++;
258
259         return process_fetch_insn_bottom(code, val, dest, base);
260 }
261 NOKPROBE_SYMBOL(process_fetch_insn)
262
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
275 static inline bool is_ret_probe(struct trace_uprobe *tu)
276 {
277         return tu->consumer.ret_handler != NULL;
278 }
279
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
292         return strcmp(trace_event_name(&tu->tp.call), event) == 0 &&
293                 (!system || strcmp(tu->tp.call.class->system, system) == 0);
294 }
295
296 /*
297  * Allocate new trace_uprobe and initialize it (including uprobes).
298  */
299 static struct trace_uprobe *
300 alloc_trace_uprobe(const char *group, const char *event, int nargs, bool is_ret)
301 {
302         struct trace_uprobe *tu;
303         int ret;
304
305         tu = kzalloc(SIZEOF_TRACE_UPROBE(nargs), GFP_KERNEL);
306         if (!tu)
307                 return ERR_PTR(-ENOMEM);
308
309         ret = trace_probe_init(&tu->tp, event, group);
310         if (ret < 0)
311                 goto error;
312
313         dyn_event_init(&tu->devent, &trace_uprobe_ops);
314         tu->consumer.handler = uprobe_dispatcher;
315         if (is_ret)
316                 tu->consumer.ret_handler = uretprobe_dispatcher;
317         init_trace_uprobe_filter(&tu->filter);
318         return tu;
319
320 error:
321         kfree(tu);
322
323         return ERR_PTR(ret);
324 }
325
326 static void free_trace_uprobe(struct trace_uprobe *tu)
327 {
328         if (!tu)
329                 return;
330
331         path_put(&tu->path);
332         trace_probe_cleanup(&tu->tp);
333         kfree(tu->filename);
334         kfree(tu);
335 }
336
337 static struct trace_uprobe *find_probe_event(const char *event, const char *group)
338 {
339         struct dyn_event *pos;
340         struct trace_uprobe *tu;
341
342         for_each_trace_uprobe(tu, pos)
343                 if (strcmp(trace_event_name(&tu->tp.call), event) == 0 &&
344                     strcmp(tu->tp.call.class->system, group) == 0)
345                         return tu;
346
347         return NULL;
348 }
349
350 /* Unregister a trace_uprobe and probe_event */
351 static int unregister_trace_uprobe(struct trace_uprobe *tu)
352 {
353         int ret;
354
355         ret = unregister_uprobe_event(tu);
356         if (ret)
357                 return ret;
358
359         dyn_event_remove(&tu->devent);
360         free_trace_uprobe(tu);
361         return 0;
362 }
363
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 {
375         struct dyn_event *pos;
376         struct trace_uprobe *tmp, *old = NULL;
377         struct inode *new_inode = d_real_inode(new->path.dentry);
378
379         old = find_probe_event(trace_event_name(&new->tp.call),
380                                 new->tp.call.class->system);
381
382         for_each_trace_uprobe(tmp, pos) {
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
394 /* Register a trace_uprobe and probe_event */
395 static int register_trace_uprobe(struct trace_uprobe *tu)
396 {
397         struct trace_uprobe *old_tu;
398         int ret;
399
400         mutex_lock(&event_mutex);
401
402         /* register as an event */
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
409         if (old_tu) {
410                 /* delete old event */
411                 ret = unregister_trace_uprobe(old_tu);
412                 if (ret)
413                         goto end;
414         }
415
416         ret = register_uprobe_event(tu);
417         if (ret) {
418                 pr_warn("Failed to register probe event(%d)\n", ret);
419                 goto end;
420         }
421
422         dyn_event_add(&tu->devent);
423
424 end:
425         mutex_unlock(&event_mutex);
426
427         return ret;
428 }
429
430 /*
431  * Argument syntax:
432  *  - Add uprobe: p|r[:[GRP/]EVENT] PATH:OFFSET [FETCHARGS]
433  *
434  *  - Remove uprobe: -:[GRP/]EVENT
435  */
436 static int trace_uprobe_create(int argc, const char **argv)
437 {
438         struct trace_uprobe *tu;
439         const char *event = NULL, *group = UPROBE_EVENT_SYSTEM;
440         char *arg, *filename, *rctr, *rctr_end, *tmp;
441         char buf[MAX_EVENT_NAME_LEN];
442         struct path path;
443         unsigned long offset, ref_ctr_offset;
444         bool is_return = false;
445         int i, ret;
446
447         ret = 0;
448         ref_ctr_offset = 0;
449
450         /* argc must be >= 1 */
451         if (argv[0][0] == 'r')
452                 is_return = true;
453         else if (argv[0][0] != 'p' || argc < 2)
454                 return -ECANCELED;
455
456         if (argv[0][1] == ':')
457                 event = &argv[0][2];
458
459         if (!strchr(argv[1], '/'))
460                 return -ECANCELED;
461
462         filename = kstrdup(argv[1], GFP_KERNEL);
463         if (!filename)
464                 return -ENOMEM;
465
466         /* Find the last occurrence, in case the path contains ':' too. */
467         arg = strrchr(filename, ':');
468         if (!arg || !isdigit(arg[1])) {
469                 kfree(filename);
470                 return -ECANCELED;
471         }
472
473         trace_probe_log_init("trace_uprobe", argc, argv);
474         trace_probe_log_set_index(1);   /* filename is the 2nd argument */
475
476         *arg++ = '\0';
477         ret = kern_path(filename, LOOKUP_FOLLOW, &path);
478         if (ret) {
479                 trace_probe_log_err(0, FILE_NOT_FOUND);
480                 kfree(filename);
481                 trace_probe_log_clear();
482                 return ret;
483         }
484         if (!d_is_reg(path.dentry)) {
485                 trace_probe_log_err(0, NO_REGULAR_FILE);
486                 ret = -EINVAL;
487                 goto fail_address_parse;
488         }
489
490         /* Parse reference counter offset if specified. */
491         rctr = strchr(arg, '(');
492         if (rctr) {
493                 rctr_end = strchr(rctr, ')');
494                 if (!rctr_end) {
495                         ret = -EINVAL;
496                         rctr_end = rctr + strlen(rctr);
497                         trace_probe_log_err(rctr_end - filename,
498                                             REFCNT_OPEN_BRACE);
499                         goto fail_address_parse;
500                 } else if (rctr_end[1] != '\0') {
501                         ret = -EINVAL;
502                         trace_probe_log_err(rctr_end + 1 - filename,
503                                             BAD_REFCNT_SUFFIX);
504                         goto fail_address_parse;
505                 }
506
507                 *rctr++ = '\0';
508                 *rctr_end = '\0';
509                 ret = kstrtoul(rctr, 0, &ref_ctr_offset);
510                 if (ret) {
511                         trace_probe_log_err(rctr - filename, BAD_REFCNT);
512                         goto fail_address_parse;
513                 }
514         }
515
516         /* Parse uprobe offset. */
517         ret = kstrtoul(arg, 0, &offset);
518         if (ret) {
519                 trace_probe_log_err(arg - filename, BAD_UPROBE_OFFS);
520                 goto fail_address_parse;
521         }
522
523         /* setup a probe */
524         trace_probe_log_set_index(0);
525         if (event) {
526                 ret = traceprobe_parse_event_name(&event, &group, buf,
527                                                   event - argv[0]);
528                 if (ret)
529                         goto fail_address_parse;
530         } else {
531                 char *tail;
532                 char *ptr;
533
534                 tail = kstrdup(kbasename(filename), GFP_KERNEL);
535                 if (!tail) {
536                         ret = -ENOMEM;
537                         goto fail_address_parse;
538                 }
539
540                 ptr = strpbrk(tail, ".-_");
541                 if (ptr)
542                         *ptr = '\0';
543
544                 snprintf(buf, MAX_EVENT_NAME_LEN, "%c_%s_0x%lx", 'p', tail, offset);
545                 event = buf;
546                 kfree(tail);
547         }
548
549         argc -= 2;
550         argv += 2;
551
552         tu = alloc_trace_uprobe(group, event, argc, is_return);
553         if (IS_ERR(tu)) {
554                 ret = PTR_ERR(tu);
555                 /* This must return -ENOMEM otherwise there is a bug */
556                 WARN_ON_ONCE(ret != -ENOMEM);
557                 goto fail_address_parse;
558         }
559         tu->offset = offset;
560         tu->ref_ctr_offset = ref_ctr_offset;
561         tu->path = path;
562         tu->filename = filename;
563
564         /* parse arguments */
565         for (i = 0; i < argc && i < MAX_TRACE_ARGS; i++) {
566                 tmp = kstrdup(argv[i], GFP_KERNEL);
567                 if (!tmp) {
568                         ret = -ENOMEM;
569                         goto error;
570                 }
571
572                 trace_probe_log_set_index(i + 2);
573                 ret = traceprobe_parse_probe_arg(&tu->tp, i, tmp,
574                                         is_return ? TPARG_FL_RETURN : 0);
575                 kfree(tmp);
576                 if (ret)
577                         goto error;
578         }
579
580         ret = traceprobe_set_print_fmt(&tu->tp, is_ret_probe(tu));
581         if (ret < 0)
582                 goto error;
583
584         ret = register_trace_uprobe(tu);
585         if (!ret)
586                 goto out;
587
588 error:
589         free_trace_uprobe(tu);
590 out:
591         trace_probe_log_clear();
592         return ret;
593
594 fail_address_parse:
595         trace_probe_log_clear();
596         path_put(&path);
597         kfree(filename);
598
599         return ret;
600 }
601
602 static int create_or_delete_trace_uprobe(int argc, char **argv)
603 {
604         int ret;
605
606         if (argv[0][0] == '-')
607                 return dyn_event_release(argc, argv, &trace_uprobe_ops);
608
609         ret = trace_uprobe_create(argc, (const char **)argv);
610         return ret == -ECANCELED ? -EINVAL : ret;
611 }
612
613 static int trace_uprobe_release(struct dyn_event *ev)
614 {
615         struct trace_uprobe *tu = to_trace_uprobe(ev);
616
617         return unregister_trace_uprobe(tu);
618 }
619
620 /* Probes listing interfaces */
621 static int trace_uprobe_show(struct seq_file *m, struct dyn_event *ev)
622 {
623         struct trace_uprobe *tu = to_trace_uprobe(ev);
624         char c = is_ret_probe(tu) ? 'r' : 'p';
625         int i;
626
627         seq_printf(m, "%c:%s/%s %s:0x%0*lx", c, tu->tp.call.class->system,
628                         trace_event_name(&tu->tp.call), tu->filename,
629                         (int)(sizeof(void *) * 2), tu->offset);
630
631         if (tu->ref_ctr_offset)
632                 seq_printf(m, "(0x%lx)", tu->ref_ctr_offset);
633
634         for (i = 0; i < tu->tp.nr_args; i++)
635                 seq_printf(m, " %s=%s", tu->tp.args[i].name, tu->tp.args[i].comm);
636
637         seq_putc(m, '\n');
638         return 0;
639 }
640
641 static int probes_seq_show(struct seq_file *m, void *v)
642 {
643         struct dyn_event *ev = v;
644
645         if (!is_trace_uprobe(ev))
646                 return 0;
647
648         return trace_uprobe_show(m, ev);
649 }
650
651 static const struct seq_operations probes_seq_op = {
652         .start  = dyn_event_seq_start,
653         .next   = dyn_event_seq_next,
654         .stop   = dyn_event_seq_stop,
655         .show   = probes_seq_show
656 };
657
658 static int probes_open(struct inode *inode, struct file *file)
659 {
660         int ret;
661
662         if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_TRUNC)) {
663                 ret = dyn_events_release_all(&trace_uprobe_ops);
664                 if (ret)
665                         return ret;
666         }
667
668         return seq_open(file, &probes_seq_op);
669 }
670
671 static ssize_t probes_write(struct file *file, const char __user *buffer,
672                             size_t count, loff_t *ppos)
673 {
674         return trace_parse_run_command(file, buffer, count, ppos,
675                                         create_or_delete_trace_uprobe);
676 }
677
678 static const struct file_operations uprobe_events_ops = {
679         .owner          = THIS_MODULE,
680         .open           = probes_open,
681         .read           = seq_read,
682         .llseek         = seq_lseek,
683         .release        = seq_release,
684         .write          = probes_write,
685 };
686
687 /* Probes profiling interfaces */
688 static int probes_profile_seq_show(struct seq_file *m, void *v)
689 {
690         struct dyn_event *ev = v;
691         struct trace_uprobe *tu;
692
693         if (!is_trace_uprobe(ev))
694                 return 0;
695
696         tu = to_trace_uprobe(ev);
697         seq_printf(m, "  %s %-44s %15lu\n", tu->filename,
698                         trace_event_name(&tu->tp.call), tu->nhit);
699         return 0;
700 }
701
702 static const struct seq_operations profile_seq_op = {
703         .start  = dyn_event_seq_start,
704         .next   = dyn_event_seq_next,
705         .stop   = dyn_event_seq_stop,
706         .show   = probes_profile_seq_show
707 };
708
709 static int profile_open(struct inode *inode, struct file *file)
710 {
711         return seq_open(file, &profile_seq_op);
712 }
713
714 static const struct file_operations uprobe_profile_ops = {
715         .owner          = THIS_MODULE,
716         .open           = profile_open,
717         .read           = seq_read,
718         .llseek         = seq_lseek,
719         .release        = seq_release,
720 };
721
722 struct uprobe_cpu_buffer {
723         struct mutex mutex;
724         void *buf;
725 };
726 static struct uprobe_cpu_buffer __percpu *uprobe_cpu_buffer;
727 static int uprobe_buffer_refcnt;
728
729 static int uprobe_buffer_init(void)
730 {
731         int cpu, err_cpu;
732
733         uprobe_cpu_buffer = alloc_percpu(struct uprobe_cpu_buffer);
734         if (uprobe_cpu_buffer == NULL)
735                 return -ENOMEM;
736
737         for_each_possible_cpu(cpu) {
738                 struct page *p = alloc_pages_node(cpu_to_node(cpu),
739                                                   GFP_KERNEL, 0);
740                 if (p == NULL) {
741                         err_cpu = cpu;
742                         goto err;
743                 }
744                 per_cpu_ptr(uprobe_cpu_buffer, cpu)->buf = page_address(p);
745                 mutex_init(&per_cpu_ptr(uprobe_cpu_buffer, cpu)->mutex);
746         }
747
748         return 0;
749
750 err:
751         for_each_possible_cpu(cpu) {
752                 if (cpu == err_cpu)
753                         break;
754                 free_page((unsigned long)per_cpu_ptr(uprobe_cpu_buffer, cpu)->buf);
755         }
756
757         free_percpu(uprobe_cpu_buffer);
758         return -ENOMEM;
759 }
760
761 static int uprobe_buffer_enable(void)
762 {
763         int ret = 0;
764
765         BUG_ON(!mutex_is_locked(&event_mutex));
766
767         if (uprobe_buffer_refcnt++ == 0) {
768                 ret = uprobe_buffer_init();
769                 if (ret < 0)
770                         uprobe_buffer_refcnt--;
771         }
772
773         return ret;
774 }
775
776 static void uprobe_buffer_disable(void)
777 {
778         int cpu;
779
780         BUG_ON(!mutex_is_locked(&event_mutex));
781
782         if (--uprobe_buffer_refcnt == 0) {
783                 for_each_possible_cpu(cpu)
784                         free_page((unsigned long)per_cpu_ptr(uprobe_cpu_buffer,
785                                                              cpu)->buf);
786
787                 free_percpu(uprobe_cpu_buffer);
788                 uprobe_cpu_buffer = NULL;
789         }
790 }
791
792 static struct uprobe_cpu_buffer *uprobe_buffer_get(void)
793 {
794         struct uprobe_cpu_buffer *ucb;
795         int cpu;
796
797         cpu = raw_smp_processor_id();
798         ucb = per_cpu_ptr(uprobe_cpu_buffer, cpu);
799
800         /*
801          * Use per-cpu buffers for fastest access, but we might migrate
802          * so the mutex makes sure we have sole access to it.
803          */
804         mutex_lock(&ucb->mutex);
805
806         return ucb;
807 }
808
809 static void uprobe_buffer_put(struct uprobe_cpu_buffer *ucb)
810 {
811         mutex_unlock(&ucb->mutex);
812 }
813
814 static void __uprobe_trace_func(struct trace_uprobe *tu,
815                                 unsigned long func, struct pt_regs *regs,
816                                 struct uprobe_cpu_buffer *ucb, int dsize,
817                                 struct trace_event_file *trace_file)
818 {
819         struct uprobe_trace_entry_head *entry;
820         struct ring_buffer_event *event;
821         struct ring_buffer *buffer;
822         void *data;
823         int size, esize;
824         struct trace_event_call *call = &tu->tp.call;
825
826         WARN_ON(call != trace_file->event_call);
827
828         if (WARN_ON_ONCE(tu->tp.size + dsize > PAGE_SIZE))
829                 return;
830
831         if (trace_trigger_soft_disabled(trace_file))
832                 return;
833
834         esize = SIZEOF_TRACE_ENTRY(is_ret_probe(tu));
835         size = esize + tu->tp.size + dsize;
836         event = trace_event_buffer_lock_reserve(&buffer, trace_file,
837                                                 call->event.type, size, 0, 0);
838         if (!event)
839                 return;
840
841         entry = ring_buffer_event_data(event);
842         if (is_ret_probe(tu)) {
843                 entry->vaddr[0] = func;
844                 entry->vaddr[1] = instruction_pointer(regs);
845                 data = DATAOF_TRACE_ENTRY(entry, true);
846         } else {
847                 entry->vaddr[0] = instruction_pointer(regs);
848                 data = DATAOF_TRACE_ENTRY(entry, false);
849         }
850
851         memcpy(data, ucb->buf, tu->tp.size + dsize);
852
853         event_trigger_unlock_commit(trace_file, buffer, event, entry, 0, 0);
854 }
855
856 /* uprobe handler */
857 static int uprobe_trace_func(struct trace_uprobe *tu, struct pt_regs *regs,
858                              struct uprobe_cpu_buffer *ucb, int dsize)
859 {
860         struct event_file_link *link;
861
862         if (is_ret_probe(tu))
863                 return 0;
864
865         rcu_read_lock();
866         list_for_each_entry_rcu(link, &tu->tp.files, list)
867                 __uprobe_trace_func(tu, 0, regs, ucb, dsize, link->file);
868         rcu_read_unlock();
869
870         return 0;
871 }
872
873 static void uretprobe_trace_func(struct trace_uprobe *tu, unsigned long func,
874                                  struct pt_regs *regs,
875                                  struct uprobe_cpu_buffer *ucb, int dsize)
876 {
877         struct event_file_link *link;
878
879         rcu_read_lock();
880         list_for_each_entry_rcu(link, &tu->tp.files, list)
881                 __uprobe_trace_func(tu, func, regs, ucb, dsize, link->file);
882         rcu_read_unlock();
883 }
884
885 /* Event entry printers */
886 static enum print_line_t
887 print_uprobe_event(struct trace_iterator *iter, int flags, struct trace_event *event)
888 {
889         struct uprobe_trace_entry_head *entry;
890         struct trace_seq *s = &iter->seq;
891         struct trace_uprobe *tu;
892         u8 *data;
893
894         entry = (struct uprobe_trace_entry_head *)iter->ent;
895         tu = container_of(event, struct trace_uprobe, tp.call.event);
896
897         if (is_ret_probe(tu)) {
898                 trace_seq_printf(s, "%s: (0x%lx <- 0x%lx)",
899                                  trace_event_name(&tu->tp.call),
900                                  entry->vaddr[1], entry->vaddr[0]);
901                 data = DATAOF_TRACE_ENTRY(entry, true);
902         } else {
903                 trace_seq_printf(s, "%s: (0x%lx)",
904                                  trace_event_name(&tu->tp.call),
905                                  entry->vaddr[0]);
906                 data = DATAOF_TRACE_ENTRY(entry, false);
907         }
908
909         if (print_probe_args(s, tu->tp.args, tu->tp.nr_args, data, entry) < 0)
910                 goto out;
911
912         trace_seq_putc(s, '\n');
913
914  out:
915         return trace_handle_return(s);
916 }
917
918 typedef bool (*filter_func_t)(struct uprobe_consumer *self,
919                                 enum uprobe_filter_ctx ctx,
920                                 struct mm_struct *mm);
921
922 static int
923 probe_event_enable(struct trace_uprobe *tu, struct trace_event_file *file,
924                    filter_func_t filter)
925 {
926         bool enabled = trace_probe_is_enabled(&tu->tp);
927         struct event_file_link *link = NULL;
928         int ret;
929
930         if (file) {
931                 if (tu->tp.flags & TP_FLAG_PROFILE)
932                         return -EINTR;
933
934                 link = kmalloc(sizeof(*link), GFP_KERNEL);
935                 if (!link)
936                         return -ENOMEM;
937
938                 link->file = file;
939                 list_add_tail_rcu(&link->list, &tu->tp.files);
940
941                 tu->tp.flags |= TP_FLAG_TRACE;
942         } else {
943                 if (tu->tp.flags & TP_FLAG_TRACE)
944                         return -EINTR;
945
946                 tu->tp.flags |= TP_FLAG_PROFILE;
947         }
948
949         WARN_ON(!uprobe_filter_is_empty(&tu->filter));
950
951         if (enabled)
952                 return 0;
953
954         ret = uprobe_buffer_enable();
955         if (ret)
956                 goto err_flags;
957
958         tu->consumer.filter = filter;
959         tu->inode = d_real_inode(tu->path.dentry);
960         if (tu->ref_ctr_offset) {
961                 ret = uprobe_register_refctr(tu->inode, tu->offset,
962                                 tu->ref_ctr_offset, &tu->consumer);
963         } else {
964                 ret = uprobe_register(tu->inode, tu->offset, &tu->consumer);
965         }
966
967         if (ret)
968                 goto err_buffer;
969
970         return 0;
971
972  err_buffer:
973         uprobe_buffer_disable();
974
975  err_flags:
976         if (file) {
977                 list_del(&link->list);
978                 kfree(link);
979                 tu->tp.flags &= ~TP_FLAG_TRACE;
980         } else {
981                 tu->tp.flags &= ~TP_FLAG_PROFILE;
982         }
983         return ret;
984 }
985
986 static void
987 probe_event_disable(struct trace_uprobe *tu, struct trace_event_file *file)
988 {
989         if (!trace_probe_is_enabled(&tu->tp))
990                 return;
991
992         if (file) {
993                 struct event_file_link *link;
994
995                 link = find_event_file_link(&tu->tp, file);
996                 if (!link)
997                         return;
998
999                 list_del_rcu(&link->list);
1000                 /* synchronize with u{,ret}probe_trace_func */
1001                 synchronize_rcu();
1002                 kfree(link);
1003
1004                 if (!list_empty(&tu->tp.files))
1005                         return;
1006         }
1007
1008         WARN_ON(!uprobe_filter_is_empty(&tu->filter));
1009
1010         uprobe_unregister(tu->inode, tu->offset, &tu->consumer);
1011         tu->inode = NULL;
1012         tu->tp.flags &= file ? ~TP_FLAG_TRACE : ~TP_FLAG_PROFILE;
1013
1014         uprobe_buffer_disable();
1015 }
1016
1017 static int uprobe_event_define_fields(struct trace_event_call *event_call)
1018 {
1019         int ret, size;
1020         struct uprobe_trace_entry_head field;
1021         struct trace_uprobe *tu = event_call->data;
1022
1023         if (is_ret_probe(tu)) {
1024                 DEFINE_FIELD(unsigned long, vaddr[0], FIELD_STRING_FUNC, 0);
1025                 DEFINE_FIELD(unsigned long, vaddr[1], FIELD_STRING_RETIP, 0);
1026                 size = SIZEOF_TRACE_ENTRY(true);
1027         } else {
1028                 DEFINE_FIELD(unsigned long, vaddr[0], FIELD_STRING_IP, 0);
1029                 size = SIZEOF_TRACE_ENTRY(false);
1030         }
1031
1032         return traceprobe_define_arg_fields(event_call, size, &tu->tp);
1033 }
1034
1035 #ifdef CONFIG_PERF_EVENTS
1036 static bool
1037 __uprobe_perf_filter(struct trace_uprobe_filter *filter, struct mm_struct *mm)
1038 {
1039         struct perf_event *event;
1040
1041         if (filter->nr_systemwide)
1042                 return true;
1043
1044         list_for_each_entry(event, &filter->perf_events, hw.tp_list) {
1045                 if (event->hw.target->mm == mm)
1046                         return true;
1047         }
1048
1049         return false;
1050 }
1051
1052 static inline bool
1053 uprobe_filter_event(struct trace_uprobe *tu, struct perf_event *event)
1054 {
1055         return __uprobe_perf_filter(&tu->filter, event->hw.target->mm);
1056 }
1057
1058 static int uprobe_perf_close(struct trace_uprobe *tu, struct perf_event *event)
1059 {
1060         bool done;
1061
1062         write_lock(&tu->filter.rwlock);
1063         if (event->hw.target) {
1064                 list_del(&event->hw.tp_list);
1065                 done = tu->filter.nr_systemwide ||
1066                         (event->hw.target->flags & PF_EXITING) ||
1067                         uprobe_filter_event(tu, event);
1068         } else {
1069                 tu->filter.nr_systemwide--;
1070                 done = tu->filter.nr_systemwide;
1071         }
1072         write_unlock(&tu->filter.rwlock);
1073
1074         if (!done)
1075                 return uprobe_apply(tu->inode, tu->offset, &tu->consumer, false);
1076
1077         return 0;
1078 }
1079
1080 static int uprobe_perf_open(struct trace_uprobe *tu, struct perf_event *event)
1081 {
1082         bool done;
1083         int err;
1084
1085         write_lock(&tu->filter.rwlock);
1086         if (event->hw.target) {
1087                 /*
1088                  * event->parent != NULL means copy_process(), we can avoid
1089                  * uprobe_apply(). current->mm must be probed and we can rely
1090                  * on dup_mmap() which preserves the already installed bp's.
1091                  *
1092                  * attr.enable_on_exec means that exec/mmap will install the
1093                  * breakpoints we need.
1094                  */
1095                 done = tu->filter.nr_systemwide ||
1096                         event->parent || event->attr.enable_on_exec ||
1097                         uprobe_filter_event(tu, event);
1098                 list_add(&event->hw.tp_list, &tu->filter.perf_events);
1099         } else {
1100                 done = tu->filter.nr_systemwide;
1101                 tu->filter.nr_systemwide++;
1102         }
1103         write_unlock(&tu->filter.rwlock);
1104
1105         err = 0;
1106         if (!done) {
1107                 err = uprobe_apply(tu->inode, tu->offset, &tu->consumer, true);
1108                 if (err)
1109                         uprobe_perf_close(tu, event);
1110         }
1111         return err;
1112 }
1113
1114 static bool uprobe_perf_filter(struct uprobe_consumer *uc,
1115                                 enum uprobe_filter_ctx ctx, struct mm_struct *mm)
1116 {
1117         struct trace_uprobe *tu;
1118         int ret;
1119
1120         tu = container_of(uc, struct trace_uprobe, consumer);
1121         read_lock(&tu->filter.rwlock);
1122         ret = __uprobe_perf_filter(&tu->filter, mm);
1123         read_unlock(&tu->filter.rwlock);
1124
1125         return ret;
1126 }
1127
1128 static void __uprobe_perf_func(struct trace_uprobe *tu,
1129                                unsigned long func, struct pt_regs *regs,
1130                                struct uprobe_cpu_buffer *ucb, int dsize)
1131 {
1132         struct trace_event_call *call = &tu->tp.call;
1133         struct uprobe_trace_entry_head *entry;
1134         struct hlist_head *head;
1135         void *data;
1136         int size, esize;
1137         int rctx;
1138
1139         if (bpf_prog_array_valid(call) && !trace_call_bpf(call, regs))
1140                 return;
1141
1142         esize = SIZEOF_TRACE_ENTRY(is_ret_probe(tu));
1143
1144         size = esize + tu->tp.size + dsize;
1145         size = ALIGN(size + sizeof(u32), sizeof(u64)) - sizeof(u32);
1146         if (WARN_ONCE(size > PERF_MAX_TRACE_SIZE, "profile buffer not large enough"))
1147                 return;
1148
1149         preempt_disable();
1150         head = this_cpu_ptr(call->perf_events);
1151         if (hlist_empty(head))
1152                 goto out;
1153
1154         entry = perf_trace_buf_alloc(size, NULL, &rctx);
1155         if (!entry)
1156                 goto out;
1157
1158         if (is_ret_probe(tu)) {
1159                 entry->vaddr[0] = func;
1160                 entry->vaddr[1] = instruction_pointer(regs);
1161                 data = DATAOF_TRACE_ENTRY(entry, true);
1162         } else {
1163                 entry->vaddr[0] = instruction_pointer(regs);
1164                 data = DATAOF_TRACE_ENTRY(entry, false);
1165         }
1166
1167         memcpy(data, ucb->buf, tu->tp.size + dsize);
1168
1169         if (size - esize > tu->tp.size + dsize) {
1170                 int len = tu->tp.size + dsize;
1171
1172                 memset(data + len, 0, size - esize - len);
1173         }
1174
1175         perf_trace_buf_submit(entry, size, rctx, call->event.type, 1, regs,
1176                               head, NULL);
1177  out:
1178         preempt_enable();
1179 }
1180
1181 /* uprobe profile handler */
1182 static int uprobe_perf_func(struct trace_uprobe *tu, struct pt_regs *regs,
1183                             struct uprobe_cpu_buffer *ucb, int dsize)
1184 {
1185         if (!uprobe_perf_filter(&tu->consumer, 0, current->mm))
1186                 return UPROBE_HANDLER_REMOVE;
1187
1188         if (!is_ret_probe(tu))
1189                 __uprobe_perf_func(tu, 0, regs, ucb, dsize);
1190         return 0;
1191 }
1192
1193 static void uretprobe_perf_func(struct trace_uprobe *tu, unsigned long func,
1194                                 struct pt_regs *regs,
1195                                 struct uprobe_cpu_buffer *ucb, int dsize)
1196 {
1197         __uprobe_perf_func(tu, func, regs, ucb, dsize);
1198 }
1199
1200 int bpf_get_uprobe_info(const struct perf_event *event, u32 *fd_type,
1201                         const char **filename, u64 *probe_offset,
1202                         bool perf_type_tracepoint)
1203 {
1204         const char *pevent = trace_event_name(event->tp_event);
1205         const char *group = event->tp_event->class->system;
1206         struct trace_uprobe *tu;
1207
1208         if (perf_type_tracepoint)
1209                 tu = find_probe_event(pevent, group);
1210         else
1211                 tu = event->tp_event->data;
1212         if (!tu)
1213                 return -EINVAL;
1214
1215         *fd_type = is_ret_probe(tu) ? BPF_FD_TYPE_URETPROBE
1216                                     : BPF_FD_TYPE_UPROBE;
1217         *filename = tu->filename;
1218         *probe_offset = tu->offset;
1219         return 0;
1220 }
1221 #endif  /* CONFIG_PERF_EVENTS */
1222
1223 static int
1224 trace_uprobe_register(struct trace_event_call *event, enum trace_reg type,
1225                       void *data)
1226 {
1227         struct trace_uprobe *tu = event->data;
1228         struct trace_event_file *file = data;
1229
1230         switch (type) {
1231         case TRACE_REG_REGISTER:
1232                 return probe_event_enable(tu, file, NULL);
1233
1234         case TRACE_REG_UNREGISTER:
1235                 probe_event_disable(tu, file);
1236                 return 0;
1237
1238 #ifdef CONFIG_PERF_EVENTS
1239         case TRACE_REG_PERF_REGISTER:
1240                 return probe_event_enable(tu, NULL, uprobe_perf_filter);
1241
1242         case TRACE_REG_PERF_UNREGISTER:
1243                 probe_event_disable(tu, NULL);
1244                 return 0;
1245
1246         case TRACE_REG_PERF_OPEN:
1247                 return uprobe_perf_open(tu, data);
1248
1249         case TRACE_REG_PERF_CLOSE:
1250                 return uprobe_perf_close(tu, data);
1251
1252 #endif
1253         default:
1254                 return 0;
1255         }
1256         return 0;
1257 }
1258
1259 static int uprobe_dispatcher(struct uprobe_consumer *con, struct pt_regs *regs)
1260 {
1261         struct trace_uprobe *tu;
1262         struct uprobe_dispatch_data udd;
1263         struct uprobe_cpu_buffer *ucb;
1264         int dsize, esize;
1265         int ret = 0;
1266
1267
1268         tu = container_of(con, struct trace_uprobe, consumer);
1269         tu->nhit++;
1270
1271         udd.tu = tu;
1272         udd.bp_addr = instruction_pointer(regs);
1273
1274         current->utask->vaddr = (unsigned long) &udd;
1275
1276         if (WARN_ON_ONCE(!uprobe_cpu_buffer))
1277                 return 0;
1278
1279         dsize = __get_data_size(&tu->tp, regs);
1280         esize = SIZEOF_TRACE_ENTRY(is_ret_probe(tu));
1281
1282         ucb = uprobe_buffer_get();
1283         store_trace_args(ucb->buf, &tu->tp, regs, esize, dsize);
1284
1285         if (tu->tp.flags & TP_FLAG_TRACE)
1286                 ret |= uprobe_trace_func(tu, regs, ucb, dsize);
1287
1288 #ifdef CONFIG_PERF_EVENTS
1289         if (tu->tp.flags & TP_FLAG_PROFILE)
1290                 ret |= uprobe_perf_func(tu, regs, ucb, dsize);
1291 #endif
1292         uprobe_buffer_put(ucb);
1293         return ret;
1294 }
1295
1296 static int uretprobe_dispatcher(struct uprobe_consumer *con,
1297                                 unsigned long func, struct pt_regs *regs)
1298 {
1299         struct trace_uprobe *tu;
1300         struct uprobe_dispatch_data udd;
1301         struct uprobe_cpu_buffer *ucb;
1302         int dsize, esize;
1303
1304         tu = container_of(con, struct trace_uprobe, consumer);
1305
1306         udd.tu = tu;
1307         udd.bp_addr = func;
1308
1309         current->utask->vaddr = (unsigned long) &udd;
1310
1311         if (WARN_ON_ONCE(!uprobe_cpu_buffer))
1312                 return 0;
1313
1314         dsize = __get_data_size(&tu->tp, regs);
1315         esize = SIZEOF_TRACE_ENTRY(is_ret_probe(tu));
1316
1317         ucb = uprobe_buffer_get();
1318         store_trace_args(ucb->buf, &tu->tp, regs, esize, dsize);
1319
1320         if (tu->tp.flags & TP_FLAG_TRACE)
1321                 uretprobe_trace_func(tu, func, regs, ucb, dsize);
1322
1323 #ifdef CONFIG_PERF_EVENTS
1324         if (tu->tp.flags & TP_FLAG_PROFILE)
1325                 uretprobe_perf_func(tu, func, regs, ucb, dsize);
1326 #endif
1327         uprobe_buffer_put(ucb);
1328         return 0;
1329 }
1330
1331 static struct trace_event_functions uprobe_funcs = {
1332         .trace          = print_uprobe_event
1333 };
1334
1335 static inline void init_trace_event_call(struct trace_uprobe *tu,
1336                                          struct trace_event_call *call)
1337 {
1338         call->event.funcs = &uprobe_funcs;
1339         call->class->define_fields = uprobe_event_define_fields;
1340
1341         call->flags = TRACE_EVENT_FL_UPROBE;
1342         call->class->reg = trace_uprobe_register;
1343         call->data = tu;
1344 }
1345
1346 static int register_uprobe_event(struct trace_uprobe *tu)
1347 {
1348         struct trace_event_call *call = &tu->tp.call;
1349         int ret = 0;
1350
1351         init_trace_event_call(tu, call);
1352
1353         ret = register_trace_event(&call->event);
1354         if (!ret)
1355                 return -ENODEV;
1356
1357         ret = trace_add_event_call(call);
1358
1359         if (ret) {
1360                 pr_info("Failed to register uprobe event: %s\n",
1361                         trace_event_name(call));
1362                 unregister_trace_event(&call->event);
1363         }
1364
1365         return ret;
1366 }
1367
1368 static int unregister_uprobe_event(struct trace_uprobe *tu)
1369 {
1370         /* tu->event is unregistered in trace_remove_event_call() */
1371         return trace_remove_event_call(&tu->tp.call);
1372 }
1373
1374 #ifdef CONFIG_PERF_EVENTS
1375 struct trace_event_call *
1376 create_local_trace_uprobe(char *name, unsigned long offs,
1377                           unsigned long ref_ctr_offset, bool is_return)
1378 {
1379         struct trace_uprobe *tu;
1380         struct path path;
1381         int ret;
1382
1383         ret = kern_path(name, LOOKUP_FOLLOW, &path);
1384         if (ret)
1385                 return ERR_PTR(ret);
1386
1387         if (!d_is_reg(path.dentry)) {
1388                 path_put(&path);
1389                 return ERR_PTR(-EINVAL);
1390         }
1391
1392         /*
1393          * local trace_kprobes are not added to dyn_event, so they are never
1394          * searched in find_trace_kprobe(). Therefore, there is no concern of
1395          * duplicated name "DUMMY_EVENT" here.
1396          */
1397         tu = alloc_trace_uprobe(UPROBE_EVENT_SYSTEM, "DUMMY_EVENT", 0,
1398                                 is_return);
1399
1400         if (IS_ERR(tu)) {
1401                 pr_info("Failed to allocate trace_uprobe.(%d)\n",
1402                         (int)PTR_ERR(tu));
1403                 path_put(&path);
1404                 return ERR_CAST(tu);
1405         }
1406
1407         tu->offset = offs;
1408         tu->path = path;
1409         tu->ref_ctr_offset = ref_ctr_offset;
1410         tu->filename = kstrdup(name, GFP_KERNEL);
1411         init_trace_event_call(tu, &tu->tp.call);
1412
1413         if (traceprobe_set_print_fmt(&tu->tp, is_ret_probe(tu)) < 0) {
1414                 ret = -ENOMEM;
1415                 goto error;
1416         }
1417
1418         return &tu->tp.call;
1419 error:
1420         free_trace_uprobe(tu);
1421         return ERR_PTR(ret);
1422 }
1423
1424 void destroy_local_trace_uprobe(struct trace_event_call *event_call)
1425 {
1426         struct trace_uprobe *tu;
1427
1428         tu = container_of(event_call, struct trace_uprobe, tp.call);
1429
1430         free_trace_uprobe(tu);
1431 }
1432 #endif /* CONFIG_PERF_EVENTS */
1433
1434 /* Make a trace interface for controling probe points */
1435 static __init int init_uprobe_trace(void)
1436 {
1437         struct dentry *d_tracer;
1438         int ret;
1439
1440         ret = dyn_event_register(&trace_uprobe_ops);
1441         if (ret)
1442                 return ret;
1443
1444         d_tracer = tracing_init_dentry();
1445         if (IS_ERR(d_tracer))
1446                 return 0;
1447
1448         trace_create_file("uprobe_events", 0644, d_tracer,
1449                                     NULL, &uprobe_events_ops);
1450         /* Profile interface */
1451         trace_create_file("uprobe_profile", 0444, d_tracer,
1452                                     NULL, &uprobe_profile_ops);
1453         return 0;
1454 }
1455
1456 fs_initcall(init_uprobe_trace);