]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
async, kmod: warn on synchronous request_module() from async workers
authorTejun Heo <tj@kernel.org>
Wed, 23 Jan 2013 00:48:03 +0000 (16:48 -0800)
committerTejun Heo <tj@kernel.org>
Wed, 23 Jan 2013 00:48:03 +0000 (16:48 -0800)
Synchronous requet_module() from an async worker can lead to deadlock
because module init path may invoke async_synchronize_full().  The
async worker waits for request_module() to complete and the module
loading waits for the async task to finish.  This bug happened in the
block layer because of default elevator auto-loading.

Block layer has been updated not to do default elevator auto-loading
and it has been decided to disallow synchronous request_module() from
async workers.

Trigger WARN_ON_ONCE() on synchronous request_module() from async
workers.

For more details, please refer to the following thread.

  http://thread.gmane.org/gmane.linux.kernel/1420814

Signed-off-by: Tejun Heo <tj@kernel.org>
Reported-by: Alex Riesen <raa.lkml@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Arjan van de Ven <arjan@linux.intel.com>
kernel/kmod.c

index 1c317e386831869a3c4ff17a675a06b3b985c06d..ecd42b484db8cd9fe05cd62c169dcc217c1bfa06 100644 (file)
@@ -38,6 +38,7 @@
 #include <linux/suspend.h>
 #include <linux/rwsem.h>
 #include <linux/ptrace.h>
+#include <linux/async.h>
 #include <asm/uaccess.h>
 
 #include <trace/events/module.h>
@@ -130,6 +131,14 @@ int __request_module(bool wait, const char *fmt, ...)
 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
        static int kmod_loop_msg;
 
+       /*
+        * We don't allow synchronous module loading from async.  Module
+        * init may invoke async_synchronize_full() which will end up
+        * waiting for this task which already is waiting for the module
+        * loading to complete, leading to a deadlock.
+        */
+       WARN_ON_ONCE(wait && current_is_async());
+
        va_start(args, fmt);
        ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
        va_end(args);