Skip to content

Commit 96ad595

Browse files
committed
crypto: api - Remove instance larval fulfilment
In order to allow testing to complete asynchronously after the registration process, instance larvals need to complete prior to having a test result. Support this by redoing the lookup for instance larvals after completion. This should locate the pending test larval and then repeat the wait on that (if it is still pending). As the lookup is now repeated there is no longer any need to compute the fulfilment status and all that code can be removed. Signed-off-by: Herbert Xu <[email protected]>
1 parent 7ccb750 commit 96ad595

File tree

3 files changed

+23
-49
lines changed

3 files changed

+23
-49
lines changed

crypto/algapi.c

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ void crypto_remove_spawns(struct crypto_alg *alg, struct list_head *list,
235235
EXPORT_SYMBOL_GPL(crypto_remove_spawns);
236236

237237
static void crypto_alg_finish_registration(struct crypto_alg *alg,
238-
bool fulfill_requests,
239238
struct list_head *algs_to_put)
240239
{
241240
struct crypto_alg *q;
@@ -247,30 +246,8 @@ static void crypto_alg_finish_registration(struct crypto_alg *alg,
247246
if (crypto_is_moribund(q))
248247
continue;
249248

250-
if (crypto_is_larval(q)) {
251-
struct crypto_larval *larval = (void *)q;
252-
253-
/*
254-
* Check to see if either our generic name or
255-
* specific name can satisfy the name requested
256-
* by the larval entry q.
257-
*/
258-
if (strcmp(alg->cra_name, q->cra_name) &&
259-
strcmp(alg->cra_driver_name, q->cra_name))
260-
continue;
261-
262-
if (larval->adult)
263-
continue;
264-
if ((q->cra_flags ^ alg->cra_flags) & larval->mask)
265-
continue;
266-
267-
if (fulfill_requests && crypto_mod_get(alg))
268-
larval->adult = alg;
269-
else
270-
larval->adult = ERR_PTR(-EAGAIN);
271-
249+
if (crypto_is_larval(q))
272250
continue;
273-
}
274251

275252
if (strcmp(alg->cra_name, q->cra_name))
276253
continue;
@@ -359,7 +336,7 @@ __crypto_register_alg(struct crypto_alg *alg, struct list_head *algs_to_put)
359336
list_add(&larval->alg.cra_list, &crypto_alg_list);
360337
} else {
361338
alg->cra_flags |= CRYPTO_ALG_TESTED;
362-
crypto_alg_finish_registration(alg, true, algs_to_put);
339+
crypto_alg_finish_registration(alg, algs_to_put);
363340
}
364341

365342
out:
@@ -376,7 +353,6 @@ void crypto_alg_tested(const char *name, int err)
376353
struct crypto_alg *alg;
377354
struct crypto_alg *q;
378355
LIST_HEAD(list);
379-
bool best;
380356

381357
down_write(&crypto_alg_sem);
382358
list_for_each_entry(q, &crypto_alg_list, cra_list) {
@@ -408,25 +384,7 @@ void crypto_alg_tested(const char *name, int err)
408384

409385
alg->cra_flags |= CRYPTO_ALG_TESTED;
410386

411-
/*
412-
* If a higher-priority implementation of the same algorithm is
413-
* currently being tested, then don't fulfill request larvals.
414-
*/
415-
best = true;
416-
list_for_each_entry(q, &crypto_alg_list, cra_list) {
417-
if (crypto_is_moribund(q) || !crypto_is_larval(q))
418-
continue;
419-
420-
if (strcmp(alg->cra_name, q->cra_name))
421-
continue;
422-
423-
if (q->cra_priority > alg->cra_priority) {
424-
best = false;
425-
break;
426-
}
427-
}
428-
429-
crypto_alg_finish_registration(alg, best, &list);
387+
crypto_alg_finish_registration(alg, &list);
430388

431389
complete:
432390
complete_all(&test->completion);

crypto/algboss.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ static int cryptomgr_probe(void *data)
6464
crypto_tmpl_put(tmpl);
6565

6666
out:
67+
param->larval->alg.cra_flags |= CRYPTO_ALG_DEAD;
6768
complete_all(&param->larval->completion);
6869
crypto_alg_put(&param->larval->alg);
6970
kfree(param);

crypto/api.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ DEFINE_STATIC_KEY_FALSE(__crypto_boot_test_finished);
3737
#endif
3838

3939
static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg);
40+
static struct crypto_alg *crypto_alg_lookup(const char *name, u32 type,
41+
u32 mask);
4042

4143
struct crypto_alg *crypto_mod_get(struct crypto_alg *alg)
4244
{
@@ -201,9 +203,12 @@ static void crypto_start_test(struct crypto_larval *larval)
201203

202204
static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg)
203205
{
204-
struct crypto_larval *larval = (void *)alg;
206+
struct crypto_larval *larval;
205207
long time_left;
206208

209+
again:
210+
larval = container_of(alg, struct crypto_larval, alg);
211+
207212
if (!crypto_boot_test_finished())
208213
crypto_start_test(larval);
209214

@@ -215,9 +220,16 @@ static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg)
215220
alg = ERR_PTR(-EINTR);
216221
else if (!time_left)
217222
alg = ERR_PTR(-ETIMEDOUT);
218-
else if (!alg)
219-
alg = ERR_PTR(-ENOENT);
220-
else if (IS_ERR(alg))
223+
else if (!alg) {
224+
u32 type;
225+
u32 mask;
226+
227+
alg = &larval->alg;
228+
type = alg->cra_flags & ~(CRYPTO_ALG_LARVAL | CRYPTO_ALG_DEAD);
229+
mask = larval->mask;
230+
alg = crypto_alg_lookup(alg->cra_name, type, mask) ?:
231+
ERR_PTR(-ENOENT);
232+
} else if (IS_ERR(alg))
221233
;
222234
else if (crypto_is_test_larval(larval) &&
223235
!(alg->cra_flags & CRYPTO_ALG_TESTED))
@@ -228,6 +240,9 @@ static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg)
228240
alg = ERR_PTR(-EAGAIN);
229241
crypto_mod_put(&larval->alg);
230242

243+
if (!IS_ERR(alg) && crypto_is_larval(alg))
244+
goto again;
245+
231246
return alg;
232247
}
233248

0 commit comments

Comments
 (0)