Skip to content

Commit 586b286

Browse files
committed
dm crypt: constrain crypt device's max_segment_size to PAGE_SIZE
Setting the dm-crypt device's max_segment_size to PAGE_SIZE is an unfortunate constraint that is required to avoid the potential for exceeding dm-crypt's underlying device's max_segments limits -- due to crypt_alloc_buffer() possibly allocating pages for the encryption bio that are not as physically contiguous as the original bio. It is interesting to note that this problem was already fixed back in 2007 via commit 91e1062 ("dm crypt: use bio_add_page"). But Linux 4.0 commit cf2f1ab ("dm crypt: don't allocate pages for a partial request") regressed dm-crypt back to _not_ using bio_add_page(). But given dm-crypt's cpu parallelization changes all depend on commit cf2f1ab's abandoning of the more complex io fragments processing that dm-crypt previously had we cannot easily go back to using bio_add_page(). So all said the cleanest way to resolve this issue is to fix dm-crypt to properly constrain the original bios entering dm-crypt so the encryption bios that dm-crypt generates from the original bios are always compatible with the underlying device's max_segments queue limits. It should be noted that technically Linux 4.3 does _not_ need this fix because of the block core's new late bio-splitting capability. But, it is reasoned, there is little to be gained by having the block core split the encrypted bio that is composed of PAGE_SIZE segments. That said, in the future we may revert this change. Fixes: cf2f1ab ("dm crypt: don't allocate pages for a partial request") Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=104421 Suggested-by: Jeff Moyer <jmoyer@redhat.com> Signed-off-by: Mike Snitzer <snitzer@redhat.com> Cc: stable@vger.kernel.org # 4.0+
1 parent 2160767 commit 586b286

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

drivers/md/dm-crypt.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,8 @@ static void crypt_free_buffer_pages(struct crypt_config *cc, struct bio *clone);
968968

969969
/*
970970
* Generate a new unfragmented bio with the given size
971-
* This should never violate the device limitations
971+
* This should never violate the device limitations (but only because
972+
* max_segment_size is being constrained to PAGE_SIZE).
972973
*
973974
* This function may be called concurrently. If we allocate from the mempool
974975
* concurrently, there is a possibility of deadlock. For example, if we have
@@ -2045,9 +2046,20 @@ static int crypt_iterate_devices(struct dm_target *ti,
20452046
return fn(ti, cc->dev, cc->start, ti->len, data);
20462047
}
20472048

2049+
static void crypt_io_hints(struct dm_target *ti, struct queue_limits *limits)
2050+
{
2051+
/*
2052+
* Unfortunate constraint that is required to avoid the potential
2053+
* for exceeding underlying device's max_segments limits -- due to
2054+
* crypt_alloc_buffer() possibly allocating pages for the encryption
2055+
* bio that are not as physically contiguous as the original bio.
2056+
*/
2057+
limits->max_segment_size = PAGE_SIZE;
2058+
}
2059+
20482060
static struct target_type crypt_target = {
20492061
.name = "crypt",
2050-
.version = {1, 14, 0},
2062+
.version = {1, 14, 1},
20512063
.module = THIS_MODULE,
20522064
.ctr = crypt_ctr,
20532065
.dtr = crypt_dtr,
@@ -2058,6 +2070,7 @@ static struct target_type crypt_target = {
20582070
.resume = crypt_resume,
20592071
.message = crypt_message,
20602072
.iterate_devices = crypt_iterate_devices,
2073+
.io_hints = crypt_io_hints,
20612074
};
20622075

20632076
static int __init dm_crypt_init(void)

0 commit comments

Comments
 (0)