All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Christoph Hellwig <hch@infradead.org>
Cc: Jens Axboe <axboe@kernel.dk>,
	linux-block@vger.kernel.org, Keith Busch <kbusch@kernel.org>,
	Bart Van Assche <bvanassche@acm.org>,
	Mikulas Patocka <mpatocka@redhat.com>,
	Mike Snitzer <snitzer@kernel.org>,
	ming.lei@redhat.com
Subject: Re: [PATCH V2] block: fail unaligned bio from submit_bio_noacct()
Date: Mon, 25 Mar 2024 11:03:25 +0800	[thread overview]
Message-ID: <ZgDpfW8HRHrZgQYv@fedora> (raw)
In-Reply-To: <ZgC2UPEBOSLW9Xdz@infradead.org>

On Sun, Mar 24, 2024 at 04:25:04PM -0700, Christoph Hellwig wrote:
> 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.

OK, will remove the blank line.

> 
> > 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.

OK.

Also only q->limits.logical_block_size is fetched for small BS IO
fast path, I think log(lbs) can be cached in request_queue for avoiding the
extra fetch of q.limits. Especially, it could be easier to do so
with your recent queue limit atomic update changes.


Thanks, 
Ming


  reply	other threads:[~2024-03-25  3:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-24 13:37 [PATCH V2] block: fail unaligned bio from submit_bio_noacct() Ming Lei
2024-03-24 21:48 ` Mike Snitzer
2024-03-24 23:25 ` Christoph Hellwig
2024-03-25  3:03   ` Ming Lei [this message]
2024-03-25  3:12     ` Christoph Hellwig
2024-03-25  3:50       ` Ming Lei
2024-03-25 18:53 ` Keith Busch
2024-03-26  1:19   ` Ming Lei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZgDpfW8HRHrZgQYv@fedora \
    --to=ming.lei@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --cc=hch@infradead.org \
    --cc=kbusch@kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=mpatocka@redhat.com \
    --cc=snitzer@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.