Merge branch 'chromeos-misc-3.4' into chromeos-3.4
[cascardo/linux.git] / fs / proc / breakme.c
1 #include <linux/cpumask.h>
2 #include <linux/fs.h>
3 #include <linux/gfp.h>
4 #include <linux/init.h>
5 #include <linux/interrupt.h>
6 #include <linux/kernel_stat.h>
7 #include <linux/proc_fs.h>
8 #include <linux/sched.h>
9 #include <linux/seq_file.h>
10 #include <linux/slab.h>
11 #include <linux/time.h>
12 #include <linux/irqnr.h>
13 #include <asm/cputime.h>
14 #include <asm/uaccess.h>
15
16 #define MAX_BREAKME_WRITE 64
17 static ssize_t write_breakme(struct file *file, const char __user *buf,
18                                    size_t count, loff_t *ppos)
19 {
20         char kbuf[MAX_BREAKME_WRITE + 1];
21         DEFINE_SPINLOCK(lock_me_up);
22
23         if (count) {
24                 if (count > MAX_BREAKME_WRITE)
25                         return -EINVAL;
26                 if (copy_from_user(&kbuf, buf, count))
27                         return -EFAULT;
28                 kbuf[min(count, sizeof(kbuf))-1] = '\0';
29
30                 /* Null pointer dereference */
31                 if (!strcmp(kbuf, "nullptr"))
32                         *(unsigned long *)0 = 0;
33                 /* BUG() */
34                 else if (!strcmp(kbuf, "bug"))
35                         BUG();
36                 /* hung_task stuck in unkillable D state */
37                 else if (!strcmp(kbuf, "hungtask"))
38                         schedule_timeout_uninterruptible(MAX_SCHEDULE_TIMEOUT);
39                 /* Panic */
40                 else if (!strcmp(kbuf, "panic"))
41                         panic("Testing panic");
42                 /* Set up a deadlock (call this twice) */
43                 else if (!strcmp(kbuf, "deadlock"))
44                         spin_lock(&lock_me_up);
45                 /* lockup */
46                 else if (!strcmp(kbuf, "softlockup")) {
47                         while (1)
48                                 ;
49                 }
50                 /* lockup with interrupts enabled */
51                 else if (!strcmp(kbuf, "irqlockup")) {
52                         spin_lock(&lock_me_up);
53                         while (1)
54                                 ;
55                 }
56                 /* lockup with interrupts disabled */
57                 else if (!strcmp(kbuf, "nmiwatchdog")) {
58                         spin_lock_irq(&lock_me_up);
59                         while (1)
60                                 ;
61                 }
62         }
63         return count;
64 }
65
66 static struct file_operations proc_breakme_operations = {
67         .write          = write_breakme,
68 };
69
70 void __init proc_breakme_init(void)
71 {
72         proc_create("breakme", S_IWUSR, NULL, &proc_breakme_operations);
73 }