Commit acae05156551fd7528fbb616271e672789388e3c
Committed by
Rusty Russell
1 parent
8c8ef42aee
Exists in
master
and in
4 other branches
module: create a request_module_nowait()
There seems to be a common pattern in the kernel where drivers want to call request_module() from inside a module_init() function. Currently this would deadlock. As a result, several drivers go through hoops like scheduling things via kevent, or creating custom work queues (because kevent can deadlock on them). This patch changes this to use a request_module_nowait() function macro instead, which just fires the modprobe off but doesn't wait for it, and thus avoids the original deadlock entirely. On my laptop this already results in one less kernel thread running.. (Includes Jiri's patch to use enum umh_wait) Signed-off-by: Arjan van de Ven <arjan@linux.intel.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (bool-ified) Cc: Jiri Slaby <jirislaby@gmail.com>
Showing 2 changed files with 14 additions and 7 deletions Side-by-side Diff
include/linux/kmod.h
... | ... | @@ -29,10 +29,15 @@ |
29 | 29 | #ifdef CONFIG_MODULES |
30 | 30 | /* modprobe exit status on success, -ve on error. Return value |
31 | 31 | * usually useless though. */ |
32 | -extern int request_module(const char * name, ...) __attribute__ ((format (printf, 1, 2))); | |
33 | -#define try_then_request_module(x, mod...) ((x) ?: (request_module(mod), (x))) | |
32 | +extern int __request_module(bool wait, const char *name, ...) \ | |
33 | + __attribute__((format(printf, 2, 3))); | |
34 | +#define request_module(mod...) __request_module(true, mod) | |
35 | +#define request_module_nowait(mod...) __request_module(false, mod) | |
36 | +#define try_then_request_module(x, mod...) \ | |
37 | + ((x) ?: (__request_module(false, mod), (x))) | |
34 | 38 | #else |
35 | -static inline int request_module(const char * name, ...) { return -ENOSYS; } | |
39 | +static inline int request_module(const char *name, ...) { return -ENOSYS; } | |
40 | +static inline int request_module_nowait(const char *name, ...) { return -ENOSYS; } | |
36 | 41 | #define try_then_request_module(x, mod...) (x) |
37 | 42 | #endif |
38 | 43 |
kernel/kmod.c
... | ... | @@ -50,7 +50,8 @@ |
50 | 50 | char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe"; |
51 | 51 | |
52 | 52 | /** |
53 | - * request_module - try to load a kernel module | |
53 | + * __request_module - try to load a kernel module | |
54 | + * @wait: wait (or not) for the operation to complete | |
54 | 55 | * @fmt: printf style format string for the name of the module |
55 | 56 | * @...: arguments as specified in the format string |
56 | 57 | * |
... | ... | @@ -63,7 +64,7 @@ |
63 | 64 | * If module auto-loading support is disabled then this function |
64 | 65 | * becomes a no-operation. |
65 | 66 | */ |
66 | -int request_module(const char *fmt, ...) | |
67 | +int __request_module(bool wait, const char *fmt, ...) | |
67 | 68 | { |
68 | 69 | va_list args; |
69 | 70 | char module_name[MODULE_NAME_LEN]; |
70 | 71 | |
... | ... | @@ -108,11 +109,12 @@ |
108 | 109 | return -ENOMEM; |
109 | 110 | } |
110 | 111 | |
111 | - ret = call_usermodehelper(modprobe_path, argv, envp, 1); | |
112 | + ret = call_usermodehelper(modprobe_path, argv, envp, | |
113 | + wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC); | |
112 | 114 | atomic_dec(&kmod_concurrent); |
113 | 115 | return ret; |
114 | 116 | } |
115 | -EXPORT_SYMBOL(request_module); | |
117 | +EXPORT_SYMBOL(__request_module); | |
116 | 118 | #endif /* CONFIG_MODULES */ |
117 | 119 | |
118 | 120 | struct subprocess_info { |