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