locktorture: Prevent hangs for invalid arguments
authorPaul E. McKenney <paulmck@kernel.org>
Fri, 18 Sep 2020 18:18:06 +0000 (11:18 -0700)
committerPaul E. McKenney <paulmck@kernel.org>
Sat, 7 Nov 2020 01:13:53 +0000 (17:13 -0800)
If an locktorture torture-test run is given a bad kvm.sh argument, the
test will complain to the console, which is good.  What is bad is that
from the user's perspective, it will just hang for the time specified
by the --duration argument.  This commit therefore forces an immediate
kernel shutdown if a lock_torture_init()-time error occurs, thus avoiding
the appearance of a hang.  It also forces a console splat in this case
to clearly indicate the presence of an error.

Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
kernel/locking/locktorture.c

index 046ea2d2bc8cb23df259dcb1397aa56802f1cd40..79fbd97d3882e5b4ba839587ce17a7f33e0fdc88 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/slab.h>
 #include <linux/percpu-rwsem.h>
 #include <linux/torture.h>
+#include <linux/reboot.h>
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Paul E. McKenney <paulmck@linux.ibm.com>");
@@ -1041,6 +1042,10 @@ static int __init lock_torture_init(void)
 unwind:
        torture_init_end();
        lock_torture_cleanup();
+       if (shutdown_secs) {
+               WARN_ON(!IS_MODULE(CONFIG_LOCK_TORTURE_TEST));
+               kernel_power_off();
+       }
        return firsterr;
 }