]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
blk-crypto: optimize bio splitting in blk_crypto_fallback_encrypt_bio
authorChristoph Hellwig <hch@lst.de>
Fri, 9 Jan 2026 06:07:45 +0000 (07:07 +0100)
committerJens Axboe <axboe@kernel.dk>
Sun, 11 Jan 2026 19:55:41 +0000 (12:55 -0700)
commitb37fbce460ad60b0c4449c1c7566cf24f3016713
tree226301b0edd2d1de73a62fcbb31aded71e9bcd7c
parentaefc2a1fa2edc2a486aaf857e48b3fd13062b0eb
blk-crypto: optimize bio splitting in blk_crypto_fallback_encrypt_bio

The current code in blk_crypto_fallback_encrypt_bio is inefficient and
prone to deadlocks under memory pressure: It first walks the passed in
plaintext bio to see how much of it can fit into a single encrypted
bio using up to BIO_MAX_VEC PAGE_SIZE segments, and then allocates a
plaintext clone that fits the size, only to allocate another bio for
the ciphertext later.  While the plaintext clone uses a bioset to avoid
deadlocks when allocations could fail, the ciphertex one uses bio_kmalloc
which is a no-go in the file system I/O path.

Switch blk_crypto_fallback_encrypt_bio to walk the source plaintext bio
while consuming bi_iter without cloning it, and instead allocate a
ciphertext bio at the beginning and whenever we fille up the previous
one.  The existing bio_set for the plaintext clones is reused for the
ciphertext bios to remove the deadlock risk.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-crypto-fallback.c