[PATCH v2 23/23] netoops: Add an interface to trigger various typesof crashes.

From: Mike Waychison
Date: Mon Nov 08 2010 - 15:34:34 EST


It is very useful to be able to test the crash path, but in order to do so, we
need to expose various ways to crash the kernel in a deterministic fashion.

This commit adds a file, /proc/sys/kernel/net_dump_now that takes various
tokens that will crash the kernel in various ways.

This requires kmsg_dump() be accessible to modules, so export it.

Signed-off-by: Mike Waychison <mikew@xxxxxxxxxx>
---
Changelog:
- v2
- Folded EXPORT_SYMBOL_GPL(kmsg_dump) into this patch

TODO: User visible ABI needs a better interface
---
drivers/net/netoops.c | 31 +++++++++++++++++++++++++++++++
kernel/printk.c | 1 +
2 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/drivers/net/netoops.c b/drivers/net/netoops.c
index 1ffd0f0..60683c5 100644
--- a/drivers/net/netoops.c
+++ b/drivers/net/netoops.c
@@ -288,6 +288,32 @@ static struct kmsg_dumper netoops_dumper = {
.dump = netoops,
};

+static int proc_netoops_now(struct ctl_table *table, int write,
+ void __user *buffer, size_t *lenp, loff_t *ppos)
+{
+ if (write) {
+ char magic[20];
+ /* just crash in kernel mode. */
+ if (copy_from_user(magic, buffer, min(*lenp, sizeof(magic))))
+ return -EFAULT;
+ magic[min(*lenp, sizeof(magic))-1] = 0;
+ if (!strcmp(magic, "elgooG")) {
+ /* Test a simple crash */
+ *(unsigned long *)0 = 0;
+ } else if (!strcmp(magic, "guB")) {
+ /* Test the BUG() handler */
+ BUG();
+ } else if (!strcmp(magic, "cinaP")) {
+ panic("Testing panic");
+ } else if (!strcmp(magic, "pmuD")) {
+ kmsg_dump(KMSG_DUMP_SOFT, NULL);
+ }
+ return 0;
+ }
+ *lenp = 0;
+ return 0;
+}
+
static struct ctl_table kern_table[] = {
{
.procname = "net_dump_one_shot",
@@ -296,6 +322,11 @@ static struct ctl_table kern_table[] = {
.mode = 0644,
.proc_handler = &proc_dointvec,
},
+ {
+ .procname = "net_dump_now",
+ .mode = 0600,
+ .proc_handler = &proc_netoops_now,
+ },
{},
};

diff --git a/kernel/printk.c b/kernel/printk.c
index 159b4d6..9323339 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -1573,4 +1573,5 @@ void kmsg_dump(enum kmsg_dump_reason reason, struct pt_regs *pt_regs)
dumper->dump(dumper, reason, pt_regs, s1, l1, s2, l2);
spin_unlock_irqrestore(&dump_list_lock, flags);
}
+EXPORT_SYMBOL_GPL(kmsg_dump);
#endif

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/