trace_uprobe.c 31 KB

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