Re: [PATCH V2] block: fail unaligned bio from submit_bio_noacct()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Mar 24, 2024 at 09:37:02PM +0800, Ming Lei wrote:
> +static bool bio_check_alignment(struct bio *bio, struct request_queue *q)
> +{
> +	unsigned int bs = q->limits.logical_block_size;
> +
> +	if (bio->bi_iter.bi_size & (bs - 1))
> +		return false;
> +
> +	if (bio->bi_iter.bi_sector & ((bs >> SECTOR_SHIFT) - 1))
> +		return false;
> +
> +	return true;
> +}


This should still use bdev_logic_block_size.  And maybe it's just me,
but I think dropping thelines after the false returns would actually
make it more readle.

> diff --git a/block/fops.c b/block/fops.c
> index 679d9b752fe8..75595c728190 100644
> --- a/block/fops.c
> +++ b/block/fops.c
> @@ -37,8 +37,7 @@ static blk_opf_t dio_bio_write_op(struct kiocb *iocb)
>  static bool blkdev_dio_unaligned(struct block_device *bdev, loff_t pos,
>  			      struct iov_iter *iter)
>  {
> -	return pos & (bdev_logical_block_size(bdev) - 1) ||
> -		!bdev_iter_is_aligned(bdev, iter);
> +	return !bdev_iter_is_aligned(bdev, iter);

If you drop this:

 - we now actually go all the way down to building and submiting a
   bio for a trivial bounds check.
 - your get a trivial to trigger WARN_ON.

I'd strongly advise against dropping this check.





[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux