diff mbox series

[v4,9/9] block: add WARN_ON_ONCE() to bio_split() for sector alignment

Message ID 20210707052943.3960-10-satyaprateek2357@gmail.com (mailing list archive)
State New, archived
Headers show
Series ensure bios aren't split in middle of crypto data unit | expand

Commit Message

Satya Tangirala July 7, 2021, 5:29 a.m. UTC
From: Satya Tangirala <satyat@google.com>

The number of sectors passed to bio_split() must be aligned to
bio_required_sector_alignment(). All callers (other than bounce.c) have
been updated to ensure this, so add a WARN_ON_ONCE() if the number of
sectors is not aligned. (bounce.c was not updated since it's legacy code
- any device that enables bounce buffering won't declare inline
encryption support, so bounce.c will never see a bio with an encryption
context).

Signed-off-by: Satya Tangirala <satyat@google.com>
---
 block/bio.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Eric Biggers July 23, 2021, 5:30 p.m. UTC | #1
On Tue, Jul 06, 2021 at 10:29:43PM -0700, Satya Tangirala wrote:
> From: Satya Tangirala <satyat@google.com>
> 
> The number of sectors passed to bio_split() must be aligned to
> bio_required_sector_alignment(). All callers (other than bounce.c) have
> been updated to ensure this, so add a WARN_ON_ONCE() if the number of
> sectors is not aligned. (bounce.c was not updated since it's legacy code
> - any device that enables bounce buffering won't declare inline
> encryption support, so bounce.c will never see a bio with an encryption
> context).

The last sentence could say "so bounce.c will never see a bio with
bio_required_sector_alignment() greater than the logical block size".

> 
> Signed-off-by: Satya Tangirala <satyat@google.com>
> ---
>  block/bio.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/block/bio.c b/block/bio.c
> index 1fab762e079b..4c7bfdeefe76 100644
> --- a/block/bio.c
> +++ b/block/bio.c
> @@ -1435,6 +1435,7 @@ struct bio *bio_split(struct bio *bio, int sectors,
>  
>  	BUG_ON(sectors <= 0);
>  	BUG_ON(sectors >= bio_sectors(bio));
> +	WARN_ON_ONCE(!IS_ALIGNED(sectors, bio_required_sector_alignment(bio)));
>  
>  	/* Zone append commands cannot be split */
>  	if (WARN_ON_ONCE(bio_op(bio) == REQ_OP_ZONE_APPEND))

Reviewed-by: Eric Biggers <ebiggers@google.com>

- Eric
diff mbox series

Patch

diff --git a/block/bio.c b/block/bio.c
index 1fab762e079b..4c7bfdeefe76 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1435,6 +1435,7 @@  struct bio *bio_split(struct bio *bio, int sectors,
 
 	BUG_ON(sectors <= 0);
 	BUG_ON(sectors >= bio_sectors(bio));
+	WARN_ON_ONCE(!IS_ALIGNED(sectors, bio_required_sector_alignment(bio)));
 
 	/* Zone append commands cannot be split */
 	if (WARN_ON_ONCE(bio_op(bio) == REQ_OP_ZONE_APPEND))