aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHou Tao <houtao1@huawei.com>2023-03-06 21:49:30 +0800
committerMike Snitzer <snitzer@kernel.org>2023-03-06 16:51:07 -0500
commitd9fe0a98a2e0a1cf585e8a6555afb33be968bd13 (patch)
tree3543cd5ec8523c7c3539236165eb2715a7a2b25c
parentfb294b1c0ba982144ca467a75e7d01ff26304e2b (diff)
downloadlinux-dm-d9fe0a98a2e0a1cf585e8a6555afb33be968bd13.tar.gz
dm crypt: initialize tasklet in crypt_io_init()
Notice: this object is not reachable from any branch.
When neither no_read_workqueue nor no_write_workqueue are enabled, tasklet_trylock() in crypt_dec_pending() may still return false due to an uninitialized state, and dm-crypt will do io completion in io_queue instead of current context unnecessarily. Fix it by initializing io->tasklet in crypt_io_init(). Fixes: 8e14f610159d ("dm crypt: do not call bio_endio() from the dm-crypt tasklet") Signed-off-by: Hou Tao <houtao1@huawei.com> Signed-off-by: Mike Snitzer <snitzer@kernel.org>
Notice: this object is not reachable from any branch.
-rw-r--r--drivers/md/dm-crypt.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index faba1be572f90..641457e726036 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -239,6 +239,7 @@ static void crypt_endio(struct bio *clone);
static void kcryptd_queue_crypt(struct dm_crypt_io *io);
static struct scatterlist *crypt_get_sg_data(struct crypt_config *cc,
struct scatterlist *sg);
+static void kcryptd_crypt_tasklet(unsigned long work);
static bool crypt_integrity_aead(struct crypt_config *cc);
@@ -1729,6 +1730,12 @@ static void crypt_io_init(struct dm_crypt_io *io, struct crypt_config *cc,
io->sector = sector;
io->error = 0;
io->ctx.r.req = NULL;
+ /*
+ * tasklet_init() here to ensure crypt_dec_pending()'s
+ * tasklet_trylock() doesn't incorrectly return false
+ * even when tasklet isn't in use.
+ */
+ tasklet_init(&io->tasklet, kcryptd_crypt_tasklet, (unsigned long)&io->work);
io->integrity_metadata = NULL;
io->integrity_metadata_from_pool = false;
atomic_set(&io->io_pending, 0);
@@ -2233,7 +2240,6 @@ static void kcryptd_queue_crypt(struct dm_crypt_io *io)
* it is being executed with irqs disabled.
*/
if (in_hardirq() || irqs_disabled()) {
- tasklet_init(&io->tasklet, kcryptd_crypt_tasklet, (unsigned long)&io->work);
tasklet_schedule(&io->tasklet);
return;
}