Skip to content

Commit

Permalink
dm crypt: use dm_submit_bio_remap
Browse files Browse the repository at this point in the history
Care was taken to support kcryptd_io_read being called from crypt_map
or workqueue.  Use of an intermediate CRYPT_MAP_READ_GFP gfp_t
(defined as GFP_NOWAIT) should protect from maintenance burden if that
flag were to change for some reason.

Reviewed-by: Mikulas Patocka <[email protected]>
Signed-off-by: Mike Snitzer <[email protected]>
  • Loading branch information
snitm committed Feb 21, 2022
1 parent 0fbb4d9 commit e5524e1
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions drivers/md/dm-crypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1828,6 +1828,8 @@ static void crypt_endio(struct bio *clone)
crypt_dec_pending(io);
}

#define CRYPT_MAP_READ_GFP GFP_NOWAIT

static int kcryptd_io_read(struct dm_crypt_io *io, gfp_t gfp)
{
struct crypt_config *cc = io->cc;
Expand Down Expand Up @@ -1855,7 +1857,7 @@ static int kcryptd_io_read(struct dm_crypt_io *io, gfp_t gfp)
return 1;
}

submit_bio_noacct(clone);
dm_submit_bio_remap(io->base_bio, clone, (gfp != CRYPT_MAP_READ_GFP));
return 0;
}

Expand All @@ -1881,7 +1883,7 @@ static void kcryptd_io_write(struct dm_crypt_io *io)
{
struct bio *clone = io->ctx.bio_out;

submit_bio_noacct(clone);
dm_submit_bio_remap(io->base_bio, clone, true);
}

#define crypt_io_from_node(node) rb_entry((node), struct dm_crypt_io, rb_node)
Expand Down Expand Up @@ -1960,7 +1962,7 @@ static void kcryptd_crypt_write_io_submit(struct dm_crypt_io *io, int async)

if ((likely(!async) && test_bit(DM_CRYPT_NO_OFFLOAD, &cc->flags)) ||
test_bit(DM_CRYPT_NO_WRITE_WORKQUEUE, &cc->flags)) {
submit_bio_noacct(clone);
dm_submit_bio_remap(io->base_bio, clone, true);
return;
}

Expand Down Expand Up @@ -3363,6 +3365,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)

ti->num_flush_bios = 1;
ti->limit_swap_bios = true;
ti->accounts_remapped_io = true;

dm_audit_log_ctr(DM_MSG_PREFIX, ti, 1);
return 0;
Expand Down Expand Up @@ -3431,7 +3434,7 @@ static int crypt_map(struct dm_target *ti, struct bio *bio)
io->ctx.r.req = (struct skcipher_request *)(io + 1);

if (bio_data_dir(io->base_bio) == READ) {
if (kcryptd_io_read(io, GFP_NOWAIT))
if (kcryptd_io_read(io, CRYPT_MAP_READ_GFP))
kcryptd_queue_read(io);
} else
kcryptd_queue_crypt(io);
Expand Down Expand Up @@ -3626,7 +3629,7 @@ static void crypt_io_hints(struct dm_target *ti, struct queue_limits *limits)

static struct target_type crypt_target = {
.name = "crypt",
.version = {1, 23, 0},
.version = {1, 24, 0},
.module = THIS_MODULE,
.ctr = crypt_ctr,
.dtr = crypt_dtr,
Expand Down

0 comments on commit e5524e1

Please sign in to comment.