Commit 398710379f516012c52d2ae396a9ba919bd6a7ab

Authored by Herbert Xu
1 parent 3387e7d690

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: Herbert Xu <herbert@gondor.apana.org.au>

Showing 3 changed files with 9 additions and 26 deletions Side-by-side Diff

... ... @@ -24,22 +24,6 @@
24 24  
25 25 static LIST_HEAD(crypto_template_list);
26 26  
27   -void crypto_larval_error(const char *name, u32 type, u32 mask)
28   -{
29   - struct crypto_alg *alg;
30   -
31   - alg = crypto_alg_lookup(name, type, mask);
32   -
33   - if (alg) {
34   - if (crypto_is_larval(alg)) {
35   - struct crypto_larval *larval = (void *)alg;
36   - complete_all(&larval->completion);
37   - }
38   - crypto_mod_put(alg);
39   - }
40   -}
41   -EXPORT_SYMBOL_GPL(crypto_larval_error);
42   -
43 27 static inline int crypto_set_driver_name(struct crypto_alg *alg)
44 28 {
45 29 static const char suffix[] = "-generic";
... ... @@ -295,7 +279,6 @@
295 279 continue;
296 280  
297 281 larval->adult = alg;
298   - complete_all(&larval->completion);
299 282 continue;
300 283 }
301 284  
... ... @@ -11,6 +11,7 @@
11 11 */
12 12  
13 13 #include <crypto/internal/aead.h>
  14 +#include <linux/completion.h>
14 15 #include <linux/ctype.h>
15 16 #include <linux/err.h>
16 17 #include <linux/init.h>
... ... @@ -47,6 +48,8 @@
47 48 char larval[CRYPTO_MAX_ALG_NAME];
48 49 char template[CRYPTO_MAX_ALG_NAME];
49 50  
  51 + struct completion *completion;
  52 +
50 53 u32 otype;
51 54 u32 omask;
52 55 };
... ... @@ -66,7 +69,7 @@
66 69  
67 70 tmpl = crypto_lookup_template(param->template);
68 71 if (!tmpl)
69   - goto err;
  72 + goto out;
70 73  
71 74 do {
72 75 if (tmpl->create) {
73 76  
74 77  
... ... @@ -83,16 +86,10 @@
83 86  
84 87 crypto_tmpl_put(tmpl);
85 88  
86   - if (err)
87   - goto err;
88   -
89 89 out:
  90 + complete(param->completion);
90 91 kfree(param);
91 92 module_put_and_exit(0);
92   -
93   -err:
94   - crypto_larval_error(param->larval, param->otype, param->omask);
95   - goto out;
96 93 }
97 94  
98 95 static int cryptomgr_schedule_probe(struct crypto_larval *larval)
99 96  
... ... @@ -192,9 +189,13 @@
192 189  
193 190 memcpy(param->larval, larval->alg.cra_name, CRYPTO_MAX_ALG_NAME);
194 191  
  192 + param->completion = &larval->completion;
  193 +
195 194 thread = kthread_run(cryptomgr_probe, param, "cryptomgr_probe");
196 195 if (IS_ERR(thread))
197 196 goto err_free_param;
  197 +
  198 + wait_for_completion_interruptible(&larval->completion);
198 199  
199 200 return NOTIFY_STOP;
200 201  
... ... @@ -83,7 +83,6 @@
83 83 struct crypto_larval *crypto_larval_alloc(const char *name, u32 type, u32 mask);
84 84 void crypto_larval_kill(struct crypto_alg *alg);
85 85 struct crypto_alg *crypto_larval_lookup(const char *name, u32 type, u32 mask);
86   -void crypto_larval_error(const char *name, u32 type, u32 mask);
87 86 void crypto_alg_tested(const char *name, int err);
88 87  
89 88 void crypto_remove_spawns(struct crypto_alg *alg, struct list_head *list,