Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Kprobe module for testing crash dumps |
| 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 as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | * |
| 18 | * Copyright (C) IBM Corporation, 2006 |
| 19 | * |
| 20 | * Author: Ankita Garg <ankita@in.ibm.com> |
| 21 | * |
| 22 | * This module induces system failures at predefined crashpoints to |
| 23 | * evaluate the reliability of crash dumps obtained using different dumping |
| 24 | * solutions. |
| 25 | * |
| 26 | * It is adapted from the Linux Kernel Dump Test Tool by |
| 27 | * Fernando Luis Vazquez Cao <http://lkdtt.sourceforge.net> |
| 28 | * |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 29 | * Debugfs support added by Simon Kagstrom <simon.kagstrom@netinsight.net> |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 30 | * |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 31 | * See Documentation/fault-injection/provoke-crashes.txt for instructions |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 32 | */ |
| 33 | |
| 34 | #include <linux/kernel.h> |
Randy Dunlap | 5d861d9 | 2006-11-02 22:07:06 -0800 | [diff] [blame] | 35 | #include <linux/fs.h> |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 36 | #include <linux/module.h> |
Randy Dunlap | 5d861d9 | 2006-11-02 22:07:06 -0800 | [diff] [blame] | 37 | #include <linux/buffer_head.h> |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 38 | #include <linux/kprobes.h> |
Randy Dunlap | 5d861d9 | 2006-11-02 22:07:06 -0800 | [diff] [blame] | 39 | #include <linux/list.h> |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 40 | #include <linux/init.h> |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 41 | #include <linux/interrupt.h> |
Randy Dunlap | 5d861d9 | 2006-11-02 22:07:06 -0800 | [diff] [blame] | 42 | #include <linux/hrtimer.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 43 | #include <linux/slab.h> |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 44 | #include <scsi/scsi_cmnd.h> |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 45 | #include <linux/debugfs.h> |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 46 | |
| 47 | #ifdef CONFIG_IDE |
| 48 | #include <linux/ide.h> |
| 49 | #endif |
| 50 | |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 51 | #define DEFAULT_COUNT 10 |
| 52 | #define REC_NUM_DEFAULT 10 |
| 53 | |
| 54 | enum cname { |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 55 | CN_INVALID, |
| 56 | CN_INT_HARDWARE_ENTRY, |
| 57 | CN_INT_HW_IRQ_EN, |
| 58 | CN_INT_TASKLET_ENTRY, |
| 59 | CN_FS_DEVRW, |
| 60 | CN_MEM_SWAPOUT, |
| 61 | CN_TIMERADD, |
| 62 | CN_SCSI_DISPATCH_CMD, |
| 63 | CN_IDE_CORE_CP, |
| 64 | CN_DIRECT, |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | enum ctype { |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 68 | CT_NONE, |
| 69 | CT_PANIC, |
| 70 | CT_BUG, |
Kees Cook | 65892723 | 2013-07-08 10:01:31 -0700 | [diff] [blame^] | 71 | CT_WARNING, |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 72 | CT_EXCEPTION, |
| 73 | CT_LOOP, |
| 74 | CT_OVERFLOW, |
| 75 | CT_CORRUPT_STACK, |
| 76 | CT_UNALIGNED_LOAD_STORE_WRITE, |
| 77 | CT_OVERWRITE_ALLOCATION, |
| 78 | CT_WRITE_AFTER_FREE, |
| 79 | CT_SOFTLOCKUP, |
| 80 | CT_HARDLOCKUP, |
| 81 | CT_HUNG_TASK, |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | static char* cp_name[] = { |
| 85 | "INT_HARDWARE_ENTRY", |
| 86 | "INT_HW_IRQ_EN", |
| 87 | "INT_TASKLET_ENTRY", |
| 88 | "FS_DEVRW", |
| 89 | "MEM_SWAPOUT", |
| 90 | "TIMERADD", |
| 91 | "SCSI_DISPATCH_CMD", |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 92 | "IDE_CORE_CP", |
| 93 | "DIRECT", |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | static char* cp_type[] = { |
| 97 | "PANIC", |
| 98 | "BUG", |
Kees Cook | 65892723 | 2013-07-08 10:01:31 -0700 | [diff] [blame^] | 99 | "WARNING", |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 100 | "EXCEPTION", |
| 101 | "LOOP", |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 102 | "OVERFLOW", |
| 103 | "CORRUPT_STACK", |
| 104 | "UNALIGNED_LOAD_STORE_WRITE", |
| 105 | "OVERWRITE_ALLOCATION", |
| 106 | "WRITE_AFTER_FREE", |
Frederic Weisbecker | a48223f | 2010-05-26 14:44:29 -0700 | [diff] [blame] | 107 | "SOFTLOCKUP", |
| 108 | "HARDLOCKUP", |
| 109 | "HUNG_TASK", |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | static struct jprobe lkdtm; |
| 113 | |
| 114 | static int lkdtm_parse_commandline(void); |
| 115 | static void lkdtm_handler(void); |
| 116 | |
Al Viro | ec1c620 | 2007-02-09 16:05:17 +0000 | [diff] [blame] | 117 | static char* cpoint_name; |
| 118 | static char* cpoint_type; |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 119 | static int cpoint_count = DEFAULT_COUNT; |
| 120 | static int recur_count = REC_NUM_DEFAULT; |
| 121 | |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 122 | static enum cname cpoint = CN_INVALID; |
| 123 | static enum ctype cptype = CT_NONE; |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 124 | static int count = DEFAULT_COUNT; |
Josh Hunt | aa2c96d | 2011-06-27 16:18:08 -0700 | [diff] [blame] | 125 | static DEFINE_SPINLOCK(count_lock); |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 126 | |
| 127 | module_param(recur_count, int, 0644); |
Randy Dunlap | 5d861d9 | 2006-11-02 22:07:06 -0800 | [diff] [blame] | 128 | MODULE_PARM_DESC(recur_count, " Recursion level for the stack overflow test, "\ |
| 129 | "default is 10"); |
Rusty Russell | dca4130 | 2010-08-11 23:04:21 -0600 | [diff] [blame] | 130 | module_param(cpoint_name, charp, 0444); |
Randy Dunlap | 5d861d9 | 2006-11-02 22:07:06 -0800 | [diff] [blame] | 131 | MODULE_PARM_DESC(cpoint_name, " Crash Point, where kernel is to be crashed"); |
Rusty Russell | dca4130 | 2010-08-11 23:04:21 -0600 | [diff] [blame] | 132 | module_param(cpoint_type, charp, 0444); |
Randy Dunlap | 5d861d9 | 2006-11-02 22:07:06 -0800 | [diff] [blame] | 133 | MODULE_PARM_DESC(cpoint_type, " Crash Point Type, action to be taken on "\ |
| 134 | "hitting the crash point"); |
| 135 | module_param(cpoint_count, int, 0644); |
| 136 | MODULE_PARM_DESC(cpoint_count, " Crash Point Count, number of times the "\ |
| 137 | "crash point is to be hit to trigger action"); |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 138 | |
Adrian Bunk | 2118116 | 2008-02-06 01:36:50 -0800 | [diff] [blame] | 139 | static unsigned int jp_do_irq(unsigned int irq) |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 140 | { |
| 141 | lkdtm_handler(); |
| 142 | jprobe_return(); |
| 143 | return 0; |
| 144 | } |
| 145 | |
Adrian Bunk | 2118116 | 2008-02-06 01:36:50 -0800 | [diff] [blame] | 146 | static irqreturn_t jp_handle_irq_event(unsigned int irq, |
| 147 | struct irqaction *action) |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 148 | { |
| 149 | lkdtm_handler(); |
| 150 | jprobe_return(); |
| 151 | return 0; |
| 152 | } |
| 153 | |
Adrian Bunk | 2118116 | 2008-02-06 01:36:50 -0800 | [diff] [blame] | 154 | static void jp_tasklet_action(struct softirq_action *a) |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 155 | { |
| 156 | lkdtm_handler(); |
| 157 | jprobe_return(); |
| 158 | } |
| 159 | |
Adrian Bunk | 2118116 | 2008-02-06 01:36:50 -0800 | [diff] [blame] | 160 | static void jp_ll_rw_block(int rw, int nr, struct buffer_head *bhs[]) |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 161 | { |
| 162 | lkdtm_handler(); |
| 163 | jprobe_return(); |
| 164 | } |
| 165 | |
| 166 | struct scan_control; |
| 167 | |
Adrian Bunk | 2118116 | 2008-02-06 01:36:50 -0800 | [diff] [blame] | 168 | static unsigned long jp_shrink_inactive_list(unsigned long max_scan, |
| 169 | struct zone *zone, |
| 170 | struct scan_control *sc) |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 171 | { |
| 172 | lkdtm_handler(); |
| 173 | jprobe_return(); |
| 174 | return 0; |
| 175 | } |
| 176 | |
Adrian Bunk | 2118116 | 2008-02-06 01:36:50 -0800 | [diff] [blame] | 177 | static int jp_hrtimer_start(struct hrtimer *timer, ktime_t tim, |
| 178 | const enum hrtimer_mode mode) |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 179 | { |
| 180 | lkdtm_handler(); |
| 181 | jprobe_return(); |
| 182 | return 0; |
| 183 | } |
| 184 | |
Adrian Bunk | 2118116 | 2008-02-06 01:36:50 -0800 | [diff] [blame] | 185 | static int jp_scsi_dispatch_cmd(struct scsi_cmnd *cmd) |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 186 | { |
| 187 | lkdtm_handler(); |
| 188 | jprobe_return(); |
| 189 | return 0; |
| 190 | } |
| 191 | |
| 192 | #ifdef CONFIG_IDE |
| 193 | int jp_generic_ide_ioctl(ide_drive_t *drive, struct file *file, |
| 194 | struct block_device *bdev, unsigned int cmd, |
| 195 | unsigned long arg) |
| 196 | { |
| 197 | lkdtm_handler(); |
| 198 | jprobe_return(); |
| 199 | return 0; |
| 200 | } |
| 201 | #endif |
| 202 | |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 203 | /* Return the crashpoint number or NONE if the name is invalid */ |
| 204 | static enum ctype parse_cp_type(const char *what, size_t count) |
| 205 | { |
| 206 | int i; |
| 207 | |
| 208 | for (i = 0; i < ARRAY_SIZE(cp_type); i++) { |
| 209 | if (!strcmp(what, cp_type[i])) |
| 210 | return i + 1; |
| 211 | } |
| 212 | |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 213 | return CT_NONE; |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | static const char *cp_type_to_str(enum ctype type) |
| 217 | { |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 218 | if (type == CT_NONE || type < 0 || type > ARRAY_SIZE(cp_type)) |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 219 | return "None"; |
| 220 | |
| 221 | return cp_type[type - 1]; |
| 222 | } |
| 223 | |
| 224 | static const char *cp_name_to_str(enum cname name) |
| 225 | { |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 226 | if (name == CN_INVALID || name < 0 || name > ARRAY_SIZE(cp_name)) |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 227 | return "INVALID"; |
| 228 | |
| 229 | return cp_name[name - 1]; |
| 230 | } |
| 231 | |
| 232 | |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 233 | static int lkdtm_parse_commandline(void) |
| 234 | { |
| 235 | int i; |
Josh Hunt | aa2c96d | 2011-06-27 16:18:08 -0700 | [diff] [blame] | 236 | unsigned long flags; |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 237 | |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 238 | if (cpoint_count < 1 || recur_count < 1) |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 239 | return -EINVAL; |
| 240 | |
Josh Hunt | aa2c96d | 2011-06-27 16:18:08 -0700 | [diff] [blame] | 241 | spin_lock_irqsave(&count_lock, flags); |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 242 | count = cpoint_count; |
Josh Hunt | aa2c96d | 2011-06-27 16:18:08 -0700 | [diff] [blame] | 243 | spin_unlock_irqrestore(&count_lock, flags); |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 244 | |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 245 | /* No special parameters */ |
| 246 | if (!cpoint_type && !cpoint_name) |
| 247 | return 0; |
| 248 | |
| 249 | /* Neither or both of these need to be set */ |
| 250 | if (!cpoint_type || !cpoint_name) |
| 251 | return -EINVAL; |
| 252 | |
| 253 | cptype = parse_cp_type(cpoint_type, strlen(cpoint_type)); |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 254 | if (cptype == CT_NONE) |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 255 | return -EINVAL; |
| 256 | |
| 257 | for (i = 0; i < ARRAY_SIZE(cp_name); i++) { |
| 258 | if (!strcmp(cpoint_name, cp_name[i])) { |
| 259 | cpoint = i + 1; |
| 260 | return 0; |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | /* Could not find a valid crash point */ |
| 265 | return -EINVAL; |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | static int recursive_loop(int a) |
| 269 | { |
| 270 | char buf[1024]; |
| 271 | |
| 272 | memset(buf,0xFF,1024); |
| 273 | recur_count--; |
| 274 | if (!recur_count) |
| 275 | return 0; |
| 276 | else |
| 277 | return recursive_loop(a); |
| 278 | } |
| 279 | |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 280 | static void lkdtm_do_action(enum ctype which) |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 281 | { |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 282 | switch (which) { |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 283 | case CT_PANIC: |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 284 | panic("dumptest"); |
| 285 | break; |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 286 | case CT_BUG: |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 287 | BUG(); |
| 288 | break; |
Kees Cook | 65892723 | 2013-07-08 10:01:31 -0700 | [diff] [blame^] | 289 | case CT_WARNING: |
| 290 | WARN_ON(1); |
| 291 | break; |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 292 | case CT_EXCEPTION: |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 293 | *((int *) 0) = 0; |
| 294 | break; |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 295 | case CT_LOOP: |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 296 | for (;;) |
| 297 | ; |
| 298 | break; |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 299 | case CT_OVERFLOW: |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 300 | (void) recursive_loop(0); |
| 301 | break; |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 302 | case CT_CORRUPT_STACK: { |
Kees Cook | 4f19828 | 2013-07-08 10:01:30 -0700 | [diff] [blame] | 303 | /* Make sure the compiler creates and uses an 8 char array. */ |
| 304 | volatile char data[8]; |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 305 | |
Kees Cook | 4f19828 | 2013-07-08 10:01:30 -0700 | [diff] [blame] | 306 | memset((void *)data, 0, 64); |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 307 | break; |
| 308 | } |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 309 | case CT_UNALIGNED_LOAD_STORE_WRITE: { |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 310 | static u8 data[5] __attribute__((aligned(4))) = {1, 2, |
| 311 | 3, 4, 5}; |
| 312 | u32 *p; |
| 313 | u32 val = 0x12345678; |
| 314 | |
| 315 | p = (u32 *)(data + 1); |
| 316 | if (*p == 0) |
| 317 | val = 0x87654321; |
| 318 | *p = val; |
| 319 | break; |
| 320 | } |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 321 | case CT_OVERWRITE_ALLOCATION: { |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 322 | size_t len = 1020; |
| 323 | u32 *data = kmalloc(len, GFP_KERNEL); |
| 324 | |
| 325 | data[1024 / sizeof(u32)] = 0x12345678; |
| 326 | kfree(data); |
| 327 | break; |
| 328 | } |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 329 | case CT_WRITE_AFTER_FREE: { |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 330 | size_t len = 1024; |
| 331 | u32 *data = kmalloc(len, GFP_KERNEL); |
| 332 | |
| 333 | kfree(data); |
| 334 | schedule(); |
| 335 | memset(data, 0x78, len); |
| 336 | break; |
| 337 | } |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 338 | case CT_SOFTLOCKUP: |
Frederic Weisbecker | a48223f | 2010-05-26 14:44:29 -0700 | [diff] [blame] | 339 | preempt_disable(); |
| 340 | for (;;) |
| 341 | cpu_relax(); |
| 342 | break; |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 343 | case CT_HARDLOCKUP: |
Frederic Weisbecker | a48223f | 2010-05-26 14:44:29 -0700 | [diff] [blame] | 344 | local_irq_disable(); |
| 345 | for (;;) |
| 346 | cpu_relax(); |
| 347 | break; |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 348 | case CT_HUNG_TASK: |
Frederic Weisbecker | a48223f | 2010-05-26 14:44:29 -0700 | [diff] [blame] | 349 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 350 | schedule(); |
| 351 | break; |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 352 | case CT_NONE: |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 353 | default: |
| 354 | break; |
| 355 | } |
| 356 | |
| 357 | } |
| 358 | |
| 359 | static void lkdtm_handler(void) |
| 360 | { |
Josh Hunt | aa2c96d | 2011-06-27 16:18:08 -0700 | [diff] [blame] | 361 | unsigned long flags; |
Cong Wang | 9261818 | 2012-02-03 15:37:15 -0800 | [diff] [blame] | 362 | bool do_it = false; |
Josh Hunt | aa2c96d | 2011-06-27 16:18:08 -0700 | [diff] [blame] | 363 | |
| 364 | spin_lock_irqsave(&count_lock, flags); |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 365 | count--; |
| 366 | printk(KERN_INFO "lkdtm: Crash point %s of type %s hit, trigger in %d rounds\n", |
| 367 | cp_name_to_str(cpoint), cp_type_to_str(cptype), count); |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 368 | |
| 369 | if (count == 0) { |
Cong Wang | 9261818 | 2012-02-03 15:37:15 -0800 | [diff] [blame] | 370 | do_it = true; |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 371 | count = cpoint_count; |
| 372 | } |
Josh Hunt | aa2c96d | 2011-06-27 16:18:08 -0700 | [diff] [blame] | 373 | spin_unlock_irqrestore(&count_lock, flags); |
Cong Wang | 9261818 | 2012-02-03 15:37:15 -0800 | [diff] [blame] | 374 | |
| 375 | if (do_it) |
| 376 | lkdtm_do_action(cptype); |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 377 | } |
| 378 | |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 379 | static int lkdtm_register_cpoint(enum cname which) |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 380 | { |
| 381 | int ret; |
| 382 | |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 383 | cpoint = CN_INVALID; |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 384 | if (lkdtm.entry != NULL) |
| 385 | unregister_jprobe(&lkdtm); |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 386 | |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 387 | switch (which) { |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 388 | case CN_DIRECT: |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 389 | lkdtm_do_action(cptype); |
| 390 | return 0; |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 391 | case CN_INT_HARDWARE_ENTRY: |
M. Mohan Kumar | f58f2fa | 2009-09-22 16:43:29 -0700 | [diff] [blame] | 392 | lkdtm.kp.symbol_name = "do_IRQ"; |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 393 | lkdtm.entry = (kprobe_opcode_t*) jp_do_irq; |
| 394 | break; |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 395 | case CN_INT_HW_IRQ_EN: |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 396 | lkdtm.kp.symbol_name = "handle_IRQ_event"; |
| 397 | lkdtm.entry = (kprobe_opcode_t*) jp_handle_irq_event; |
| 398 | break; |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 399 | case CN_INT_TASKLET_ENTRY: |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 400 | lkdtm.kp.symbol_name = "tasklet_action"; |
| 401 | lkdtm.entry = (kprobe_opcode_t*) jp_tasklet_action; |
| 402 | break; |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 403 | case CN_FS_DEVRW: |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 404 | lkdtm.kp.symbol_name = "ll_rw_block"; |
| 405 | lkdtm.entry = (kprobe_opcode_t*) jp_ll_rw_block; |
| 406 | break; |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 407 | case CN_MEM_SWAPOUT: |
Ankita Garg | 18a61e4 | 2006-11-05 23:52:07 -0800 | [diff] [blame] | 408 | lkdtm.kp.symbol_name = "shrink_inactive_list"; |
| 409 | lkdtm.entry = (kprobe_opcode_t*) jp_shrink_inactive_list; |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 410 | break; |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 411 | case CN_TIMERADD: |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 412 | lkdtm.kp.symbol_name = "hrtimer_start"; |
| 413 | lkdtm.entry = (kprobe_opcode_t*) jp_hrtimer_start; |
| 414 | break; |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 415 | case CN_SCSI_DISPATCH_CMD: |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 416 | lkdtm.kp.symbol_name = "scsi_dispatch_cmd"; |
| 417 | lkdtm.entry = (kprobe_opcode_t*) jp_scsi_dispatch_cmd; |
| 418 | break; |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 419 | case CN_IDE_CORE_CP: |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 420 | #ifdef CONFIG_IDE |
| 421 | lkdtm.kp.symbol_name = "generic_ide_ioctl"; |
| 422 | lkdtm.entry = (kprobe_opcode_t*) jp_generic_ide_ioctl; |
| 423 | #else |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 424 | printk(KERN_INFO "lkdtm: Crash point not available\n"); |
| 425 | return -EINVAL; |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 426 | #endif |
| 427 | break; |
| 428 | default: |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 429 | printk(KERN_INFO "lkdtm: Invalid Crash Point\n"); |
| 430 | return -EINVAL; |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 431 | } |
| 432 | |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 433 | cpoint = which; |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 434 | if ((ret = register_jprobe(&lkdtm)) < 0) { |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 435 | printk(KERN_INFO "lkdtm: Couldn't register jprobe\n"); |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 436 | cpoint = CN_INVALID; |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 437 | } |
| 438 | |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 439 | return ret; |
| 440 | } |
| 441 | |
| 442 | static ssize_t do_register_entry(enum cname which, struct file *f, |
| 443 | const char __user *user_buf, size_t count, loff_t *off) |
| 444 | { |
| 445 | char *buf; |
| 446 | int err; |
| 447 | |
| 448 | if (count >= PAGE_SIZE) |
| 449 | return -EINVAL; |
| 450 | |
| 451 | buf = (char *)__get_free_page(GFP_KERNEL); |
| 452 | if (!buf) |
| 453 | return -ENOMEM; |
| 454 | if (copy_from_user(buf, user_buf, count)) { |
| 455 | free_page((unsigned long) buf); |
| 456 | return -EFAULT; |
| 457 | } |
| 458 | /* NULL-terminate and remove enter */ |
| 459 | buf[count] = '\0'; |
| 460 | strim(buf); |
| 461 | |
| 462 | cptype = parse_cp_type(buf, count); |
| 463 | free_page((unsigned long) buf); |
| 464 | |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 465 | if (cptype == CT_NONE) |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 466 | return -EINVAL; |
| 467 | |
| 468 | err = lkdtm_register_cpoint(which); |
| 469 | if (err < 0) |
| 470 | return err; |
| 471 | |
| 472 | *off += count; |
| 473 | |
| 474 | return count; |
| 475 | } |
| 476 | |
| 477 | /* Generic read callback that just prints out the available crash types */ |
| 478 | static ssize_t lkdtm_debugfs_read(struct file *f, char __user *user_buf, |
| 479 | size_t count, loff_t *off) |
| 480 | { |
| 481 | char *buf; |
| 482 | int i, n, out; |
| 483 | |
| 484 | buf = (char *)__get_free_page(GFP_KERNEL); |
Alan Cox | 086ff4b | 2012-07-30 14:43:24 -0700 | [diff] [blame] | 485 | if (buf == NULL) |
| 486 | return -ENOMEM; |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 487 | |
| 488 | n = snprintf(buf, PAGE_SIZE, "Available crash types:\n"); |
| 489 | for (i = 0; i < ARRAY_SIZE(cp_type); i++) |
| 490 | n += snprintf(buf + n, PAGE_SIZE - n, "%s\n", cp_type[i]); |
| 491 | buf[n] = '\0'; |
| 492 | |
| 493 | out = simple_read_from_buffer(user_buf, count, off, |
| 494 | buf, n); |
| 495 | free_page((unsigned long) buf); |
| 496 | |
| 497 | return out; |
| 498 | } |
| 499 | |
| 500 | static int lkdtm_debugfs_open(struct inode *inode, struct file *file) |
| 501 | { |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 502 | return 0; |
| 503 | } |
| 504 | |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 505 | |
| 506 | static ssize_t int_hardware_entry(struct file *f, const char __user *buf, |
| 507 | size_t count, loff_t *off) |
| 508 | { |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 509 | return do_register_entry(CN_INT_HARDWARE_ENTRY, f, buf, count, off); |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | static ssize_t int_hw_irq_en(struct file *f, const char __user *buf, |
| 513 | size_t count, loff_t *off) |
| 514 | { |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 515 | return do_register_entry(CN_INT_HW_IRQ_EN, f, buf, count, off); |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | static ssize_t int_tasklet_entry(struct file *f, const char __user *buf, |
| 519 | size_t count, loff_t *off) |
| 520 | { |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 521 | return do_register_entry(CN_INT_TASKLET_ENTRY, f, buf, count, off); |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | static ssize_t fs_devrw_entry(struct file *f, const char __user *buf, |
| 525 | size_t count, loff_t *off) |
| 526 | { |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 527 | return do_register_entry(CN_FS_DEVRW, f, buf, count, off); |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | static ssize_t mem_swapout_entry(struct file *f, const char __user *buf, |
| 531 | size_t count, loff_t *off) |
| 532 | { |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 533 | return do_register_entry(CN_MEM_SWAPOUT, f, buf, count, off); |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | static ssize_t timeradd_entry(struct file *f, const char __user *buf, |
| 537 | size_t count, loff_t *off) |
| 538 | { |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 539 | return do_register_entry(CN_TIMERADD, f, buf, count, off); |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | static ssize_t scsi_dispatch_cmd_entry(struct file *f, |
| 543 | const char __user *buf, size_t count, loff_t *off) |
| 544 | { |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 545 | return do_register_entry(CN_SCSI_DISPATCH_CMD, f, buf, count, off); |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | static ssize_t ide_core_cp_entry(struct file *f, const char __user *buf, |
| 549 | size_t count, loff_t *off) |
| 550 | { |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 551 | return do_register_entry(CN_IDE_CORE_CP, f, buf, count, off); |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | /* Special entry to just crash directly. Available without KPROBEs */ |
| 555 | static ssize_t direct_entry(struct file *f, const char __user *user_buf, |
| 556 | size_t count, loff_t *off) |
| 557 | { |
| 558 | enum ctype type; |
| 559 | char *buf; |
| 560 | |
| 561 | if (count >= PAGE_SIZE) |
| 562 | return -EINVAL; |
| 563 | if (count < 1) |
| 564 | return -EINVAL; |
| 565 | |
| 566 | buf = (char *)__get_free_page(GFP_KERNEL); |
| 567 | if (!buf) |
| 568 | return -ENOMEM; |
| 569 | if (copy_from_user(buf, user_buf, count)) { |
| 570 | free_page((unsigned long) buf); |
| 571 | return -EFAULT; |
| 572 | } |
| 573 | /* NULL-terminate and remove enter */ |
| 574 | buf[count] = '\0'; |
| 575 | strim(buf); |
| 576 | |
| 577 | type = parse_cp_type(buf, count); |
| 578 | free_page((unsigned long) buf); |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 579 | if (type == CT_NONE) |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 580 | return -EINVAL; |
| 581 | |
| 582 | printk(KERN_INFO "lkdtm: Performing direct entry %s\n", |
| 583 | cp_type_to_str(type)); |
| 584 | lkdtm_do_action(type); |
| 585 | *off += count; |
| 586 | |
| 587 | return count; |
| 588 | } |
| 589 | |
| 590 | struct crash_entry { |
| 591 | const char *name; |
| 592 | const struct file_operations fops; |
| 593 | }; |
| 594 | |
| 595 | static const struct crash_entry crash_entries[] = { |
| 596 | {"DIRECT", {.read = lkdtm_debugfs_read, |
Arnd Bergmann | 05271ec | 2010-07-06 19:10:26 +0200 | [diff] [blame] | 597 | .llseek = generic_file_llseek, |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 598 | .open = lkdtm_debugfs_open, |
| 599 | .write = direct_entry} }, |
| 600 | {"INT_HARDWARE_ENTRY", {.read = lkdtm_debugfs_read, |
Arnd Bergmann | 05271ec | 2010-07-06 19:10:26 +0200 | [diff] [blame] | 601 | .llseek = generic_file_llseek, |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 602 | .open = lkdtm_debugfs_open, |
| 603 | .write = int_hardware_entry} }, |
| 604 | {"INT_HW_IRQ_EN", {.read = lkdtm_debugfs_read, |
Arnd Bergmann | 05271ec | 2010-07-06 19:10:26 +0200 | [diff] [blame] | 605 | .llseek = generic_file_llseek, |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 606 | .open = lkdtm_debugfs_open, |
| 607 | .write = int_hw_irq_en} }, |
| 608 | {"INT_TASKLET_ENTRY", {.read = lkdtm_debugfs_read, |
Arnd Bergmann | 05271ec | 2010-07-06 19:10:26 +0200 | [diff] [blame] | 609 | .llseek = generic_file_llseek, |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 610 | .open = lkdtm_debugfs_open, |
| 611 | .write = int_tasklet_entry} }, |
| 612 | {"FS_DEVRW", {.read = lkdtm_debugfs_read, |
Arnd Bergmann | 05271ec | 2010-07-06 19:10:26 +0200 | [diff] [blame] | 613 | .llseek = generic_file_llseek, |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 614 | .open = lkdtm_debugfs_open, |
| 615 | .write = fs_devrw_entry} }, |
| 616 | {"MEM_SWAPOUT", {.read = lkdtm_debugfs_read, |
Arnd Bergmann | 05271ec | 2010-07-06 19:10:26 +0200 | [diff] [blame] | 617 | .llseek = generic_file_llseek, |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 618 | .open = lkdtm_debugfs_open, |
| 619 | .write = mem_swapout_entry} }, |
| 620 | {"TIMERADD", {.read = lkdtm_debugfs_read, |
Arnd Bergmann | 05271ec | 2010-07-06 19:10:26 +0200 | [diff] [blame] | 621 | .llseek = generic_file_llseek, |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 622 | .open = lkdtm_debugfs_open, |
| 623 | .write = timeradd_entry} }, |
| 624 | {"SCSI_DISPATCH_CMD", {.read = lkdtm_debugfs_read, |
Arnd Bergmann | 05271ec | 2010-07-06 19:10:26 +0200 | [diff] [blame] | 625 | .llseek = generic_file_llseek, |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 626 | .open = lkdtm_debugfs_open, |
| 627 | .write = scsi_dispatch_cmd_entry} }, |
| 628 | {"IDE_CORE_CP", {.read = lkdtm_debugfs_read, |
Arnd Bergmann | 05271ec | 2010-07-06 19:10:26 +0200 | [diff] [blame] | 629 | .llseek = generic_file_llseek, |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 630 | .open = lkdtm_debugfs_open, |
| 631 | .write = ide_core_cp_entry} }, |
| 632 | }; |
| 633 | |
| 634 | static struct dentry *lkdtm_debugfs_root; |
| 635 | |
| 636 | static int __init lkdtm_module_init(void) |
| 637 | { |
| 638 | int ret = -EINVAL; |
| 639 | int n_debugfs_entries = 1; /* Assume only the direct entry */ |
| 640 | int i; |
| 641 | |
| 642 | /* Register debugfs interface */ |
| 643 | lkdtm_debugfs_root = debugfs_create_dir("provoke-crash", NULL); |
| 644 | if (!lkdtm_debugfs_root) { |
| 645 | printk(KERN_ERR "lkdtm: creating root dir failed\n"); |
| 646 | return -ENODEV; |
| 647 | } |
| 648 | |
| 649 | #ifdef CONFIG_KPROBES |
| 650 | n_debugfs_entries = ARRAY_SIZE(crash_entries); |
| 651 | #endif |
| 652 | |
| 653 | for (i = 0; i < n_debugfs_entries; i++) { |
| 654 | const struct crash_entry *cur = &crash_entries[i]; |
| 655 | struct dentry *de; |
| 656 | |
| 657 | de = debugfs_create_file(cur->name, 0644, lkdtm_debugfs_root, |
| 658 | NULL, &cur->fops); |
| 659 | if (de == NULL) { |
| 660 | printk(KERN_ERR "lkdtm: could not create %s\n", |
| 661 | cur->name); |
| 662 | goto out_err; |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | if (lkdtm_parse_commandline() == -EINVAL) { |
| 667 | printk(KERN_INFO "lkdtm: Invalid command\n"); |
| 668 | goto out_err; |
| 669 | } |
| 670 | |
Namhyung Kim | 93e2f58 | 2010-10-26 14:22:40 -0700 | [diff] [blame] | 671 | if (cpoint != CN_INVALID && cptype != CT_NONE) { |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 672 | ret = lkdtm_register_cpoint(cpoint); |
| 673 | if (ret < 0) { |
| 674 | printk(KERN_INFO "lkdtm: Invalid crash point %d\n", |
| 675 | cpoint); |
| 676 | goto out_err; |
| 677 | } |
| 678 | printk(KERN_INFO "lkdtm: Crash point %s of type %s registered\n", |
| 679 | cpoint_name, cpoint_type); |
| 680 | } else { |
| 681 | printk(KERN_INFO "lkdtm: No crash points registered, enable through debugfs\n"); |
| 682 | } |
| 683 | |
| 684 | return 0; |
| 685 | |
| 686 | out_err: |
| 687 | debugfs_remove_recursive(lkdtm_debugfs_root); |
| 688 | return ret; |
| 689 | } |
| 690 | |
Adrian Bunk | 2118116 | 2008-02-06 01:36:50 -0800 | [diff] [blame] | 691 | static void __exit lkdtm_module_exit(void) |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 692 | { |
Simon Kagstrom | 0347af4 | 2010-03-05 13:42:49 -0800 | [diff] [blame] | 693 | debugfs_remove_recursive(lkdtm_debugfs_root); |
| 694 | |
| 695 | unregister_jprobe(&lkdtm); |
| 696 | printk(KERN_INFO "lkdtm: Crash point unregistered\n"); |
Ankita Garg | 8bb31b9 | 2006-10-02 02:17:36 -0700 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | module_init(lkdtm_module_init); |
| 700 | module_exit(lkdtm_module_exit); |
| 701 | |
| 702 | MODULE_LICENSE("GPL"); |