xref: /aosp_15_r20/external/ltp/testcases/kdump/lib/lkdtm/lkdtm.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker /*
2*49cdfc7eSAndroid Build Coastguard Worker  * Kprobe module for testing crash dumps
3*49cdfc7eSAndroid Build Coastguard Worker  *
4*49cdfc7eSAndroid Build Coastguard Worker  * This program is free software; you can redistribute it and/or modify
5*49cdfc7eSAndroid Build Coastguard Worker  * it under the terms of the GNU General Public License as published by
6*49cdfc7eSAndroid Build Coastguard Worker  * the Free Software Foundation; either version 2 of the License, or
7*49cdfc7eSAndroid Build Coastguard Worker  * (at your option) any later version.
8*49cdfc7eSAndroid Build Coastguard Worker  *
9*49cdfc7eSAndroid Build Coastguard Worker  * This program is distributed in the hope that it will be useful,
10*49cdfc7eSAndroid Build Coastguard Worker  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11*49cdfc7eSAndroid Build Coastguard Worker  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12*49cdfc7eSAndroid Build Coastguard Worker  * GNU General Public License for more details.
13*49cdfc7eSAndroid Build Coastguard Worker  *
14*49cdfc7eSAndroid Build Coastguard Worker  * You should have received a copy of the GNU General Public License
15*49cdfc7eSAndroid Build Coastguard Worker  * along with this program; if not, write to the Free Software
16*49cdfc7eSAndroid Build Coastguard Worker  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17*49cdfc7eSAndroid Build Coastguard Worker  *
18*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (C) IBM Corporation, 2006
19*49cdfc7eSAndroid Build Coastguard Worker  *
20*49cdfc7eSAndroid Build Coastguard Worker  * Author: Ankita Garg <[email protected]>
21*49cdfc7eSAndroid Build Coastguard Worker  *         Sachin Sant <[email protected]>
22*49cdfc7eSAndroid Build Coastguard Worker  *         Cai Qian <[email protected]>
23*49cdfc7eSAndroid Build Coastguard Worker  *
24*49cdfc7eSAndroid Build Coastguard Worker  * This module induces system failures at predefined crashpoints to
25*49cdfc7eSAndroid Build Coastguard Worker  * evaluate the reliability of crash dumps obtained using different dumping
26*49cdfc7eSAndroid Build Coastguard Worker  * solutions.
27*49cdfc7eSAndroid Build Coastguard Worker  *
28*49cdfc7eSAndroid Build Coastguard Worker  * It is adapted from the Linux Kernel Dump Test Tool by
29*49cdfc7eSAndroid Build Coastguard Worker  * Fernando Luis Vazquez Cao <http://lkdtt.sourceforge.net>
30*49cdfc7eSAndroid Build Coastguard Worker  *
31*49cdfc7eSAndroid Build Coastguard Worker  * Usage :  insmod lkdtm.ko [recur_count={>0}] cpoint_name=<> cpoint_type=<>
32*49cdfc7eSAndroid Build Coastguard Worker  *							[cpoint_count={>0}]
33*49cdfc7eSAndroid Build Coastguard Worker  *
34*49cdfc7eSAndroid Build Coastguard Worker  * recur_count : Recursion level for the stack overflow test. Default is 10.
35*49cdfc7eSAndroid Build Coastguard Worker  *
36*49cdfc7eSAndroid Build Coastguard Worker  * cpoint_name : Crash point where the kernel is to be crashed. It can be
37*49cdfc7eSAndroid Build Coastguard Worker  *		 one of INT_HARDWARE_ENTRY, INT_HW_IRQ_EN, INT_TASKLET_ENTRY,
38*49cdfc7eSAndroid Build Coastguard Worker  *		 FS_DEVRW, MEM_SWAPOUT, TIMERADD, SCSI_DISPATCH_CMD,
39*49cdfc7eSAndroid Build Coastguard Worker  *		 IDE_CORE_CP
40*49cdfc7eSAndroid Build Coastguard Worker  *
41*49cdfc7eSAndroid Build Coastguard Worker  * cpoint_type : Indicates the action to be taken on hitting the crash point.
42*49cdfc7eSAndroid Build Coastguard Worker  *		 It can be one of PANIC, BUG, EXCEPTION, LOOP, OVERFLOW
43*49cdfc7eSAndroid Build Coastguard Worker  *
44*49cdfc7eSAndroid Build Coastguard Worker  * cpoint_count : Indicates the number of times the crash point is to be hit
45*49cdfc7eSAndroid Build Coastguard Worker  *		  to trigger an action. The default is 10.
46*49cdfc7eSAndroid Build Coastguard Worker  */
47*49cdfc7eSAndroid Build Coastguard Worker 
48*49cdfc7eSAndroid Build Coastguard Worker #include <linux/kernel.h>
49*49cdfc7eSAndroid Build Coastguard Worker #include <linux/fs.h>
50*49cdfc7eSAndroid Build Coastguard Worker #include <linux/module.h>
51*49cdfc7eSAndroid Build Coastguard Worker #include <linux/buffer_head.h>
52*49cdfc7eSAndroid Build Coastguard Worker #include <linux/kprobes.h>
53*49cdfc7eSAndroid Build Coastguard Worker #include <linux/list.h>
54*49cdfc7eSAndroid Build Coastguard Worker #include <linux/init.h>
55*49cdfc7eSAndroid Build Coastguard Worker #include <linux/interrupt.h>
56*49cdfc7eSAndroid Build Coastguard Worker #include <linux/hrtimer.h>
57*49cdfc7eSAndroid Build Coastguard Worker #include <scsi/scsi_cmnd.h>
58*49cdfc7eSAndroid Build Coastguard Worker #include <linux/version.h>
59*49cdfc7eSAndroid Build Coastguard Worker #include <linux/kallsyms.h>
60*49cdfc7eSAndroid Build Coastguard Worker 
61*49cdfc7eSAndroid Build Coastguard Worker #ifdef CONFIG_IDE
62*49cdfc7eSAndroid Build Coastguard Worker #include <linux/ide.h>
63*49cdfc7eSAndroid Build Coastguard Worker #endif
64*49cdfc7eSAndroid Build Coastguard Worker 
65*49cdfc7eSAndroid Build Coastguard Worker #define NUM_CPOINTS 8
66*49cdfc7eSAndroid Build Coastguard Worker #define NUM_CPOINT_TYPES 5
67*49cdfc7eSAndroid Build Coastguard Worker #define DEFAULT_COUNT 10
68*49cdfc7eSAndroid Build Coastguard Worker #define REC_NUM_DEFAULT 10
69*49cdfc7eSAndroid Build Coastguard Worker 
70*49cdfc7eSAndroid Build Coastguard Worker enum cname {
71*49cdfc7eSAndroid Build Coastguard Worker 	INVALID,
72*49cdfc7eSAndroid Build Coastguard Worker 	INT_HARDWARE_ENTRY,
73*49cdfc7eSAndroid Build Coastguard Worker 	INT_HW_IRQ_EN,
74*49cdfc7eSAndroid Build Coastguard Worker 	INT_TASKLET_ENTRY,
75*49cdfc7eSAndroid Build Coastguard Worker 	FS_DEVRW,
76*49cdfc7eSAndroid Build Coastguard Worker 	MEM_SWAPOUT,
77*49cdfc7eSAndroid Build Coastguard Worker 	TIMERADD,
78*49cdfc7eSAndroid Build Coastguard Worker 	SCSI_DISPATCH_CMD,
79*49cdfc7eSAndroid Build Coastguard Worker 	IDE_CORE_CP
80*49cdfc7eSAndroid Build Coastguard Worker };
81*49cdfc7eSAndroid Build Coastguard Worker 
82*49cdfc7eSAndroid Build Coastguard Worker enum ctype {
83*49cdfc7eSAndroid Build Coastguard Worker 	NONE,
84*49cdfc7eSAndroid Build Coastguard Worker 	PANIC,
85*49cdfc7eSAndroid Build Coastguard Worker 	BUG,
86*49cdfc7eSAndroid Build Coastguard Worker 	EXCEPTION,
87*49cdfc7eSAndroid Build Coastguard Worker 	LOOP,
88*49cdfc7eSAndroid Build Coastguard Worker 	OVERFLOW
89*49cdfc7eSAndroid Build Coastguard Worker };
90*49cdfc7eSAndroid Build Coastguard Worker 
91*49cdfc7eSAndroid Build Coastguard Worker static char *cp_name[] = {
92*49cdfc7eSAndroid Build Coastguard Worker 	"INT_HARDWARE_ENTRY",
93*49cdfc7eSAndroid Build Coastguard Worker 	"INT_HW_IRQ_EN",
94*49cdfc7eSAndroid Build Coastguard Worker 	"INT_TASKLET_ENTRY",
95*49cdfc7eSAndroid Build Coastguard Worker 	"FS_DEVRW",
96*49cdfc7eSAndroid Build Coastguard Worker 	"MEM_SWAPOUT",
97*49cdfc7eSAndroid Build Coastguard Worker 	"TIMERADD",
98*49cdfc7eSAndroid Build Coastguard Worker 	"SCSI_DISPATCH_CMD",
99*49cdfc7eSAndroid Build Coastguard Worker 	"IDE_CORE_CP"
100*49cdfc7eSAndroid Build Coastguard Worker };
101*49cdfc7eSAndroid Build Coastguard Worker 
102*49cdfc7eSAndroid Build Coastguard Worker static char *cp_type[] = {
103*49cdfc7eSAndroid Build Coastguard Worker 	"PANIC",
104*49cdfc7eSAndroid Build Coastguard Worker 	"BUG",
105*49cdfc7eSAndroid Build Coastguard Worker 	"EXCEPTION",
106*49cdfc7eSAndroid Build Coastguard Worker 	"LOOP",
107*49cdfc7eSAndroid Build Coastguard Worker 	"OVERFLOW"
108*49cdfc7eSAndroid Build Coastguard Worker };
109*49cdfc7eSAndroid Build Coastguard Worker 
110*49cdfc7eSAndroid Build Coastguard Worker static struct jprobe lkdtm;
111*49cdfc7eSAndroid Build Coastguard Worker 
112*49cdfc7eSAndroid Build Coastguard Worker static int lkdtm_parse_commandline(void);
113*49cdfc7eSAndroid Build Coastguard Worker static void lkdtm_handler(void);
114*49cdfc7eSAndroid Build Coastguard Worker 
115*49cdfc7eSAndroid Build Coastguard Worker static char *cpoint_name = INVALID;
116*49cdfc7eSAndroid Build Coastguard Worker static char *cpoint_type = NONE;
117*49cdfc7eSAndroid Build Coastguard Worker static int cpoint_count = DEFAULT_COUNT;
118*49cdfc7eSAndroid Build Coastguard Worker static int recur_count = REC_NUM_DEFAULT;
119*49cdfc7eSAndroid Build Coastguard Worker 
120*49cdfc7eSAndroid Build Coastguard Worker static enum cname cpoint = INVALID;
121*49cdfc7eSAndroid Build Coastguard Worker static enum ctype cptype = NONE;
122*49cdfc7eSAndroid Build Coastguard Worker static int count = DEFAULT_COUNT;
123*49cdfc7eSAndroid Build Coastguard Worker 
124*49cdfc7eSAndroid Build Coastguard Worker module_param(recur_count, int, 0644);
125*49cdfc7eSAndroid Build Coastguard Worker MODULE_PARM_DESC(recur_count, " Recursion level for the stack overflow test, "
126*49cdfc7eSAndroid Build Coastguard Worker 		 "default is 10");
127*49cdfc7eSAndroid Build Coastguard Worker module_param(cpoint_name, charp, 0644);
128*49cdfc7eSAndroid Build Coastguard Worker MODULE_PARM_DESC(cpoint_name, " Crash Point, where kernel is to be crashed");
129*49cdfc7eSAndroid Build Coastguard Worker module_param(cpoint_type, charp, 0644);
130*49cdfc7eSAndroid Build Coastguard Worker MODULE_PARM_DESC(cpoint_type, " Crash Point Type, action to be taken on "
131*49cdfc7eSAndroid Build Coastguard Worker 		 "hitting the crash point");
132*49cdfc7eSAndroid Build Coastguard Worker module_param(cpoint_count, int, 0644);
133*49cdfc7eSAndroid Build Coastguard Worker MODULE_PARM_DESC(cpoint_count, " Crash Point Count, number of times the "
134*49cdfc7eSAndroid Build Coastguard Worker 		 "crash point is to be hit to trigger action");
135*49cdfc7eSAndroid Build Coastguard Worker 
jp_do_irq(unsigned int irq)136*49cdfc7eSAndroid Build Coastguard Worker unsigned int jp_do_irq(unsigned int irq)
137*49cdfc7eSAndroid Build Coastguard Worker {
138*49cdfc7eSAndroid Build Coastguard Worker 	lkdtm_handler();
139*49cdfc7eSAndroid Build Coastguard Worker 	jprobe_return();
140*49cdfc7eSAndroid Build Coastguard Worker 	return 0;
141*49cdfc7eSAndroid Build Coastguard Worker }
142*49cdfc7eSAndroid Build Coastguard Worker 
jp_handle_irq_event(unsigned int irq,struct irqaction * action)143*49cdfc7eSAndroid Build Coastguard Worker irqreturn_t jp_handle_irq_event(unsigned int irq, struct irqaction * action)
144*49cdfc7eSAndroid Build Coastguard Worker {
145*49cdfc7eSAndroid Build Coastguard Worker 	lkdtm_handler();
146*49cdfc7eSAndroid Build Coastguard Worker 	jprobe_return();
147*49cdfc7eSAndroid Build Coastguard Worker 	return 0;
148*49cdfc7eSAndroid Build Coastguard Worker }
149*49cdfc7eSAndroid Build Coastguard Worker 
jp_tasklet_action(struct softirq_action * a)150*49cdfc7eSAndroid Build Coastguard Worker void jp_tasklet_action(struct softirq_action *a)
151*49cdfc7eSAndroid Build Coastguard Worker {
152*49cdfc7eSAndroid Build Coastguard Worker 	lkdtm_handler();
153*49cdfc7eSAndroid Build Coastguard Worker 	jprobe_return();
154*49cdfc7eSAndroid Build Coastguard Worker }
155*49cdfc7eSAndroid Build Coastguard Worker 
jp_ll_rw_block(int rw,int nr,struct buffer_head * bhs[])156*49cdfc7eSAndroid Build Coastguard Worker void jp_ll_rw_block(int rw, int nr, struct buffer_head *bhs[])
157*49cdfc7eSAndroid Build Coastguard Worker {
158*49cdfc7eSAndroid Build Coastguard Worker 	lkdtm_handler();
159*49cdfc7eSAndroid Build Coastguard Worker 	jprobe_return();
160*49cdfc7eSAndroid Build Coastguard Worker }
161*49cdfc7eSAndroid Build Coastguard Worker 
162*49cdfc7eSAndroid Build Coastguard Worker struct scan_control;
163*49cdfc7eSAndroid Build Coastguard Worker 
jp_shrink_page_list(struct list_head * page_list,struct scan_control * sc)164*49cdfc7eSAndroid Build Coastguard Worker unsigned long jp_shrink_page_list(struct list_head *page_list,
165*49cdfc7eSAndroid Build Coastguard Worker 				  struct scan_control *sc)
166*49cdfc7eSAndroid Build Coastguard Worker {
167*49cdfc7eSAndroid Build Coastguard Worker 	lkdtm_handler();
168*49cdfc7eSAndroid Build Coastguard Worker 	jprobe_return();
169*49cdfc7eSAndroid Build Coastguard Worker 	return 0;
170*49cdfc7eSAndroid Build Coastguard Worker }
171*49cdfc7eSAndroid Build Coastguard Worker 
jp_hrtimer_start(struct hrtimer * timer,ktime_t tim,const enum hrtimer_mode mode)172*49cdfc7eSAndroid Build Coastguard Worker int jp_hrtimer_start(struct hrtimer *timer, ktime_t tim,
173*49cdfc7eSAndroid Build Coastguard Worker 		     const enum hrtimer_mode mode)
174*49cdfc7eSAndroid Build Coastguard Worker {
175*49cdfc7eSAndroid Build Coastguard Worker 	lkdtm_handler();
176*49cdfc7eSAndroid Build Coastguard Worker 	jprobe_return();
177*49cdfc7eSAndroid Build Coastguard Worker 	return 0;
178*49cdfc7eSAndroid Build Coastguard Worker }
179*49cdfc7eSAndroid Build Coastguard Worker 
jp_scsi_dispatch_cmd(struct scsi_cmnd * cmd)180*49cdfc7eSAndroid Build Coastguard Worker int jp_scsi_dispatch_cmd(struct scsi_cmnd *cmd)
181*49cdfc7eSAndroid Build Coastguard Worker {
182*49cdfc7eSAndroid Build Coastguard Worker 	lkdtm_handler();
183*49cdfc7eSAndroid Build Coastguard Worker 	jprobe_return();
184*49cdfc7eSAndroid Build Coastguard Worker 	return 0;
185*49cdfc7eSAndroid Build Coastguard Worker }
186*49cdfc7eSAndroid Build Coastguard Worker 
187*49cdfc7eSAndroid Build Coastguard Worker #ifdef CONFIG_IDE
jp_generic_ide_ioctl(ide_drive_t * drive,struct file * file,struct block_device * bdev,unsigned int cmd,unsigned long arg)188*49cdfc7eSAndroid Build Coastguard Worker int jp_generic_ide_ioctl(ide_drive_t * drive, struct file *file,
189*49cdfc7eSAndroid Build Coastguard Worker 			 struct block_device *bdev, unsigned int cmd,
190*49cdfc7eSAndroid Build Coastguard Worker 			 unsigned long arg)
191*49cdfc7eSAndroid Build Coastguard Worker {
192*49cdfc7eSAndroid Build Coastguard Worker 	lkdtm_handler();
193*49cdfc7eSAndroid Build Coastguard Worker 	jprobe_return();
194*49cdfc7eSAndroid Build Coastguard Worker 	return 0;
195*49cdfc7eSAndroid Build Coastguard Worker }
196*49cdfc7eSAndroid Build Coastguard Worker #endif
197*49cdfc7eSAndroid Build Coastguard Worker 
lkdtm_parse_commandline(void)198*49cdfc7eSAndroid Build Coastguard Worker static int lkdtm_parse_commandline(void)
199*49cdfc7eSAndroid Build Coastguard Worker {
200*49cdfc7eSAndroid Build Coastguard Worker 	int i;
201*49cdfc7eSAndroid Build Coastguard Worker 
202*49cdfc7eSAndroid Build Coastguard Worker 	if (cpoint_name == INVALID || cpoint_type == NONE ||
203*49cdfc7eSAndroid Build Coastguard Worker 	    cpoint_count < 1 || recur_count < 1)
204*49cdfc7eSAndroid Build Coastguard Worker 		return -EINVAL;
205*49cdfc7eSAndroid Build Coastguard Worker 
206*49cdfc7eSAndroid Build Coastguard Worker 	for (i = 0; i < NUM_CPOINTS; ++i) {
207*49cdfc7eSAndroid Build Coastguard Worker 		if (!strcmp(cpoint_name, cp_name[i])) {
208*49cdfc7eSAndroid Build Coastguard Worker 			cpoint = i + 1;
209*49cdfc7eSAndroid Build Coastguard Worker 			break;
210*49cdfc7eSAndroid Build Coastguard Worker 		}
211*49cdfc7eSAndroid Build Coastguard Worker 	}
212*49cdfc7eSAndroid Build Coastguard Worker 
213*49cdfc7eSAndroid Build Coastguard Worker 	for (i = 0; i < NUM_CPOINT_TYPES; ++i) {
214*49cdfc7eSAndroid Build Coastguard Worker 		if (!strcmp(cpoint_type, cp_type[i])) {
215*49cdfc7eSAndroid Build Coastguard Worker 			cptype = i + 1;
216*49cdfc7eSAndroid Build Coastguard Worker 			break;
217*49cdfc7eSAndroid Build Coastguard Worker 		}
218*49cdfc7eSAndroid Build Coastguard Worker 	}
219*49cdfc7eSAndroid Build Coastguard Worker 
220*49cdfc7eSAndroid Build Coastguard Worker 	if (cpoint == INVALID || cptype == NONE)
221*49cdfc7eSAndroid Build Coastguard Worker 		return -EINVAL;
222*49cdfc7eSAndroid Build Coastguard Worker 
223*49cdfc7eSAndroid Build Coastguard Worker 	count = cpoint_count;
224*49cdfc7eSAndroid Build Coastguard Worker 
225*49cdfc7eSAndroid Build Coastguard Worker 	return 0;
226*49cdfc7eSAndroid Build Coastguard Worker }
227*49cdfc7eSAndroid Build Coastguard Worker 
recursive_loop(int a)228*49cdfc7eSAndroid Build Coastguard Worker static int recursive_loop(int a)
229*49cdfc7eSAndroid Build Coastguard Worker {
230*49cdfc7eSAndroid Build Coastguard Worker 	char buf[1024];
231*49cdfc7eSAndroid Build Coastguard Worker 
232*49cdfc7eSAndroid Build Coastguard Worker 	memset(buf, 0xFF, 1024);
233*49cdfc7eSAndroid Build Coastguard Worker 	recur_count--;
234*49cdfc7eSAndroid Build Coastguard Worker 	if (!recur_count)
235*49cdfc7eSAndroid Build Coastguard Worker 		return 0;
236*49cdfc7eSAndroid Build Coastguard Worker 	else
237*49cdfc7eSAndroid Build Coastguard Worker 		return recursive_loop(a);
238*49cdfc7eSAndroid Build Coastguard Worker }
239*49cdfc7eSAndroid Build Coastguard Worker 
lkdtm_handler(void)240*49cdfc7eSAndroid Build Coastguard Worker void lkdtm_handler(void)
241*49cdfc7eSAndroid Build Coastguard Worker {
242*49cdfc7eSAndroid Build Coastguard Worker 	/* Escape endless loop. */
243*49cdfc7eSAndroid Build Coastguard Worker 	if (count < 0)
244*49cdfc7eSAndroid Build Coastguard Worker 		return;
245*49cdfc7eSAndroid Build Coastguard Worker 
246*49cdfc7eSAndroid Build Coastguard Worker 	printk(KERN_INFO "lkdtm : Crash point %s of type %s hit\n",
247*49cdfc7eSAndroid Build Coastguard Worker 	       cpoint_name, cpoint_type);
248*49cdfc7eSAndroid Build Coastguard Worker 	--count;
249*49cdfc7eSAndroid Build Coastguard Worker 
250*49cdfc7eSAndroid Build Coastguard Worker 	if (count == 0) {
251*49cdfc7eSAndroid Build Coastguard Worker 		switch (cptype) {
252*49cdfc7eSAndroid Build Coastguard Worker 		case NONE:
253*49cdfc7eSAndroid Build Coastguard Worker 			break;
254*49cdfc7eSAndroid Build Coastguard Worker 		case PANIC:
255*49cdfc7eSAndroid Build Coastguard Worker 			printk(KERN_INFO "lkdtm : PANIC\n");
256*49cdfc7eSAndroid Build Coastguard Worker 			panic("dumptest");
257*49cdfc7eSAndroid Build Coastguard Worker 			break;
258*49cdfc7eSAndroid Build Coastguard Worker 		case BUG:
259*49cdfc7eSAndroid Build Coastguard Worker 			printk(KERN_INFO "lkdtm : BUG\n");
260*49cdfc7eSAndroid Build Coastguard Worker 			BUG();
261*49cdfc7eSAndroid Build Coastguard Worker 			break;
262*49cdfc7eSAndroid Build Coastguard Worker 		case EXCEPTION:
263*49cdfc7eSAndroid Build Coastguard Worker 			printk(KERN_INFO "lkdtm : EXCEPTION\n");
264*49cdfc7eSAndroid Build Coastguard Worker 			*((int *)0) = 0;
265*49cdfc7eSAndroid Build Coastguard Worker 			break;
266*49cdfc7eSAndroid Build Coastguard Worker 		case LOOP:
267*49cdfc7eSAndroid Build Coastguard Worker 			printk(KERN_INFO "lkdtm : LOOP\n");
268*49cdfc7eSAndroid Build Coastguard Worker 			for (;;) ;
269*49cdfc7eSAndroid Build Coastguard Worker 			break;
270*49cdfc7eSAndroid Build Coastguard Worker 		case OVERFLOW:
271*49cdfc7eSAndroid Build Coastguard Worker 			printk(KERN_INFO "lkdtm : OVERFLOW\n");
272*49cdfc7eSAndroid Build Coastguard Worker 			(void)recursive_loop(0);
273*49cdfc7eSAndroid Build Coastguard Worker 			break;
274*49cdfc7eSAndroid Build Coastguard Worker 		default:
275*49cdfc7eSAndroid Build Coastguard Worker 			break;
276*49cdfc7eSAndroid Build Coastguard Worker 		}
277*49cdfc7eSAndroid Build Coastguard Worker 		count = cpoint_count;
278*49cdfc7eSAndroid Build Coastguard Worker 	}
279*49cdfc7eSAndroid Build Coastguard Worker }
280*49cdfc7eSAndroid Build Coastguard Worker 
281*49cdfc7eSAndroid Build Coastguard Worker #ifdef USE_SYMBOL_NAME
lkdtm_symbol_name(char * name,void (* entry)(void))282*49cdfc7eSAndroid Build Coastguard Worker void lkdtm_symbol_name(char *name, void (*entry) (void))
283*49cdfc7eSAndroid Build Coastguard Worker {
284*49cdfc7eSAndroid Build Coastguard Worker 	lkdtm.kp.symbol_name = name;
285*49cdfc7eSAndroid Build Coastguard Worker 	lkdtm.entry = (kprobe_opcode_t *) entry;
286*49cdfc7eSAndroid Build Coastguard Worker }
287*49cdfc7eSAndroid Build Coastguard Worker 
288*49cdfc7eSAndroid Build Coastguard Worker #else
lkdtm_lookup_name(char * name,void (* entry)(void))289*49cdfc7eSAndroid Build Coastguard Worker void lkdtm_lookup_name(char *name, void (*entry) (void))
290*49cdfc7eSAndroid Build Coastguard Worker {
291*49cdfc7eSAndroid Build Coastguard Worker 	unsigned long addr;
292*49cdfc7eSAndroid Build Coastguard Worker 
293*49cdfc7eSAndroid Build Coastguard Worker 	addr = kallsyms_lookup_name(name);
294*49cdfc7eSAndroid Build Coastguard Worker 	if (addr) {
295*49cdfc7eSAndroid Build Coastguard Worker 		*(lkdtm.kp.addr) = addr;
296*49cdfc7eSAndroid Build Coastguard Worker 		lkdtm.entry = JPROBE_ENTRY(entry);
297*49cdfc7eSAndroid Build Coastguard Worker 	} else
298*49cdfc7eSAndroid Build Coastguard Worker 		printk(KERN_INFO "lkdtm : Crash point not available\n");
299*49cdfc7eSAndroid Build Coastguard Worker }
300*49cdfc7eSAndroid Build Coastguard Worker #endif
301*49cdfc7eSAndroid Build Coastguard Worker 
lkdtm_module_init(void)302*49cdfc7eSAndroid Build Coastguard Worker int lkdtm_module_init(void)
303*49cdfc7eSAndroid Build Coastguard Worker {
304*49cdfc7eSAndroid Build Coastguard Worker 	int ret;
305*49cdfc7eSAndroid Build Coastguard Worker 
306*49cdfc7eSAndroid Build Coastguard Worker 	if (lkdtm_parse_commandline() == -EINVAL) {
307*49cdfc7eSAndroid Build Coastguard Worker 		printk(KERN_INFO "lkdtm : Invalid command\n");
308*49cdfc7eSAndroid Build Coastguard Worker 		return -EINVAL;
309*49cdfc7eSAndroid Build Coastguard Worker 	}
310*49cdfc7eSAndroid Build Coastguard Worker 
311*49cdfc7eSAndroid Build Coastguard Worker 	switch (cpoint) {
312*49cdfc7eSAndroid Build Coastguard Worker 	case INT_HARDWARE_ENTRY:
313*49cdfc7eSAndroid Build Coastguard Worker 
314*49cdfc7eSAndroid Build Coastguard Worker #ifdef USE_SYMBOL_NAME
315*49cdfc7eSAndroid Build Coastguard Worker 
316*49cdfc7eSAndroid Build Coastguard Worker #ifdef __powerpc__
317*49cdfc7eSAndroid Build Coastguard Worker 		lkdtm_symbol_name(".__do_IRQ", (void (*)(void))jp_do_irq);
318*49cdfc7eSAndroid Build Coastguard Worker #else
319*49cdfc7eSAndroid Build Coastguard Worker 		lkdtm_symbol_name("__do_IRQ", (void (*)(void))jp_do_irq);
320*49cdfc7eSAndroid Build Coastguard Worker #endif /*__powerpc__*/
321*49cdfc7eSAndroid Build Coastguard Worker 
322*49cdfc7eSAndroid Build Coastguard Worker #else /* USE_SYMBOL_NAME */
323*49cdfc7eSAndroid Build Coastguard Worker 		lkdtm_lookup_name("__do_IRQ", (void (*)(void))jp_do_irq);
324*49cdfc7eSAndroid Build Coastguard Worker 
325*49cdfc7eSAndroid Build Coastguard Worker #endif /* USE_SYMBOL_NAME */
326*49cdfc7eSAndroid Build Coastguard Worker 		break;
327*49cdfc7eSAndroid Build Coastguard Worker 
328*49cdfc7eSAndroid Build Coastguard Worker 	case INT_HW_IRQ_EN:
329*49cdfc7eSAndroid Build Coastguard Worker 
330*49cdfc7eSAndroid Build Coastguard Worker #ifdef USE_SYMBOL_NAME
331*49cdfc7eSAndroid Build Coastguard Worker 
332*49cdfc7eSAndroid Build Coastguard Worker #ifdef __powerpc__
333*49cdfc7eSAndroid Build Coastguard Worker 		lkdtm_symbol_name(".handle_IRQ_event",
334*49cdfc7eSAndroid Build Coastguard Worker 				  (void (*)(void))jp_handle_irq_event);
335*49cdfc7eSAndroid Build Coastguard Worker #else
336*49cdfc7eSAndroid Build Coastguard Worker 		lkdtm_symbol_name("handle_IRQ_event",
337*49cdfc7eSAndroid Build Coastguard Worker 				  (void (*)(void))jp_handle_irq_event);
338*49cdfc7eSAndroid Build Coastguard Worker #endif /*__powerpc__*/
339*49cdfc7eSAndroid Build Coastguard Worker 
340*49cdfc7eSAndroid Build Coastguard Worker #else /* USE_SYMBOL_NAME */
341*49cdfc7eSAndroid Build Coastguard Worker 		lkdtm_lookup_name("handle_IRQ_event",
342*49cdfc7eSAndroid Build Coastguard Worker 				  (void (*)(void))jp_handle_irq_event);
343*49cdfc7eSAndroid Build Coastguard Worker 
344*49cdfc7eSAndroid Build Coastguard Worker #endif /* USE_SYMBOL_NAME */
345*49cdfc7eSAndroid Build Coastguard Worker 		break;
346*49cdfc7eSAndroid Build Coastguard Worker 
347*49cdfc7eSAndroid Build Coastguard Worker 	case INT_TASKLET_ENTRY:
348*49cdfc7eSAndroid Build Coastguard Worker 
349*49cdfc7eSAndroid Build Coastguard Worker #ifdef USE_SYMBOL_NAME
350*49cdfc7eSAndroid Build Coastguard Worker 
351*49cdfc7eSAndroid Build Coastguard Worker #ifdef __powerpc__
352*49cdfc7eSAndroid Build Coastguard Worker 		lkdtm_symbol_name(".tasklet_action",
353*49cdfc7eSAndroid Build Coastguard Worker 				  (void (*)(void))jp_tasklet_action);
354*49cdfc7eSAndroid Build Coastguard Worker #else
355*49cdfc7eSAndroid Build Coastguard Worker 		lkdtm_symbol_name("tasklet_action",
356*49cdfc7eSAndroid Build Coastguard Worker 				  (void (*)(void))jp_tasklet_action);
357*49cdfc7eSAndroid Build Coastguard Worker #endif /*__powerpc__*/
358*49cdfc7eSAndroid Build Coastguard Worker 
359*49cdfc7eSAndroid Build Coastguard Worker #else /* USE_SYMBOL_NAME */
360*49cdfc7eSAndroid Build Coastguard Worker 		lkdtm_lookup_name("tasklet_action",
361*49cdfc7eSAndroid Build Coastguard Worker 				  (void (*)(void))jp_tasklet_action);
362*49cdfc7eSAndroid Build Coastguard Worker 
363*49cdfc7eSAndroid Build Coastguard Worker #endif /* USE_SYMBOL_NAME */
364*49cdfc7eSAndroid Build Coastguard Worker 		break;
365*49cdfc7eSAndroid Build Coastguard Worker 
366*49cdfc7eSAndroid Build Coastguard Worker 	case FS_DEVRW:
367*49cdfc7eSAndroid Build Coastguard Worker 
368*49cdfc7eSAndroid Build Coastguard Worker #ifdef USE_SYMBOL_NAME
369*49cdfc7eSAndroid Build Coastguard Worker 
370*49cdfc7eSAndroid Build Coastguard Worker #ifdef __powerpc__
371*49cdfc7eSAndroid Build Coastguard Worker 		lkdtm_symbol_name(".ll_rw_block",
372*49cdfc7eSAndroid Build Coastguard Worker 				  (void (*)(void))jp_ll_rw_block);
373*49cdfc7eSAndroid Build Coastguard Worker #else
374*49cdfc7eSAndroid Build Coastguard Worker 		lkdtm_symbol_name("ll_rw_block",
375*49cdfc7eSAndroid Build Coastguard Worker 				  (void (*)(void))jp_ll_rw_block);
376*49cdfc7eSAndroid Build Coastguard Worker #endif /*__powerpc__*/
377*49cdfc7eSAndroid Build Coastguard Worker 
378*49cdfc7eSAndroid Build Coastguard Worker #else /* USE_SYMBOL_NAME */
379*49cdfc7eSAndroid Build Coastguard Worker 		lkdtm_lookup_name("ll_rw_block",
380*49cdfc7eSAndroid Build Coastguard Worker 				  (void (*)(void))jp_ll_rw_block);
381*49cdfc7eSAndroid Build Coastguard Worker 
382*49cdfc7eSAndroid Build Coastguard Worker #endif /* USE_SYMBOL_NAME */
383*49cdfc7eSAndroid Build Coastguard Worker 		break;
384*49cdfc7eSAndroid Build Coastguard Worker 
385*49cdfc7eSAndroid Build Coastguard Worker 	case MEM_SWAPOUT:
386*49cdfc7eSAndroid Build Coastguard Worker 
387*49cdfc7eSAndroid Build Coastguard Worker #ifdef USE_SYMBOL_NAME
388*49cdfc7eSAndroid Build Coastguard Worker 
389*49cdfc7eSAndroid Build Coastguard Worker #ifdef __powerpc__
390*49cdfc7eSAndroid Build Coastguard Worker 		lkdtm_symbol_name(".shrink_inactive_list",
391*49cdfc7eSAndroid Build Coastguard Worker 				  (void (*)(void))jp_shrink_page_list);
392*49cdfc7eSAndroid Build Coastguard Worker #else
393*49cdfc7eSAndroid Build Coastguard Worker 		lkdtm_symbol_name("shrink_inactive_list",
394*49cdfc7eSAndroid Build Coastguard Worker 				  (void (*)(void))jp_shrink_page_list);
395*49cdfc7eSAndroid Build Coastguard Worker #endif /*__powerpc__*/
396*49cdfc7eSAndroid Build Coastguard Worker 
397*49cdfc7eSAndroid Build Coastguard Worker #else /* USE_SYMBOL_NAME */
398*49cdfc7eSAndroid Build Coastguard Worker 		lkdtm_lookup_name("shrink_inactive_list",
399*49cdfc7eSAndroid Build Coastguard Worker 				  (void (*)(void))jp_shrink_page_list);
400*49cdfc7eSAndroid Build Coastguard Worker 
401*49cdfc7eSAndroid Build Coastguard Worker #endif /* USE_SYMBOL_NAME */
402*49cdfc7eSAndroid Build Coastguard Worker 		break;
403*49cdfc7eSAndroid Build Coastguard Worker 
404*49cdfc7eSAndroid Build Coastguard Worker 	case TIMERADD:
405*49cdfc7eSAndroid Build Coastguard Worker 
406*49cdfc7eSAndroid Build Coastguard Worker #ifdef USE_SYMBOL_NAME
407*49cdfc7eSAndroid Build Coastguard Worker 
408*49cdfc7eSAndroid Build Coastguard Worker #ifdef __powerpc__
409*49cdfc7eSAndroid Build Coastguard Worker 		lkdtm_symbol_name(".hrtimer_start",
410*49cdfc7eSAndroid Build Coastguard Worker 				  (void (*)(void))jp_hrtimer_start);
411*49cdfc7eSAndroid Build Coastguard Worker #else
412*49cdfc7eSAndroid Build Coastguard Worker 		lkdtm_symbol_name("hrtimer_start",
413*49cdfc7eSAndroid Build Coastguard Worker 				  (void (*)(void))jp_hrtimer_start);
414*49cdfc7eSAndroid Build Coastguard Worker #endif /*__powerpc__*/
415*49cdfc7eSAndroid Build Coastguard Worker 
416*49cdfc7eSAndroid Build Coastguard Worker #else /* USE_SYMBOL_NAME */
417*49cdfc7eSAndroid Build Coastguard Worker 		lkdtm_lookup_name("hrtimer_start",
418*49cdfc7eSAndroid Build Coastguard Worker 				  (void (*)(void))jp_hrtimer_start);
419*49cdfc7eSAndroid Build Coastguard Worker 
420*49cdfc7eSAndroid Build Coastguard Worker #endif /* USE_SYMBOL_NAME */
421*49cdfc7eSAndroid Build Coastguard Worker 		break;
422*49cdfc7eSAndroid Build Coastguard Worker 
423*49cdfc7eSAndroid Build Coastguard Worker 	case SCSI_DISPATCH_CMD:
424*49cdfc7eSAndroid Build Coastguard Worker 
425*49cdfc7eSAndroid Build Coastguard Worker #ifdef USE_SYMBOL_NAME
426*49cdfc7eSAndroid Build Coastguard Worker 
427*49cdfc7eSAndroid Build Coastguard Worker #ifdef __powerpc__
428*49cdfc7eSAndroid Build Coastguard Worker 		lkdtm_symbol_name(".scsi_dispatch_cmd",
429*49cdfc7eSAndroid Build Coastguard Worker 				  (void (*)(void))jp_scsi_dispatch_cmd);
430*49cdfc7eSAndroid Build Coastguard Worker #else
431*49cdfc7eSAndroid Build Coastguard Worker 		lkdtm_symbol_name("scsi_dispatch_cmd",
432*49cdfc7eSAndroid Build Coastguard Worker 				  (void (*)(void))jp_scsi_dispatch_cmd);
433*49cdfc7eSAndroid Build Coastguard Worker #endif /*__powerpc__*/
434*49cdfc7eSAndroid Build Coastguard Worker 
435*49cdfc7eSAndroid Build Coastguard Worker #else /* USE_SYMBOL_NAME */
436*49cdfc7eSAndroid Build Coastguard Worker 		lkdtm_lookup_name("scsi_dispatch_cmd",
437*49cdfc7eSAndroid Build Coastguard Worker 				  (void (*)(void))jp_scsi_dispatch_cmd);
438*49cdfc7eSAndroid Build Coastguard Worker 
439*49cdfc7eSAndroid Build Coastguard Worker #endif /* USE_SYMBOL_NAME */
440*49cdfc7eSAndroid Build Coastguard Worker 		break;
441*49cdfc7eSAndroid Build Coastguard Worker 
442*49cdfc7eSAndroid Build Coastguard Worker 	case IDE_CORE_CP:
443*49cdfc7eSAndroid Build Coastguard Worker #ifdef CONFIG_IDE
444*49cdfc7eSAndroid Build Coastguard Worker 
445*49cdfc7eSAndroid Build Coastguard Worker #ifdef USE_SYMBOL_NAME
446*49cdfc7eSAndroid Build Coastguard Worker 
447*49cdfc7eSAndroid Build Coastguard Worker #ifdef __powerpc__
448*49cdfc7eSAndroid Build Coastguard Worker 		lkdtm_symbol_name(".scsi_dispatch_cmd",
449*49cdfc7eSAndroid Build Coastguard Worker 				  (void (*)(void))jp_scsi_dispatch_cmd);
450*49cdfc7eSAndroid Build Coastguard Worker #else
451*49cdfc7eSAndroid Build Coastguard Worker 		lkdtm_symbol_name("scsi_dispatch_cmd",
452*49cdfc7eSAndroid Build Coastguard Worker 				  (void (*)(void))jp_scsi_dispatch_cmd);
453*49cdfc7eSAndroid Build Coastguard Worker #endif /*__powerpc__*/
454*49cdfc7eSAndroid Build Coastguard Worker 
455*49cdfc7eSAndroid Build Coastguard Worker #else /* USE_SYMBOL_NAME */
456*49cdfc7eSAndroid Build Coastguard Worker 		lkdtm_lookup_name("scsi_dispatch_cmd",
457*49cdfc7eSAndroid Build Coastguard Worker 				  (void (*)(void))jp_scsi_dispatch_cmd);
458*49cdfc7eSAndroid Build Coastguard Worker 
459*49cdfc7eSAndroid Build Coastguard Worker #endif /* USE_SYMBOL_NAME */
460*49cdfc7eSAndroid Build Coastguard Worker #endif /* CONFIG_IDE */
461*49cdfc7eSAndroid Build Coastguard Worker 		break;
462*49cdfc7eSAndroid Build Coastguard Worker 
463*49cdfc7eSAndroid Build Coastguard Worker 	default:
464*49cdfc7eSAndroid Build Coastguard Worker 		printk(KERN_INFO "lkdtm : Invalid Crash Point\n");
465*49cdfc7eSAndroid Build Coastguard Worker 		break;
466*49cdfc7eSAndroid Build Coastguard Worker 	}
467*49cdfc7eSAndroid Build Coastguard Worker 
468*49cdfc7eSAndroid Build Coastguard Worker 	if ((ret = register_jprobe(&lkdtm)) < 0) {
469*49cdfc7eSAndroid Build Coastguard Worker 		printk(KERN_INFO "lkdtm : Couldn't register jprobe\n");
470*49cdfc7eSAndroid Build Coastguard Worker 		return ret;
471*49cdfc7eSAndroid Build Coastguard Worker 	}
472*49cdfc7eSAndroid Build Coastguard Worker 
473*49cdfc7eSAndroid Build Coastguard Worker 	printk(KERN_INFO "lkdtm : Crash point %s of type %s registered\n",
474*49cdfc7eSAndroid Build Coastguard Worker 	       cpoint_name, cpoint_type);
475*49cdfc7eSAndroid Build Coastguard Worker 	return 0;
476*49cdfc7eSAndroid Build Coastguard Worker }
477*49cdfc7eSAndroid Build Coastguard Worker 
lkdtm_module_exit(void)478*49cdfc7eSAndroid Build Coastguard Worker void lkdtm_module_exit(void)
479*49cdfc7eSAndroid Build Coastguard Worker {
480*49cdfc7eSAndroid Build Coastguard Worker 	unregister_jprobe(&lkdtm);
481*49cdfc7eSAndroid Build Coastguard Worker 	printk(KERN_INFO "lkdtm : Crash point unregistered\n");
482*49cdfc7eSAndroid Build Coastguard Worker }
483*49cdfc7eSAndroid Build Coastguard Worker 
484*49cdfc7eSAndroid Build Coastguard Worker module_init(lkdtm_module_init);
485*49cdfc7eSAndroid Build Coastguard Worker module_exit(lkdtm_module_exit);
486*49cdfc7eSAndroid Build Coastguard Worker 
487*49cdfc7eSAndroid Build Coastguard Worker MODULE_LICENSE("GPL");
488