trace_uprobe.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365
  1. /*
  2. * uprobes-based tracing events
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. *
  17. * Copyright (C) IBM Corporation, 2010-2012
  18. * Author: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
  19. */
  20. #include <linux/module.h>
  21. #include <linux/uaccess.h>
  22. #include <linux/uprobes.h>
  23. #include <linux/namei.h>
  24. #include <linux/string.h>
  25. #include "trace_probe.h"
  26. #define UPROBE_EVENT_SYSTEM "uprobes"
  27. struct uprobe_trace_entry_head {
  28. struct trace_entry ent;
  29. unsigned long vaddr[];
  30. };
  31. #define SIZEOF_TRACE_ENTRY(is_return) \
  32. (sizeof(struct uprobe_trace_entry_head) + \
  33. sizeof(unsigned long) * (is_return ? 2 : 1))
  34. #define DATAOF_TRACE_ENTRY(entry, is_return) \
  35. ((void*)(entry) + SIZEOF_TRACE_ENTRY(is_return))
  36. struct trace_uprobe_filter {
  37. rwlock_t rwlock;
  38. int nr_systemwide;
  39. struct list_head perf_events;
  40. };
  41. /*
  42. * uprobe event core functions
  43. */
  44. struct trace_uprobe {
  45. struct list_head list;
  46. struct trace_uprobe_filter filter;
  47. struct uprobe_consumer consumer;
  48. struct inode *inode;
  49. char *filename;
  50. unsigned long offset;
  51. unsigned long nhit;
  52. struct trace_probe tp;
  53. };
  54. #define SIZEOF_TRACE_UPROBE(n) \
  55. (offsetof(struct trace_uprobe, tp.args) + \
  56. (sizeof(struct probe_arg) * (n)))
  57. static int register_uprobe_event(struct trace_uprobe *tu);
  58. static int unregister_uprobe_event(struct trace_uprobe *tu);
  59. static DEFINE_MUTEX(uprobe_lock);
  60. static LIST_HEAD(uprobe_list);
  61. struct uprobe_dispatch_data {
  62. struct trace_uprobe *tu;
  63. unsigned long bp_addr;
  64. };
  65. static int uprobe_dispatcher(struct uprobe_consumer *con, struct pt_regs *regs);
  66. static int uretprobe_dispatcher(struct uprobe_consumer *con,
  67. unsigned long func, struct pt_regs *regs);
  68. #ifdef CONFIG_STACK_GROWSUP
  69. static unsigned long adjust_stack_addr(unsigned long addr, unsigned int n)
  70. {
  71. return addr - (n * sizeof(long));
  72. }
  73. #else
  74. static unsigned long adjust_stack_addr(unsigned long addr, unsigned int n)
  75. {
  76. return addr + (n * sizeof(long));
  77. }
  78. #endif
  79. static unsigned long get_user_stack_nth(struct pt_regs *regs, unsigned int n)
  80. {
  81. unsigned long ret;
  82. unsigned long addr = user_stack_pointer(regs);
  83. addr = adjust_stack_addr(addr, n);
  84. if (copy_from_user(&ret, (void __force __user *) addr, sizeof(ret)))
  85. return 0;
  86. return ret;
  87. }
  88. /*
  89. * Uprobes-specific fetch functions
  90. */
  91. #define DEFINE_FETCH_stack(type) \
  92. static void FETCH_FUNC_NAME(stack, type)(struct pt_regs *regs, \
  93. void *offset, void *dest) \
  94. { \
  95. *(type *)dest = (type)get_user_stack_nth(regs, \
  96. ((unsigned long)offset)); \
  97. }
  98. DEFINE_BASIC_FETCH_FUNCS(stack)
  99. /* No string on the stack entry */
  100. #define fetch_stack_string NULL
  101. #define fetch_stack_string_size NULL
  102. #define DEFINE_FETCH_memory(type) \
  103. static void FETCH_FUNC_NAME(memory, type)(struct pt_regs *regs, \
  104. void *addr, void *dest) \
  105. { \
  106. type retval; \
  107. void __user *vaddr = (void __force __user *) addr; \
  108. \
  109. if (copy_from_user(&retval, vaddr, sizeof(type))) \
  110. *(type *)dest = 0; \
  111. else \
  112. *(type *) dest = retval; \
  113. }
  114. DEFINE_BASIC_FETCH_FUNCS(memory)
  115. /*
  116. * Fetch a null-terminated string. Caller MUST set *(u32 *)dest with max
  117. * length and relative data location.
  118. */
  119. static void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
  120. void *addr, void *dest)
  121. {
  122. long ret;
  123. u32 rloc = *(u32 *)dest;
  124. int maxlen = get_rloc_len(rloc);
  125. u8 *dst = get_rloc_data(dest);
  126. void __user *src = (void __force __user *) addr;
  127. if (!maxlen)
  128. return;
  129. ret = strncpy_from_user(dst, src, maxlen);
  130. if (ret == maxlen)
  131. dst[ret - 1] = '\0';
  132. else if (ret >= 0)
  133. /*
  134. * Include the terminating null byte. In this case it
  135. * was copied by strncpy_from_user but not accounted
  136. * for in ret.
  137. */
  138. ret++;
  139. if (ret < 0) { /* Failed to fetch string */
  140. ((u8 *)get_rloc_data(dest))[0] = '\0';
  141. *(u32 *)dest = make_data_rloc(0, get_rloc_offs(rloc));
  142. } else {
  143. *(u32 *)dest = make_data_rloc(ret, get_rloc_offs(rloc));
  144. }
  145. }
  146. static void FETCH_FUNC_NAME(memory, string_size)(struct pt_regs *regs,
  147. void *addr, void *dest)
  148. {
  149. int len;
  150. void __user *vaddr = (void __force __user *) addr;
  151. len = strnlen_user(vaddr, MAX_STRING_SIZE);
  152. if (len == 0 || len > MAX_STRING_SIZE) /* Failed to check length */
  153. *(u32 *)dest = 0;
  154. else
  155. *(u32 *)dest = len;
  156. }
  157. static unsigned long translate_user_vaddr(void *file_offset)
  158. {
  159. unsigned long base_addr;
  160. struct uprobe_dispatch_data *udd;
  161. udd = (void *) current->utask->vaddr;
  162. base_addr = udd->bp_addr - udd->tu->offset;
  163. return base_addr + (unsigned long)file_offset;
  164. }
  165. #define DEFINE_FETCH_file_offset(type) \
  166. static void FETCH_FUNC_NAME(file_offset, type)(struct pt_regs *regs, \
  167. void *offset, void *dest)\
  168. { \
  169. void *vaddr = (void *)translate_user_vaddr(offset); \
  170. \
  171. FETCH_FUNC_NAME(memory, type)(regs, vaddr, dest); \
  172. }
  173. DEFINE_BASIC_FETCH_FUNCS(file_offset)
  174. DEFINE_FETCH_file_offset(string)
  175. DEFINE_FETCH_file_offset(string_size)
  176. /* Fetch type information table */
  177. static const struct fetch_type uprobes_fetch_type_table[] = {
  178. /* Special types */
  179. [FETCH_TYPE_STRING] = __ASSIGN_FETCH_TYPE("string", string, string,
  180. sizeof(u32), 1, "__data_loc char[]"),
  181. [FETCH_TYPE_STRSIZE] = __ASSIGN_FETCH_TYPE("string_size", u32,
  182. string_size, sizeof(u32), 0, "u32"),
  183. /* Basic types */
  184. ASSIGN_FETCH_TYPE(u8, u8, 0),
  185. ASSIGN_FETCH_TYPE(u16, u16, 0),
  186. ASSIGN_FETCH_TYPE(u32, u32, 0),
  187. ASSIGN_FETCH_TYPE(u64, u64, 0),
  188. ASSIGN_FETCH_TYPE(s8, u8, 1),
  189. ASSIGN_FETCH_TYPE(s16, u16, 1),
  190. ASSIGN_FETCH_TYPE(s32, u32, 1),
  191. ASSIGN_FETCH_TYPE(s64, u64, 1),
  192. ASSIGN_FETCH_TYPE_END
  193. };
  194. static inline void init_trace_uprobe_filter(struct trace_uprobe_filter *filter)
  195. {
  196. rwlock_init(&filter->rwlock);
  197. filter->nr_systemwide = 0;
  198. INIT_LIST_HEAD(&filter->perf_events);
  199. }
  200. static inline bool uprobe_filter_is_empty(struct trace_uprobe_filter *filter)
  201. {
  202. return !filter->nr_systemwide && list_empty(&filter->perf_events);
  203. }
  204. static inline bool is_ret_probe(struct trace_uprobe *tu)
  205. {
  206. return tu->consumer.ret_handler != NULL;
  207. }
  208. /*
  209. * Allocate new trace_uprobe and initialize it (including uprobes).
  210. */
  211. static struct trace_uprobe *
  212. alloc_trace_uprobe(const char *group, const char *event, int nargs, bool is_ret)
  213. {
  214. struct trace_uprobe *tu;
  215. if (!event || !is_good_name(event))
  216. return ERR_PTR(-EINVAL);
  217. if (!group || !is_good_name(group))
  218. return ERR_PTR(-EINVAL);
  219. tu = kzalloc(SIZEOF_TRACE_UPROBE(nargs), GFP_KERNEL);
  220. if (!tu)
  221. return ERR_PTR(-ENOMEM);
  222. tu->tp.call.class = &tu->tp.class;
  223. tu->tp.call.name = kstrdup(event, GFP_KERNEL);
  224. if (!tu->tp.call.name)
  225. goto error;
  226. tu->tp.class.system = kstrdup(group, GFP_KERNEL);
  227. if (!tu->tp.class.system)
  228. goto error;
  229. INIT_LIST_HEAD(&tu->list);
  230. INIT_LIST_HEAD(&tu->tp.files);
  231. tu->consumer.handler = uprobe_dispatcher;
  232. if (is_ret)
  233. tu->consumer.ret_handler = uretprobe_dispatcher;
  234. init_trace_uprobe_filter(&tu->filter);
  235. return tu;
  236. error:
  237. kfree(tu->tp.call.name);
  238. kfree(tu);
  239. return ERR_PTR(-ENOMEM);
  240. }
  241. static void free_trace_uprobe(struct trace_uprobe *tu)
  242. {
  243. int i;
  244. for (i = 0; i < tu->tp.nr_args; i++)
  245. traceprobe_free_probe_arg(&tu->tp.args[i]);
  246. iput(tu->inode);
  247. kfree(tu->tp.call.class->system);
  248. kfree(tu->tp.call.name);
  249. kfree(tu->filename);
  250. kfree(tu);
  251. }
  252. static struct trace_uprobe *find_probe_event(const char *event, const char *group)
  253. {
  254. struct trace_uprobe *tu;
  255. list_for_each_entry(tu, &uprobe_list, list)
  256. if (strcmp(trace_event_name(&tu->tp.call), event) == 0 &&
  257. strcmp(tu->tp.call.class->system, group) == 0)
  258. return tu;
  259. return NULL;
  260. }
  261. /* Unregister a trace_uprobe and probe_event: call with locking uprobe_lock */
  262. static int unregister_trace_uprobe(struct trace_uprobe *tu)
  263. {
  264. int ret;
  265. ret = unregister_uprobe_event(tu);
  266. if (ret)
  267. return ret;
  268. list_del(&tu->list);
  269. free_trace_uprobe(tu);
  270. return 0;
  271. }
  272. /* Register a trace_uprobe and probe_event */
  273. static int register_trace_uprobe(struct trace_uprobe *tu)
  274. {
  275. struct trace_uprobe *old_tu;
  276. int ret;
  277. mutex_lock(&uprobe_lock);
  278. /* register as an event */
  279. old_tu = find_probe_event(trace_event_name(&tu->tp.call),
  280. tu->tp.call.class->system);
  281. if (old_tu) {
  282. /* delete old event */
  283. ret = unregister_trace_uprobe(old_tu);
  284. if (ret)
  285. goto end;
  286. }
  287. ret = register_uprobe_event(tu);
  288. if (ret) {
  289. pr_warning("Failed to register probe event(%d)\n", ret);
  290. goto end;
  291. }
  292. list_add_tail(&tu->list, &uprobe_list);
  293. end:
  294. mutex_unlock(&uprobe_lock);
  295. return ret;
  296. }
  297. /*
  298. * Argument syntax:
  299. * - Add uprobe: p|r[:[GRP/]EVENT] PATH:OFFSET [FETCHARGS]
  300. *
  301. * - Remove uprobe: -:[GRP/]EVENT
  302. */
  303. static int create_trace_uprobe(int argc, char **argv)
  304. {
  305. struct trace_uprobe *tu;
  306. struct inode *inode;
  307. char *arg, *event, *group, *filename;
  308. char buf[MAX_EVENT_NAME_LEN];
  309. struct path path;
  310. unsigned long offset;
  311. bool is_delete, is_return;
  312. int i, ret;
  313. inode = NULL;
  314. ret = 0;
  315. is_delete = false;
  316. is_return = false;
  317. event = NULL;
  318. group = NULL;
  319. /* argc must be >= 1 */
  320. if (argv[0][0] == '-')
  321. is_delete = true;
  322. else if (argv[0][0] == 'r')
  323. is_return = true;
  324. else if (argv[0][0] != 'p') {
  325. pr_info("Probe definition must be started with 'p', 'r' or '-'.\n");
  326. return -EINVAL;
  327. }
  328. if (argv[0][1] == ':') {
  329. event = &argv[0][2];
  330. arg = strchr(event, '/');
  331. if (arg) {
  332. group = event;
  333. event = arg + 1;
  334. event[-1] = '\0';
  335. if (strlen(group) == 0) {
  336. pr_info("Group name is not specified\n");
  337. return -EINVAL;
  338. }
  339. }
  340. if (strlen(event) == 0) {
  341. pr_info("Event name is not specified\n");
  342. return -EINVAL;
  343. }
  344. }
  345. if (!group)
  346. group = UPROBE_EVENT_SYSTEM;
  347. if (is_delete) {
  348. int ret;
  349. if (!event) {
  350. pr_info("Delete command needs an event name.\n");
  351. return -EINVAL;
  352. }
  353. mutex_lock(&uprobe_lock);
  354. tu = find_probe_event(event, group);
  355. if (!tu) {
  356. mutex_unlock(&uprobe_lock);
  357. pr_info("Event %s/%s doesn't exist.\n", group, event);
  358. return -ENOENT;
  359. }
  360. /* delete an event */
  361. ret = unregister_trace_uprobe(tu);
  362. mutex_unlock(&uprobe_lock);
  363. return ret;
  364. }
  365. if (argc < 2) {
  366. pr_info("Probe point is not specified.\n");
  367. return -EINVAL;
  368. }
  369. if (isdigit(argv[1][0])) {
  370. pr_info("probe point must be have a filename.\n");
  371. return -EINVAL;
  372. }
  373. arg = strchr(argv[1], ':');
  374. if (!arg) {
  375. ret = -EINVAL;
  376. goto fail_address_parse;
  377. }
  378. *arg++ = '\0';
  379. filename = argv[1];
  380. ret = kern_path(filename, LOOKUP_FOLLOW, &path);
  381. if (ret)
  382. goto fail_address_parse;
  383. inode = igrab(d_inode(path.dentry));
  384. path_put(&path);
  385. if (!inode || !S_ISREG(inode->i_mode)) {
  386. ret = -EINVAL;
  387. goto fail_address_parse;
  388. }
  389. ret = kstrtoul(arg, 0, &offset);
  390. if (ret)
  391. goto fail_address_parse;
  392. argc -= 2;
  393. argv += 2;
  394. /* setup a probe */
  395. if (!event) {
  396. char *tail;
  397. char *ptr;
  398. tail = kstrdup(kbasename(filename), GFP_KERNEL);
  399. if (!tail) {
  400. ret = -ENOMEM;
  401. goto fail_address_parse;
  402. }
  403. ptr = strpbrk(tail, ".-_");
  404. if (ptr)
  405. *ptr = '\0';
  406. snprintf(buf, MAX_EVENT_NAME_LEN, "%c_%s_0x%lx", 'p', tail, offset);
  407. event = buf;
  408. kfree(tail);
  409. }
  410. tu = alloc_trace_uprobe(group, event, argc, is_return);
  411. if (IS_ERR(tu)) {
  412. pr_info("Failed to allocate trace_uprobe.(%d)\n", (int)PTR_ERR(tu));
  413. ret = PTR_ERR(tu);
  414. goto fail_address_parse;
  415. }
  416. tu->offset = offset;
  417. tu->inode = inode;
  418. tu->filename = kstrdup(filename, GFP_KERNEL);
  419. if (!tu->filename) {
  420. pr_info("Failed to allocate filename.\n");
  421. ret = -ENOMEM;
  422. goto error;
  423. }
  424. /* parse arguments */
  425. ret = 0;
  426. for (i = 0; i < argc && i < MAX_TRACE_ARGS; i++) {
  427. struct probe_arg *parg = &tu->tp.args[i];
  428. /* Increment count for freeing args in error case */
  429. tu->tp.nr_args++;
  430. /* Parse argument name */
  431. arg = strchr(argv[i], '=');
  432. if (arg) {
  433. *arg++ = '\0';
  434. parg->name = kstrdup(argv[i], GFP_KERNEL);
  435. } else {
  436. arg = argv[i];
  437. /* If argument name is omitted, set "argN" */
  438. snprintf(buf, MAX_EVENT_NAME_LEN, "arg%d", i + 1);
  439. parg->name = kstrdup(buf, GFP_KERNEL);
  440. }
  441. if (!parg->name) {
  442. pr_info("Failed to allocate argument[%d] name.\n", i);
  443. ret = -ENOMEM;
  444. goto error;
  445. }
  446. if (!is_good_name(parg->name)) {
  447. pr_info("Invalid argument[%d] name: %s\n", i, parg->name);
  448. ret = -EINVAL;
  449. goto error;
  450. }
  451. if (traceprobe_conflict_field_name(parg->name, tu->tp.args, i)) {
  452. pr_info("Argument[%d] name '%s' conflicts with "
  453. "another field.\n", i, argv[i]);
  454. ret = -EINVAL;
  455. goto error;
  456. }
  457. /* Parse fetch argument */
  458. ret = traceprobe_parse_probe_arg(arg, &tu->tp.size, parg,
  459. is_return, false,
  460. uprobes_fetch_type_table);
  461. if (ret) {
  462. pr_info("Parse error at argument[%d]. (%d)\n", i, ret);
  463. goto error;
  464. }
  465. }
  466. ret = register_trace_uprobe(tu);
  467. if (ret)
  468. goto error;
  469. return 0;
  470. error:
  471. free_trace_uprobe(tu);
  472. return ret;
  473. fail_address_parse:
  474. iput(inode);
  475. pr_info("Failed to parse address or file.\n");
  476. return ret;
  477. }
  478. static int cleanup_all_probes(void)
  479. {
  480. struct trace_uprobe *tu;
  481. int ret = 0;
  482. mutex_lock(&uprobe_lock);
  483. while (!list_empty(&uprobe_list)) {
  484. tu = list_entry(uprobe_list.next, struct trace_uprobe, list);
  485. ret = unregister_trace_uprobe(tu);
  486. if (ret)
  487. break;
  488. }
  489. mutex_unlock(&uprobe_lock);
  490. return ret;
  491. }
  492. /* Probes listing interfaces */
  493. static void *probes_seq_start(struct seq_file *m, loff_t *pos)
  494. {
  495. mutex_lock(&uprobe_lock);
  496. return seq_list_start(&uprobe_list, *pos);
  497. }
  498. static void *probes_seq_next(struct seq_file *m, void *v, loff_t *pos)
  499. {
  500. return seq_list_next(v, &uprobe_list, pos);
  501. }
  502. static void probes_seq_stop(struct seq_file *m, void *v)
  503. {
  504. mutex_unlock(&uprobe_lock);
  505. }
  506. static int probes_seq_show(struct seq_file *m, void *v)
  507. {
  508. struct trace_uprobe *tu = v;
  509. char c = is_ret_probe(tu) ? 'r' : 'p';
  510. int i;
  511. seq_printf(m, "%c:%s/%s", c, tu->tp.call.class->system,
  512. trace_event_name(&tu->tp.call));
  513. seq_printf(m, " %s:", tu->filename);
  514. /* Don't print "0x (null)" when offset is 0 */
  515. if (tu->offset) {
  516. seq_printf(m, "0x%p", (void *)tu->offset);
  517. } else {
  518. switch (sizeof(void *)) {
  519. case 4:
  520. seq_printf(m, "0x00000000");
  521. break;
  522. case 8:
  523. default:
  524. seq_printf(m, "0x0000000000000000");
  525. break;
  526. }
  527. }
  528. for (i = 0; i < tu->tp.nr_args; i++)
  529. seq_printf(m, " %s=%s", tu->tp.args[i].name, tu->tp.args[i].comm);
  530. seq_putc(m, '\n');
  531. return 0;
  532. }
  533. static const struct seq_operations probes_seq_op = {
  534. .start = probes_seq_start,
  535. .next = probes_seq_next,
  536. .stop = probes_seq_stop,
  537. .show = probes_seq_show
  538. };
  539. static int probes_open(struct inode *inode, struct file *file)
  540. {
  541. int ret;
  542. if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_TRUNC)) {
  543. ret = cleanup_all_probes();
  544. if (ret)
  545. return ret;
  546. }
  547. return seq_open(file, &probes_seq_op);
  548. }
  549. static ssize_t probes_write(struct file *file, const char __user *buffer,
  550. size_t count, loff_t *ppos)
  551. {
  552. return traceprobe_probes_write(file, buffer, count, ppos, create_trace_uprobe);
  553. }
  554. static const struct file_operations uprobe_events_ops = {
  555. .owner = THIS_MODULE,
  556. .open = probes_open,
  557. .read = seq_read,
  558. .llseek = seq_lseek,
  559. .release = seq_release,
  560. .write = probes_write,
  561. };
  562. /* Probes profiling interfaces */
  563. static int probes_profile_seq_show(struct seq_file *m, void *v)
  564. {
  565. struct trace_uprobe *tu = v;
  566. seq_printf(m, " %s %-44s %15lu\n", tu->filename,
  567. trace_event_name(&tu->tp.call), tu->nhit);
  568. return 0;
  569. }
  570. static const struct seq_operations profile_seq_op = {
  571. .start = probes_seq_start,
  572. .next = probes_seq_next,
  573. .stop = probes_seq_stop,
  574. .show = probes_profile_seq_show
  575. };
  576. static int profile_open(struct inode *inode, struct file *file)
  577. {
  578. return seq_open(file, &profile_seq_op);
  579. }
  580. static const struct file_operations uprobe_profile_ops = {
  581. .owner = THIS_MODULE,
  582. .open = profile_open,
  583. .read = seq_read,
  584. .llseek = seq_lseek,
  585. .release = seq_release,
  586. };
  587. struct uprobe_cpu_buffer {
  588. struct mutex mutex;
  589. void *buf;
  590. };
  591. static struct uprobe_cpu_buffer __percpu *uprobe_cpu_buffer;
  592. static int uprobe_buffer_refcnt;
  593. static int uprobe_buffer_init(void)
  594. {
  595. int cpu, err_cpu;
  596. uprobe_cpu_buffer = alloc_percpu(struct uprobe_cpu_buffer);
  597. if (uprobe_cpu_buffer == NULL)
  598. return -ENOMEM;
  599. for_each_possible_cpu(cpu) {
  600. struct page *p = alloc_pages_node(cpu_to_node(cpu),
  601. GFP_KERNEL, 0);
  602. if (p == NULL) {
  603. err_cpu = cpu;
  604. goto err;
  605. }
  606. per_cpu_ptr(uprobe_cpu_buffer, cpu)->buf = page_address(p);
  607. mutex_init(&per_cpu_ptr(uprobe_cpu_buffer, cpu)->mutex);
  608. }
  609. return 0;
  610. err:
  611. for_each_possible_cpu(cpu) {
  612. if (cpu == err_cpu)
  613. break;
  614. free_page((unsigned long)per_cpu_ptr(uprobe_cpu_buffer, cpu)->buf);
  615. }
  616. free_percpu(uprobe_cpu_buffer);
  617. return -ENOMEM;
  618. }
  619. static int uprobe_buffer_enable(void)
  620. {
  621. int ret = 0;
  622. BUG_ON(!mutex_is_locked(&event_mutex));
  623. if (uprobe_buffer_refcnt++ == 0) {
  624. ret = uprobe_buffer_init();
  625. if (ret < 0)
  626. uprobe_buffer_refcnt--;
  627. }
  628. return ret;
  629. }
  630. static void uprobe_buffer_disable(void)
  631. {
  632. int cpu;
  633. BUG_ON(!mutex_is_locked(&event_mutex));
  634. if (--uprobe_buffer_refcnt == 0) {
  635. for_each_possible_cpu(cpu)
  636. free_page((unsigned long)per_cpu_ptr(uprobe_cpu_buffer,
  637. cpu)->buf);
  638. free_percpu(uprobe_cpu_buffer);
  639. uprobe_cpu_buffer = NULL;
  640. }
  641. }
  642. static struct uprobe_cpu_buffer *uprobe_buffer_get(void)
  643. {
  644. struct uprobe_cpu_buffer *ucb;
  645. int cpu;
  646. cpu = raw_smp_processor_id();
  647. ucb = per_cpu_ptr(uprobe_cpu_buffer, cpu);
  648. /*
  649. * Use per-cpu buffers for fastest access, but we might migrate
  650. * so the mutex makes sure we have sole access to it.
  651. */
  652. mutex_lock(&ucb->mutex);
  653. return ucb;
  654. }
  655. static void uprobe_buffer_put(struct uprobe_cpu_buffer *ucb)
  656. {
  657. mutex_unlock(&ucb->mutex);
  658. }
  659. static void __uprobe_trace_func(struct trace_uprobe *tu,
  660. unsigned long func, struct pt_regs *regs,
  661. struct uprobe_cpu_buffer *ucb, int dsize,
  662. struct trace_event_file *trace_file)
  663. {
  664. struct uprobe_trace_entry_head *entry;
  665. struct ring_buffer_event *event;
  666. struct ring_buffer *buffer;
  667. void *data;
  668. int size, esize;
  669. struct trace_event_call *call = &tu->tp.call;
  670. WARN_ON(call != trace_file->event_call);
  671. if (WARN_ON_ONCE(tu->tp.size + dsize > PAGE_SIZE))
  672. return;
  673. if (trace_trigger_soft_disabled(trace_file))
  674. return;
  675. esize = SIZEOF_TRACE_ENTRY(is_ret_probe(tu));
  676. size = esize + tu->tp.size + dsize;
  677. event = trace_event_buffer_lock_reserve(&buffer, trace_file,
  678. call->event.type, size, 0, 0);
  679. if (!event)
  680. return;
  681. entry = ring_buffer_event_data(event);
  682. if (is_ret_probe(tu)) {
  683. entry->vaddr[0] = func;
  684. entry->vaddr[1] = instruction_pointer(regs);
  685. data = DATAOF_TRACE_ENTRY(entry, true);
  686. } else {
  687. entry->vaddr[0] = instruction_pointer(regs);
  688. data = DATAOF_TRACE_ENTRY(entry, false);
  689. }
  690. memcpy(data, ucb->buf, tu->tp.size + dsize);
  691. event_trigger_unlock_commit(trace_file, buffer, event, entry, 0, 0);
  692. }
  693. /* uprobe handler */
  694. static int uprobe_trace_func(struct trace_uprobe *tu, struct pt_regs *regs,
  695. struct uprobe_cpu_buffer *ucb, int dsize)
  696. {
  697. struct event_file_link *link;
  698. if (is_ret_probe(tu))
  699. return 0;
  700. rcu_read_lock();
  701. list_for_each_entry_rcu(link, &tu->tp.files, list)
  702. __uprobe_trace_func(tu, 0, regs, ucb, dsize, link->file);
  703. rcu_read_unlock();
  704. return 0;
  705. }
  706. static void uretprobe_trace_func(struct trace_uprobe *tu, unsigned long func,
  707. struct pt_regs *regs,
  708. struct uprobe_cpu_buffer *ucb, int dsize)
  709. {
  710. struct event_file_link *link;
  711. rcu_read_lock();
  712. list_for_each_entry_rcu(link, &tu->tp.files, list)
  713. __uprobe_trace_func(tu, func, regs, ucb, dsize, link->file);
  714. rcu_read_unlock();
  715. }
  716. /* Event entry printers */
  717. static enum print_line_t
  718. print_uprobe_event(struct trace_iterator *iter, int flags, struct trace_event *event)
  719. {
  720. struct uprobe_trace_entry_head *entry;
  721. struct trace_seq *s = &iter->seq;
  722. struct trace_uprobe *tu;
  723. u8 *data;
  724. int i;
  725. entry = (struct uprobe_trace_entry_head *)iter->ent;
  726. tu = container_of(event, struct trace_uprobe, tp.call.event);
  727. if (is_ret_probe(tu)) {
  728. trace_seq_printf(s, "%s: (0x%lx <- 0x%lx)",
  729. trace_event_name(&tu->tp.call),
  730. entry->vaddr[1], entry->vaddr[0]);
  731. data = DATAOF_TRACE_ENTRY(entry, true);
  732. } else {
  733. trace_seq_printf(s, "%s: (0x%lx)",
  734. trace_event_name(&tu->tp.call),
  735. entry->vaddr[0]);
  736. data = DATAOF_TRACE_ENTRY(entry, false);
  737. }
  738. for (i = 0; i < tu->tp.nr_args; i++) {
  739. struct probe_arg *parg = &tu->tp.args[i];
  740. if (!parg->type->print(s, parg->name, data + parg->offset, entry))
  741. goto out;
  742. }
  743. trace_seq_putc(s, '\n');
  744. out:
  745. return trace_handle_return(s);
  746. }
  747. typedef bool (*filter_func_t)(struct uprobe_consumer *self,
  748. enum uprobe_filter_ctx ctx,
  749. struct mm_struct *mm);
  750. static int
  751. probe_event_enable(struct trace_uprobe *tu, struct trace_event_file *file,
  752. filter_func_t filter)
  753. {
  754. bool enabled = trace_probe_is_enabled(&tu->tp);
  755. struct event_file_link *link = NULL;
  756. int ret;
  757. if (file) {
  758. if (tu->tp.flags & TP_FLAG_PROFILE)
  759. return -EINTR;
  760. link = kmalloc(sizeof(*link), GFP_KERNEL);
  761. if (!link)
  762. return -ENOMEM;
  763. link->file = file;
  764. list_add_tail_rcu(&link->list, &tu->tp.files);
  765. tu->tp.flags |= TP_FLAG_TRACE;
  766. } else {
  767. if (tu->tp.flags & TP_FLAG_TRACE)
  768. return -EINTR;
  769. tu->tp.flags |= TP_FLAG_PROFILE;
  770. }
  771. WARN_ON(!uprobe_filter_is_empty(&tu->filter));
  772. if (enabled)
  773. return 0;
  774. ret = uprobe_buffer_enable();
  775. if (ret)
  776. goto err_flags;
  777. tu->consumer.filter = filter;
  778. ret = uprobe_register(tu->inode, tu->offset, &tu->consumer);
  779. if (ret)
  780. goto err_buffer;
  781. return 0;
  782. err_buffer:
  783. uprobe_buffer_disable();
  784. err_flags:
  785. if (file) {
  786. list_del(&link->list);
  787. kfree(link);
  788. tu->tp.flags &= ~TP_FLAG_TRACE;
  789. } else {
  790. tu->tp.flags &= ~TP_FLAG_PROFILE;
  791. }
  792. return ret;
  793. }
  794. static void
  795. probe_event_disable(struct trace_uprobe *tu, struct trace_event_file *file)
  796. {
  797. if (!trace_probe_is_enabled(&tu->tp))
  798. return;
  799. if (file) {
  800. struct event_file_link *link;
  801. link = find_event_file_link(&tu->tp, file);
  802. if (!link)
  803. return;
  804. list_del_rcu(&link->list);
  805. /* synchronize with u{,ret}probe_trace_func */
  806. synchronize_rcu();
  807. kfree(link);
  808. if (!list_empty(&tu->tp.files))
  809. return;
  810. }
  811. WARN_ON(!uprobe_filter_is_empty(&tu->filter));
  812. uprobe_unregister(tu->inode, tu->offset, &tu->consumer);
  813. tu->tp.flags &= file ? ~TP_FLAG_TRACE : ~TP_FLAG_PROFILE;
  814. uprobe_buffer_disable();
  815. }
  816. static int uprobe_event_define_fields(struct trace_event_call *event_call)
  817. {
  818. int ret, i, size;
  819. struct uprobe_trace_entry_head field;
  820. struct trace_uprobe *tu = event_call->data;
  821. if (is_ret_probe(tu)) {
  822. DEFINE_FIELD(unsigned long, vaddr[0], FIELD_STRING_FUNC, 0);
  823. DEFINE_FIELD(unsigned long, vaddr[1], FIELD_STRING_RETIP, 0);
  824. size = SIZEOF_TRACE_ENTRY(true);
  825. } else {
  826. DEFINE_FIELD(unsigned long, vaddr[0], FIELD_STRING_IP, 0);
  827. size = SIZEOF_TRACE_ENTRY(false);
  828. }
  829. /* Set argument names as fields */
  830. for (i = 0; i < tu->tp.nr_args; i++) {
  831. struct probe_arg *parg = &tu->tp.args[i];
  832. ret = trace_define_field(event_call, parg->type->fmttype,
  833. parg->name, size + parg->offset,
  834. parg->type->size, parg->type->is_signed,
  835. FILTER_OTHER);
  836. if (ret)
  837. return ret;
  838. }
  839. return 0;
  840. }
  841. #ifdef CONFIG_PERF_EVENTS
  842. static bool
  843. __uprobe_perf_filter(struct trace_uprobe_filter *filter, struct mm_struct *mm)
  844. {
  845. struct perf_event *event;
  846. if (filter->nr_systemwide)
  847. return true;
  848. list_for_each_entry(event, &filter->perf_events, hw.tp_list) {
  849. if (event->hw.target->mm == mm)
  850. return true;
  851. }
  852. return false;
  853. }
  854. static inline bool
  855. uprobe_filter_event(struct trace_uprobe *tu, struct perf_event *event)
  856. {
  857. return __uprobe_perf_filter(&tu->filter, event->hw.target->mm);
  858. }
  859. static int uprobe_perf_close(struct trace_uprobe *tu, struct perf_event *event)
  860. {
  861. bool done;
  862. write_lock(&tu->filter.rwlock);
  863. if (event->hw.target) {
  864. list_del(&event->hw.tp_list);
  865. done = tu->filter.nr_systemwide ||
  866. (event->hw.target->flags & PF_EXITING) ||
  867. uprobe_filter_event(tu, event);
  868. } else {
  869. tu->filter.nr_systemwide--;
  870. done = tu->filter.nr_systemwide;
  871. }
  872. write_unlock(&tu->filter.rwlock);
  873. if (!done)
  874. return uprobe_apply(tu->inode, tu->offset, &tu->consumer, false);
  875. return 0;
  876. }
  877. static int uprobe_perf_open(struct trace_uprobe *tu, struct perf_event *event)
  878. {
  879. bool done;
  880. int err;
  881. write_lock(&tu->filter.rwlock);
  882. if (event->hw.target) {
  883. /*
  884. * event->parent != NULL means copy_process(), we can avoid
  885. * uprobe_apply(). current->mm must be probed and we can rely
  886. * on dup_mmap() which preserves the already installed bp's.
  887. *
  888. * attr.enable_on_exec means that exec/mmap will install the
  889. * breakpoints we need.
  890. */
  891. done = tu->filter.nr_systemwide ||
  892. event->parent || event->attr.enable_on_exec ||
  893. uprobe_filter_event(tu, event);
  894. list_add(&event->hw.tp_list, &tu->filter.perf_events);
  895. } else {
  896. done = tu->filter.nr_systemwide;
  897. tu->filter.nr_systemwide++;
  898. }
  899. write_unlock(&tu->filter.rwlock);
  900. err = 0;
  901. if (!done) {
  902. err = uprobe_apply(tu->inode, tu->offset, &tu->consumer, true);
  903. if (err)
  904. uprobe_perf_close(tu, event);
  905. }
  906. return err;
  907. }
  908. static bool uprobe_perf_filter(struct uprobe_consumer *uc,
  909. enum uprobe_filter_ctx ctx, struct mm_struct *mm)
  910. {
  911. struct trace_uprobe *tu;
  912. int ret;
  913. tu = container_of(uc, struct trace_uprobe, consumer);
  914. read_lock(&tu->filter.rwlock);
  915. ret = __uprobe_perf_filter(&tu->filter, mm);
  916. read_unlock(&tu->filter.rwlock);
  917. return ret;
  918. }
  919. static void __uprobe_perf_func(struct trace_uprobe *tu,
  920. unsigned long func, struct pt_regs *regs,
  921. struct uprobe_cpu_buffer *ucb, int dsize)
  922. {
  923. struct trace_event_call *call = &tu->tp.call;
  924. struct uprobe_trace_entry_head *entry;
  925. struct bpf_prog *prog = call->prog;
  926. struct hlist_head *head;
  927. void *data;
  928. int size, esize;
  929. int rctx;
  930. if (prog && !trace_call_bpf(prog, regs))
  931. return;
  932. esize = SIZEOF_TRACE_ENTRY(is_ret_probe(tu));
  933. size = esize + tu->tp.size + dsize;
  934. size = ALIGN(size + sizeof(u32), sizeof(u64)) - sizeof(u32);
  935. if (WARN_ONCE(size > PERF_MAX_TRACE_SIZE, "profile buffer not large enough"))
  936. return;
  937. preempt_disable();
  938. head = this_cpu_ptr(call->perf_events);
  939. if (hlist_empty(head))
  940. goto out;
  941. entry = perf_trace_buf_prepare(size, call->event.type, NULL, &rctx);
  942. if (!entry)
  943. goto out;
  944. if (is_ret_probe(tu)) {
  945. entry->vaddr[0] = func;
  946. entry->vaddr[1] = instruction_pointer(regs);
  947. data = DATAOF_TRACE_ENTRY(entry, true);
  948. } else {
  949. entry->vaddr[0] = instruction_pointer(regs);
  950. data = DATAOF_TRACE_ENTRY(entry, false);
  951. }
  952. memcpy(data, ucb->buf, tu->tp.size + dsize);
  953. if (size - esize > tu->tp.size + dsize) {
  954. int len = tu->tp.size + dsize;
  955. memset(data + len, 0, size - esize - len);
  956. }
  957. perf_trace_buf_submit(entry, size, rctx, 0, 1, regs, head, NULL);
  958. out:
  959. preempt_enable();
  960. }
  961. /* uprobe profile handler */
  962. static int uprobe_perf_func(struct trace_uprobe *tu, struct pt_regs *regs,
  963. struct uprobe_cpu_buffer *ucb, int dsize)
  964. {
  965. if (!uprobe_perf_filter(&tu->consumer, 0, current->mm))
  966. return UPROBE_HANDLER_REMOVE;
  967. if (!is_ret_probe(tu))
  968. __uprobe_perf_func(tu, 0, regs, ucb, dsize);
  969. return 0;
  970. }
  971. static void uretprobe_perf_func(struct trace_uprobe *tu, unsigned long func,
  972. struct pt_regs *regs,
  973. struct uprobe_cpu_buffer *ucb, int dsize)
  974. {
  975. __uprobe_perf_func(tu, func, regs, ucb, dsize);
  976. }
  977. #endif /* CONFIG_PERF_EVENTS */
  978. static int
  979. trace_uprobe_register(struct trace_event_call *event, enum trace_reg type,
  980. void *data)
  981. {
  982. struct trace_uprobe *tu = event->data;
  983. struct trace_event_file *file = data;
  984. switch (type) {
  985. case TRACE_REG_REGISTER:
  986. return probe_event_enable(tu, file, NULL);
  987. case TRACE_REG_UNREGISTER:
  988. probe_event_disable(tu, file);
  989. return 0;
  990. #ifdef CONFIG_PERF_EVENTS
  991. case TRACE_REG_PERF_REGISTER:
  992. return probe_event_enable(tu, NULL, uprobe_perf_filter);
  993. case TRACE_REG_PERF_UNREGISTER:
  994. probe_event_disable(tu, NULL);
  995. return 0;
  996. case TRACE_REG_PERF_OPEN:
  997. return uprobe_perf_open(tu, data);
  998. case TRACE_REG_PERF_CLOSE:
  999. return uprobe_perf_close(tu, data);
  1000. #endif
  1001. default:
  1002. return 0;
  1003. }
  1004. return 0;
  1005. }
  1006. static int uprobe_dispatcher(struct uprobe_consumer *con, struct pt_regs *regs)
  1007. {
  1008. struct trace_uprobe *tu;
  1009. struct uprobe_dispatch_data udd;
  1010. struct uprobe_cpu_buffer *ucb;
  1011. int dsize, esize;
  1012. int ret = 0;
  1013. tu = container_of(con, struct trace_uprobe, consumer);
  1014. tu->nhit++;
  1015. udd.tu = tu;
  1016. udd.bp_addr = instruction_pointer(regs);
  1017. current->utask->vaddr = (unsigned long) &udd;
  1018. if (WARN_ON_ONCE(!uprobe_cpu_buffer))
  1019. return 0;
  1020. dsize = __get_data_size(&tu->tp, regs);
  1021. esize = SIZEOF_TRACE_ENTRY(is_ret_probe(tu));
  1022. ucb = uprobe_buffer_get();
  1023. store_trace_args(esize, &tu->tp, regs, ucb->buf, dsize);
  1024. if (tu->tp.flags & TP_FLAG_TRACE)
  1025. ret |= uprobe_trace_func(tu, regs, ucb, dsize);
  1026. #ifdef CONFIG_PERF_EVENTS
  1027. if (tu->tp.flags & TP_FLAG_PROFILE)
  1028. ret |= uprobe_perf_func(tu, regs, ucb, dsize);
  1029. #endif
  1030. uprobe_buffer_put(ucb);
  1031. return ret;
  1032. }
  1033. static int uretprobe_dispatcher(struct uprobe_consumer *con,
  1034. unsigned long func, struct pt_regs *regs)
  1035. {
  1036. struct trace_uprobe *tu;
  1037. struct uprobe_dispatch_data udd;
  1038. struct uprobe_cpu_buffer *ucb;
  1039. int dsize, esize;
  1040. tu = container_of(con, struct trace_uprobe, consumer);
  1041. udd.tu = tu;
  1042. udd.bp_addr = func;
  1043. current->utask->vaddr = (unsigned long) &udd;
  1044. if (WARN_ON_ONCE(!uprobe_cpu_buffer))
  1045. return 0;
  1046. dsize = __get_data_size(&tu->tp, regs);
  1047. esize = SIZEOF_TRACE_ENTRY(is_ret_probe(tu));
  1048. ucb = uprobe_buffer_get();
  1049. store_trace_args(esize, &tu->tp, regs, ucb->buf, dsize);
  1050. if (tu->tp.flags & TP_FLAG_TRACE)
  1051. uretprobe_trace_func(tu, func, regs, ucb, dsize);
  1052. #ifdef CONFIG_PERF_EVENTS
  1053. if (tu->tp.flags & TP_FLAG_PROFILE)
  1054. uretprobe_perf_func(tu, func, regs, ucb, dsize);
  1055. #endif
  1056. uprobe_buffer_put(ucb);
  1057. return 0;
  1058. }
  1059. static struct trace_event_functions uprobe_funcs = {
  1060. .trace = print_uprobe_event
  1061. };
  1062. static int register_uprobe_event(struct trace_uprobe *tu)
  1063. {
  1064. struct trace_event_call *call = &tu->tp.call;
  1065. int ret;
  1066. /* Initialize trace_event_call */
  1067. INIT_LIST_HEAD(&call->class->fields);
  1068. call->event.funcs = &uprobe_funcs;
  1069. call->class->define_fields = uprobe_event_define_fields;
  1070. if (set_print_fmt(&tu->tp, is_ret_probe(tu)) < 0)
  1071. return -ENOMEM;
  1072. ret = register_trace_event(&call->event);
  1073. if (!ret) {
  1074. kfree(call->print_fmt);
  1075. return -ENODEV;
  1076. }
  1077. call->flags = TRACE_EVENT_FL_UPROBE;
  1078. call->class->reg = trace_uprobe_register;
  1079. call->data = tu;
  1080. ret = trace_add_event_call(call);
  1081. if (ret) {
  1082. pr_info("Failed to register uprobe event: %s\n",
  1083. trace_event_name(call));
  1084. kfree(call->print_fmt);
  1085. unregister_trace_event(&call->event);
  1086. }
  1087. return ret;
  1088. }
  1089. static int unregister_uprobe_event(struct trace_uprobe *tu)
  1090. {
  1091. int ret;
  1092. /* tu->event is unregistered in trace_remove_event_call() */
  1093. ret = trace_remove_event_call(&tu->tp.call);
  1094. if (ret)
  1095. return ret;
  1096. kfree(tu->tp.call.print_fmt);
  1097. tu->tp.call.print_fmt = NULL;
  1098. return 0;
  1099. }
  1100. /* Make a trace interface for controling probe points */
  1101. static __init int init_uprobe_trace(void)
  1102. {
  1103. struct dentry *d_tracer;
  1104. d_tracer = tracing_init_dentry();
  1105. if (IS_ERR(d_tracer))
  1106. return 0;
  1107. trace_create_file("uprobe_events", 0644, d_tracer,
  1108. NULL, &uprobe_events_ops);
  1109. /* Profile interface */
  1110. trace_create_file("uprobe_profile", 0444, d_tracer,
  1111. NULL, &uprobe_profile_ops);
  1112. return 0;
  1113. }
  1114. fs_initcall(init_uprobe_trace);