blk-crypto: relax alignment requirements for bvecs in bios

In order to support direct I/O on encrypted files as well as possibly
other future use cases such as filesystem metadata encryption, we need
to relax the restriction that if a bio has an encryption context, then
all its bvecs must be be aligned to the encryption context's data unit
size.  Instead we'll just require that the bio's total size be aligned
to the data unit size (in addition to the usual logical_block_size
alignment requirement on bvecs).

Now that the rest of the block layer has been updated to be compatible
with the new requirements, update __blk_crypto_bio_prep() accordingly to
just validate the alignment of the total size.

Co-developed-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Satya Tangirala <satyat@google.com>
diff --git a/block/blk-crypto.c b/block/blk-crypto.c
index c5bdaaf..06f81e6 100644
--- a/block/blk-crypto.c
+++ b/block/blk-crypto.c
@@ -200,22 +200,6 @@
 	return !bc1 || bio_crypt_dun_is_contiguous(bc1, bc1_bytes, bc2->bc_dun);
 }
 
-/* Check that all I/O segments are data unit aligned. */
-static bool bio_crypt_check_alignment(struct bio *bio)
-{
-	const unsigned int data_unit_size =
-		bio->bi_crypt_context->bc_key->crypto_cfg.data_unit_size;
-	struct bvec_iter iter;
-	struct bio_vec bv;
-
-	bio_for_each_segment(bv, bio, iter) {
-		if (!IS_ALIGNED(bv.bv_len | bv.bv_offset, data_unit_size))
-			return false;
-	}
-
-	return true;
-}
-
 blk_status_t __blk_crypto_init_request(struct request *rq)
 {
 	return blk_ksm_get_slot_for_key(rq->q->ksm, rq->crypt_ctx->bc_key,
@@ -271,7 +255,8 @@
 		goto fail;
 	}
 
-	if (!bio_crypt_check_alignment(bio)) {
+	if (!IS_ALIGNED(bio->bi_iter.bi_size,
+			bc_key->crypto_cfg.data_unit_size)) {
 		bio->bi_status = BLK_STS_IOERR;
 		goto fail;
 	}