Commit 39871037 authored by Herbert Xu's avatar Herbert Xu

crypto: algapi - Move larval completion into algboss

It has been observed that sometimes the crypto allocation code
will get stuck for 60 seconds or multiples thereof.  This is
usually caused by an algorithm failing to pass the self-test.

If an algorithm fails to be constructed, we will immediately notify
all larval waiters.  However, if it succeeds in construction, but
then fails the self-test, we won't notify anyone at all.

This patch fixes this by merging the notification in the case
where the algorithm fails to be constructed with that of the
the case where it pases the self-test.  This way regardless of
what happens, we'll give the larval waiters an answer.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 3387e7d6
...@@ -24,22 +24,6 @@ ...@@ -24,22 +24,6 @@
static LIST_HEAD(crypto_template_list); static LIST_HEAD(crypto_template_list);
void crypto_larval_error(const char *name, u32 type, u32 mask)
{
struct crypto_alg *alg;
alg = crypto_alg_lookup(name, type, mask);
if (alg) {
if (crypto_is_larval(alg)) {
struct crypto_larval *larval = (void *)alg;
complete_all(&larval->completion);
}
crypto_mod_put(alg);
}
}
EXPORT_SYMBOL_GPL(crypto_larval_error);
static inline int crypto_set_driver_name(struct crypto_alg *alg) static inline int crypto_set_driver_name(struct crypto_alg *alg)
{ {
static const char suffix[] = "-generic"; static const char suffix[] = "-generic";
...@@ -295,7 +279,6 @@ void crypto_alg_tested(const char *name, int err) ...@@ -295,7 +279,6 @@ void crypto_alg_tested(const char *name, int err)
continue; continue;
larval->adult = alg; larval->adult = alg;
complete_all(&larval->completion);
continue; continue;
} }
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
*/ */
#include <crypto/internal/aead.h> #include <crypto/internal/aead.h>
#include <linux/completion.h>
#include <linux/ctype.h> #include <linux/ctype.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/init.h> #include <linux/init.h>
...@@ -47,6 +48,8 @@ struct cryptomgr_param { ...@@ -47,6 +48,8 @@ struct cryptomgr_param {
char larval[CRYPTO_MAX_ALG_NAME]; char larval[CRYPTO_MAX_ALG_NAME];
char template[CRYPTO_MAX_ALG_NAME]; char template[CRYPTO_MAX_ALG_NAME];
struct completion *completion;
u32 otype; u32 otype;
u32 omask; u32 omask;
}; };
...@@ -66,7 +69,7 @@ static int cryptomgr_probe(void *data) ...@@ -66,7 +69,7 @@ static int cryptomgr_probe(void *data)
tmpl = crypto_lookup_template(param->template); tmpl = crypto_lookup_template(param->template);
if (!tmpl) if (!tmpl)
goto err; goto out;
do { do {
if (tmpl->create) { if (tmpl->create) {
...@@ -83,16 +86,10 @@ static int cryptomgr_probe(void *data) ...@@ -83,16 +86,10 @@ static int cryptomgr_probe(void *data)
crypto_tmpl_put(tmpl); crypto_tmpl_put(tmpl);
if (err)
goto err;
out: out:
complete(param->completion);
kfree(param); kfree(param);
module_put_and_exit(0); module_put_and_exit(0);
err:
crypto_larval_error(param->larval, param->otype, param->omask);
goto out;
} }
static int cryptomgr_schedule_probe(struct crypto_larval *larval) static int cryptomgr_schedule_probe(struct crypto_larval *larval)
...@@ -192,10 +189,14 @@ static int cryptomgr_schedule_probe(struct crypto_larval *larval) ...@@ -192,10 +189,14 @@ static int cryptomgr_schedule_probe(struct crypto_larval *larval)
memcpy(param->larval, larval->alg.cra_name, CRYPTO_MAX_ALG_NAME); memcpy(param->larval, larval->alg.cra_name, CRYPTO_MAX_ALG_NAME);
param->completion = &larval->completion;
thread = kthread_run(cryptomgr_probe, param, "cryptomgr_probe"); thread = kthread_run(cryptomgr_probe, param, "cryptomgr_probe");
if (IS_ERR(thread)) if (IS_ERR(thread))
goto err_free_param; goto err_free_param;
wait_for_completion_interruptible(&larval->completion);
return NOTIFY_STOP; return NOTIFY_STOP;
err_free_param: err_free_param:
......
...@@ -83,7 +83,6 @@ void crypto_exit_compress_ops(struct crypto_tfm *tfm); ...@@ -83,7 +83,6 @@ void crypto_exit_compress_ops(struct crypto_tfm *tfm);
struct crypto_larval *crypto_larval_alloc(const char *name, u32 type, u32 mask); struct crypto_larval *crypto_larval_alloc(const char *name, u32 type, u32 mask);
void crypto_larval_kill(struct crypto_alg *alg); void crypto_larval_kill(struct crypto_alg *alg);
struct crypto_alg *crypto_larval_lookup(const char *name, u32 type, u32 mask); struct crypto_alg *crypto_larval_lookup(const char *name, u32 type, u32 mask);
void crypto_larval_error(const char *name, u32 type, u32 mask);
void crypto_alg_tested(const char *name, int err); void crypto_alg_tested(const char *name, int err);
void crypto_remove_spawns(struct crypto_alg *alg, struct list_head *list, void crypto_remove_spawns(struct crypto_alg *alg, struct list_head *list,
......
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