Pushkar Joshi | 61af718 | 2012-09-12 14:29:23 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2012, 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 | |
| 13 | /* |
| 14 | * DLKM to register a callback with a ftrace event |
| 15 | */ |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/slab.h> |
| 19 | #include <linux/init.h> |
| 20 | #include <linux/sched.h> |
| 21 | #include <linux/tracepoint.h> |
| 22 | #include <linux/coresight.h> |
| 23 | |
| 24 | #include <trace/events/exception.h> |
| 25 | |
| 26 | static void abort_coresight_tracing(void *ignore, struct task_struct *task,\ |
| 27 | unsigned long addr, unsigned int fsr) |
| 28 | { |
| 29 | coresight_abort(); |
| 30 | pr_debug("control_trace: task_name: %s, addr: %lu, fsr:%u",\ |
| 31 | (char *)task->comm, addr, fsr); |
| 32 | } |
| 33 | |
| 34 | static void abort_tracing_undef_instr(void *ignore, struct pt_regs *regs,\ |
| 35 | void *pc) |
| 36 | { |
| 37 | if (user_mode(regs)) { |
| 38 | coresight_abort(); |
| 39 | pr_debug("control_trace: pc: %p", pc); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | static int __init control_trace_init(void) |
| 44 | { |
| 45 | int ret_user_fault, ret_undef_instr; |
| 46 | ret_user_fault = register_trace_user_fault(abort_coresight_tracing,\ |
| 47 | NULL); |
| 48 | ret_undef_instr = register_trace_undef_instr(abort_tracing_undef_instr,\ |
| 49 | NULL); |
| 50 | if (ret_user_fault != 0 || ret_undef_instr != 0) { |
| 51 | pr_info("control_trace: Module Not Registered\n"); |
| 52 | return (ret_user_fault < 0 ?\ |
| 53 | ret_user_fault : ret_undef_instr); |
| 54 | } |
| 55 | pr_info("control_trace: Module Registered\n"); |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | module_init(control_trace_init); |
| 60 | |
| 61 | static void __exit control_trace_exit(void) |
| 62 | { |
| 63 | unregister_trace_user_fault(abort_coresight_tracing, NULL); |
| 64 | unregister_trace_undef_instr(abort_tracing_undef_instr, NULL); |
| 65 | pr_info("control_trace: Module Removed\n"); |
| 66 | } |
| 67 | |
| 68 | module_exit(control_trace_exit); |
| 69 | |
| 70 | MODULE_LICENSE("GPL v2"); |
| 71 | MODULE_DESCRIPTION("Kernel Module to abort tracing"); |