Re: Testing watchdog timer card...?

Keith Owens (kaos@ocs.com.au)
Fri, 16 Oct 1998 13:08:14 +1000


On 14 Oct 1998 09:34:28 -0700,
Jim Dennis <jimd@starshine.org> wrote:
> Is there a way I can force a kernel to hang
> so as to test the functionality of a watchdog timer
> card?

This was against 2.1.105, should still fit.

This patch adds adds commands OOPS, STACKFAULT and KERNEL_LOOP to the
reboot syscall. Note that these reboot commands are not controlled by
config options, applying the patch makes them available. Command OOPS
lets root force a kernel oops from user space, the other two commands
are mainly used for testing kernel recovery from stack overflow and
never ending loops. Trivial code to cause a kernel oops with this
patch :-

#include <unistd.h>
#include <linux/reboot.h>
int main(void)
{
return(reboot(0xfee1dead, 672274793, LINUX_REBOOT_CMD_OOPS));
}

--- linux-2.1.105/include/linux/reboot.h Sat, 18 Apr 1998 19:35:16 +1000 keith (linux-2.1/R/24_reboot.h 1.1.2.1 644) 105.3
+++ linux/include/linux/reboot.h Mon, 08 Jun 1998 17:15:12 +1000 keith (linux-2.1/R/24_reboot.h 1.1.1.2 644) 105.3(w)
@@ -20,6 +20,9 @@
* CAD_OFF Ctrl-Alt-Del sequence sends SIGINT to init task.
* POWER_OFF Stop OS and remove all power from system, if possible.
* RESTART2 Restart system using given command string.
+ * OOPS Cause a kernel Oops, the machine should continue afterwards.
+ * STACKFAULT Overflow the kernel stack with recursion.
+ * KERNEL_LOOP Endless kernel loop, unlocked.
*/

#define LINUX_REBOOT_CMD_RESTART 0x01234567
@@ -28,7 +31,9 @@
#define LINUX_REBOOT_CMD_CAD_OFF 0x00000000
#define LINUX_REBOOT_CMD_POWER_OFF 0x4321FEDC
#define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4
-
+#define LINUX_REBOOT_CMD_OOPS 0x4F6F7001
+#define LINUX_REBOOT_CMD_STACKFAULT 0x53746602
+#define LINUX_REBOOT_CMD_KERNEL_LOOP 0x4C6F7003

#ifdef __KERNEL__

--- linux-2.1.105/kernel/sys.c Sat, 06 Jun 1998 09:36:23 +1000 keith (linux-2.1/X/3_sys.c 1.9.2.7 644) 105.3
+++ linux/kernel/sys.c Mon, 08 Jun 1998 17:15:13 +1000 keith (linux-2.1/X/3_sys.c 1.9.1.5 644) 105.3(w)
@@ -157,6 +157,37 @@
return max_prio;
}

+/* routines to trip various softlockup conditions, driven from reboot */
+static void kstack_test1 (void);
+static void kstack_test2 (void);
+static void kstack_test3 (void);
+static void kstack_test4 (void);
+
+static void kstack_test1 (void)
+{
+ kstack_test2();
+}
+
+static void kstack_test2 (void)
+{
+ kstack_test3();
+}
+
+static void kstack_test3 (void)
+{
+ kstack_test4();
+}
+
+static void kstack_test4 (void)
+{
+ kstack_test1(); /* curse and recurse, stack overflow */
+}
+
+static volatile int softlockup_count=0;
+void softlockup_looptest(void)
+{
+ softlockup_count++;
+}

/*
* Reboot system call: for obvious reasons only root may call it,
@@ -220,6 +251,34 @@
notifier_call_chain(&reboot_notifier_list, SYS_RESTART, buffer);
printk(KERN_EMERG "Restarting system with command '%s'.\n", buffer);
machine_restart(buffer);
+ break;
+
+ case LINUX_REBOOT_CMD_OOPS:
+ /* Kernel oops, the machine should recover afterwards */
+ *(char *)0=0;
+ break;
+
+ /* Trip various software lockup conditions. Overloading sys_reboot
+ * because they do not justify their own syscall. These do not notify
+ * the reboot list.
+ */
+
+ case LINUX_REBOOT_CMD_STACKFAULT:
+ /* stack fault via endless recursion */
+#ifndef CONFIG_DEBUG_KSTACK
+ printk(KERN_WARNING "Invoking STACKFAULT without CONFIG_DEBUG_KSTACK\n"
+ "Machine may not recover!\n");
+#endif
+ kstack_test1();
+ break;
+
+ case LINUX_REBOOT_CMD_KERNEL_LOOP:
+ /* lockup via endless loop */
+#ifndef CONFIG_DEBUG_SOFTLOCKUP
+ printk(KERN_WARNING "Invoking KERNEL_LOOP without CONFIG_DEBUG_SOFTLOCKUP\n"
+ "Machine may not recover!\n");
+#endif
+ for (;;) softlockup_looptest();
break;

default:

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