trace_uprobe.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359
  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. #define pr_fmt(fmt) "trace_kprobe: " fmt
  21. #include <linux/module.h>
  22. #include <linux/uaccess.h>
  23. #include <linux/uprobes.h>
  24. #include <linux/namei.h>
  25. #include <linux/string.h>
  26. #include <linux/rculist.h>
  27. #include "trace_probe.h"
  28. #define UPROBE_EVENT_SYSTEM "uprobes"
  29. struct uprobe_trace_entry_head {
  30. struct trace_entry ent;
  31. unsigned long vaddr[];
  32. };
  33. #define SIZEOF_TRACE_ENTRY(is_return) \
  34. (sizeof(struct uprobe_trace_entry_head) + \
  35. sizeof(unsigned long) * (is_return ? 2 : 1))
  36. #define DATAOF_TRACE_ENTRY(entry, is_return) \
  37. ((void*)(entry) + SIZEOF_TRACE_ENTRY(is_return))
  38. struct trace_uprobe_filter {
  39. rwlock_t rwlock;
  40. int nr_systemwide;
  41. struct list_head perf_events;
  42. };
  43. /*
  44. * uprobe event core functions
  45. */
  46. struct trace_uprobe {
  47. struct list_head list;
  48. struct trace_uprobe_filter filter;
  49. struct uprobe_consumer consumer;
  50. struct inode *inode;
  51. char *filename;
  52. unsigned long offset;
  53. unsigned long nhit;
  54. struct trace_probe tp;
  55. };
  56. #define SIZEOF_TRACE_UPROBE(n) \
  57. (offsetof(struct trace_uprobe, tp.args) + \
  58. (sizeof(struct probe_arg) * (n)))
  59. static int register_uprobe_event(struct trace_uprobe *tu);
  60. static int unregister_uprobe_event(struct trace_uprobe *tu);
  61. static DEFINE_MUTEX(uprobe_lock);
  62. static LIST_HEAD(uprobe_list);
  63. struct uprobe_dispatch_data {
  64. struct trace_uprobe *tu;
  65. unsigned long bp_addr;
  66. };
  67. static int uprobe_dispatcher(struct uprobe_consumer *con, struct pt_regs *regs);
  68. static int uretprobe_dispatcher(struct uprobe_consumer *con,
  69. unsigned long func, struct pt_regs *regs);
  70. #ifdef CONFIG_STACK_GROWSUP
  71. static unsigned long adjust_stack_addr(unsigned long addr, unsigned int n)
  72. {
  73. return addr - (n * sizeof(long));
  74. }
  75. #else
  76. static unsigned long adjust_stack_addr(unsigned long addr, unsigned int n)
  77. {
  78. return addr + (n * sizeof(long));
  79. }
  80. #endif
  81. static unsigned long get_user_stack_nth(struct pt_regs *regs, unsigned int n)
  82. {
  83. unsigned long ret;
  84. unsigned long addr = user_stack_pointer(regs);
  85. addr = adjust_stack_addr(addr, n);
  86. if (copy_from_user(&ret, (void __force __user *) addr, sizeof(ret)))
  87. return 0;
  88. return ret;
  89. }
  90. /*
  91. * Uprobes-specific fetch functions
  92. */
  93. #define DEFINE_FETCH_stack(type) \
  94. static void FETCH_FUNC_NAME(stack, type)(struct pt_regs *regs, \
  95. void *offset, void *dest) \
  96. { \
  97. *(type *)dest = (type)get_user_stack_nth(regs, \
  98. ((unsigned long)offset)); \
  99. }
  100. DEFINE_BASIC_FETCH_FUNCS(stack)
  101. /* No string on the stack entry */
  102. #define fetch_stack_string NULL
  103. #define fetch_stack_string_size NULL
  104. #define DEFINE_FETCH_memory(type) \
  105. static void FETCH_FUNC_NAME(memory, type)(struct pt_regs *regs, \
  106. void *addr, void *dest) \
  107. { \
  108. type retval; \
  109. void __user *vaddr = (void __force __user *) addr; \
  110. \
  111. if (copy_from_user(&retval, vaddr, sizeof(type))) \
  112. *(type *)dest = 0; \
  113. else \
  114. *(type *) dest = retval; \
  115. }
  116. DEFINE_BASIC_FETCH_FUNCS(memory)
  117. /*
  118. * Fetch a null-terminated string. Caller MUST set *(u32 *)dest with max
  119. * length and relative data location.
  120. */
  121. static void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
  122. void *addr, void *dest)
  123. {
  124. long ret;
  125. u32 rloc = *(u32 *)dest;
  126. int maxlen = get_rloc_len(rloc);
  127. u8 *dst = get_rloc_data(dest);
  128. void __user *src = (void __force __user *) addr;
  129. if (!maxlen)
  130. return;
  131. ret = strncpy_from_user(dst, src, maxlen);
  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. /* Find the last occurrence, in case the path contains ':' too. */
  367. arg = strrchr(argv[1], ':');
  368. if (!arg) {
  369. ret = -EINVAL;
  370. goto fail_address_parse;
  371. }
  372. *arg++ = '\0';
  373. filename = argv[1];
  374. ret = kern_path(filename, LOOKUP_FOLLOW, &path);
  375. if (ret)
  376. goto fail_address_parse;
  377. inode = igrab(d_inode(path.dentry));
  378. path_put(&path);
  379. if (!inode || !S_ISREG(inode->i_mode)) {
  380. ret = -EINVAL;
  381. goto fail_address_parse;
  382. }
  383. ret = kstrtoul(arg, 0, &offset);
  384. if (ret)
  385. goto fail_address_parse;
  386. argc -= 2;
  387. argv += 2;
  388. /* setup a probe */
  389. if (!event) {
  390. char *tail;
  391. char *ptr;
  392. tail = kstrdup(kbasename(filename), GFP_KERNEL);
  393. if (!tail) {
  394. ret = -ENOMEM;
  395. goto fail_address_parse;
  396. }
  397. ptr = strpbrk(tail, ".-_");
  398. if (ptr)
  399. *ptr = '\0';
  400. snprintf(buf, MAX_EVENT_NAME_LEN, "%c_%s_0x%lx", 'p', tail, offset);
  401. event = buf;
  402. kfree(tail);
  403. }
  404. tu = alloc_trace_uprobe(group, event, argc, is_return);
  405. if (IS_ERR(tu)) {
  406. pr_info("Failed to allocate trace_uprobe.(%d)\n", (int)PTR_ERR(tu));
  407. ret = PTR_ERR(tu);
  408. goto fail_address_parse;
  409. }
  410. tu->offset = offset;
  411. tu->inode = inode;
  412. tu->filename = kstrdup(filename, GFP_KERNEL);
  413. if (!tu->filename) {
  414. pr_info("Failed to allocate filename.\n");
  415. ret = -ENOMEM;
  416. goto error;
  417. }
  418. /* parse arguments */
  419. ret = 0;
  420. for (i = 0; i < argc && i < MAX_TRACE_ARGS; i++) {
  421. struct probe_arg *parg = &tu->tp.args[i];
  422. /* Increment count for freeing args in error case */
  423. tu->tp.nr_args++;
  424. /* Parse argument name */
  425. arg = strchr(argv[i], '=');
  426. if (arg) {
  427. *arg++ = '\0';
  428. parg->name = kstrdup(argv[i], GFP_KERNEL);
  429. } else {
  430. arg = argv[i];
  431. /* If argument name is omitted, set "argN" */
  432. snprintf(buf, MAX_EVENT_NAME_LEN, "arg%d", i + 1);
  433. parg->name = kstrdup(buf, GFP_KERNEL);
  434. }
  435. if (!parg->name) {
  436. pr_info("Failed to allocate argument[%d] name.\n", i);
  437. ret = -ENOMEM;
  438. goto error;
  439. }
  440. if (!is_good_name(parg->name)) {
  441. pr_info("Invalid argument[%d] name: %s\n", i, parg->name);
  442. ret = -EINVAL;
  443. goto error;
  444. }
  445. if (traceprobe_conflict_field_name(parg->name, tu->tp.args, i)) {
  446. pr_info("Argument[%d] name '%s' conflicts with "
  447. "another field.\n", i, argv[i]);
  448. ret = -EINVAL;
  449. goto error;
  450. }
  451. /* Parse fetch argument */
  452. ret = traceprobe_parse_probe_arg(arg, &tu->tp.size, parg,
  453. is_return, false,
  454. uprobes_fetch_type_table);
  455. if (ret) {
  456. pr_info("Parse error at argument[%d]. (%d)\n", i, ret);
  457. goto error;
  458. }
  459. }
  460. ret = register_trace_uprobe(tu);
  461. if (ret)
  462. goto error;
  463. return 0;
  464. error:
  465. free_trace_uprobe(tu);
  466. return ret;
  467. fail_address_parse:
  468. iput(inode);
  469. pr_info("Failed to parse address or file.\n");
  470. return ret;
  471. }
  472. static int cleanup_all_probes(void)
  473. {
  474. struct trace_uprobe *tu;
  475. int ret = 0;
  476. mutex_lock(&uprobe_lock);
  477. while (!list_empty(&uprobe_list)) {
  478. tu = list_entry(uprobe_list.next, struct trace_uprobe, list);
  479. ret = unregister_trace_uprobe(tu);
  480. if (ret)
  481. break;
  482. }
  483. mutex_unlock(&uprobe_lock);
  484. return ret;
  485. }
  486. /* Probes listing interfaces */
  487. static void *probes_seq_start(struct seq_file *m, loff_t *pos)
  488. {
  489. mutex_lock(&uprobe_lock);
  490. return seq_list_start(&uprobe_list, *pos);
  491. }
  492. static void *probes_seq_next(struct seq_file *m, void *v, loff_t *pos)
  493. {
  494. return seq_list_next(v, &uprobe_list, pos);
  495. }
  496. static void probes_seq_stop(struct seq_file *m, void *v)
  497. {
  498. mutex_unlock(&uprobe_lock);
  499. }
  500. static int probes_seq_show(struct seq_file *m, void *v)
  501. {
  502. struct trace_uprobe *tu = v;
  503. char c = is_ret_probe(tu) ? 'r' : 'p';
  504. int i;
  505. seq_printf(m, "%c:%s/%s", c, tu->tp.call.class->system,
  506. trace_event_name(&tu->tp.call));
  507. seq_printf(m, " %s:", tu->filename);
  508. /* Don't print "0x (null)" when offset is 0 */
  509. if (tu->offset) {
  510. seq_printf(m, "0x%p", (void *)tu->offset);
  511. } else {
  512. switch (sizeof(void *)) {
  513. case 4:
  514. seq_printf(m, "0x00000000");
  515. break;
  516. case 8:
  517. default:
  518. seq_printf(m, "0x0000000000000000");
  519. break;
  520. }
  521. }
  522. for (i = 0; i < tu->tp.nr_args; i++)
  523. seq_printf(m, " %s=%s", tu->tp.args[i].name, tu->tp.args[i].comm);
  524. seq_putc(m, '\n');
  525. return 0;
  526. }
  527. static const struct seq_operations probes_seq_op = {
  528. .start = probes_seq_start,
  529. .next = probes_seq_next,
  530. .stop = probes_seq_stop,
  531. .show = probes_seq_show
  532. };
  533. static int probes_open(struct inode *inode, struct file *file)
  534. {
  535. int ret;
  536. if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_TRUNC)) {
  537. ret = cleanup_all_probes();
  538. if (ret)
  539. return ret;
  540. }
  541. return seq_open(file, &probes_seq_op);
  542. }
  543. static ssize_t probes_write(struct file *file, const char __user *buffer,
  544. size_t count, loff_t *ppos)
  545. {
  546. return trace_parse_run_command(file, buffer, count, ppos, create_trace_uprobe);
  547. }
  548. static const struct file_operations uprobe_events_ops = {
  549. .owner = THIS_MODULE,
  550. .open = probes_open,
  551. .read = seq_read,
  552. .llseek = seq_lseek,
  553. .release = seq_release,
  554. .write = probes_write,
  555. };
  556. /* Probes profiling interfaces */
  557. static int probes_profile_seq_show(struct seq_file *m, void *v)
  558. {
  559. struct trace_uprobe *tu = v;
  560. seq_printf(m, " %s %-44s %15lu\n", tu->filename,
  561. trace_event_name(&tu->tp.call), tu->nhit);
  562. return 0;
  563. }
  564. static const struct seq_operations profile_seq_op = {
  565. .start = probes_seq_start,
  566. .next = probes_seq_next,
  567. .stop = probes_seq_stop,
  568. .show = probes_profile_seq_show
  569. };
  570. static int profile_open(struct inode *inode, struct file *file)
  571. {
  572. return seq_open(file, &profile_seq_op);
  573. }
  574. static const struct file_operations uprobe_profile_ops = {
  575. .owner = THIS_MODULE,
  576. .open = profile_open,
  577. .read = seq_read,
  578. .llseek = seq_lseek,
  579. .release = seq_release,
  580. };
  581. struct uprobe_cpu_buffer {
  582. struct mutex mutex;
  583. void *buf;
  584. };
  585. static struct uprobe_cpu_buffer __percpu *uprobe_cpu_buffer;
  586. static int uprobe_buffer_refcnt;
  587. static int uprobe_buffer_init(void)
  588. {
  589. int cpu, err_cpu;
  590. uprobe_cpu_buffer = alloc_percpu(struct uprobe_cpu_buffer);
  591. if (uprobe_cpu_buffer == NULL)
  592. return -ENOMEM;
  593. for_each_possible_cpu(cpu) {
  594. struct page *p = alloc_pages_node(cpu_to_node(cpu),
  595. GFP_KERNEL, 0);
  596. if (p == NULL) {
  597. err_cpu = cpu;
  598. goto err;
  599. }
  600. per_cpu_ptr(uprobe_cpu_buffer, cpu)->buf = page_address(p);
  601. mutex_init(&per_cpu_ptr(uprobe_cpu_buffer, cpu)->mutex);
  602. }
  603. return 0;
  604. err:
  605. for_each_possible_cpu(cpu) {
  606. if (cpu == err_cpu)
  607. break;
  608. free_page((unsigned long)per_cpu_ptr(uprobe_cpu_buffer, cpu)->buf);
  609. }
  610. free_percpu(uprobe_cpu_buffer);
  611. return -ENOMEM;
  612. }
  613. static int uprobe_buffer_enable(void)
  614. {
  615. int ret = 0;
  616. BUG_ON(!mutex_is_locked(&event_mutex));
  617. if (uprobe_buffer_refcnt++ == 0) {
  618. ret = uprobe_buffer_init();
  619. if (ret < 0)
  620. uprobe_buffer_refcnt--;
  621. }
  622. return ret;
  623. }
  624. static void uprobe_buffer_disable(void)
  625. {
  626. int cpu;
  627. BUG_ON(!mutex_is_locked(&event_mutex));
  628. if (--uprobe_buffer_refcnt == 0) {
  629. for_each_possible_cpu(cpu)
  630. free_page((unsigned long)per_cpu_ptr(uprobe_cpu_buffer,
  631. cpu)->buf);
  632. free_percpu(uprobe_cpu_buffer);
  633. uprobe_cpu_buffer = NULL;
  634. }
  635. }
  636. static struct uprobe_cpu_buffer *uprobe_buffer_get(void)
  637. {
  638. struct uprobe_cpu_buffer *ucb;
  639. int cpu;
  640. cpu = raw_smp_processor_id();
  641. ucb = per_cpu_ptr(uprobe_cpu_buffer, cpu);
  642. /*
  643. * Use per-cpu buffers for fastest access, but we might migrate
  644. * so the mutex makes sure we have sole access to it.
  645. */
  646. mutex_lock(&ucb->mutex);
  647. return ucb;
  648. }
  649. static void uprobe_buffer_put(struct uprobe_cpu_buffer *ucb)
  650. {
  651. mutex_unlock(&ucb->mutex);
  652. }
  653. static void __uprobe_trace_func(struct trace_uprobe *tu,
  654. unsigned long func, struct pt_regs *regs,
  655. struct uprobe_cpu_buffer *ucb, int dsize,
  656. struct trace_event_file *trace_file)
  657. {
  658. struct uprobe_trace_entry_head *entry;
  659. struct ring_buffer_event *event;
  660. struct ring_buffer *buffer;
  661. void *data;
  662. int size, esize;
  663. struct trace_event_call *call = &tu->tp.call;
  664. WARN_ON(call != trace_file->event_call);
  665. if (WARN_ON_ONCE(tu->tp.size + dsize > PAGE_SIZE))
  666. return;
  667. if (trace_trigger_soft_disabled(trace_file))
  668. return;
  669. esize = SIZEOF_TRACE_ENTRY(is_ret_probe(tu));
  670. size = esize + tu->tp.size + dsize;
  671. event = trace_event_buffer_lock_reserve(&buffer, trace_file,
  672. call->event.type, size, 0, 0);
  673. if (!event)
  674. return;
  675. entry = ring_buffer_event_data(event);
  676. if (is_ret_probe(tu)) {
  677. entry->vaddr[0] = func;
  678. entry->vaddr[1] = instruction_pointer(regs);
  679. data = DATAOF_TRACE_ENTRY(entry, true);
  680. } else {
  681. entry->vaddr[0] = instruction_pointer(regs);
  682. data = DATAOF_TRACE_ENTRY(entry, false);
  683. }
  684. memcpy(data, ucb->buf, tu->tp.size + dsize);
  685. event_trigger_unlock_commit(trace_file, buffer, event, entry, 0, 0);
  686. }
  687. /* uprobe handler */
  688. static int uprobe_trace_func(struct trace_uprobe *tu, struct pt_regs *regs,
  689. struct uprobe_cpu_buffer *ucb, int dsize)
  690. {
  691. struct event_file_link *link;
  692. if (is_ret_probe(tu))
  693. return 0;
  694. rcu_read_lock();
  695. list_for_each_entry_rcu(link, &tu->tp.files, list)
  696. __uprobe_trace_func(tu, 0, regs, ucb, dsize, link->file);
  697. rcu_read_unlock();
  698. return 0;
  699. }
  700. static void uretprobe_trace_func(struct trace_uprobe *tu, unsigned long func,
  701. struct pt_regs *regs,
  702. struct uprobe_cpu_buffer *ucb, int dsize)
  703. {
  704. struct event_file_link *link;
  705. rcu_read_lock();
  706. list_for_each_entry_rcu(link, &tu->tp.files, list)
  707. __uprobe_trace_func(tu, func, regs, ucb, dsize, link->file);
  708. rcu_read_unlock();
  709. }
  710. /* Event entry printers */
  711. static enum print_line_t
  712. print_uprobe_event(struct trace_iterator *iter, int flags, struct trace_event *event)
  713. {
  714. struct uprobe_trace_entry_head *entry;
  715. struct trace_seq *s = &iter->seq;
  716. struct trace_uprobe *tu;
  717. u8 *data;
  718. int i;
  719. entry = (struct uprobe_trace_entry_head *)iter->ent;
  720. tu = container_of(event, struct trace_uprobe, tp.call.event);
  721. if (is_ret_probe(tu)) {
  722. trace_seq_printf(s, "%s: (0x%lx <- 0x%lx)",
  723. trace_event_name(&tu->tp.call),
  724. entry->vaddr[1], entry->vaddr[0]);
  725. data = DATAOF_TRACE_ENTRY(entry, true);
  726. } else {
  727. trace_seq_printf(s, "%s: (0x%lx)",
  728. trace_event_name(&tu->tp.call),
  729. entry->vaddr[0]);
  730. data = DATAOF_TRACE_ENTRY(entry, false);
  731. }
  732. for (i = 0; i < tu->tp.nr_args; i++) {
  733. struct probe_arg *parg = &tu->tp.args[i];
  734. if (!parg->type->print(s, parg->name, data + parg->offset, entry))
  735. goto out;
  736. }
  737. trace_seq_putc(s, '\n');
  738. out:
  739. return trace_handle_return(s);
  740. }
  741. typedef bool (*filter_func_t)(struct uprobe_consumer *self,
  742. enum uprobe_filter_ctx ctx,
  743. struct mm_struct *mm);
  744. static int
  745. probe_event_enable(struct trace_uprobe *tu, struct trace_event_file *file,
  746. filter_func_t filter)
  747. {
  748. bool enabled = trace_probe_is_enabled(&tu->tp);
  749. struct event_file_link *link = NULL;
  750. int ret;
  751. if (file) {
  752. if (tu->tp.flags & TP_FLAG_PROFILE)
  753. return -EINTR;
  754. link = kmalloc(sizeof(*link), GFP_KERNEL);
  755. if (!link)
  756. return -ENOMEM;
  757. link->file = file;
  758. list_add_tail_rcu(&link->list, &tu->tp.files);
  759. tu->tp.flags |= TP_FLAG_TRACE;
  760. } else {
  761. if (tu->tp.flags & TP_FLAG_TRACE)
  762. return -EINTR;
  763. tu->tp.flags |= TP_FLAG_PROFILE;
  764. }
  765. WARN_ON(!uprobe_filter_is_empty(&tu->filter));
  766. if (enabled)
  767. return 0;
  768. ret = uprobe_buffer_enable();
  769. if (ret)
  770. goto err_flags;
  771. tu->consumer.filter = filter;
  772. ret = uprobe_register(tu->inode, tu->offset, &tu->consumer);
  773. if (ret)
  774. goto err_buffer;
  775. return 0;
  776. err_buffer:
  777. uprobe_buffer_disable();
  778. err_flags:
  779. if (file) {
  780. list_del(&link->list);
  781. kfree(link);
  782. tu->tp.flags &= ~TP_FLAG_TRACE;
  783. } else {
  784. tu->tp.flags &= ~TP_FLAG_PROFILE;
  785. }
  786. return ret;
  787. }
  788. static void
  789. probe_event_disable(struct trace_uprobe *tu, struct trace_event_file *file)
  790. {
  791. if (!trace_probe_is_enabled(&tu->tp))
  792. return;
  793. if (file) {
  794. struct event_file_link *link;
  795. link = find_event_file_link(&tu->tp, file);
  796. if (!link)
  797. return;
  798. list_del_rcu(&link->list);
  799. /* synchronize with u{,ret}probe_trace_func */
  800. synchronize_sched();
  801. kfree(link);
  802. if (!list_empty(&tu->tp.files))
  803. return;
  804. }
  805. WARN_ON(!uprobe_filter_is_empty(&tu->filter));
  806. uprobe_unregister(tu->inode, tu->offset, &tu->consumer);
  807. tu->tp.flags &= file ? ~TP_FLAG_TRACE : ~TP_FLAG_PROFILE;
  808. uprobe_buffer_disable();
  809. }
  810. static int uprobe_event_define_fields(struct trace_event_call *event_call)
  811. {
  812. int ret, i, size;
  813. struct uprobe_trace_entry_head field;
  814. struct trace_uprobe *tu = event_call->data;
  815. if (is_ret_probe(tu)) {
  816. DEFINE_FIELD(unsigned long, vaddr[0], FIELD_STRING_FUNC, 0);
  817. DEFINE_FIELD(unsigned long, vaddr[1], FIELD_STRING_RETIP, 0);
  818. size = SIZEOF_TRACE_ENTRY(true);
  819. } else {
  820. DEFINE_FIELD(unsigned long, vaddr[0], FIELD_STRING_IP, 0);
  821. size = SIZEOF_TRACE_ENTRY(false);
  822. }
  823. /* Set argument names as fields */
  824. for (i = 0; i < tu->tp.nr_args; i++) {
  825. struct probe_arg *parg = &tu->tp.args[i];
  826. ret = trace_define_field(event_call, parg->type->fmttype,
  827. parg->name, size + parg->offset,
  828. parg->type->size, parg->type->is_signed,
  829. FILTER_OTHER);
  830. if (ret)
  831. return ret;
  832. }
  833. return 0;
  834. }
  835. #ifdef CONFIG_PERF_EVENTS
  836. static bool
  837. __uprobe_perf_filter(struct trace_uprobe_filter *filter, struct mm_struct *mm)
  838. {
  839. struct perf_event *event;
  840. if (filter->nr_systemwide)
  841. return true;
  842. list_for_each_entry(event, &filter->perf_events, hw.tp_list) {
  843. if (event->hw.target->mm == mm)
  844. return true;
  845. }
  846. return false;
  847. }
  848. static inline bool
  849. uprobe_filter_event(struct trace_uprobe *tu, struct perf_event *event)
  850. {
  851. return __uprobe_perf_filter(&tu->filter, event->hw.target->mm);
  852. }
  853. static int uprobe_perf_close(struct trace_uprobe *tu, struct perf_event *event)
  854. {
  855. bool done;
  856. write_lock(&tu->filter.rwlock);
  857. if (event->hw.target) {
  858. list_del(&event->hw.tp_list);
  859. done = tu->filter.nr_systemwide ||
  860. (event->hw.target->flags & PF_EXITING) ||
  861. uprobe_filter_event(tu, event);
  862. } else {
  863. tu->filter.nr_systemwide--;
  864. done = tu->filter.nr_systemwide;
  865. }
  866. write_unlock(&tu->filter.rwlock);
  867. if (!done)
  868. return uprobe_apply(tu->inode, tu->offset, &tu->consumer, false);
  869. return 0;
  870. }
  871. static int uprobe_perf_open(struct trace_uprobe *tu, struct perf_event *event)
  872. {
  873. bool done;
  874. int err;
  875. write_lock(&tu->filter.rwlock);
  876. if (event->hw.target) {
  877. /*
  878. * event->parent != NULL means copy_process(), we can avoid
  879. * uprobe_apply(). current->mm must be probed and we can rely
  880. * on dup_mmap() which preserves the already installed bp's.
  881. *
  882. * attr.enable_on_exec means that exec/mmap will install the
  883. * breakpoints we need.
  884. */
  885. done = tu->filter.nr_systemwide ||
  886. event->parent || event->attr.enable_on_exec ||
  887. uprobe_filter_event(tu, event);
  888. list_add(&event->hw.tp_list, &tu->filter.perf_events);
  889. } else {
  890. done = tu->filter.nr_systemwide;
  891. tu->filter.nr_systemwide++;
  892. }
  893. write_unlock(&tu->filter.rwlock);
  894. err = 0;
  895. if (!done) {
  896. err = uprobe_apply(tu->inode, tu->offset, &tu->consumer, true);
  897. if (err)
  898. uprobe_perf_close(tu, event);
  899. }
  900. return err;
  901. }
  902. static bool uprobe_perf_filter(struct uprobe_consumer *uc,
  903. enum uprobe_filter_ctx ctx, struct mm_struct *mm)
  904. {
  905. struct trace_uprobe *tu;
  906. int ret;
  907. tu = container_of(uc, struct trace_uprobe, consumer);
  908. read_lock(&tu->filter.rwlock);
  909. ret = __uprobe_perf_filter(&tu->filter, mm);
  910. read_unlock(&tu->filter.rwlock);
  911. return ret;
  912. }
  913. static void __uprobe_perf_func(struct trace_uprobe *tu,
  914. unsigned long func, struct pt_regs *regs,
  915. struct uprobe_cpu_buffer *ucb, int dsize)
  916. {
  917. struct trace_event_call *call = &tu->tp.call;
  918. struct uprobe_trace_entry_head *entry;
  919. struct hlist_head *head;
  920. void *data;
  921. int size, esize;
  922. int rctx;
  923. if (bpf_prog_array_valid(call) && !trace_call_bpf(call, 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);