trace_uprobe.c 31 KB

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