ftrace.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456
  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. #include <linux/stop_machine.h>
  16. #include <linux/clocksource.h>
  17. #include <linux/kallsyms.h>
  18. #include <linux/seq_file.h>
  19. #include <linux/debugfs.h>
  20. #include <linux/hardirq.h>
  21. #include <linux/kthread.h>
  22. #include <linux/uaccess.h>
  23. #include <linux/kprobes.h>
  24. #include <linux/ftrace.h>
  25. #include <linux/sysctl.h>
  26. #include <linux/ctype.h>
  27. #include <linux/list.h>
  28. #include <asm/ftrace.h>
  29. #include "trace.h"
  30. #define FTRACE_WARN_ON(cond) \
  31. do { \
  32. if (WARN_ON(cond)) \
  33. ftrace_kill(); \
  34. } while (0)
  35. #define FTRACE_WARN_ON_ONCE(cond) \
  36. do { \
  37. if (WARN_ON_ONCE(cond)) \
  38. ftrace_kill(); \
  39. } while (0)
  40. /* ftrace_enabled is a method to turn ftrace on or off */
  41. int ftrace_enabled __read_mostly;
  42. static int last_ftrace_enabled;
  43. /*
  44. * ftrace_disabled is set when an anomaly is discovered.
  45. * ftrace_disabled is much stronger than ftrace_enabled.
  46. */
  47. static int ftrace_disabled __read_mostly;
  48. static DEFINE_SPINLOCK(ftrace_lock);
  49. static DEFINE_MUTEX(ftrace_sysctl_lock);
  50. static struct ftrace_ops ftrace_list_end __read_mostly =
  51. {
  52. .func = ftrace_stub,
  53. };
  54. static struct ftrace_ops *ftrace_list __read_mostly = &ftrace_list_end;
  55. ftrace_func_t ftrace_trace_function __read_mostly = ftrace_stub;
  56. static void ftrace_list_func(unsigned long ip, unsigned long parent_ip)
  57. {
  58. struct ftrace_ops *op = ftrace_list;
  59. /* in case someone actually ports this to alpha! */
  60. read_barrier_depends();
  61. while (op != &ftrace_list_end) {
  62. /* silly alpha */
  63. read_barrier_depends();
  64. op->func(ip, parent_ip);
  65. op = op->next;
  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. static int __register_ftrace_function(struct ftrace_ops *ops)
  79. {
  80. /* should not be called from interrupt context */
  81. spin_lock(&ftrace_lock);
  82. ops->next = ftrace_list;
  83. /*
  84. * We are entering ops into the ftrace_list but another
  85. * CPU might be walking that list. We need to make sure
  86. * the ops->next pointer is valid before another CPU sees
  87. * the ops pointer included into the ftrace_list.
  88. */
  89. smp_wmb();
  90. ftrace_list = ops;
  91. if (ftrace_enabled) {
  92. /*
  93. * For one func, simply call it directly.
  94. * For more than one func, call the chain.
  95. */
  96. if (ops->next == &ftrace_list_end)
  97. ftrace_trace_function = ops->func;
  98. else
  99. ftrace_trace_function = ftrace_list_func;
  100. }
  101. spin_unlock(&ftrace_lock);
  102. return 0;
  103. }
  104. static int __unregister_ftrace_function(struct ftrace_ops *ops)
  105. {
  106. struct ftrace_ops **p;
  107. int ret = 0;
  108. /* should not be called from interrupt context */
  109. spin_lock(&ftrace_lock);
  110. /*
  111. * If we are removing the last function, then simply point
  112. * to the ftrace_stub.
  113. */
  114. if (ftrace_list == ops && ops->next == &ftrace_list_end) {
  115. ftrace_trace_function = ftrace_stub;
  116. ftrace_list = &ftrace_list_end;
  117. goto out;
  118. }
  119. for (p = &ftrace_list; *p != &ftrace_list_end; p = &(*p)->next)
  120. if (*p == ops)
  121. break;
  122. if (*p != ops) {
  123. ret = -1;
  124. goto out;
  125. }
  126. *p = (*p)->next;
  127. if (ftrace_enabled) {
  128. /* If we only have one func left, then call that directly */
  129. if (ftrace_list == &ftrace_list_end ||
  130. ftrace_list->next == &ftrace_list_end)
  131. ftrace_trace_function = ftrace_list->func;
  132. }
  133. out:
  134. spin_unlock(&ftrace_lock);
  135. return ret;
  136. }
  137. #ifdef CONFIG_DYNAMIC_FTRACE
  138. #ifndef CONFIG_FTRACE_MCOUNT_RECORD
  139. # error Dynamic ftrace depends on MCOUNT_RECORD
  140. #endif
  141. /*
  142. * Since MCOUNT_ADDR may point to mcount itself, we do not want
  143. * to get it confused by reading a reference in the code as we
  144. * are parsing on objcopy output of text. Use a variable for
  145. * it instead.
  146. */
  147. static unsigned long mcount_addr = MCOUNT_ADDR;
  148. enum {
  149. FTRACE_ENABLE_CALLS = (1 << 0),
  150. FTRACE_DISABLE_CALLS = (1 << 1),
  151. FTRACE_UPDATE_TRACE_FUNC = (1 << 2),
  152. FTRACE_ENABLE_MCOUNT = (1 << 3),
  153. FTRACE_DISABLE_MCOUNT = (1 << 4),
  154. };
  155. static int ftrace_filtered;
  156. static LIST_HEAD(ftrace_new_addrs);
  157. static DEFINE_MUTEX(ftrace_regex_lock);
  158. struct ftrace_page {
  159. struct ftrace_page *next;
  160. unsigned long index;
  161. struct dyn_ftrace records[];
  162. };
  163. #define ENTRIES_PER_PAGE \
  164. ((PAGE_SIZE - sizeof(struct ftrace_page)) / sizeof(struct dyn_ftrace))
  165. /* estimate from running different kernels */
  166. #define NR_TO_INIT 10000
  167. static struct ftrace_page *ftrace_pages_start;
  168. static struct ftrace_page *ftrace_pages;
  169. static struct dyn_ftrace *ftrace_free_records;
  170. #ifdef CONFIG_KPROBES
  171. static int frozen_record_count;
  172. static inline void freeze_record(struct dyn_ftrace *rec)
  173. {
  174. if (!(rec->flags & FTRACE_FL_FROZEN)) {
  175. rec->flags |= FTRACE_FL_FROZEN;
  176. frozen_record_count++;
  177. }
  178. }
  179. static inline void unfreeze_record(struct dyn_ftrace *rec)
  180. {
  181. if (rec->flags & FTRACE_FL_FROZEN) {
  182. rec->flags &= ~FTRACE_FL_FROZEN;
  183. frozen_record_count--;
  184. }
  185. }
  186. static inline int record_frozen(struct dyn_ftrace *rec)
  187. {
  188. return rec->flags & FTRACE_FL_FROZEN;
  189. }
  190. #else
  191. # define freeze_record(rec) ({ 0; })
  192. # define unfreeze_record(rec) ({ 0; })
  193. # define record_frozen(rec) ({ 0; })
  194. #endif /* CONFIG_KPROBES */
  195. static void ftrace_free_rec(struct dyn_ftrace *rec)
  196. {
  197. rec->ip = (unsigned long)ftrace_free_records;
  198. ftrace_free_records = rec;
  199. rec->flags |= FTRACE_FL_FREE;
  200. }
  201. void ftrace_release(void *start, unsigned long size)
  202. {
  203. struct dyn_ftrace *rec;
  204. struct ftrace_page *pg;
  205. unsigned long s = (unsigned long)start;
  206. unsigned long e = s + size;
  207. int i;
  208. if (ftrace_disabled || !start)
  209. return;
  210. /* should not be called from interrupt context */
  211. spin_lock(&ftrace_lock);
  212. for (pg = ftrace_pages_start; pg; pg = pg->next) {
  213. for (i = 0; i < pg->index; i++) {
  214. rec = &pg->records[i];
  215. if ((rec->ip >= s) && (rec->ip < e))
  216. ftrace_free_rec(rec);
  217. }
  218. }
  219. spin_unlock(&ftrace_lock);
  220. }
  221. static struct dyn_ftrace *ftrace_alloc_dyn_node(unsigned long ip)
  222. {
  223. struct dyn_ftrace *rec;
  224. /* First check for freed records */
  225. if (ftrace_free_records) {
  226. rec = ftrace_free_records;
  227. if (unlikely(!(rec->flags & FTRACE_FL_FREE))) {
  228. FTRACE_WARN_ON_ONCE(1);
  229. ftrace_free_records = NULL;
  230. return NULL;
  231. }
  232. ftrace_free_records = (void *)rec->ip;
  233. memset(rec, 0, sizeof(*rec));
  234. return rec;
  235. }
  236. if (ftrace_pages->index == ENTRIES_PER_PAGE) {
  237. if (!ftrace_pages->next) {
  238. /* allocate another page */
  239. ftrace_pages->next =
  240. (void *)get_zeroed_page(GFP_KERNEL);
  241. if (!ftrace_pages->next)
  242. return NULL;
  243. }
  244. ftrace_pages = ftrace_pages->next;
  245. }
  246. return &ftrace_pages->records[ftrace_pages->index++];
  247. }
  248. static struct dyn_ftrace *
  249. ftrace_record_ip(unsigned long ip)
  250. {
  251. struct dyn_ftrace *rec;
  252. if (!ftrace_enabled || ftrace_disabled)
  253. return NULL;
  254. rec = ftrace_alloc_dyn_node(ip);
  255. if (!rec)
  256. return NULL;
  257. rec->ip = ip;
  258. list_add(&rec->list, &ftrace_new_addrs);
  259. return rec;
  260. }
  261. #define FTRACE_ADDR ((long)(ftrace_caller))
  262. static int
  263. __ftrace_replace_code(struct dyn_ftrace *rec,
  264. unsigned char *old, unsigned char *new, int enable)
  265. {
  266. unsigned long ip, fl;
  267. ip = rec->ip;
  268. if (ftrace_filtered && enable) {
  269. /*
  270. * If filtering is on:
  271. *
  272. * If this record is set to be filtered and
  273. * is enabled then do nothing.
  274. *
  275. * If this record is set to be filtered and
  276. * it is not enabled, enable it.
  277. *
  278. * If this record is not set to be filtered
  279. * and it is not enabled do nothing.
  280. *
  281. * If this record is set not to trace then
  282. * do nothing.
  283. *
  284. * If this record is set not to trace and
  285. * it is enabled then disable it.
  286. *
  287. * If this record is not set to be filtered and
  288. * it is enabled, disable it.
  289. */
  290. fl = rec->flags & (FTRACE_FL_FILTER | FTRACE_FL_NOTRACE |
  291. FTRACE_FL_ENABLED);
  292. if ((fl == (FTRACE_FL_FILTER | FTRACE_FL_ENABLED)) ||
  293. (fl == (FTRACE_FL_FILTER | FTRACE_FL_NOTRACE)) ||
  294. !fl || (fl == FTRACE_FL_NOTRACE))
  295. return 0;
  296. /*
  297. * If it is enabled disable it,
  298. * otherwise enable it!
  299. */
  300. if (fl & FTRACE_FL_ENABLED) {
  301. /* swap new and old */
  302. new = old;
  303. old = ftrace_call_replace(ip, FTRACE_ADDR);
  304. rec->flags &= ~FTRACE_FL_ENABLED;
  305. } else {
  306. new = ftrace_call_replace(ip, FTRACE_ADDR);
  307. rec->flags |= FTRACE_FL_ENABLED;
  308. }
  309. } else {
  310. if (enable) {
  311. /*
  312. * If this record is set not to trace and is
  313. * not enabled, do nothing.
  314. */
  315. fl = rec->flags & (FTRACE_FL_NOTRACE | FTRACE_FL_ENABLED);
  316. if (fl == FTRACE_FL_NOTRACE)
  317. return 0;
  318. new = ftrace_call_replace(ip, FTRACE_ADDR);
  319. } else
  320. old = ftrace_call_replace(ip, FTRACE_ADDR);
  321. if (enable) {
  322. if (rec->flags & FTRACE_FL_ENABLED)
  323. return 0;
  324. rec->flags |= FTRACE_FL_ENABLED;
  325. } else {
  326. if (!(rec->flags & FTRACE_FL_ENABLED))
  327. return 0;
  328. rec->flags &= ~FTRACE_FL_ENABLED;
  329. }
  330. }
  331. return ftrace_modify_code(ip, old, new);
  332. }
  333. static void ftrace_replace_code(int enable)
  334. {
  335. int i, failed;
  336. unsigned char *new = NULL, *old = NULL;
  337. struct dyn_ftrace *rec;
  338. struct ftrace_page *pg;
  339. if (enable)
  340. old = ftrace_nop_replace();
  341. else
  342. new = ftrace_nop_replace();
  343. for (pg = ftrace_pages_start; pg; pg = pg->next) {
  344. for (i = 0; i < pg->index; i++) {
  345. rec = &pg->records[i];
  346. /* don't modify code that has already faulted */
  347. if (rec->flags & FTRACE_FL_FAILED)
  348. continue;
  349. /* ignore updates to this record's mcount site */
  350. if (get_kprobe((void *)rec->ip)) {
  351. freeze_record(rec);
  352. continue;
  353. } else {
  354. unfreeze_record(rec);
  355. }
  356. failed = __ftrace_replace_code(rec, old, new, enable);
  357. if (failed && (rec->flags & FTRACE_FL_CONVERTED)) {
  358. rec->flags |= FTRACE_FL_FAILED;
  359. if ((system_state == SYSTEM_BOOTING) ||
  360. !core_kernel_text(rec->ip)) {
  361. ftrace_free_rec(rec);
  362. }
  363. }
  364. }
  365. }
  366. }
  367. static void print_ip_ins(const char *fmt, unsigned char *p)
  368. {
  369. int i;
  370. printk(KERN_CONT "%s", fmt);
  371. for (i = 0; i < MCOUNT_INSN_SIZE; i++)
  372. printk(KERN_CONT "%s%02x", i ? ":" : "", p[i]);
  373. }
  374. static int
  375. ftrace_code_disable(struct dyn_ftrace *rec)
  376. {
  377. unsigned long ip;
  378. unsigned char *nop, *call;
  379. int ret;
  380. ip = rec->ip;
  381. nop = ftrace_nop_replace();
  382. call = ftrace_call_replace(ip, mcount_addr);
  383. ret = ftrace_modify_code(ip, call, nop);
  384. if (ret) {
  385. switch (ret) {
  386. case -EFAULT:
  387. FTRACE_WARN_ON_ONCE(1);
  388. pr_info("ftrace faulted on modifying ");
  389. print_ip_sym(ip);
  390. break;
  391. case -EINVAL:
  392. FTRACE_WARN_ON_ONCE(1);
  393. pr_info("ftrace failed to modify ");
  394. print_ip_sym(ip);
  395. print_ip_ins(" expected: ", call);
  396. print_ip_ins(" actual: ", (unsigned char *)ip);
  397. print_ip_ins(" replace: ", nop);
  398. printk(KERN_CONT "\n");
  399. break;
  400. case -EPERM:
  401. FTRACE_WARN_ON_ONCE(1);
  402. pr_info("ftrace faulted on writing ");
  403. print_ip_sym(ip);
  404. break;
  405. default:
  406. FTRACE_WARN_ON_ONCE(1);
  407. pr_info("ftrace faulted on unknown error ");
  408. print_ip_sym(ip);
  409. }
  410. rec->flags |= FTRACE_FL_FAILED;
  411. return 0;
  412. }
  413. return 1;
  414. }
  415. static int __ftrace_modify_code(void *data)
  416. {
  417. int *command = data;
  418. if (*command & FTRACE_ENABLE_CALLS)
  419. ftrace_replace_code(1);
  420. else if (*command & FTRACE_DISABLE_CALLS)
  421. ftrace_replace_code(0);
  422. if (*command & FTRACE_UPDATE_TRACE_FUNC)
  423. ftrace_update_ftrace_func(ftrace_trace_function);
  424. return 0;
  425. }
  426. static void ftrace_run_update_code(int command)
  427. {
  428. stop_machine(__ftrace_modify_code, &command, NULL);
  429. }
  430. static ftrace_func_t saved_ftrace_func;
  431. static int ftrace_start;
  432. static DEFINE_MUTEX(ftrace_start_lock);
  433. static void ftrace_startup(void)
  434. {
  435. int command = 0;
  436. if (unlikely(ftrace_disabled))
  437. return;
  438. mutex_lock(&ftrace_start_lock);
  439. ftrace_start++;
  440. if (ftrace_start == 1)
  441. command |= FTRACE_ENABLE_CALLS;
  442. if (saved_ftrace_func != ftrace_trace_function) {
  443. saved_ftrace_func = ftrace_trace_function;
  444. command |= FTRACE_UPDATE_TRACE_FUNC;
  445. }
  446. if (!command || !ftrace_enabled)
  447. goto out;
  448. ftrace_run_update_code(command);
  449. out:
  450. mutex_unlock(&ftrace_start_lock);
  451. }
  452. static void ftrace_shutdown(void)
  453. {
  454. int command = 0;
  455. if (unlikely(ftrace_disabled))
  456. return;
  457. mutex_lock(&ftrace_start_lock);
  458. ftrace_start--;
  459. if (!ftrace_start)
  460. command |= FTRACE_DISABLE_CALLS;
  461. if (saved_ftrace_func != ftrace_trace_function) {
  462. saved_ftrace_func = ftrace_trace_function;
  463. command |= FTRACE_UPDATE_TRACE_FUNC;
  464. }
  465. if (!command || !ftrace_enabled)
  466. goto out;
  467. ftrace_run_update_code(command);
  468. out:
  469. mutex_unlock(&ftrace_start_lock);
  470. }
  471. static void ftrace_startup_sysctl(void)
  472. {
  473. int command = FTRACE_ENABLE_MCOUNT;
  474. if (unlikely(ftrace_disabled))
  475. return;
  476. mutex_lock(&ftrace_start_lock);
  477. /* Force update next time */
  478. saved_ftrace_func = NULL;
  479. /* ftrace_start is true if we want ftrace running */
  480. if (ftrace_start)
  481. command |= FTRACE_ENABLE_CALLS;
  482. ftrace_run_update_code(command);
  483. mutex_unlock(&ftrace_start_lock);
  484. }
  485. static void ftrace_shutdown_sysctl(void)
  486. {
  487. int command = FTRACE_DISABLE_MCOUNT;
  488. if (unlikely(ftrace_disabled))
  489. return;
  490. mutex_lock(&ftrace_start_lock);
  491. /* ftrace_start is true if ftrace is running */
  492. if (ftrace_start)
  493. command |= FTRACE_DISABLE_CALLS;
  494. ftrace_run_update_code(command);
  495. mutex_unlock(&ftrace_start_lock);
  496. }
  497. static cycle_t ftrace_update_time;
  498. static unsigned long ftrace_update_cnt;
  499. unsigned long ftrace_update_tot_cnt;
  500. static int ftrace_update_code(void)
  501. {
  502. struct dyn_ftrace *p, *t;
  503. cycle_t start, stop;
  504. start = ftrace_now(raw_smp_processor_id());
  505. ftrace_update_cnt = 0;
  506. list_for_each_entry_safe(p, t, &ftrace_new_addrs, list) {
  507. /* If something went wrong, bail without enabling anything */
  508. if (unlikely(ftrace_disabled))
  509. return -1;
  510. list_del_init(&p->list);
  511. /* convert record (i.e, patch mcount-call with NOP) */
  512. if (ftrace_code_disable(p)) {
  513. p->flags |= FTRACE_FL_CONVERTED;
  514. ftrace_update_cnt++;
  515. } else
  516. ftrace_free_rec(p);
  517. }
  518. stop = ftrace_now(raw_smp_processor_id());
  519. ftrace_update_time = stop - start;
  520. ftrace_update_tot_cnt += ftrace_update_cnt;
  521. return 0;
  522. }
  523. static int __init ftrace_dyn_table_alloc(unsigned long num_to_init)
  524. {
  525. struct ftrace_page *pg;
  526. int cnt;
  527. int i;
  528. /* allocate a few pages */
  529. ftrace_pages_start = (void *)get_zeroed_page(GFP_KERNEL);
  530. if (!ftrace_pages_start)
  531. return -1;
  532. /*
  533. * Allocate a few more pages.
  534. *
  535. * TODO: have some parser search vmlinux before
  536. * final linking to find all calls to ftrace.
  537. * Then we can:
  538. * a) know how many pages to allocate.
  539. * and/or
  540. * b) set up the table then.
  541. *
  542. * The dynamic code is still necessary for
  543. * modules.
  544. */
  545. pg = ftrace_pages = ftrace_pages_start;
  546. cnt = num_to_init / ENTRIES_PER_PAGE;
  547. pr_info("ftrace: allocating %ld entries in %d pages\n",
  548. num_to_init, cnt + 1);
  549. for (i = 0; i < cnt; i++) {
  550. pg->next = (void *)get_zeroed_page(GFP_KERNEL);
  551. /* If we fail, we'll try later anyway */
  552. if (!pg->next)
  553. break;
  554. pg = pg->next;
  555. }
  556. return 0;
  557. }
  558. enum {
  559. FTRACE_ITER_FILTER = (1 << 0),
  560. FTRACE_ITER_CONT = (1 << 1),
  561. FTRACE_ITER_NOTRACE = (1 << 2),
  562. FTRACE_ITER_FAILURES = (1 << 3),
  563. };
  564. #define FTRACE_BUFF_MAX (KSYM_SYMBOL_LEN+4) /* room for wildcards */
  565. struct ftrace_iterator {
  566. loff_t pos;
  567. struct ftrace_page *pg;
  568. unsigned idx;
  569. unsigned flags;
  570. unsigned char buffer[FTRACE_BUFF_MAX+1];
  571. unsigned buffer_idx;
  572. unsigned filtered;
  573. };
  574. static void *
  575. t_next(struct seq_file *m, void *v, loff_t *pos)
  576. {
  577. struct ftrace_iterator *iter = m->private;
  578. struct dyn_ftrace *rec = NULL;
  579. (*pos)++;
  580. /* should not be called from interrupt context */
  581. spin_lock(&ftrace_lock);
  582. retry:
  583. if (iter->idx >= iter->pg->index) {
  584. if (iter->pg->next) {
  585. iter->pg = iter->pg->next;
  586. iter->idx = 0;
  587. goto retry;
  588. }
  589. } else {
  590. rec = &iter->pg->records[iter->idx++];
  591. if ((rec->flags & FTRACE_FL_FREE) ||
  592. (!(iter->flags & FTRACE_ITER_FAILURES) &&
  593. (rec->flags & FTRACE_FL_FAILED)) ||
  594. ((iter->flags & FTRACE_ITER_FAILURES) &&
  595. !(rec->flags & FTRACE_FL_FAILED)) ||
  596. ((iter->flags & FTRACE_ITER_NOTRACE) &&
  597. !(rec->flags & FTRACE_FL_NOTRACE))) {
  598. rec = NULL;
  599. goto retry;
  600. }
  601. }
  602. spin_unlock(&ftrace_lock);
  603. iter->pos = *pos;
  604. return rec;
  605. }
  606. static void *t_start(struct seq_file *m, loff_t *pos)
  607. {
  608. struct ftrace_iterator *iter = m->private;
  609. void *p = NULL;
  610. loff_t l = -1;
  611. if (*pos > iter->pos)
  612. *pos = iter->pos;
  613. l = *pos;
  614. p = t_next(m, p, &l);
  615. return p;
  616. }
  617. static void t_stop(struct seq_file *m, void *p)
  618. {
  619. }
  620. static int t_show(struct seq_file *m, void *v)
  621. {
  622. struct ftrace_iterator *iter = m->private;
  623. struct dyn_ftrace *rec = v;
  624. char str[KSYM_SYMBOL_LEN];
  625. int ret = 0;
  626. if (!rec)
  627. return 0;
  628. kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
  629. ret = seq_printf(m, "%s\n", str);
  630. if (ret < 0) {
  631. iter->pos--;
  632. iter->idx--;
  633. }
  634. return 0;
  635. }
  636. static struct seq_operations show_ftrace_seq_ops = {
  637. .start = t_start,
  638. .next = t_next,
  639. .stop = t_stop,
  640. .show = t_show,
  641. };
  642. static int
  643. ftrace_avail_open(struct inode *inode, struct file *file)
  644. {
  645. struct ftrace_iterator *iter;
  646. int ret;
  647. if (unlikely(ftrace_disabled))
  648. return -ENODEV;
  649. iter = kzalloc(sizeof(*iter), GFP_KERNEL);
  650. if (!iter)
  651. return -ENOMEM;
  652. iter->pg = ftrace_pages_start;
  653. iter->pos = 0;
  654. ret = seq_open(file, &show_ftrace_seq_ops);
  655. if (!ret) {
  656. struct seq_file *m = file->private_data;
  657. m->private = iter;
  658. } else {
  659. kfree(iter);
  660. }
  661. return ret;
  662. }
  663. int ftrace_avail_release(struct inode *inode, struct file *file)
  664. {
  665. struct seq_file *m = (struct seq_file *)file->private_data;
  666. struct ftrace_iterator *iter = m->private;
  667. seq_release(inode, file);
  668. kfree(iter);
  669. return 0;
  670. }
  671. static int
  672. ftrace_failures_open(struct inode *inode, struct file *file)
  673. {
  674. int ret;
  675. struct seq_file *m;
  676. struct ftrace_iterator *iter;
  677. ret = ftrace_avail_open(inode, file);
  678. if (!ret) {
  679. m = (struct seq_file *)file->private_data;
  680. iter = (struct ftrace_iterator *)m->private;
  681. iter->flags = FTRACE_ITER_FAILURES;
  682. }
  683. return ret;
  684. }
  685. static void ftrace_filter_reset(int enable)
  686. {
  687. struct ftrace_page *pg;
  688. struct dyn_ftrace *rec;
  689. unsigned long type = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE;
  690. unsigned i;
  691. /* should not be called from interrupt context */
  692. spin_lock(&ftrace_lock);
  693. if (enable)
  694. ftrace_filtered = 0;
  695. pg = ftrace_pages_start;
  696. while (pg) {
  697. for (i = 0; i < pg->index; i++) {
  698. rec = &pg->records[i];
  699. if (rec->flags & FTRACE_FL_FAILED)
  700. continue;
  701. rec->flags &= ~type;
  702. }
  703. pg = pg->next;
  704. }
  705. spin_unlock(&ftrace_lock);
  706. }
  707. static int
  708. ftrace_regex_open(struct inode *inode, struct file *file, int enable)
  709. {
  710. struct ftrace_iterator *iter;
  711. int ret = 0;
  712. if (unlikely(ftrace_disabled))
  713. return -ENODEV;
  714. iter = kzalloc(sizeof(*iter), GFP_KERNEL);
  715. if (!iter)
  716. return -ENOMEM;
  717. mutex_lock(&ftrace_regex_lock);
  718. if ((file->f_mode & FMODE_WRITE) &&
  719. !(file->f_flags & O_APPEND))
  720. ftrace_filter_reset(enable);
  721. if (file->f_mode & FMODE_READ) {
  722. iter->pg = ftrace_pages_start;
  723. iter->pos = 0;
  724. iter->flags = enable ? FTRACE_ITER_FILTER :
  725. FTRACE_ITER_NOTRACE;
  726. ret = seq_open(file, &show_ftrace_seq_ops);
  727. if (!ret) {
  728. struct seq_file *m = file->private_data;
  729. m->private = iter;
  730. } else
  731. kfree(iter);
  732. } else
  733. file->private_data = iter;
  734. mutex_unlock(&ftrace_regex_lock);
  735. return ret;
  736. }
  737. static int
  738. ftrace_filter_open(struct inode *inode, struct file *file)
  739. {
  740. return ftrace_regex_open(inode, file, 1);
  741. }
  742. static int
  743. ftrace_notrace_open(struct inode *inode, struct file *file)
  744. {
  745. return ftrace_regex_open(inode, file, 0);
  746. }
  747. static ssize_t
  748. ftrace_regex_read(struct file *file, char __user *ubuf,
  749. size_t cnt, loff_t *ppos)
  750. {
  751. if (file->f_mode & FMODE_READ)
  752. return seq_read(file, ubuf, cnt, ppos);
  753. else
  754. return -EPERM;
  755. }
  756. static loff_t
  757. ftrace_regex_lseek(struct file *file, loff_t offset, int origin)
  758. {
  759. loff_t ret;
  760. if (file->f_mode & FMODE_READ)
  761. ret = seq_lseek(file, offset, origin);
  762. else
  763. file->f_pos = ret = 1;
  764. return ret;
  765. }
  766. enum {
  767. MATCH_FULL,
  768. MATCH_FRONT_ONLY,
  769. MATCH_MIDDLE_ONLY,
  770. MATCH_END_ONLY,
  771. };
  772. static void
  773. ftrace_match(unsigned char *buff, int len, int enable)
  774. {
  775. char str[KSYM_SYMBOL_LEN];
  776. char *search = NULL;
  777. struct ftrace_page *pg;
  778. struct dyn_ftrace *rec;
  779. int type = MATCH_FULL;
  780. unsigned long flag = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE;
  781. unsigned i, match = 0, search_len = 0;
  782. for (i = 0; i < len; i++) {
  783. if (buff[i] == '*') {
  784. if (!i) {
  785. search = buff + i + 1;
  786. type = MATCH_END_ONLY;
  787. search_len = len - (i + 1);
  788. } else {
  789. if (type == MATCH_END_ONLY) {
  790. type = MATCH_MIDDLE_ONLY;
  791. } else {
  792. match = i;
  793. type = MATCH_FRONT_ONLY;
  794. }
  795. buff[i] = 0;
  796. break;
  797. }
  798. }
  799. }
  800. /* should not be called from interrupt context */
  801. spin_lock(&ftrace_lock);
  802. if (enable)
  803. ftrace_filtered = 1;
  804. pg = ftrace_pages_start;
  805. while (pg) {
  806. for (i = 0; i < pg->index; i++) {
  807. int matched = 0;
  808. char *ptr;
  809. rec = &pg->records[i];
  810. if (rec->flags & FTRACE_FL_FAILED)
  811. continue;
  812. kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
  813. switch (type) {
  814. case MATCH_FULL:
  815. if (strcmp(str, buff) == 0)
  816. matched = 1;
  817. break;
  818. case MATCH_FRONT_ONLY:
  819. if (memcmp(str, buff, match) == 0)
  820. matched = 1;
  821. break;
  822. case MATCH_MIDDLE_ONLY:
  823. if (strstr(str, search))
  824. matched = 1;
  825. break;
  826. case MATCH_END_ONLY:
  827. ptr = strstr(str, search);
  828. if (ptr && (ptr[search_len] == 0))
  829. matched = 1;
  830. break;
  831. }
  832. if (matched)
  833. rec->flags |= flag;
  834. }
  835. pg = pg->next;
  836. }
  837. spin_unlock(&ftrace_lock);
  838. }
  839. static ssize_t
  840. ftrace_regex_write(struct file *file, const char __user *ubuf,
  841. size_t cnt, loff_t *ppos, int enable)
  842. {
  843. struct ftrace_iterator *iter;
  844. char ch;
  845. size_t read = 0;
  846. ssize_t ret;
  847. if (!cnt || cnt < 0)
  848. return 0;
  849. mutex_lock(&ftrace_regex_lock);
  850. if (file->f_mode & FMODE_READ) {
  851. struct seq_file *m = file->private_data;
  852. iter = m->private;
  853. } else
  854. iter = file->private_data;
  855. if (!*ppos) {
  856. iter->flags &= ~FTRACE_ITER_CONT;
  857. iter->buffer_idx = 0;
  858. }
  859. ret = get_user(ch, ubuf++);
  860. if (ret)
  861. goto out;
  862. read++;
  863. cnt--;
  864. if (!(iter->flags & ~FTRACE_ITER_CONT)) {
  865. /* skip white space */
  866. while (cnt && isspace(ch)) {
  867. ret = get_user(ch, ubuf++);
  868. if (ret)
  869. goto out;
  870. read++;
  871. cnt--;
  872. }
  873. if (isspace(ch)) {
  874. file->f_pos += read;
  875. ret = read;
  876. goto out;
  877. }
  878. iter->buffer_idx = 0;
  879. }
  880. while (cnt && !isspace(ch)) {
  881. if (iter->buffer_idx < FTRACE_BUFF_MAX)
  882. iter->buffer[iter->buffer_idx++] = ch;
  883. else {
  884. ret = -EINVAL;
  885. goto out;
  886. }
  887. ret = get_user(ch, ubuf++);
  888. if (ret)
  889. goto out;
  890. read++;
  891. cnt--;
  892. }
  893. if (isspace(ch)) {
  894. iter->filtered++;
  895. iter->buffer[iter->buffer_idx] = 0;
  896. ftrace_match(iter->buffer, iter->buffer_idx, enable);
  897. iter->buffer_idx = 0;
  898. } else
  899. iter->flags |= FTRACE_ITER_CONT;
  900. file->f_pos += read;
  901. ret = read;
  902. out:
  903. mutex_unlock(&ftrace_regex_lock);
  904. return ret;
  905. }
  906. static ssize_t
  907. ftrace_filter_write(struct file *file, const char __user *ubuf,
  908. size_t cnt, loff_t *ppos)
  909. {
  910. return ftrace_regex_write(file, ubuf, cnt, ppos, 1);
  911. }
  912. static ssize_t
  913. ftrace_notrace_write(struct file *file, const char __user *ubuf,
  914. size_t cnt, loff_t *ppos)
  915. {
  916. return ftrace_regex_write(file, ubuf, cnt, ppos, 0);
  917. }
  918. static void
  919. ftrace_set_regex(unsigned char *buf, int len, int reset, int enable)
  920. {
  921. if (unlikely(ftrace_disabled))
  922. return;
  923. mutex_lock(&ftrace_regex_lock);
  924. if (reset)
  925. ftrace_filter_reset(enable);
  926. if (buf)
  927. ftrace_match(buf, len, enable);
  928. mutex_unlock(&ftrace_regex_lock);
  929. }
  930. /**
  931. * ftrace_set_filter - set a function to filter on in ftrace
  932. * @buf - the string that holds the function filter text.
  933. * @len - the length of the string.
  934. * @reset - non zero to reset all filters before applying this filter.
  935. *
  936. * Filters denote which functions should be enabled when tracing is enabled.
  937. * If @buf is NULL and reset is set, all functions will be enabled for tracing.
  938. */
  939. void ftrace_set_filter(unsigned char *buf, int len, int reset)
  940. {
  941. ftrace_set_regex(buf, len, reset, 1);
  942. }
  943. /**
  944. * ftrace_set_notrace - set a function to not trace in ftrace
  945. * @buf - the string that holds the function notrace text.
  946. * @len - the length of the string.
  947. * @reset - non zero to reset all filters before applying this filter.
  948. *
  949. * Notrace Filters denote which functions should not be enabled when tracing
  950. * is enabled. If @buf is NULL and reset is set, all functions will be enabled
  951. * for tracing.
  952. */
  953. void ftrace_set_notrace(unsigned char *buf, int len, int reset)
  954. {
  955. ftrace_set_regex(buf, len, reset, 0);
  956. }
  957. static int
  958. ftrace_regex_release(struct inode *inode, struct file *file, int enable)
  959. {
  960. struct seq_file *m = (struct seq_file *)file->private_data;
  961. struct ftrace_iterator *iter;
  962. mutex_lock(&ftrace_regex_lock);
  963. if (file->f_mode & FMODE_READ) {
  964. iter = m->private;
  965. seq_release(inode, file);
  966. } else
  967. iter = file->private_data;
  968. if (iter->buffer_idx) {
  969. iter->filtered++;
  970. iter->buffer[iter->buffer_idx] = 0;
  971. ftrace_match(iter->buffer, iter->buffer_idx, enable);
  972. }
  973. mutex_lock(&ftrace_sysctl_lock);
  974. mutex_lock(&ftrace_start_lock);
  975. if (iter->filtered && ftrace_start && ftrace_enabled)
  976. ftrace_run_update_code(FTRACE_ENABLE_CALLS);
  977. mutex_unlock(&ftrace_start_lock);
  978. mutex_unlock(&ftrace_sysctl_lock);
  979. kfree(iter);
  980. mutex_unlock(&ftrace_regex_lock);
  981. return 0;
  982. }
  983. static int
  984. ftrace_filter_release(struct inode *inode, struct file *file)
  985. {
  986. return ftrace_regex_release(inode, file, 1);
  987. }
  988. static int
  989. ftrace_notrace_release(struct inode *inode, struct file *file)
  990. {
  991. return ftrace_regex_release(inode, file, 0);
  992. }
  993. static struct file_operations ftrace_avail_fops = {
  994. .open = ftrace_avail_open,
  995. .read = seq_read,
  996. .llseek = seq_lseek,
  997. .release = ftrace_avail_release,
  998. };
  999. static struct file_operations ftrace_failures_fops = {
  1000. .open = ftrace_failures_open,
  1001. .read = seq_read,
  1002. .llseek = seq_lseek,
  1003. .release = ftrace_avail_release,
  1004. };
  1005. static struct file_operations ftrace_filter_fops = {
  1006. .open = ftrace_filter_open,
  1007. .read = ftrace_regex_read,
  1008. .write = ftrace_filter_write,
  1009. .llseek = ftrace_regex_lseek,
  1010. .release = ftrace_filter_release,
  1011. };
  1012. static struct file_operations ftrace_notrace_fops = {
  1013. .open = ftrace_notrace_open,
  1014. .read = ftrace_regex_read,
  1015. .write = ftrace_notrace_write,
  1016. .llseek = ftrace_regex_lseek,
  1017. .release = ftrace_notrace_release,
  1018. };
  1019. static __init int ftrace_init_debugfs(void)
  1020. {
  1021. struct dentry *d_tracer;
  1022. struct dentry *entry;
  1023. d_tracer = tracing_init_dentry();
  1024. entry = debugfs_create_file("available_filter_functions", 0444,
  1025. d_tracer, NULL, &ftrace_avail_fops);
  1026. if (!entry)
  1027. pr_warning("Could not create debugfs "
  1028. "'available_filter_functions' entry\n");
  1029. entry = debugfs_create_file("failures", 0444,
  1030. d_tracer, NULL, &ftrace_failures_fops);
  1031. if (!entry)
  1032. pr_warning("Could not create debugfs 'failures' entry\n");
  1033. entry = debugfs_create_file("set_ftrace_filter", 0644, d_tracer,
  1034. NULL, &ftrace_filter_fops);
  1035. if (!entry)
  1036. pr_warning("Could not create debugfs "
  1037. "'set_ftrace_filter' entry\n");
  1038. entry = debugfs_create_file("set_ftrace_notrace", 0644, d_tracer,
  1039. NULL, &ftrace_notrace_fops);
  1040. if (!entry)
  1041. pr_warning("Could not create debugfs "
  1042. "'set_ftrace_notrace' entry\n");
  1043. return 0;
  1044. }
  1045. fs_initcall(ftrace_init_debugfs);
  1046. static int ftrace_convert_nops(unsigned long *start,
  1047. unsigned long *end)
  1048. {
  1049. unsigned long *p;
  1050. unsigned long addr;
  1051. unsigned long flags;
  1052. mutex_lock(&ftrace_start_lock);
  1053. p = start;
  1054. while (p < end) {
  1055. addr = ftrace_call_adjust(*p++);
  1056. ftrace_record_ip(addr);
  1057. }
  1058. /* disable interrupts to prevent kstop machine */
  1059. local_irq_save(flags);
  1060. ftrace_update_code();
  1061. local_irq_restore(flags);
  1062. mutex_unlock(&ftrace_start_lock);
  1063. return 0;
  1064. }
  1065. void ftrace_init_module(unsigned long *start, unsigned long *end)
  1066. {
  1067. if (ftrace_disabled || start == end)
  1068. return;
  1069. ftrace_convert_nops(start, end);
  1070. }
  1071. extern unsigned long __start_mcount_loc[];
  1072. extern unsigned long __stop_mcount_loc[];
  1073. void __init ftrace_init(void)
  1074. {
  1075. unsigned long count, addr, flags;
  1076. int ret;
  1077. /* Keep the ftrace pointer to the stub */
  1078. addr = (unsigned long)ftrace_stub;
  1079. local_irq_save(flags);
  1080. ftrace_dyn_arch_init(&addr);
  1081. local_irq_restore(flags);
  1082. /* ftrace_dyn_arch_init places the return code in addr */
  1083. if (addr)
  1084. goto failed;
  1085. count = __stop_mcount_loc - __start_mcount_loc;
  1086. ret = ftrace_dyn_table_alloc(count);
  1087. if (ret)
  1088. goto failed;
  1089. last_ftrace_enabled = ftrace_enabled = 1;
  1090. ret = ftrace_convert_nops(__start_mcount_loc,
  1091. __stop_mcount_loc);
  1092. return;
  1093. failed:
  1094. ftrace_disabled = 1;
  1095. }
  1096. #else
  1097. static int __init ftrace_nodyn_init(void)
  1098. {
  1099. ftrace_enabled = 1;
  1100. return 0;
  1101. }
  1102. device_initcall(ftrace_nodyn_init);
  1103. # define ftrace_startup() do { } while (0)
  1104. # define ftrace_shutdown() do { } while (0)
  1105. # define ftrace_startup_sysctl() do { } while (0)
  1106. # define ftrace_shutdown_sysctl() do { } while (0)
  1107. #endif /* CONFIG_DYNAMIC_FTRACE */
  1108. /**
  1109. * ftrace_kill - kill ftrace
  1110. *
  1111. * This function should be used by panic code. It stops ftrace
  1112. * but in a not so nice way. If you need to simply kill ftrace
  1113. * from a non-atomic section, use ftrace_kill.
  1114. */
  1115. void ftrace_kill(void)
  1116. {
  1117. ftrace_disabled = 1;
  1118. ftrace_enabled = 0;
  1119. clear_ftrace_function();
  1120. }
  1121. /**
  1122. * register_ftrace_function - register a function for profiling
  1123. * @ops - ops structure that holds the function for profiling.
  1124. *
  1125. * Register a function to be called by all functions in the
  1126. * kernel.
  1127. *
  1128. * Note: @ops->func and all the functions it calls must be labeled
  1129. * with "notrace", otherwise it will go into a
  1130. * recursive loop.
  1131. */
  1132. int register_ftrace_function(struct ftrace_ops *ops)
  1133. {
  1134. int ret;
  1135. if (unlikely(ftrace_disabled))
  1136. return -1;
  1137. mutex_lock(&ftrace_sysctl_lock);
  1138. ret = __register_ftrace_function(ops);
  1139. ftrace_startup();
  1140. mutex_unlock(&ftrace_sysctl_lock);
  1141. return ret;
  1142. }
  1143. /**
  1144. * unregister_ftrace_function - unresgister a function for profiling.
  1145. * @ops - ops structure that holds the function to unregister
  1146. *
  1147. * Unregister a function that was added to be called by ftrace profiling.
  1148. */
  1149. int unregister_ftrace_function(struct ftrace_ops *ops)
  1150. {
  1151. int ret;
  1152. mutex_lock(&ftrace_sysctl_lock);
  1153. ret = __unregister_ftrace_function(ops);
  1154. ftrace_shutdown();
  1155. mutex_unlock(&ftrace_sysctl_lock);
  1156. return ret;
  1157. }
  1158. int
  1159. ftrace_enable_sysctl(struct ctl_table *table, int write,
  1160. struct file *file, void __user *buffer, size_t *lenp,
  1161. loff_t *ppos)
  1162. {
  1163. int ret;
  1164. if (unlikely(ftrace_disabled))
  1165. return -ENODEV;
  1166. mutex_lock(&ftrace_sysctl_lock);
  1167. ret = proc_dointvec(table, write, file, buffer, lenp, ppos);
  1168. if (ret || !write || (last_ftrace_enabled == ftrace_enabled))
  1169. goto out;
  1170. last_ftrace_enabled = ftrace_enabled;
  1171. if (ftrace_enabled) {
  1172. ftrace_startup_sysctl();
  1173. /* we are starting ftrace again */
  1174. if (ftrace_list != &ftrace_list_end) {
  1175. if (ftrace_list->next == &ftrace_list_end)
  1176. ftrace_trace_function = ftrace_list->func;
  1177. else
  1178. ftrace_trace_function = ftrace_list_func;
  1179. }
  1180. } else {
  1181. /* stopping ftrace calls (just send to ftrace_stub) */
  1182. ftrace_trace_function = ftrace_stub;
  1183. ftrace_shutdown_sysctl();
  1184. }
  1185. out:
  1186. mutex_unlock(&ftrace_sysctl_lock);
  1187. return ret;
  1188. }