OSDN Git Service

dm crypt: constrain crypt device's max_segment_size to PAGE_SIZE
authorMike Snitzer <snitzer@redhat.com>
Thu, 10 Sep 2015 01:34:51 +0000 (21:34 -0400)
committerMike Snitzer <snitzer@redhat.com>
Mon, 14 Sep 2015 16:04:24 +0000 (12:04 -0400)
commit586b286b110e94eb31840ac5afc0c24e0881fe34
tree2fce4bc41cba4b2b5dda57b9295a5860b2bd1e34
parent216076705d6ac291d42e0f8dd85e6a0da98c0fa3
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 91e106259 ("dm crypt: use bio_add_page").  But Linux 4.0
commit cf2f1abfb ("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
cf2f1abfb'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: cf2f1abfb ("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+
drivers/md/dm-crypt.c