diff --git a/drivers/Kconfig b/drivers/Kconfig index 4915a63..979a6e7 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -251,4 +251,6 @@ source "drivers/hte/Kconfig" source "drivers/cdx/Kconfig" +source "drivers/warden-test/Kconfig" + endmenu diff --git a/drivers/Makefile b/drivers/Makefile index 8e1ffa4..e120fc2 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -197,3 +197,6 @@ obj-$(CONFIG_DPLL) += dpll/ obj-$(CONFIG_DIBS) += dibs/ obj-$(CONFIG_S390) += s390/ + +# Test-only modules (bench fault F5): built only when the test flavour enables them. +obj-$(CONFIG_WARDEN_TEST_HANG) += warden-test/ diff --git a/drivers/warden-test/Kconfig b/drivers/warden-test/Kconfig new file mode 100644 index 0000000..3c6b7d8 --- /dev/null +++ b/drivers/warden-test/Kconfig @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Test-only modules for the WardenOS bench. The SDK builds a symbol here only +# when the caller lists its directory in WARDEN_MODULES_COLLECT (build/build-kernel.sh), +# which only the test flavour does. Release and debug kernels never enable them. + +config WARDEN_TEST_HANG + tristate "Warden test: kernel hang on a debugfs write (bench fault F5)" + depends on DEBUG_FS + help + Test-only. Creates /sys/kernel/debug/warden_hang/trigger. A write to it + turns interrupts off and never returns, so warden-io stops beating and + the board is reset by its watchdog (d07 fault F5). Never enable this in + a release or debug kernel. + + If unsure, say N. diff --git a/drivers/warden-test/Makefile b/drivers/warden-test/Makefile new file mode 100644 index 0000000..c586de7 --- /dev/null +++ b/drivers/warden-test/Makefile @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0-only +# Test-only modules. Built only when their Kconfig symbol is =m, which build/build-kernel.sh +# sets for the test flavour (WARDEN_MODULES_COLLECT lists this directory). +obj-$(CONFIG_WARDEN_TEST_HANG) += warden_hang.o diff --git a/drivers/warden-test/warden_hang.c b/drivers/warden-test/warden_hang.c new file mode 100644 index 0000000..3307532 --- /dev/null +++ b/drivers/warden-test/warden_hang.c @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Warden test-only kernel hang (bench fault F5, d07 "Fault Matrix"). + * + * A write to /sys/kernel/debug/warden_hang/trigger turns interrupts off on the + * only core and never returns. Nothing runs after that: warden-io stops + * beating, the HPMCU trips the relays once their deadline passes, and the + * watchdog resets the board about 90 s after the hang. + * + * Test flavour only. build/build-kernel.sh enables CONFIG_WARDEN_TEST_HANG + * when WARDEN_MODULES_COLLECT lists drivers/warden-test, and the module is + * then collected into oem.img with the kernel's vermagic. Nothing loads it on + * its own: the bench runner inserts it for the F5 case. + */ +#include +#include +#include +#include +#include +#include +#include + +static struct dentry *hang_dir; + +static void __noreturn warden_hang_spin(void) +{ + local_irq_disable(); + for (;;) + cpu_relax(); +} + +static ssize_t trigger_write(struct file *file, const char __user *buf, + size_t count, loff_t *ppos) +{ + /* Logged before interrupts go off; the spin below never returns. */ + pr_emerg("warden_hang: F5 kernel hang requested, interrupts off\n"); + warden_hang_spin(); +} + +static const struct file_operations trigger_fops = { + .owner = THIS_MODULE, + .write = trigger_write, + .llseek = noop_llseek, +}; + +static int __init warden_hang_init(void) +{ + hang_dir = debugfs_create_dir("warden_hang", NULL); + debugfs_create_file("trigger", 0200, hang_dir, NULL, &trigger_fops); + return 0; +} + +static void __exit warden_hang_exit(void) +{ + debugfs_remove_recursive(hang_dir); +} + +module_init(warden_hang_init); +module_exit(warden_hang_exit); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Warden test-only kernel hang (bench fault F5)");