mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git
synced 2026-04-18 03:23:53 -04:00
crypto: api - Do not wait for tests during registration
As registration is usually carried out during module init, this is a context where as little work as possible should be carried out. Testing may trigger module loads of underlying components, which could even lead back to the module that is registering at the moment. This may lead to dead-locks outside of the Crypto API. Avoid this by not waiting for the tests to complete. They will be scheduled but completion will be asynchronous. Any users will still wait for completion. Reported-by: Russell King <linux@armlinux.org.uk> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
41
crypto/api.c
41
crypto/api.c
@@ -154,32 +154,31 @@ static struct crypto_alg *crypto_larval_add(const char *name, u32 type,
|
||||
return alg;
|
||||
}
|
||||
|
||||
void crypto_larval_kill(struct crypto_alg *alg)
|
||||
static void crypto_larval_kill(struct crypto_larval *larval)
|
||||
{
|
||||
struct crypto_larval *larval = (void *)alg;
|
||||
bool unlinked;
|
||||
|
||||
down_write(&crypto_alg_sem);
|
||||
list_del(&alg->cra_list);
|
||||
unlinked = list_empty(&larval->alg.cra_list);
|
||||
if (!unlinked)
|
||||
list_del_init(&larval->alg.cra_list);
|
||||
up_write(&crypto_alg_sem);
|
||||
complete_all(&larval->completion);
|
||||
crypto_alg_put(alg);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(crypto_larval_kill);
|
||||
|
||||
void crypto_wait_for_test(struct crypto_larval *larval)
|
||||
if (unlinked)
|
||||
return;
|
||||
|
||||
complete_all(&larval->completion);
|
||||
crypto_alg_put(&larval->alg);
|
||||
}
|
||||
|
||||
void crypto_schedule_test(struct crypto_larval *larval)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = crypto_probing_notify(CRYPTO_MSG_ALG_REGISTER, larval->adult);
|
||||
if (WARN_ON_ONCE(err != NOTIFY_STOP))
|
||||
goto out;
|
||||
|
||||
err = wait_for_completion_killable(&larval->completion);
|
||||
WARN_ON(err);
|
||||
out:
|
||||
crypto_larval_kill(&larval->alg);
|
||||
WARN_ON_ONCE(err != NOTIFY_STOP);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(crypto_wait_for_test);
|
||||
EXPORT_SYMBOL_GPL(crypto_schedule_test);
|
||||
|
||||
static void crypto_start_test(struct crypto_larval *larval)
|
||||
{
|
||||
@@ -198,7 +197,7 @@ static void crypto_start_test(struct crypto_larval *larval)
|
||||
larval->test_started = true;
|
||||
up_write(&crypto_alg_sem);
|
||||
|
||||
crypto_wait_for_test(larval);
|
||||
crypto_schedule_test(larval);
|
||||
}
|
||||
|
||||
static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg)
|
||||
@@ -218,9 +217,11 @@ again:
|
||||
alg = larval->adult;
|
||||
if (time_left < 0)
|
||||
alg = ERR_PTR(-EINTR);
|
||||
else if (!time_left)
|
||||
else if (!time_left) {
|
||||
if (crypto_is_test_larval(larval))
|
||||
crypto_larval_kill(larval);
|
||||
alg = ERR_PTR(-ETIMEDOUT);
|
||||
else if (!alg) {
|
||||
} else if (!alg) {
|
||||
u32 type;
|
||||
u32 mask;
|
||||
|
||||
@@ -355,7 +356,7 @@ struct crypto_alg *crypto_alg_mod_lookup(const char *name, u32 type, u32 mask)
|
||||
crypto_mod_put(larval);
|
||||
alg = ERR_PTR(-ENOENT);
|
||||
}
|
||||
crypto_larval_kill(larval);
|
||||
crypto_larval_kill(container_of(larval, struct crypto_larval, alg));
|
||||
return alg;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(crypto_alg_mod_lookup);
|
||||
|
||||
Reference in New Issue
Block a user