trace_uprobe.c 31 KB

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