[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aJDkB8veXI4Znl8o@kbusch-mbp>
Date: Mon, 4 Aug 2025 10:47:03 -0600
From: Keith Busch <kbusch@...nel.org>
To: Hannes Reinecke <hare@...e.de>
Cc: Keith Busch <kbusch@...a.com>, linux-block@...r.kernel.org,
linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org,
snitzer@...nel.org, axboe@...nel.dk, dw@...idwei.uk,
brauner@...nel.org
Subject: Re: [PATCH 2/7] block: align the bio after building it
On Mon, Aug 04, 2025 at 08:08:38AM -0600, Keith Busch wrote:
> On Mon, Aug 04, 2025 at 08:54:00AM +0200, Hannes Reinecke wrote:
> > On 8/2/25 01:47, Keith Busch wrote:
> > > +static int bio_align_to_lbs(struct bio *bio, struct iov_iter *iter)
> > > +{
> > > + struct block_device *bdev = bio->bi_bdev;
> > > + size_t nbytes;
> > > +
> > > + if (!bdev)
> > > + return 0;
> > > +
> > > + nbytes = bio->bi_iter.bi_size & (bdev_logical_block_size(bdev) - 1);
> > > + if (!nbytes)
> > > + return 0;
> > > +
> > > + bio_revert(bio, nbytes);
> > > + iov_iter_revert(iter, nbytes);
> > > + if (!bio->bi_iter.bi_size)
> > > + return -EFAULT;
> > > +
> > > + return 0;
> > > +}
> > > +
> > > /**
> > > * bio_iov_iter_get_pages - add user or kernel pages to a bio
> > > * @bio: bio to add pages to
> > > @@ -1336,6 +1355,7 @@ int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter)
> > > ret = __bio_iov_iter_get_pages(bio, iter);
> > > } while (!ret && iov_iter_count(iter) && !bio_full(bio, 0));
> > > + ret = bio_align_to_lbs(bio, iter);
> > > return bio->bi_vcnt ? 0 : ret;
> >
> > Wouldn't that cause the error from bio_align_to_lba() to be ignored
> > if bio->bi_vcnt is greater than 0?
>
> That returns an error only if the alignment reduces the size to 0, so
> there would be a bug somewhere if bi_vcnt is not also 0 in that case.
But there is definitely a problem the other-way-around: if bi_vcnt is
already 0 because the first vector was a bad address, then my patch here
is mistakenly overriding 'ret' to indicate success when it wasn't.
Powered by blists - more mailing lists