Skip to content

Commit

Permalink
dm crypt: fix deadlock when async crypto algorithm returns -EBUSY
Browse files Browse the repository at this point in the history
commit 0618764cb25f6fa9fb31152995de42a8a0496475 upstream.

I suspect this doesn't show up for most anyone because software
algorithms typically don't have a sense of being too busy.  However,
when working with the Freescale CAAM driver it will return -EBUSY on
occasion under heavy -- which resulted in dm-crypt deadlock.

After checking the logic in some other drivers, the scheme for
crypt_convert() and it's callback, kcryptd_async_done(), were not
correctly laid out to properly handle -EBUSY or -EINPROGRESS.

Fix this by using the completion for both -EBUSY and -EINPROGRESS.  Now
crypt_convert()'s use of completion is comparable to
af_alg_wait_for_completion().  Similarly, kcryptd_async_done() follows
the pattern used in af_alg_complete().

Before this fix dm-crypt would lockup within 1-2 minutes running with
the CAAM driver.  Fix was regression tested against software algorithms
on PPC32 and x86_64, and things seem perfectly happy there as well.

Change-Id: I4750c93721392d358088b4ba04639af7e989192d
Signed-off-by: Ben Collins <ben.c@servergy.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
[lizf: Backported to 3.4: adjust context]
Signed-off-by: Zefan Li <lizefan@huawei.com>
  • Loading branch information
benmcollins authored and u-ra committed Sep 18, 2015
1 parent e2c1297 commit 6688d6a
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions drivers/md/dm-crypt.c
Expand Up @@ -753,11 +753,10 @@ static int crypt_convert(struct crypt_config *cc,

switch (r) {
/* async */
case -EINPROGRESS:
case -EBUSY:
wait_for_completion(&ctx->restart);
INIT_COMPLETION(ctx->restart);
/* fall through*/
case -EINPROGRESS:
ctx->req = NULL;
ctx->sector++;
continue;
Expand Down Expand Up @@ -1169,10 +1168,8 @@ static void kcryptd_async_done(struct crypto_async_request *async_req,
struct dm_crypt_io *io = container_of(ctx, struct dm_crypt_io, ctx);
struct crypt_config *cc = io->target->private;

if (error == -EINPROGRESS) {
complete(&ctx->restart);
if (error == -EINPROGRESS)
return;
}

if (!error && cc->iv_gen_ops && cc->iv_gen_ops->post)
error = cc->iv_gen_ops->post(cc, iv_of_dmreq(cc, dmreq), dmreq);
Expand All @@ -1183,12 +1180,15 @@ static void kcryptd_async_done(struct crypto_async_request *async_req,
mempool_free(req_of_dmreq(cc, dmreq), cc->req_pool);

if (!atomic_dec_and_test(&ctx->pending))
return;
goto done;

if (bio_data_dir(io->base_bio) == READ)
kcryptd_crypt_read_done(io);
else
kcryptd_crypt_write_io_submit(io, 1);
done:
if (!completion_done(&ctx->restart))
complete(&ctx->restart);
}

static void kcryptd_crypt(struct work_struct *work)
Expand Down

0 comments on commit 6688d6a

Please sign in to comment.