[PATCH] dm-crypt: introduce a module parameter that makes it possible to limit all bios

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The patch a666e5c05e7c4aaabb2c5d58117b0946803d03d2 ("dm: fix deadlock when
swapping to encrypted device") limits the number of in-flight swap bios
for the dm-crypt target. It avoids a deadlock when swapping to a dm-crypt
device.

The limit is not applied to non-swap workload because it uses shared
variables that cause cache line bouncing.

In some situations it may be desired to apply the limit on all bios, this
patch adds the file "/sys/module/dm_crypt/parameters/limit_all_bios" that
enables it. It must be enabled prior to creating a dm-crypt device.

Signed-off-by: Mikulas Patocka <mpatocka@xxxxxxxxxx>

---
 drivers/md/dm-crypt.c         |    6 +++++-
 drivers/md/dm.c               |    6 +++++-
 include/linux/device-mapper.h |    6 ++++--
 3 files changed, 14 insertions(+), 4 deletions(-)

Index: linux-2.6/include/linux/device-mapper.h
===================================================================
--- linux-2.6.orig/include/linux/device-mapper.h	2022-01-24 15:10:45.000000000 +0100
+++ linux-2.6/include/linux/device-mapper.h	2022-01-31 19:19:33.000000000 +0100
@@ -353,9 +353,11 @@ struct dm_target {
 	bool discards_supported:1;
 
 	/*
-	 * Set if we need to limit the number of in-flight bios when swapping.
+	 * 0 - don't limit the number of bios
+	 * 1 - limit only swap bios
+	 * 2 - limit all bios
 	 */
-	bool limit_swap_bios:1;
+	unsigned char limit_swap_bios:2;
 
 	/*
 	 * Set if this target implements a a zoned device and needs emulation of
Index: linux-2.6/drivers/md/dm-crypt.c
===================================================================
--- linux-2.6.orig/drivers/md/dm-crypt.c	2022-01-06 18:54:58.000000000 +0100
+++ linux-2.6/drivers/md/dm-crypt.c	2022-01-31 19:17:58.000000000 +0100
@@ -241,6 +241,10 @@ static struct scatterlist *crypt_get_sg_
 
 static bool crypt_integrity_aead(struct crypt_config *cc);
 
+static bool limit_all_bios = false;
+module_param(limit_all_bios, bool, 0644);
+MODULE_PARM_DESC(limit_all_bios, "True if you want to limit all bios; false if you want to limit only swap bios");
+
 /*
  * Use this to access cipher attributes that are independent of the key.
  */
@@ -3372,7 +3376,7 @@ static int crypt_ctr(struct dm_target *t
 	}
 
 	ti->num_flush_bios = 1;
-	ti->limit_swap_bios = true;
+	ti->limit_swap_bios = limit_all_bios ? 2 : 1;
 
 	dm_audit_log_ctr(DM_MSG_PREFIX, ti, 1);
 	return 0;
Index: linux-2.6/drivers/md/dm.c
===================================================================
--- linux-2.6.orig/drivers/md/dm.c	2022-01-24 15:10:42.000000000 +0100
+++ linux-2.6/drivers/md/dm.c	2022-01-31 19:20:29.000000000 +0100
@@ -873,7 +873,11 @@ void disable_write_zeroes(struct mapped_
 
 static bool swap_bios_limit(struct dm_target *ti, struct bio *bio)
 {
-	return unlikely((bio->bi_opf & REQ_SWAP) != 0) && unlikely(ti->limit_swap_bios);
+	if (likely(!ti->limit_swap_bios))
+		return false;
+	if (likely(ti->limit_swap_bios == 1))
+		return unlikely((bio->bi_opf & REQ_SWAP) != 0);
+	return true;
 }
 
 static void clone_endio(struct bio *bio)

--
dm-devel mailing list
dm-devel@xxxxxxxxxx
https://listman.redhat.com/mailman/listinfo/dm-devel




[Index of Archives]     [DM Crypt]     [Fedora Desktop]     [ATA RAID]     [Fedora Marketing]     [Fedora Packaging]     [Fedora SELinux]     [Yosemite Discussion]     [KDE Users]     [Fedora Docs]

  Powered by Linux