Skip to content

brd: iterate the bio by byte position, not bi_sector - #1273

Open
blktests-ci-kpd[bot] wants to merge 1 commit into
linus-master_basefrom
series/1160667=>linus-master
Open

blktests-ci-kpd[bot] wants to merge 1 commit into
linus-master_basefrom
series/1160667=>linus-master

Conversation

@blktests-ci-kpd

Copy link
Copy Markdown

Pull request for series with
subject: brd: iterate the bio by byte position, not bi_sector
version: 1
url: https://patchwork.kernel.org/series/1160668/

@blktests-ci-kpd

Copy link
Copy Markdown
Author

Upstream branch: 28924df
series: https://patchwork.kernel.org/series/1160668/
version: 1

@blktests-ci-kpd

Copy link
Copy Markdown
Author

Upstream branch: 893e117
series: https://patchwork.kernel.org/series/1160668/
version: 1

@blktests-ci-kpd
blktests-ci-kpd Bot force-pushed the series/1160667=>linus-master branch from d79c0f5 to 361c46a Compare September 9, 2026 08:02
@blktests-ci-kpd

Copy link
Copy Markdown
Author

Upstream branch: 50d05c7
series: https://patchwork.kernel.org/series/1160668/
version: 1

@blktests-ci-kpd
blktests-ci-kpd Bot force-pushed the series/1160667=>linus-master branch from 361c46a to e4c8492 Compare September 10, 2026 15:44
@blktests-ci-kpd

Copy link
Copy Markdown
Author

Upstream branch: 5225b8e
series: https://patchwork.kernel.org/series/1160668/
version: 1

@blktests-ci-kpd
blktests-ci-kpd Bot force-pushed the series/1160667=>linus-master branch from e4c8492 to 87350c6 Compare September 12, 2026 02:39
@blktests-ci-kpd

Copy link
Copy Markdown
Author

Upstream branch: 2f0c1cf
series: https://patchwork.kernel.org/series/1160668/
version: 1

@blktests-ci-kpd
blktests-ci-kpd Bot force-pushed the series/1160667=>linus-master branch from 87350c6 to c5e4aca Compare September 13, 2026 10:07
@blktests-ci-kpd

Copy link
Copy Markdown
Author

Upstream branch: 2f0c1cf
series: https://patchwork.kernel.org/series/1160668/
version: 1

@blktests-ci-kpd
blktests-ci-kpd Bot force-pushed the series/1160667=>linus-master branch from c5e4aca to f32de33 Compare September 13, 2026 23:09
brd_rw_bvec() takes the device position from bio->bi_iter.bi_sector,
which bio_advance_iter_single() advances by bytes >> SECTOR_SHIFT. For
a bvec whose length is not a multiple of the sector size the sector
cursor silently loses the sub-sector residue while the data cursor
(bi_bvec_done/bi_size) consumes the full length -- from that segment
on, data is written at a device offset short of where it belongs, and
every subsequent byte lands shifted with no error reported anywhere.

Such bvec geometry is legal at the submitter: ITER_BVEC direct I/O
passes the caller's bio_vec array through as-is (bio_iov_bvec_set()),
so e.g. NFSD's NFSD_IO_DIRECT write path hands XFS/iomap a payload
whose first fragment starts mid-page (the RPC header precedes it in
the receive buffer) and whose fragment lengths are not sector
multiples. A 1 MiB write arriving as bv0=(160,16224) + 63x(0,16384) +
(0,160) reproduces on brd as: first 15872 = ALIGN_DOWN(16224, 512)
bytes correct, everything after shifted forward by 352 = 16224 - 15872
bytes -- while the write completes successfully. Any NFSD_IO_DIRECT
(or other kernel bvec direct I/O) write to a brd-backed filesystem is
exposed; request-based drivers are unaffected because nothing in the
request path does per-bvec sector arithmetic.

Track the device position as a byte offset owned by the submit loop
and advanced by the number of bytes each segment actually processed,
instead of re-deriving it from the skewed bi_sector. Verified with a
synthetic-bio reproducer over brd directly and through nvme-loop:
mid-page-offset geometries and the page-aligned control now all read
back byte-identical, and 20 fresh NFS connections x 16 MiB of O_DIRECT
writes over an XFS-on-nvme-loop-on-brd export complete with zero data
mismatches (previously most connections corrupted).

Fixes: 3185444 ("brd: split I/O at page boundaries")
Assisted-by: Claude:claude-fable-5
Signed-off-by: Mike Snitzer <snitzer@kernel.org>
@blktests-ci-kpd

Copy link
Copy Markdown
Author

Upstream branch: 5878583
series: https://patchwork.kernel.org/series/1160668/
version: 1

@blktests-ci-kpd
blktests-ci-kpd Bot force-pushed the series/1160667=>linus-master branch from f32de33 to c3c6254 Compare September 15, 2026 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants