On Fri, 22 Mar 2024, Ming Lei wrote:
> On Thu, Mar 21, 2024 at 06:01:41PM +0100, Mikulas Patocka wrote:
> >
> >
> > > > +static bool bio_check_alignment(struct bio *bio, struct request_queue
> > > > *q)
> > > > +{
> > > > + unsigned int bs = q->limits.logical_block_size;
> > > > + unsigned int size = bio->bi_iter.bi_size;
> > > > +
> > > > + if (size & (bs - 1))
> > > > + return false;
> > > > +
> > > > + if (size && ((bio->bi_iter.bi_sector << SECTOR_SHIFT) & (bs -
> > > > 1)))
> > > > + return false;
> > > > +
> > > > + return true;
> > > > +}
> >
> > I would change it to
> >
> > if (unlikely(((bi_iter.bi_sector | bio_sectors(bio)) &
> > ((queue_logical_block_size(q) >> 9) - 1)) != 0))
> > return false;
>
> What if bio->bi_iter.bi_size isn't aligned with 512? The above check
> can't find that at all.
Could it happen that bi_size is not aligned to 512? I haven't seen such a
bio yet. If you have seen it, say where was it created.
Mikulas