coresight-event.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/kernel.h>
  14. #include <linux/slab.h>
  15. #include <linux/init.h>
  16. #include <linux/sched.h>
  17. #include <linux/tracepoint.h>
  18. #include <linux/coresight.h>
  19. #include <trace/events/exception.h>
  20. static int event_abort_enable;
  21. static int event_abort_set(const char *val, struct kernel_param *kp);
  22. module_param_call(event_abort_enable, event_abort_set, param_get_int,
  23. &event_abort_enable, 0644);
  24. static void event_abort_user_fault(void *ignore,
  25. struct task_struct *task,
  26. unsigned long addr,
  27. unsigned int fsr)
  28. {
  29. coresight_abort();
  30. pr_debug("coresight_event: task_name: %s, addr: %lu, fsr:%u",
  31. (char *)task->comm, addr, fsr);
  32. }
  33. static void event_abort_undef_instr(void *ignore,
  34. struct pt_regs *regs,
  35. void *pc)
  36. {
  37. if (user_mode(regs)) {
  38. coresight_abort();
  39. pr_debug("coresight_event: pc: %p", pc);
  40. }
  41. }
  42. static void event_abort_unhandled_abort(void *ignore,
  43. struct pt_regs *regs,
  44. unsigned long addr,
  45. unsigned int fsr)
  46. {
  47. if (user_mode(regs)) {
  48. coresight_abort();
  49. pr_debug("coresight_event: addr: %lu, fsr:%u", addr, fsr);
  50. }
  51. }
  52. static int event_abort_register(void)
  53. {
  54. int ret;
  55. ret = register_trace_user_fault(event_abort_user_fault, NULL);
  56. if (ret)
  57. goto err_usr_fault;
  58. ret = register_trace_undef_instr(event_abort_undef_instr, NULL);
  59. if (ret)
  60. goto err_undef_instr;
  61. ret = register_trace_unhandled_abort(event_abort_unhandled_abort, NULL);
  62. if (ret)
  63. goto err_unhandled_abort;
  64. return 0;
  65. err_unhandled_abort:
  66. unregister_trace_undef_instr(event_abort_undef_instr, NULL);
  67. err_undef_instr:
  68. unregister_trace_user_fault(event_abort_user_fault, NULL);
  69. err_usr_fault:
  70. return ret;
  71. }
  72. static void event_abort_unregister(void)
  73. {
  74. unregister_trace_user_fault(event_abort_user_fault, NULL);
  75. unregister_trace_undef_instr(event_abort_undef_instr, NULL);
  76. unregister_trace_unhandled_abort(event_abort_unhandled_abort, NULL);
  77. }
  78. static int event_abort_set(const char *val, struct kernel_param *kp)
  79. {
  80. int ret;
  81. ret = param_set_int(val, kp);
  82. if (ret) {
  83. pr_err("coresight_event: error setting value %d\n", ret);
  84. return ret;
  85. }
  86. if (event_abort_enable)
  87. ret = event_abort_register();
  88. else
  89. event_abort_unregister();
  90. return ret;
  91. }
  92. static int __init event_init(void)
  93. {
  94. return 0;
  95. }
  96. module_init(event_init);
  97. static void __exit event_exit(void)
  98. {
  99. }
  100. module_exit(event_exit);
  101. MODULE_LICENSE("GPL v2");
  102. MODULE_DESCRIPTION("Coresight Event driver to abort tracing");