aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc/lkdtm.c
diff options
context:
space:
mode:
authorAnkita Garg <ankita@in.ibm.com>2006-10-02 05:17:36 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-10-02 10:57:16 -0400
commit8bb31b9d5340ed3dfef45d322f59fcf18a0d598b (patch)
treeb0c225ebc5ed8ca6b0ad3c10b09f715d9ad67ad9 /drivers/misc/lkdtm.c
parent99219a3fbc2dcf2eaa954f7b2ac27299fd7894cd (diff)
[PATCH] Linux Kernel Dump Test Module
A simple module to test Linux Kernel Dump mechanism. This module uses jprobes to install/activate pre-defined crash points. At different crash points, various types of crashing scenarios are created like a BUG(), panic(), exception, recursive loop and stack overflow. The user can activate a crash point with specific type by providing parameters at the time of module insertion. Please see the file header for usage information. The module is based on the Linux Kernel Dump Test Tool by Fernando <http://lkdtt.sourceforge.net>. This module could be merged with mainline. Jprobes is used here so that the context in which crash point is hit, could be maintained. This implements all the crash points as done by LKDTT except the one in the middle of tasklet_action(). Signed-off-by: Ankita Garg <ankita@in.ibm.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers/misc/lkdtm.c')
-rw-r--r--drivers/misc/lkdtm.c342
1 files changed, 342 insertions, 0 deletions
diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c
new file mode 100644
index 000000000000..e689ee94ac3d
--- /dev/null
+++ b/drivers/misc/lkdtm.c
@@ -0,0 +1,342 @@
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 *
29 * Usage : insmod lkdtm.ko [recur_count={>0}] cpoint_name=<> cpoint_type=<>
30 * [cpoint_count={>0}]
31 *
32 * recur_count : Recursion level for the stack overflow test. Default is 10.
33 *
34 * cpoint_name : Crash point where the kernel is to be crashed. It can be
35 * one of INT_HARDWARE_ENTRY, INT_HW_IRQ_EN, INT_TASKLET_ENTRY,
36 * FS_DEVRW, MEM_SWAPOUT, TIMERADD, SCSI_DISPATCH_CMD,
37 * IDE_CORE_CP
38 *
39 * cpoint_type : Indicates the action to be taken on hitting the crash point.
40 * It can be one of PANIC, BUG, EXCEPTION, LOOP, OVERFLOW
41 *
42 * cpoint_count : Indicates the number of times the crash point is to be hit
43 * to trigger an action. The default is 10.
44 */
45
46#include <linux/kernel.h>
47#include <linux/module.h>
48#include <linux/kprobes.h>
49#include <linux/kallsyms.h>
50#include <linux/init.h>
51#include <linux/irq.h>
52#include <linux/interrupt.h>
53#include <scsi/scsi_cmnd.h>
54
55#ifdef CONFIG_IDE
56#include <linux/ide.h>
57#endif
58
59#define NUM_CPOINTS 8
60#define NUM_CPOINT_TYPES 5
61#define DEFAULT_COUNT 10
62#define REC_NUM_DEFAULT 10
63
64enum cname {
65 INVALID,
66 INT_HARDWARE_ENTRY,
67 INT_HW_IRQ_EN,
68 INT_TASKLET_ENTRY,
69 FS_DEVRW,
70 MEM_SWAPOUT,
71 TIMERADD,
72 SCSI_DISPATCH_CMD,
73 IDE_CORE_CP
74};
75
76enum ctype {
77 NONE,
78 PANIC,
79 BUG,
80 EXCEPTION,
81 LOOP,
82 OVERFLOW
83};
84
85static char* cp_name[] = {
86 "INT_HARDWARE_ENTRY",
87 "INT_HW_IRQ_EN",
88 "INT_TASKLET_ENTRY",
89 "FS_DEVRW",
90 "MEM_SWAPOUT",
91 "TIMERADD",
92 "SCSI_DISPATCH_CMD",
93 "IDE_CORE_CP"
94};
95
96static char* cp_type[] = {
97 "PANIC",
98 "BUG",
99 "EXCEPTION",
100 "LOOP",
101 "OVERFLOW"
102};
103
104static struct jprobe lkdtm;
105
106static int lkdtm_parse_commandline(void);
107static void lkdtm_handler(void);
108
109static char* cpoint_name = INVALID;
110static char* cpoint_type = NONE;
111static int cpoint_count = DEFAULT_COUNT;
112static int recur_count = REC_NUM_DEFAULT;
113
114static enum cname cpoint = INVALID;
115static enum ctype cptype = NONE;
116static int count = DEFAULT_COUNT;
117
118module_param(recur_count, int, 0644);
119MODULE_PARM_DESC(recur_count, "Recurcion level for the stack overflow test,\
120 default is 10");
121module_param(cpoint_name, charp, 0644);
122MODULE_PARM_DESC(cpoint_name, "Crash Point, where kernel is to be crashed");
123module_param(cpoint_type, charp, 06444);
124MODULE_PARM_DESC(cpoint_type, "Crash Point Type, action to be taken on\
125 hitting the crash point");
126module_param(cpoint_count, int, 06444);
127MODULE_PARM_DESC(cpoint_count, "Crash Point Count, number of times the \
128 crash point is to be hit to trigger action");
129
130unsigned int jp_do_irq(unsigned int irq, struct pt_regs *regs)
131{
132 lkdtm_handler();
133 jprobe_return();
134 return 0;
135}
136
137irqreturn_t jp_handle_irq_event(unsigned int irq, struct pt_regs *regs,
138 struct irqaction *action)
139{
140 lkdtm_handler();
141 jprobe_return();
142 return 0;
143}
144
145void jp_tasklet_action(struct softirq_action *a)
146{
147 lkdtm_handler();
148 jprobe_return();
149}
150
151void jp_ll_rw_block(int rw, int nr, struct buffer_head *bhs[])
152{
153 lkdtm_handler();
154 jprobe_return();
155}
156
157struct scan_control;
158
159unsigned long jp_shrink_page_list(struct list_head *page_list,
160 struct scan_control *sc)
161{
162 lkdtm_handler();
163 jprobe_return();
164 return 0;
165}
166
167int jp_hrtimer_start(struct hrtimer *timer, ktime_t tim,
168 const enum hrtimer_mode mode)
169{
170 lkdtm_handler();
171 jprobe_return();
172 return 0;
173}
174
175int jp_scsi_dispatch_cmd(struct scsi_cmnd *cmd)
176{
177 lkdtm_handler();
178 jprobe_return();
179 return 0;
180}
181
182#ifdef CONFIG_IDE
183int jp_generic_ide_ioctl(ide_drive_t *drive, struct file *file,
184 struct block_device *bdev, unsigned int cmd,
185 unsigned long arg)
186{
187 lkdtm_handler();
188 jprobe_return();
189 return 0;
190}
191#endif
192
193static int lkdtm_parse_commandline(void)
194{
195 int i;
196
197 if (cpoint_name == INVALID || cpoint_type == NONE ||
198 cpoint_count < 1 || recur_count < 1)
199 return -EINVAL;
200
201 for (i = 0; i < NUM_CPOINTS; ++i) {
202 if (!strcmp(cpoint_name, cp_name[i])) {
203 cpoint = i + 1;
204 break;
205 }
206 }
207
208 for (i = 0; i < NUM_CPOINT_TYPES; ++i) {
209 if (!strcmp(cpoint_type, cp_type[i])) {
210 cptype = i + 1;
211 break;
212 }
213 }
214
215 if (cpoint == INVALID || cptype == NONE)
216 return -EINVAL;
217
218 count = cpoint_count;
219
220 return 0;
221}
222
223static int recursive_loop(int a)
224{
225 char buf[1024];
226
227 memset(buf,0xFF,1024);
228 recur_count--;
229 if (!recur_count)
230 return 0;
231 else
232 return recursive_loop(a);
233}
234
235void lkdtm_handler(void)
236{
237 printk(KERN_INFO "lkdtm : Crash point %s of type %s hit\n",
238 cpoint_name, cpoint_type);
239 --count;
240
241 if (count == 0) {
242 switch (cptype) {
243 case NONE:
244 break;
245 case PANIC:
246 printk(KERN_INFO "lkdtm : PANIC\n");
247 panic("dumptest");
248 break;
249 case BUG:
250 printk(KERN_INFO "lkdtm : BUG\n");
251 BUG();
252 break;
253 case EXCEPTION:
254 printk(KERN_INFO "lkdtm : EXCEPTION\n");
255 *((int *) 0) = 0;
256 break;
257 case LOOP:
258 printk(KERN_INFO "lkdtm : LOOP\n");
259 for (;;);
260 break;
261 case OVERFLOW:
262 printk(KERN_INFO "lkdtm : OVERFLOW\n");
263 (void) recursive_loop(0);
264 break;
265 default:
266 break;
267 }
268 count = cpoint_count;
269 }
270}
271
272int lkdtm_module_init(void)
273{
274 int ret;
275
276 if (lkdtm_parse_commandline() == -EINVAL) {
277 printk(KERN_INFO "lkdtm : Invalid command\n");
278 return -EINVAL;
279 }
280
281 switch (cpoint) {
282 case INT_HARDWARE_ENTRY:
283 lkdtm.kp.symbol_name = "__do_IRQ";
284 lkdtm.entry = (kprobe_opcode_t*) jp_do_irq;
285 break;
286 case INT_HW_IRQ_EN:
287 lkdtm.kp.symbol_name = "handle_IRQ_event";
288 lkdtm.entry = (kprobe_opcode_t*) jp_handle_irq_event;
289 break;
290 case INT_TASKLET_ENTRY:
291 lkdtm.kp.symbol_name = "tasklet_action";
292 lkdtm.entry = (kprobe_opcode_t*) jp_tasklet_action;
293 break;
294 case FS_DEVRW:
295 lkdtm.kp.symbol_name = "ll_rw_block";
296 lkdtm.entry = (kprobe_opcode_t*) jp_ll_rw_block;
297 break;
298 case MEM_SWAPOUT:
299 lkdtm.kp.symbol_name = "shrink_page_list";
300 lkdtm.entry = (kprobe_opcode_t*) jp_shrink_page_list;
301 break;
302 case TIMERADD:
303 lkdtm.kp.symbol_name = "hrtimer_start";
304 lkdtm.entry = (kprobe_opcode_t*) jp_hrtimer_start;
305 break;
306 case SCSI_DISPATCH_CMD:
307 lkdtm.kp.symbol_name = "scsi_dispatch_cmd";
308 lkdtm.entry = (kprobe_opcode_t*) jp_scsi_dispatch_cmd;
309 break;
310 case IDE_CORE_CP:
311#ifdef CONFIG_IDE
312 lkdtm.kp.symbol_name = "generic_ide_ioctl";
313 lkdtm.entry = (kprobe_opcode_t*) jp_generic_ide_ioctl;
314#else
315 printk(KERN_INFO "lkdtm : Crash point not available\n");
316#endif
317 break;
318 default:
319 printk(KERN_INFO "lkdtm : Invalid Crash Point\n");
320 break;
321 }
322
323 if ((ret = register_jprobe(&lkdtm)) < 0) {
324 printk(KERN_INFO "lkdtm : Couldn't register jprobe\n");
325 return ret;
326 }
327
328 printk(KERN_INFO "lkdtm : Crash point %s of type %s registered\n",
329 cpoint_name, cpoint_type);
330 return 0;
331}
332
333void lkdtm_module_exit(void)
334{
335 unregister_jprobe(&lkdtm);
336 printk(KERN_INFO "lkdtm : Crash point unregistered\n");
337}
338
339module_init(lkdtm_module_init);
340module_exit(lkdtm_module_exit);
341
342MODULE_LICENSE("GPL");