ec54cb7d69d6bedcb35e9c9383d542086f5f3bba
[safe/jmp/linux-2.6] / kernel / trace / ftrace.c
1 /*
2  * Infrastructure for profiling code inserted by 'gcc -pg'.
3  *
4  * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
5  * Copyright (C) 2004-2008 Ingo Molnar <mingo@redhat.com>
6  *
7  * Originally ported from the -rt patch by:
8  *   Copyright (C) 2007 Arnaldo Carvalho de Melo <acme@redhat.com>
9  *
10  * Based on code in the latency_tracer, that is:
11  *
12  *  Copyright (C) 2004-2006 Ingo Molnar
13  *  Copyright (C) 2004 William Lee Irwin III
14  */
15
16 #include <linux/stop_machine.h>
17 #include <linux/clocksource.h>
18 #include <linux/kallsyms.h>
19 #include <linux/seq_file.h>
20 #include <linux/debugfs.h>
21 #include <linux/hardirq.h>
22 #include <linux/kthread.h>
23 #include <linux/uaccess.h>
24 #include <linux/ftrace.h>
25 #include <linux/sysctl.h>
26 #include <linux/ctype.h>
27 #include <linux/hash.h>
28 #include <linux/list.h>
29
30 #include "trace.h"
31
32 /* ftrace_enabled is a method to turn ftrace on or off */
33 int ftrace_enabled __read_mostly;
34 static int last_ftrace_enabled;
35
36 /*
37  * ftrace_disabled is set when an anomaly is discovered.
38  * ftrace_disabled is much stronger than ftrace_enabled.
39  */
40 static int ftrace_disabled __read_mostly;
41
42 static DEFINE_SPINLOCK(ftrace_lock);
43 static DEFINE_MUTEX(ftrace_sysctl_lock);
44
45 static struct ftrace_ops ftrace_list_end __read_mostly =
46 {
47         .func = ftrace_stub,
48 };
49
50 static struct ftrace_ops *ftrace_list __read_mostly = &ftrace_list_end;
51 ftrace_func_t ftrace_trace_function __read_mostly = ftrace_stub;
52
53 void ftrace_list_func(unsigned long ip, unsigned long parent_ip)
54 {
55         struct ftrace_ops *op = ftrace_list;
56
57         /* in case someone actually ports this to alpha! */
58         read_barrier_depends();
59
60         while (op != &ftrace_list_end) {
61                 /* silly alpha */
62                 read_barrier_depends();
63                 op->func(ip, parent_ip);
64                 op = op->next;
65         };
66 }
67
68 /**
69  * clear_ftrace_function - reset the ftrace function
70  *
71  * This NULLs the ftrace function and in essence stops
72  * tracing.  There may be lag
73  */
74 void clear_ftrace_function(void)
75 {
76         ftrace_trace_function = ftrace_stub;
77 }
78
79 static int __register_ftrace_function(struct ftrace_ops *ops)
80 {
81         /* Should never be called by interrupts */
82         spin_lock(&ftrace_lock);
83
84         ops->next = ftrace_list;
85         /*
86          * We are entering ops into the ftrace_list but another
87          * CPU might be walking that list. We need to make sure
88          * the ops->next pointer is valid before another CPU sees
89          * the ops pointer included into the ftrace_list.
90          */
91         smp_wmb();
92         ftrace_list = ops;
93
94         if (ftrace_enabled) {
95                 /*
96                  * For one func, simply call it directly.
97                  * For more than one func, call the chain.
98                  */
99                 if (ops->next == &ftrace_list_end)
100                         ftrace_trace_function = ops->func;
101                 else
102                         ftrace_trace_function = ftrace_list_func;
103         }
104
105         spin_unlock(&ftrace_lock);
106
107         return 0;
108 }
109
110 static int __unregister_ftrace_function(struct ftrace_ops *ops)
111 {
112         struct ftrace_ops **p;
113         int ret = 0;
114
115         spin_lock(&ftrace_lock);
116
117         /*
118          * If we are removing the last function, then simply point
119          * to the ftrace_stub.
120          */
121         if (ftrace_list == ops && ops->next == &ftrace_list_end) {
122                 ftrace_trace_function = ftrace_stub;
123                 ftrace_list = &ftrace_list_end;
124                 goto out;
125         }
126
127         for (p = &ftrace_list; *p != &ftrace_list_end; p = &(*p)->next)
128                 if (*p == ops)
129                         break;
130
131         if (*p != ops) {
132                 ret = -1;
133                 goto out;
134         }
135
136         *p = (*p)->next;
137
138         if (ftrace_enabled) {
139                 /* If we only have one func left, then call that directly */
140                 if (ftrace_list == &ftrace_list_end ||
141                     ftrace_list->next == &ftrace_list_end)
142                         ftrace_trace_function = ftrace_list->func;
143         }
144
145  out:
146         spin_unlock(&ftrace_lock);
147
148         return ret;
149 }
150
151 #ifdef CONFIG_DYNAMIC_FTRACE
152
153 static struct task_struct *ftraced_task;
154
155 enum {
156         FTRACE_ENABLE_CALLS             = (1 << 0),
157         FTRACE_DISABLE_CALLS            = (1 << 1),
158         FTRACE_UPDATE_TRACE_FUNC        = (1 << 2),
159         FTRACE_ENABLE_MCOUNT            = (1 << 3),
160         FTRACE_DISABLE_MCOUNT           = (1 << 4),
161 };
162
163 static int ftrace_filtered;
164
165 static struct hlist_head ftrace_hash[FTRACE_HASHSIZE];
166
167 static DEFINE_PER_CPU(int, ftrace_shutdown_disable_cpu);
168
169 static DEFINE_SPINLOCK(ftrace_shutdown_lock);
170 static DEFINE_MUTEX(ftraced_lock);
171 static DEFINE_MUTEX(ftrace_regex_lock);
172
173 struct ftrace_page {
174         struct ftrace_page      *next;
175         unsigned long           index;
176         struct dyn_ftrace       records[];
177 };
178
179 #define ENTRIES_PER_PAGE \
180   ((PAGE_SIZE - sizeof(struct ftrace_page)) / sizeof(struct dyn_ftrace))
181
182 /* estimate from running different kernels */
183 #define NR_TO_INIT              10000
184
185 static struct ftrace_page       *ftrace_pages_start;
186 static struct ftrace_page       *ftrace_pages;
187
188 static int ftraced_trigger;
189 static int ftraced_suspend;
190 static int ftraced_stop;
191
192 static int ftrace_record_suspend;
193
194 static struct dyn_ftrace *ftrace_free_records;
195
196 static inline int
197 ftrace_ip_in_hash(unsigned long ip, unsigned long key)
198 {
199         struct dyn_ftrace *p;
200         struct hlist_node *t;
201         int found = 0;
202
203         hlist_for_each_entry_rcu(p, t, &ftrace_hash[key], node) {
204                 if (p->ip == ip) {
205                         found = 1;
206                         break;
207                 }
208         }
209
210         return found;
211 }
212
213 static inline void
214 ftrace_add_hash(struct dyn_ftrace *node, unsigned long key)
215 {
216         hlist_add_head_rcu(&node->node, &ftrace_hash[key]);
217 }
218
219 /* called from kstop_machine */
220 static inline void ftrace_del_hash(struct dyn_ftrace *node)
221 {
222         hlist_del(&node->node);
223 }
224
225 static void ftrace_free_rec(struct dyn_ftrace *rec)
226 {
227         /* no locking, only called from kstop_machine */
228
229         rec->ip = (unsigned long)ftrace_free_records;
230         ftrace_free_records = rec;
231         rec->flags |= FTRACE_FL_FREE;
232 }
233
234 static struct dyn_ftrace *ftrace_alloc_dyn_node(unsigned long ip)
235 {
236         struct dyn_ftrace *rec;
237
238         /* First check for freed records */
239         if (ftrace_free_records) {
240                 rec = ftrace_free_records;
241
242                 if (unlikely(!(rec->flags & FTRACE_FL_FREE))) {
243                         WARN_ON_ONCE(1);
244                         ftrace_free_records = NULL;
245                         ftrace_disabled = 1;
246                         ftrace_enabled = 0;
247                         return NULL;
248                 }
249
250                 ftrace_free_records = (void *)rec->ip;
251                 memset(rec, 0, sizeof(*rec));
252                 return rec;
253         }
254
255         if (ftrace_pages->index == ENTRIES_PER_PAGE) {
256                 if (!ftrace_pages->next)
257                         return NULL;
258                 ftrace_pages = ftrace_pages->next;
259         }
260
261         return &ftrace_pages->records[ftrace_pages->index++];
262 }
263
264 static void
265 ftrace_record_ip(unsigned long ip)
266 {
267         struct dyn_ftrace *node;
268         unsigned long flags;
269         unsigned long key;
270         int resched;
271         int atomic;
272         int cpu;
273
274         if (!ftrace_enabled || ftrace_disabled)
275                 return;
276
277         resched = need_resched();
278         preempt_disable_notrace();
279
280         /*
281          * We simply need to protect against recursion.
282          * Use the the raw version of smp_processor_id and not
283          * __get_cpu_var which can call debug hooks that can
284          * cause a recursive crash here.
285          */
286         cpu = raw_smp_processor_id();
287         per_cpu(ftrace_shutdown_disable_cpu, cpu)++;
288         if (per_cpu(ftrace_shutdown_disable_cpu, cpu) != 1)
289                 goto out;
290
291         if (unlikely(ftrace_record_suspend))
292                 goto out;
293
294         key = hash_long(ip, FTRACE_HASHBITS);
295
296         WARN_ON_ONCE(key >= FTRACE_HASHSIZE);
297
298         if (ftrace_ip_in_hash(ip, key))
299                 goto out;
300
301         atomic = irqs_disabled();
302
303         spin_lock_irqsave(&ftrace_shutdown_lock, flags);
304
305         /* This ip may have hit the hash before the lock */
306         if (ftrace_ip_in_hash(ip, key))
307                 goto out_unlock;
308
309         /*
310          * There's a slight race that the ftraced will update the
311          * hash and reset here. If it is already converted, skip it.
312          */
313         if (ftrace_ip_converted(ip))
314                 goto out_unlock;
315
316         node = ftrace_alloc_dyn_node(ip);
317         if (!node)
318                 goto out_unlock;
319
320         node->ip = ip;
321
322         ftrace_add_hash(node, key);
323
324         ftraced_trigger = 1;
325
326  out_unlock:
327         spin_unlock_irqrestore(&ftrace_shutdown_lock, flags);
328  out:
329         per_cpu(ftrace_shutdown_disable_cpu, cpu)--;
330
331         /* prevent recursion with scheduler */
332         if (resched)
333                 preempt_enable_no_resched_notrace();
334         else
335                 preempt_enable_notrace();
336 }
337
338 #define FTRACE_ADDR ((long)(ftrace_caller))
339 #define MCOUNT_ADDR ((long)(mcount))
340
341 static int
342 __ftrace_replace_code(struct dyn_ftrace *rec,
343                       unsigned char *old, unsigned char *new, int enable)
344 {
345         unsigned long ip, fl;
346
347         ip = rec->ip;
348
349         if (ftrace_filtered && enable) {
350                 /*
351                  * If filtering is on:
352                  *
353                  * If this record is set to be filtered and
354                  * is enabled then do nothing.
355                  *
356                  * If this record is set to be filtered and
357                  * it is not enabled, enable it.
358                  *
359                  * If this record is not set to be filtered
360                  * and it is not enabled do nothing.
361                  *
362                  * If this record is set not to trace then
363                  * do nothing.
364                  *
365                  * If this record is not set to be filtered and
366                  * it is enabled, disable it.
367                  */
368                 fl = rec->flags & (FTRACE_FL_FILTER | FTRACE_FL_ENABLED);
369
370                 if ((fl ==  (FTRACE_FL_FILTER | FTRACE_FL_ENABLED)) ||
371                     (fl == 0) || (rec->flags & FTRACE_FL_NOTRACE))
372                         return 0;
373
374                 /*
375                  * If it is enabled disable it,
376                  * otherwise enable it!
377                  */
378                 if (fl == FTRACE_FL_ENABLED) {
379                         /* swap new and old */
380                         new = old;
381                         old = ftrace_call_replace(ip, FTRACE_ADDR);
382                         rec->flags &= ~FTRACE_FL_ENABLED;
383                 } else {
384                         new = ftrace_call_replace(ip, FTRACE_ADDR);
385                         rec->flags |= FTRACE_FL_ENABLED;
386                 }
387         } else {
388
389                 if (enable) {
390                         /*
391                          * If this record is set not to trace and is
392                          * not enabled, do nothing.
393                          */
394                         fl = rec->flags & (FTRACE_FL_NOTRACE | FTRACE_FL_ENABLED);
395                         if (fl == FTRACE_FL_NOTRACE)
396                                 return 0;
397
398                         new = ftrace_call_replace(ip, FTRACE_ADDR);
399                 } else
400                         old = ftrace_call_replace(ip, FTRACE_ADDR);
401
402                 if (enable) {
403                         if (rec->flags & FTRACE_FL_ENABLED)
404                                 return 0;
405                         rec->flags |= FTRACE_FL_ENABLED;
406                 } else {
407                         if (!(rec->flags & FTRACE_FL_ENABLED))
408                                 return 0;
409                         rec->flags &= ~FTRACE_FL_ENABLED;
410                 }
411         }
412
413         return ftrace_modify_code(ip, old, new);
414 }
415
416 static void ftrace_replace_code(int enable)
417 {
418         int i, failed;
419         unsigned char *new = NULL, *old = NULL;
420         struct dyn_ftrace *rec;
421         struct ftrace_page *pg;
422
423         if (enable)
424                 old = ftrace_nop_replace();
425         else
426                 new = ftrace_nop_replace();
427
428         for (pg = ftrace_pages_start; pg; pg = pg->next) {
429                 for (i = 0; i < pg->index; i++) {
430                         rec = &pg->records[i];
431
432                         /* don't modify code that has already faulted */
433                         if (rec->flags & FTRACE_FL_FAILED)
434                                 continue;
435
436                         failed = __ftrace_replace_code(rec, old, new, enable);
437                         if (failed && (rec->flags & FTRACE_FL_CONVERTED)) {
438                                 rec->flags |= FTRACE_FL_FAILED;
439                                 if ((system_state == SYSTEM_BOOTING) ||
440                                     !kernel_text_address(rec->ip)) {
441                                         ftrace_del_hash(rec);
442                                         ftrace_free_rec(rec);
443                                 }
444                         }
445                 }
446         }
447 }
448
449 static void ftrace_shutdown_replenish(void)
450 {
451         if (ftrace_pages->next)
452                 return;
453
454         /* allocate another page */
455         ftrace_pages->next = (void *)get_zeroed_page(GFP_KERNEL);
456 }
457
458 static int
459 ftrace_code_disable(struct dyn_ftrace *rec)
460 {
461         unsigned long ip;
462         unsigned char *nop, *call;
463         int failed;
464
465         ip = rec->ip;
466
467         nop = ftrace_nop_replace();
468         call = ftrace_call_replace(ip, MCOUNT_ADDR);
469
470         failed = ftrace_modify_code(ip, call, nop);
471         if (failed) {
472                 rec->flags |= FTRACE_FL_FAILED;
473                 return 0;
474         }
475         return 1;
476 }
477
478 static int __ftrace_update_code(void *ignore);
479
480 static int __ftrace_modify_code(void *data)
481 {
482         unsigned long addr;
483         int *command = data;
484
485         if (*command & FTRACE_ENABLE_CALLS) {
486                 /*
487                  * Update any recorded ips now that we have the
488                  * machine stopped
489                  */
490                 __ftrace_update_code(NULL);
491                 ftrace_replace_code(1);
492         } else if (*command & FTRACE_DISABLE_CALLS)
493                 ftrace_replace_code(0);
494
495         if (*command & FTRACE_UPDATE_TRACE_FUNC)
496                 ftrace_update_ftrace_func(ftrace_trace_function);
497
498         if (*command & FTRACE_ENABLE_MCOUNT) {
499                 addr = (unsigned long)ftrace_record_ip;
500                 ftrace_mcount_set(&addr);
501         } else if (*command & FTRACE_DISABLE_MCOUNT) {
502                 addr = (unsigned long)ftrace_stub;
503                 ftrace_mcount_set(&addr);
504         }
505
506         return 0;
507 }
508
509 static void ftrace_run_update_code(int command)
510 {
511         stop_machine_run(__ftrace_modify_code, &command, NR_CPUS);
512 }
513
514 void ftrace_disable_daemon(void)
515 {
516         /* Stop the daemon from calling kstop_machine */
517         mutex_lock(&ftraced_lock);
518         ftraced_stop = 1;
519         mutex_unlock(&ftraced_lock);
520
521         ftrace_force_update();
522 }
523
524 void ftrace_enable_daemon(void)
525 {
526         mutex_lock(&ftraced_lock);
527         ftraced_stop = 0;
528         mutex_unlock(&ftraced_lock);
529
530         ftrace_force_update();
531 }
532
533 static ftrace_func_t saved_ftrace_func;
534
535 static void ftrace_startup(void)
536 {
537         int command = 0;
538
539         if (unlikely(ftrace_disabled))
540                 return;
541
542         mutex_lock(&ftraced_lock);
543         ftraced_suspend++;
544         if (ftraced_suspend == 1)
545                 command |= FTRACE_ENABLE_CALLS;
546
547         if (saved_ftrace_func != ftrace_trace_function) {
548                 saved_ftrace_func = ftrace_trace_function;
549                 command |= FTRACE_UPDATE_TRACE_FUNC;
550         }
551
552         if (!command || !ftrace_enabled)
553                 goto out;
554
555         ftrace_run_update_code(command);
556  out:
557         mutex_unlock(&ftraced_lock);
558 }
559
560 static void ftrace_shutdown(void)
561 {
562         int command = 0;
563
564         if (unlikely(ftrace_disabled))
565                 return;
566
567         mutex_lock(&ftraced_lock);
568         ftraced_suspend--;
569         if (!ftraced_suspend)
570                 command |= FTRACE_DISABLE_CALLS;
571
572         if (saved_ftrace_func != ftrace_trace_function) {
573                 saved_ftrace_func = ftrace_trace_function;
574                 command |= FTRACE_UPDATE_TRACE_FUNC;
575         }
576
577         if (!command || !ftrace_enabled)
578                 goto out;
579
580         ftrace_run_update_code(command);
581  out:
582         mutex_unlock(&ftraced_lock);
583 }
584
585 static void ftrace_startup_sysctl(void)
586 {
587         int command = FTRACE_ENABLE_MCOUNT;
588
589         if (unlikely(ftrace_disabled))
590                 return;
591
592         mutex_lock(&ftraced_lock);
593         /* Force update next time */
594         saved_ftrace_func = NULL;
595         /* ftraced_suspend is true if we want ftrace running */
596         if (ftraced_suspend)
597                 command |= FTRACE_ENABLE_CALLS;
598
599         ftrace_run_update_code(command);
600         mutex_unlock(&ftraced_lock);
601 }
602
603 static void ftrace_shutdown_sysctl(void)
604 {
605         int command = FTRACE_DISABLE_MCOUNT;
606
607         if (unlikely(ftrace_disabled))
608                 return;
609
610         mutex_lock(&ftraced_lock);
611         /* ftraced_suspend is true if ftrace is running */
612         if (ftraced_suspend)
613                 command |= FTRACE_DISABLE_CALLS;
614
615         ftrace_run_update_code(command);
616         mutex_unlock(&ftraced_lock);
617 }
618
619 static cycle_t          ftrace_update_time;
620 static unsigned long    ftrace_update_cnt;
621 unsigned long           ftrace_update_tot_cnt;
622
623 static int __ftrace_update_code(void *ignore)
624 {
625         struct dyn_ftrace *p;
626         struct hlist_node *t, *n;
627         int save_ftrace_enabled;
628         cycle_t start, stop;
629         int i;
630
631         /* Don't be recording funcs now */
632         ftrace_record_suspend++;
633         save_ftrace_enabled = ftrace_enabled;
634         ftrace_enabled = 0;
635
636         start = ftrace_now(raw_smp_processor_id());
637         ftrace_update_cnt = 0;
638
639         /* No locks needed, the machine is stopped! */
640         for (i = 0; i < FTRACE_HASHSIZE; i++) {
641                 /* all CPUS are stopped, we are safe to modify code */
642                 hlist_for_each_entry_safe(p, t, n, &ftrace_hash[i], node) {
643                         /* Skip over failed records which have not been
644                          * freed. */
645                         if (p->flags & FTRACE_FL_FAILED)
646                                 continue;
647
648                         /* Unconverted records are always at the head of the
649                          * hash bucket. Once we encounter a converted record,
650                          * simply skip over to the next bucket. Saves ftraced
651                          * some processor cycles (ftrace does its bid for
652                          * global warming :-p ). */
653                         if (p->flags & (FTRACE_FL_CONVERTED))
654                                 break;
655
656                         if (ftrace_code_disable(p)) {
657                                 p->flags |= FTRACE_FL_CONVERTED;
658                                 ftrace_update_cnt++;
659                         } else {
660                                 if ((system_state == SYSTEM_BOOTING) ||
661                                     !kernel_text_address(p->ip)) {
662                                         ftrace_del_hash(p);
663                                         ftrace_free_rec(p);
664
665                                 }
666                         }
667                 }
668         }
669
670         stop = ftrace_now(raw_smp_processor_id());
671         ftrace_update_time = stop - start;
672         ftrace_update_tot_cnt += ftrace_update_cnt;
673         ftraced_trigger = 0;
674
675         ftrace_enabled = save_ftrace_enabled;
676         ftrace_record_suspend--;
677
678         return 0;
679 }
680
681 static int ftrace_update_code(void)
682 {
683         if (unlikely(ftrace_disabled) ||
684             !ftrace_enabled || !ftraced_trigger)
685                 return 0;
686
687         stop_machine_run(__ftrace_update_code, NULL, NR_CPUS);
688
689         return 1;
690 }
691
692 static int ftraced(void *ignore)
693 {
694         unsigned long usecs;
695
696         while (!kthread_should_stop()) {
697
698                 set_current_state(TASK_INTERRUPTIBLE);
699
700                 /* check once a second */
701                 schedule_timeout(HZ);
702
703                 if (unlikely(ftrace_disabled))
704                         continue;
705
706                 mutex_lock(&ftrace_sysctl_lock);
707                 mutex_lock(&ftraced_lock);
708                 if (!ftraced_suspend && !ftraced_stop &&
709                     ftrace_update_code()) {
710                         usecs = nsecs_to_usecs(ftrace_update_time);
711                         if (ftrace_update_tot_cnt > 100000) {
712                                 ftrace_update_tot_cnt = 0;
713                                 pr_info("hm, dftrace overflow: %lu change%s"
714                                         " (%lu total) in %lu usec%s\n",
715                                         ftrace_update_cnt,
716                                         ftrace_update_cnt != 1 ? "s" : "",
717                                         ftrace_update_tot_cnt,
718                                         usecs, usecs != 1 ? "s" : "");
719                                 ftrace_disabled = 1;
720                                 WARN_ON_ONCE(1);
721                         }
722                 }
723                 mutex_unlock(&ftraced_lock);
724                 mutex_unlock(&ftrace_sysctl_lock);
725
726                 ftrace_shutdown_replenish();
727         }
728         __set_current_state(TASK_RUNNING);
729         return 0;
730 }
731
732 static int __init ftrace_dyn_table_alloc(void)
733 {
734         struct ftrace_page *pg;
735         int cnt;
736         int i;
737
738         /* allocate a few pages */
739         ftrace_pages_start = (void *)get_zeroed_page(GFP_KERNEL);
740         if (!ftrace_pages_start)
741                 return -1;
742
743         /*
744          * Allocate a few more pages.
745          *
746          * TODO: have some parser search vmlinux before
747          *   final linking to find all calls to ftrace.
748          *   Then we can:
749          *    a) know how many pages to allocate.
750          *     and/or
751          *    b) set up the table then.
752          *
753          *  The dynamic code is still necessary for
754          *  modules.
755          */
756
757         pg = ftrace_pages = ftrace_pages_start;
758
759         cnt = NR_TO_INIT / ENTRIES_PER_PAGE;
760
761         for (i = 0; i < cnt; i++) {
762                 pg->next = (void *)get_zeroed_page(GFP_KERNEL);
763
764                 /* If we fail, we'll try later anyway */
765                 if (!pg->next)
766                         break;
767
768                 pg = pg->next;
769         }
770
771         return 0;
772 }
773
774 enum {
775         FTRACE_ITER_FILTER      = (1 << 0),
776         FTRACE_ITER_CONT        = (1 << 1),
777         FTRACE_ITER_NOTRACE     = (1 << 2),
778 };
779
780 #define FTRACE_BUFF_MAX (KSYM_SYMBOL_LEN+4) /* room for wildcards */
781
782 struct ftrace_iterator {
783         loff_t                  pos;
784         struct ftrace_page      *pg;
785         unsigned                idx;
786         unsigned                flags;
787         unsigned char           buffer[FTRACE_BUFF_MAX+1];
788         unsigned                buffer_idx;
789         unsigned                filtered;
790 };
791
792 static void *
793 t_next(struct seq_file *m, void *v, loff_t *pos)
794 {
795         struct ftrace_iterator *iter = m->private;
796         struct dyn_ftrace *rec = NULL;
797
798         (*pos)++;
799
800  retry:
801         if (iter->idx >= iter->pg->index) {
802                 if (iter->pg->next) {
803                         iter->pg = iter->pg->next;
804                         iter->idx = 0;
805                         goto retry;
806                 }
807         } else {
808                 rec = &iter->pg->records[iter->idx++];
809                 if ((rec->flags & FTRACE_FL_FAILED) ||
810                     ((iter->flags & FTRACE_ITER_FILTER) &&
811                      !(rec->flags & FTRACE_FL_FILTER)) ||
812                     ((iter->flags & FTRACE_ITER_NOTRACE) &&
813                      !(rec->flags & FTRACE_FL_NOTRACE))) {
814                         rec = NULL;
815                         goto retry;
816                 }
817         }
818
819         iter->pos = *pos;
820
821         return rec;
822 }
823
824 static void *t_start(struct seq_file *m, loff_t *pos)
825 {
826         struct ftrace_iterator *iter = m->private;
827         void *p = NULL;
828         loff_t l = -1;
829
830         if (*pos != iter->pos) {
831                 for (p = t_next(m, p, &l); p && l < *pos; p = t_next(m, p, &l))
832                         ;
833         } else {
834                 l = *pos;
835                 p = t_next(m, p, &l);
836         }
837
838         return p;
839 }
840
841 static void t_stop(struct seq_file *m, void *p)
842 {
843 }
844
845 static int t_show(struct seq_file *m, void *v)
846 {
847         struct dyn_ftrace *rec = v;
848         char str[KSYM_SYMBOL_LEN];
849
850         if (!rec)
851                 return 0;
852
853         kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
854
855         seq_printf(m, "%s\n", str);
856
857         return 0;
858 }
859
860 static struct seq_operations show_ftrace_seq_ops = {
861         .start = t_start,
862         .next = t_next,
863         .stop = t_stop,
864         .show = t_show,
865 };
866
867 static int
868 ftrace_avail_open(struct inode *inode, struct file *file)
869 {
870         struct ftrace_iterator *iter;
871         int ret;
872
873         if (unlikely(ftrace_disabled))
874                 return -ENODEV;
875
876         iter = kzalloc(sizeof(*iter), GFP_KERNEL);
877         if (!iter)
878                 return -ENOMEM;
879
880         iter->pg = ftrace_pages_start;
881         iter->pos = -1;
882
883         ret = seq_open(file, &show_ftrace_seq_ops);
884         if (!ret) {
885                 struct seq_file *m = file->private_data;
886
887                 m->private = iter;
888         } else {
889                 kfree(iter);
890         }
891
892         return ret;
893 }
894
895 int ftrace_avail_release(struct inode *inode, struct file *file)
896 {
897         struct seq_file *m = (struct seq_file *)file->private_data;
898         struct ftrace_iterator *iter = m->private;
899
900         seq_release(inode, file);
901         kfree(iter);
902
903         return 0;
904 }
905
906 static void ftrace_filter_reset(int enable)
907 {
908         struct ftrace_page *pg;
909         struct dyn_ftrace *rec;
910         unsigned long type = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE;
911         unsigned i;
912
913         /* keep kstop machine from running */
914         preempt_disable();
915         if (enable)
916                 ftrace_filtered = 0;
917         pg = ftrace_pages_start;
918         while (pg) {
919                 for (i = 0; i < pg->index; i++) {
920                         rec = &pg->records[i];
921                         if (rec->flags & FTRACE_FL_FAILED)
922                                 continue;
923                         rec->flags &= ~type;
924                 }
925                 pg = pg->next;
926         }
927         preempt_enable();
928 }
929
930 static int
931 ftrace_regex_open(struct inode *inode, struct file *file, int enable)
932 {
933         struct ftrace_iterator *iter;
934         int ret = 0;
935
936         if (unlikely(ftrace_disabled))
937                 return -ENODEV;
938
939         iter = kzalloc(sizeof(*iter), GFP_KERNEL);
940         if (!iter)
941                 return -ENOMEM;
942
943         mutex_lock(&ftrace_regex_lock);
944         if ((file->f_mode & FMODE_WRITE) &&
945             !(file->f_flags & O_APPEND))
946                 ftrace_filter_reset(enable);
947
948         if (file->f_mode & FMODE_READ) {
949                 iter->pg = ftrace_pages_start;
950                 iter->pos = -1;
951                 iter->flags = enable ? FTRACE_ITER_FILTER :
952                         FTRACE_ITER_NOTRACE;
953
954                 ret = seq_open(file, &show_ftrace_seq_ops);
955                 if (!ret) {
956                         struct seq_file *m = file->private_data;
957                         m->private = iter;
958                 } else
959                         kfree(iter);
960         } else
961                 file->private_data = iter;
962         mutex_unlock(&ftrace_regex_lock);
963
964         return ret;
965 }
966
967 static int
968 ftrace_filter_open(struct inode *inode, struct file *file)
969 {
970         return ftrace_regex_open(inode, file, 1);
971 }
972
973 static int
974 ftrace_notrace_open(struct inode *inode, struct file *file)
975 {
976         return ftrace_regex_open(inode, file, 0);
977 }
978
979 static ssize_t
980 ftrace_regex_read(struct file *file, char __user *ubuf,
981                        size_t cnt, loff_t *ppos)
982 {
983         if (file->f_mode & FMODE_READ)
984                 return seq_read(file, ubuf, cnt, ppos);
985         else
986                 return -EPERM;
987 }
988
989 static loff_t
990 ftrace_regex_lseek(struct file *file, loff_t offset, int origin)
991 {
992         loff_t ret;
993
994         if (file->f_mode & FMODE_READ)
995                 ret = seq_lseek(file, offset, origin);
996         else
997                 file->f_pos = ret = 1;
998
999         return ret;
1000 }
1001
1002 enum {
1003         MATCH_FULL,
1004         MATCH_FRONT_ONLY,
1005         MATCH_MIDDLE_ONLY,
1006         MATCH_END_ONLY,
1007 };
1008
1009 static void
1010 ftrace_match(unsigned char *buff, int len, int enable)
1011 {
1012         char str[KSYM_SYMBOL_LEN];
1013         char *search = NULL;
1014         struct ftrace_page *pg;
1015         struct dyn_ftrace *rec;
1016         int type = MATCH_FULL;
1017         unsigned long flag = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE;
1018         unsigned i, match = 0, search_len = 0;
1019
1020         for (i = 0; i < len; i++) {
1021                 if (buff[i] == '*') {
1022                         if (!i) {
1023                                 search = buff + i + 1;
1024                                 type = MATCH_END_ONLY;
1025                                 search_len = len - (i + 1);
1026                         } else {
1027                                 if (type == MATCH_END_ONLY) {
1028                                         type = MATCH_MIDDLE_ONLY;
1029                                 } else {
1030                                         match = i;
1031                                         type = MATCH_FRONT_ONLY;
1032                                 }
1033                                 buff[i] = 0;
1034                                 break;
1035                         }
1036                 }
1037         }
1038
1039         /* keep kstop machine from running */
1040         preempt_disable();
1041         if (enable)
1042                 ftrace_filtered = 1;
1043         pg = ftrace_pages_start;
1044         while (pg) {
1045                 for (i = 0; i < pg->index; i++) {
1046                         int matched = 0;
1047                         char *ptr;
1048
1049                         rec = &pg->records[i];
1050                         if (rec->flags & FTRACE_FL_FAILED)
1051                                 continue;
1052                         kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
1053                         switch (type) {
1054                         case MATCH_FULL:
1055                                 if (strcmp(str, buff) == 0)
1056                                         matched = 1;
1057                                 break;
1058                         case MATCH_FRONT_ONLY:
1059                                 if (memcmp(str, buff, match) == 0)
1060                                         matched = 1;
1061                                 break;
1062                         case MATCH_MIDDLE_ONLY:
1063                                 if (strstr(str, search))
1064                                         matched = 1;
1065                                 break;
1066                         case MATCH_END_ONLY:
1067                                 ptr = strstr(str, search);
1068                                 if (ptr && (ptr[search_len] == 0))
1069                                         matched = 1;
1070                                 break;
1071                         }
1072                         if (matched)
1073                                 rec->flags |= flag;
1074                 }
1075                 pg = pg->next;
1076         }
1077         preempt_enable();
1078 }
1079
1080 static ssize_t
1081 ftrace_regex_write(struct file *file, const char __user *ubuf,
1082                    size_t cnt, loff_t *ppos, int enable)
1083 {
1084         struct ftrace_iterator *iter;
1085         char ch;
1086         size_t read = 0;
1087         ssize_t ret;
1088
1089         if (!cnt || cnt < 0)
1090                 return 0;
1091
1092         mutex_lock(&ftrace_regex_lock);
1093
1094         if (file->f_mode & FMODE_READ) {
1095                 struct seq_file *m = file->private_data;
1096                 iter = m->private;
1097         } else
1098                 iter = file->private_data;
1099
1100         if (!*ppos) {
1101                 iter->flags &= ~FTRACE_ITER_CONT;
1102                 iter->buffer_idx = 0;
1103         }
1104
1105         ret = get_user(ch, ubuf++);
1106         if (ret)
1107                 goto out;
1108         read++;
1109         cnt--;
1110
1111         if (!(iter->flags & ~FTRACE_ITER_CONT)) {
1112                 /* skip white space */
1113                 while (cnt && isspace(ch)) {
1114                         ret = get_user(ch, ubuf++);
1115                         if (ret)
1116                                 goto out;
1117                         read++;
1118                         cnt--;
1119                 }
1120
1121                 if (isspace(ch)) {
1122                         file->f_pos += read;
1123                         ret = read;
1124                         goto out;
1125                 }
1126
1127                 iter->buffer_idx = 0;
1128         }
1129
1130         while (cnt && !isspace(ch)) {
1131                 if (iter->buffer_idx < FTRACE_BUFF_MAX)
1132                         iter->buffer[iter->buffer_idx++] = ch;
1133                 else {
1134                         ret = -EINVAL;
1135                         goto out;
1136                 }
1137                 ret = get_user(ch, ubuf++);
1138                 if (ret)
1139                         goto out;
1140                 read++;
1141                 cnt--;
1142         }
1143
1144         if (isspace(ch)) {
1145                 iter->filtered++;
1146                 iter->buffer[iter->buffer_idx] = 0;
1147                 ftrace_match(iter->buffer, iter->buffer_idx, enable);
1148                 iter->buffer_idx = 0;
1149         } else
1150                 iter->flags |= FTRACE_ITER_CONT;
1151
1152
1153         file->f_pos += read;
1154
1155         ret = read;
1156  out:
1157         mutex_unlock(&ftrace_regex_lock);
1158
1159         return ret;
1160 }
1161
1162 static ssize_t
1163 ftrace_filter_write(struct file *file, const char __user *ubuf,
1164                     size_t cnt, loff_t *ppos)
1165 {
1166         return ftrace_regex_write(file, ubuf, cnt, ppos, 1);
1167 }
1168
1169 static ssize_t
1170 ftrace_notrace_write(struct file *file, const char __user *ubuf,
1171                      size_t cnt, loff_t *ppos)
1172 {
1173         return ftrace_regex_write(file, ubuf, cnt, ppos, 0);
1174 }
1175
1176 static void
1177 ftrace_set_regex(unsigned char *buf, int len, int reset, int enable)
1178 {
1179         if (unlikely(ftrace_disabled))
1180                 return;
1181
1182         mutex_lock(&ftrace_regex_lock);
1183         if (reset)
1184                 ftrace_filter_reset(enable);
1185         if (buf)
1186                 ftrace_match(buf, len, enable);
1187         mutex_unlock(&ftrace_regex_lock);
1188 }
1189
1190 /**
1191  * ftrace_set_filter - set a function to filter on in ftrace
1192  * @buf - the string that holds the function filter text.
1193  * @len - the length of the string.
1194  * @reset - non zero to reset all filters before applying this filter.
1195  *
1196  * Filters denote which functions should be enabled when tracing is enabled.
1197  * If @buf is NULL and reset is set, all functions will be enabled for tracing.
1198  */
1199 void ftrace_set_filter(unsigned char *buf, int len, int reset)
1200 {
1201         ftrace_set_regex(buf, len, reset, 1);
1202 }
1203
1204 /**
1205  * ftrace_set_notrace - set a function to not trace in ftrace
1206  * @buf - the string that holds the function notrace text.
1207  * @len - the length of the string.
1208  * @reset - non zero to reset all filters before applying this filter.
1209  *
1210  * Notrace Filters denote which functions should not be enabled when tracing
1211  * is enabled. If @buf is NULL and reset is set, all functions will be enabled
1212  * for tracing.
1213  */
1214 void ftrace_set_notrace(unsigned char *buf, int len, int reset)
1215 {
1216         ftrace_set_regex(buf, len, reset, 0);
1217 }
1218
1219 static int
1220 ftrace_regex_release(struct inode *inode, struct file *file, int enable)
1221 {
1222         struct seq_file *m = (struct seq_file *)file->private_data;
1223         struct ftrace_iterator *iter;
1224
1225         mutex_lock(&ftrace_regex_lock);
1226         if (file->f_mode & FMODE_READ) {
1227                 iter = m->private;
1228
1229                 seq_release(inode, file);
1230         } else
1231                 iter = file->private_data;
1232
1233         if (iter->buffer_idx) {
1234                 iter->filtered++;
1235                 iter->buffer[iter->buffer_idx] = 0;
1236                 ftrace_match(iter->buffer, iter->buffer_idx, enable);
1237         }
1238
1239         mutex_lock(&ftrace_sysctl_lock);
1240         mutex_lock(&ftraced_lock);
1241         if (iter->filtered && ftraced_suspend && ftrace_enabled)
1242                 ftrace_run_update_code(FTRACE_ENABLE_CALLS);
1243         mutex_unlock(&ftraced_lock);
1244         mutex_unlock(&ftrace_sysctl_lock);
1245
1246         kfree(iter);
1247         mutex_unlock(&ftrace_regex_lock);
1248         return 0;
1249 }
1250
1251 static int
1252 ftrace_filter_release(struct inode *inode, struct file *file)
1253 {
1254         return ftrace_regex_release(inode, file, 1);
1255 }
1256
1257 static int
1258 ftrace_notrace_release(struct inode *inode, struct file *file)
1259 {
1260         return ftrace_regex_release(inode, file, 0);
1261 }
1262
1263 static ssize_t
1264 ftraced_read(struct file *filp, char __user *ubuf,
1265                      size_t cnt, loff_t *ppos)
1266 {
1267         /* don't worry about races */
1268         char *buf = ftraced_stop ? "disabled\n" : "enabled\n";
1269         int r = strlen(buf);
1270
1271         return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
1272 }
1273
1274 static ssize_t
1275 ftraced_write(struct file *filp, const char __user *ubuf,
1276                       size_t cnt, loff_t *ppos)
1277 {
1278         char buf[64];
1279         long val;
1280         int ret;
1281
1282         if (cnt >= sizeof(buf))
1283                 return -EINVAL;
1284
1285         if (copy_from_user(&buf, ubuf, cnt))
1286                 return -EFAULT;
1287
1288         if (strncmp(buf, "enable", 6) == 0)
1289                 val = 1;
1290         else if (strncmp(buf, "disable", 7) == 0)
1291                 val = 0;
1292         else {
1293                 buf[cnt] = 0;
1294
1295                 ret = strict_strtoul(buf, 10, &val);
1296                 if (ret < 0)
1297                         return ret;
1298
1299                 val = !!val;
1300         }
1301
1302         if (val)
1303                 ftrace_enable_daemon();
1304         else
1305                 ftrace_disable_daemon();
1306
1307         filp->f_pos += cnt;
1308
1309         return cnt;
1310 }
1311
1312 static struct file_operations ftrace_avail_fops = {
1313         .open = ftrace_avail_open,
1314         .read = seq_read,
1315         .llseek = seq_lseek,
1316         .release = ftrace_avail_release,
1317 };
1318
1319 static struct file_operations ftrace_filter_fops = {
1320         .open = ftrace_filter_open,
1321         .read = ftrace_regex_read,
1322         .write = ftrace_filter_write,
1323         .llseek = ftrace_regex_lseek,
1324         .release = ftrace_filter_release,
1325 };
1326
1327 static struct file_operations ftrace_notrace_fops = {
1328         .open = ftrace_notrace_open,
1329         .read = ftrace_regex_read,
1330         .write = ftrace_notrace_write,
1331         .llseek = ftrace_regex_lseek,
1332         .release = ftrace_notrace_release,
1333 };
1334
1335 static struct file_operations ftraced_fops = {
1336         .open = tracing_open_generic,
1337         .read = ftraced_read,
1338         .write = ftraced_write,
1339 };
1340
1341 /**
1342  * ftrace_force_update - force an update to all recording ftrace functions
1343  */
1344 int ftrace_force_update(void)
1345 {
1346         int ret = 0;
1347
1348         if (unlikely(ftrace_disabled))
1349                 return -ENODEV;
1350
1351         mutex_lock(&ftrace_sysctl_lock);
1352         mutex_lock(&ftraced_lock);
1353
1354         /*
1355          * If ftraced_trigger is not set, then there is nothing
1356          * to update.
1357          */
1358         if (ftraced_trigger && !ftrace_update_code())
1359                 ret = -EBUSY;
1360
1361         mutex_unlock(&ftraced_lock);
1362         mutex_unlock(&ftrace_sysctl_lock);
1363
1364         return ret;
1365 }
1366
1367 static void ftrace_force_shutdown(void)
1368 {
1369         struct task_struct *task;
1370         int command = FTRACE_DISABLE_CALLS | FTRACE_UPDATE_TRACE_FUNC;
1371
1372         mutex_lock(&ftraced_lock);
1373         task = ftraced_task;
1374         ftraced_task = NULL;
1375         ftraced_suspend = -1;
1376         ftrace_run_update_code(command);
1377         mutex_unlock(&ftraced_lock);
1378
1379         if (task)
1380                 kthread_stop(task);
1381 }
1382
1383 static __init int ftrace_init_debugfs(void)
1384 {
1385         struct dentry *d_tracer;
1386         struct dentry *entry;
1387
1388         d_tracer = tracing_init_dentry();
1389
1390         entry = debugfs_create_file("available_filter_functions", 0444,
1391                                     d_tracer, NULL, &ftrace_avail_fops);
1392         if (!entry)
1393                 pr_warning("Could not create debugfs "
1394                            "'available_filter_functions' entry\n");
1395
1396         entry = debugfs_create_file("set_ftrace_filter", 0644, d_tracer,
1397                                     NULL, &ftrace_filter_fops);
1398         if (!entry)
1399                 pr_warning("Could not create debugfs "
1400                            "'set_ftrace_filter' entry\n");
1401
1402         entry = debugfs_create_file("set_ftrace_notrace", 0644, d_tracer,
1403                                     NULL, &ftrace_notrace_fops);
1404         if (!entry)
1405                 pr_warning("Could not create debugfs "
1406                            "'set_ftrace_notrace' entry\n");
1407
1408         entry = debugfs_create_file("ftraced_enabled", 0644, d_tracer,
1409                                     NULL, &ftraced_fops);
1410         if (!entry)
1411                 pr_warning("Could not create debugfs "
1412                            "'ftraced_enabled' entry\n");
1413         return 0;
1414 }
1415
1416 fs_initcall(ftrace_init_debugfs);
1417
1418 static int __init ftrace_dynamic_init(void)
1419 {
1420         struct task_struct *p;
1421         unsigned long addr;
1422         int ret;
1423
1424         addr = (unsigned long)ftrace_record_ip;
1425
1426         stop_machine_run(ftrace_dyn_arch_init, &addr, NR_CPUS);
1427
1428         /* ftrace_dyn_arch_init places the return code in addr */
1429         if (addr) {
1430                 ret = (int)addr;
1431                 goto failed;
1432         }
1433
1434         ret = ftrace_dyn_table_alloc();
1435         if (ret)
1436                 goto failed;
1437
1438         p = kthread_run(ftraced, NULL, "ftraced");
1439         if (IS_ERR(p)) {
1440                 ret = -1;
1441                 goto failed;
1442         }
1443
1444         last_ftrace_enabled = ftrace_enabled = 1;
1445         ftraced_task = p;
1446
1447         return 0;
1448
1449  failed:
1450         ftrace_disabled = 1;
1451         return ret;
1452 }
1453
1454 core_initcall(ftrace_dynamic_init);
1455 #else
1456 # define ftrace_startup()               do { } while (0)
1457 # define ftrace_shutdown()              do { } while (0)
1458 # define ftrace_startup_sysctl()        do { } while (0)
1459 # define ftrace_shutdown_sysctl()       do { } while (0)
1460 # define ftrace_force_shutdown()        do { } while (0)
1461 #endif /* CONFIG_DYNAMIC_FTRACE */
1462
1463 /**
1464  * ftrace_kill - totally shutdown ftrace
1465  *
1466  * This is a safety measure. If something was detected that seems
1467  * wrong, calling this function will keep ftrace from doing
1468  * any more modifications, and updates.
1469  * used when something went wrong.
1470  */
1471 void ftrace_kill(void)
1472 {
1473         mutex_lock(&ftrace_sysctl_lock);
1474         ftrace_disabled = 1;
1475         ftrace_enabled = 0;
1476
1477         clear_ftrace_function();
1478         mutex_unlock(&ftrace_sysctl_lock);
1479
1480         /* Try to totally disable ftrace */
1481         ftrace_force_shutdown();
1482 }
1483
1484 /**
1485  * register_ftrace_function - register a function for profiling
1486  * @ops - ops structure that holds the function for profiling.
1487  *
1488  * Register a function to be called by all functions in the
1489  * kernel.
1490  *
1491  * Note: @ops->func and all the functions it calls must be labeled
1492  *       with "notrace", otherwise it will go into a
1493  *       recursive loop.
1494  */
1495 int register_ftrace_function(struct ftrace_ops *ops)
1496 {
1497         int ret;
1498
1499         if (unlikely(ftrace_disabled))
1500                 return -1;
1501
1502         mutex_lock(&ftrace_sysctl_lock);
1503         ret = __register_ftrace_function(ops);
1504         ftrace_startup();
1505         mutex_unlock(&ftrace_sysctl_lock);
1506
1507         return ret;
1508 }
1509
1510 /**
1511  * unregister_ftrace_function - unresgister a function for profiling.
1512  * @ops - ops structure that holds the function to unregister
1513  *
1514  * Unregister a function that was added to be called by ftrace profiling.
1515  */
1516 int unregister_ftrace_function(struct ftrace_ops *ops)
1517 {
1518         int ret;
1519
1520         mutex_lock(&ftrace_sysctl_lock);
1521         ret = __unregister_ftrace_function(ops);
1522         ftrace_shutdown();
1523         mutex_unlock(&ftrace_sysctl_lock);
1524
1525         return ret;
1526 }
1527
1528 int
1529 ftrace_enable_sysctl(struct ctl_table *table, int write,
1530                      struct file *file, void __user *buffer, size_t *lenp,
1531                      loff_t *ppos)
1532 {
1533         int ret;
1534
1535         if (unlikely(ftrace_disabled))
1536                 return -ENODEV;
1537
1538         mutex_lock(&ftrace_sysctl_lock);
1539
1540         ret  = proc_dointvec(table, write, file, buffer, lenp, ppos);
1541
1542         if (ret || !write || (last_ftrace_enabled == ftrace_enabled))
1543                 goto out;
1544
1545         last_ftrace_enabled = ftrace_enabled;
1546
1547         if (ftrace_enabled) {
1548
1549                 ftrace_startup_sysctl();
1550
1551                 /* we are starting ftrace again */
1552                 if (ftrace_list != &ftrace_list_end) {
1553                         if (ftrace_list->next == &ftrace_list_end)
1554                                 ftrace_trace_function = ftrace_list->func;
1555                         else
1556                                 ftrace_trace_function = ftrace_list_func;
1557                 }
1558
1559         } else {
1560                 /* stopping ftrace calls (just send to ftrace_stub) */
1561                 ftrace_trace_function = ftrace_stub;
1562
1563                 ftrace_shutdown_sysctl();
1564         }
1565
1566  out:
1567         mutex_unlock(&ftrace_sysctl_lock);
1568         return ret;
1569 }