From: Rusty Russell call_usermodehelper uses keventd to create a thread, guaranteeing a nice, clean kernel thread. Unfortunately, there is a case where call_usermodehelper is called with &bus->subsys.rwsem held (via bus_add_driver()), but keventd could be running bus_add_device(), which is blocked on the same lock. The result is deadlock, and it comes from using keventd for both. In this case, it can be fixed by using a completely independent thread for call_usermodehelper, or an independent workqueue. Workqueues have the infrastructure we need, so we use one. Move EXPORT_SYMBOL while we're there, too. --- 25-akpm/kernel/kmod.c | 33 +++++++++++++++------------------ 1 files changed, 15 insertions(+), 18 deletions(-) diff -puN kernel/kmod.c~use-workqueue-for-call_usermodehelper kernel/kmod.c --- 25/kernel/kmod.c~use-workqueue-for-call_usermodehelper 2004-04-18 21:28:19.067850752 -0700 +++ 25-akpm/kernel/kmod.c 2004-04-18 21:28:19.071850144 -0700 @@ -35,11 +35,13 @@ #include #include #include +#include #include extern int max_threads; #ifdef CONFIG_KMOD +static struct workqueue_struct *khelper_wq; /* modprobe_path is set via /proc/sys. @@ -109,6 +111,7 @@ int request_module(const char *fmt, ...) atomic_dec(&kmod_concurrent); return ret; } +EXPORT_SYMBOL(request_module); #endif /* CONFIG_KMOD */ #ifdef CONFIG_HOTPLUG @@ -197,9 +200,7 @@ static int wait_for_helper(void *data) return 0; } -/* - * This is run by keventd. - */ +/* This is run by khelper thread */ static void __call_usermodehelper(void *data) { struct subprocess_info *sub_info = data; @@ -249,26 +250,22 @@ int call_usermodehelper(char *path, char }; DECLARE_WORK(work, __call_usermodehelper, &sub_info); - if (system_state != SYSTEM_RUNNING) + if (!khelper_wq) return -EBUSY; if (path[0] == '\0') - goto out; + return 0; - if (current_is_keventd()) { - /* We can't wait on keventd! */ - __call_usermodehelper(&sub_info); - } else { - schedule_work(&work); - wait_for_completion(&done); - } -out: + queue_work(khelper_wq, &work); + wait_for_completion(&done); return sub_info.retval; } - EXPORT_SYMBOL(call_usermodehelper); -#ifdef CONFIG_KMOD -EXPORT_SYMBOL(request_module); -#endif - +static __init int usermodehelper_init(void) +{ + khelper_wq = create_singlethread_workqueue("khelper"); + BUG_ON(!khelper_wq); + return 0; +} +__initcall(usermodehelper_init); _