Skip to content

Commit 0fdff3e

Browse files
committed
async, kmod: warn on synchronous request_module() from async workers
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>
1 parent 21c3c5d commit 0fdff3e

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

‎kernel/kmod.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <linux/suspend.h>
3939
#include <linux/rwsem.h>
4040
#include <linux/ptrace.h>
41+
#include <linux/async.h>
4142
#include <asm/uaccess.h>
4243

4344
#include <trace/events/module.h>
@@ -130,6 +131,14 @@ int __request_module(bool wait, const char *fmt, ...)
130131
#define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
131132
static int kmod_loop_msg;
132133

134+
/*
135+
* We don't allow synchronous module loading from async. Module
136+
* init may invoke async_synchronize_full() which will end up
137+
* waiting for this task which already is waiting for the module
138+
* loading to complete, leading to a deadlock.
139+
*/
140+
WARN_ON_ONCE(wait && current_is_async());
141+
133142
va_start(args, fmt);
134143
ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
135144
va_end(args);

0 commit comments

Comments
 (0)