|
40 | 40 | * effect. Systems like these are very unlikely if modules are enabled.
|
41 | 41 | */
|
42 | 42 | #define MAX_KMOD_CONCURRENT 50
|
43 |
| -static atomic_t kmod_concurrent_max = ATOMIC_INIT(MAX_KMOD_CONCURRENT); |
44 |
| -static DECLARE_WAIT_QUEUE_HEAD(kmod_wq); |
| 43 | +static DEFINE_SEMAPHORE(kmod_concurrent_max, MAX_KMOD_CONCURRENT); |
45 | 44 |
|
46 | 45 | /*
|
47 | 46 | * This is a restriction on having *all* MAX_KMOD_CONCURRENT threads
|
@@ -148,29 +147,18 @@ int __request_module(bool wait, const char *fmt, ...)
|
148 | 147 | if (ret)
|
149 | 148 | return ret;
|
150 | 149 |
|
151 |
| - if (atomic_dec_if_positive(&kmod_concurrent_max) < 0) { |
152 |
| - pr_warn_ratelimited("request_module: kmod_concurrent_max (%u) close to 0 (max_modprobes: %u), for module %s, throttling...", |
153 |
| - atomic_read(&kmod_concurrent_max), |
154 |
| - MAX_KMOD_CONCURRENT, module_name); |
155 |
| - ret = wait_event_killable_timeout(kmod_wq, |
156 |
| - atomic_dec_if_positive(&kmod_concurrent_max) >= 0, |
157 |
| - MAX_KMOD_ALL_BUSY_TIMEOUT * HZ); |
158 |
| - if (!ret) { |
159 |
| - pr_warn_ratelimited("request_module: modprobe %s cannot be processed, kmod busy with %d threads for more than %d seconds now", |
160 |
| - module_name, MAX_KMOD_CONCURRENT, MAX_KMOD_ALL_BUSY_TIMEOUT); |
161 |
| - return -ETIME; |
162 |
| - } else if (ret == -ERESTARTSYS) { |
163 |
| - pr_warn_ratelimited("request_module: sigkill sent for modprobe %s, giving up", module_name); |
164 |
| - return ret; |
165 |
| - } |
| 150 | + ret = down_timeout(&kmod_concurrent_max, MAX_KMOD_ALL_BUSY_TIMEOUT * HZ); |
| 151 | + if (ret) { |
| 152 | + pr_warn_ratelimited("request_module: modprobe %s cannot be processed, kmod busy with %d threads for more than %d seconds now", |
| 153 | + module_name, MAX_KMOD_CONCURRENT, MAX_KMOD_ALL_BUSY_TIMEOUT); |
| 154 | + return ret; |
166 | 155 | }
|
167 | 156 |
|
168 | 157 | trace_module_request(module_name, wait, _RET_IP_);
|
169 | 158 |
|
170 | 159 | ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
|
171 | 160 |
|
172 |
| - atomic_inc(&kmod_concurrent_max); |
173 |
| - wake_up(&kmod_wq); |
| 161 | + up(&kmod_concurrent_max); |
174 | 162 |
|
175 | 163 | return ret;
|
176 | 164 | }
|
|
0 commit comments