Commit 9cc019b8 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Rusty Russell

module: Replace over-engineered nested sleep

Since the introduction of the nested sleep warning; we've established
that the occasional sleep inside a wait_event() is fine.

wait_event() loops are invariant wrt. spurious wakeups, and the
occasional sleep has a similar effect on them. As long as its occasional
its harmless.

Therefore replace the 'correct' but verbose wait_woken() thing with
a simple annotation to shut up the warning.
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent d64810f5
...@@ -2984,6 +2984,12 @@ static bool finished_loading(const char *name) ...@@ -2984,6 +2984,12 @@ static bool finished_loading(const char *name)
struct module *mod; struct module *mod;
bool ret; bool ret;
/*
* The module_mutex should not be a heavily contended lock;
* if we get the occasional sleep here, we'll go an extra iteration
* in the wait_event_interruptible(), which is harmless.
*/
sched_annotate_sleep();
mutex_lock(&module_mutex); mutex_lock(&module_mutex);
mod = find_module_all(name, strlen(name), true); mod = find_module_all(name, strlen(name), true);
ret = !mod || mod->state == MODULE_STATE_LIVE ret = !mod || mod->state == MODULE_STATE_LIVE
...@@ -3125,32 +3131,6 @@ static int may_init_module(void) ...@@ -3125,32 +3131,6 @@ static int may_init_module(void)
return 0; return 0;
} }
/*
* Can't use wait_event_interruptible() because our condition
* 'finished_loading()' contains a blocking primitive itself (mutex_lock).
*/
static int wait_finished_loading(struct module *mod)
{
DEFINE_WAIT_FUNC(wait, woken_wake_function);
int ret = 0;
add_wait_queue(&module_wq, &wait);
for (;;) {
if (finished_loading(mod->name))
break;
if (signal_pending(current)) {
ret = -ERESTARTSYS;
break;
}
wait_woken(&wait, TASK_INTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT);
}
remove_wait_queue(&module_wq, &wait);
return ret;
}
/* /*
* We try to place it in the list now to make sure it's unique before * We try to place it in the list now to make sure it's unique before
* we dedicate too many resources. In particular, temporary percpu * we dedicate too many resources. In particular, temporary percpu
...@@ -3171,8 +3151,8 @@ static int add_unformed_module(struct module *mod) ...@@ -3171,8 +3151,8 @@ static int add_unformed_module(struct module *mod)
|| old->state == MODULE_STATE_UNFORMED) { || old->state == MODULE_STATE_UNFORMED) {
/* Wait in case it fails to load. */ /* Wait in case it fails to load. */
mutex_unlock(&module_mutex); mutex_unlock(&module_mutex);
err = wait_event_interruptible(module_wq,
err = wait_finished_loading(mod); finished_loading(mod->name));
if (err) if (err)
goto out_unlocked; goto out_unlocked;
goto again; goto again;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment