don't build bios/contexts over multiple iomaps v3
Subsystems (8)
Hi all,
this patch changes how iomap submits bios for reads. The old behavior to build up bios across iomap was already considered problematic for a while, but we now ran into a erofs bug because of it, so it's time to finally fix it.
It would be great to get the fix into 7.2 as the fixed bug can be triggered by users.
Changes since v2:
- drop an unused argument
- make sure we submit for the same iteration to not leave a landmine for future changes
Changes since v1:
- don't submit fuse context after each iteration
- consolidate some code to support the above
- fix a bug in the fs PI support found while doing the above
PATCH 1/3 iomap: consolidate bio submission
Add a iomap_bio_submit_read_endio helper factored out of iomap_bio_submit_read to that all ->submit_read implementations for iomap_read_ops that use iomap_bio_read_folio_range can shared the logic.
Right now that logic is mostly trivial, but already has a bug for XFS because the XFS version is too trivial: file system integrity validation needs a workqueue context and thus can't happen from the default iomap bi_end_io I/O handler. Unfortunately the iomap refactoring just before fs integrity landed moved code around here and the call go misplaced, meaning it never got called. The PI information still is verified by the block layer, but the offloading is less efficient (and the future userspace interface can't get at it).
--- fs/exfat/iomap.c | 5 +---- fs/iomap/bio.c | 13 ++++++++++--- fs/ntfs/aops.c | 6 ++---- fs/ntfs3/inode.c | 5 +---- fs/xfs/xfs_aops.c | 3 +-- include/linux/iomap.h | 2 ++ 6 files changed, 17 insertions(+), 17 deletions(-)
fs/exfat/iomap.c +1 -4
@@ -253,10 +253,7 @@ static void exfat_iomap_read_end_io(struct bio *bio)static void exfat_iomap_bio_submit_read (const struct iomap_iter *iter,struct iomap_read_folio_ctx *ctx) { -struct bio *bio = ctx->read_ctx; - - bio->bi_end_io = exfat_iomap_read_end_io; -submit_bio (bio); +iomap_bio_submit_read_endio (iter, ctx, exfat_iomap_read_end_io); }const struct iomap_read_ops exfat_iomap_bio_read_ops = {
fs/iomap/bio.c +10 -3
@@ -78,15 +78,23 @@ u32 iomap_finish_ioend_buffered_read(struct iomap_ioend *ioend)return __iomap_read_end_io (&ioend->io_bio, ioend->io_error); } -static void iomap_bio_submit_read (const struct iomap_iter *iter, -struct iomap_read_folio_ctx *ctx) +void iomap_bio_submit_read_endio (const struct iomap_iter *iter, +struct iomap_read_folio_ctx *ctx,bio_end_io_t end_io) {struct bio *bio = ctx->read_ctx; + bio->bi_end_io = end_io;if (iter->iomap.flags &IOMAP_F_INTEGRITY )fs_bio_integrity_alloc (bio);submit_bio (bio); } +EXPORT_SYMBOL_GPL (iomap_bio_submit_read_endio); + +static void iomap_bio_submit_read (const struct iomap_iter *iter, +struct iomap_read_folio_ctx *ctx) +{ +return iomap_bio_submit_read_endio (iter, ctx, iomap_read_end_io); +}static struct bio_set *iomap_read_bio_set (struct iomap_read_folio_ctx *ctx) {
@@ -127,7 +135,6 @@ static void iomap_read_alloc_bio(const struct iomap_iter *iter,if (ctx->rac) bio->bi_opf |=REQ_RAHEAD ; bio->bi_iter.bi_sector =iomap_sector (iomap, iter->pos); - bio->bi_end_io = iomap_read_end_io;bio_add_folio_nofail (bio, folio, plen,offset_in_folio (folio, iter->pos)); ctx->read_ctx = bio;
fs/ntfs/aops.c +2 -4
@@ -38,11 +38,9 @@ static void ntfs_iomap_read_end_io(struct bio *bio) }static void ntfs_iomap_bio_submit_read (const struct iomap_iter *iter, -struct iomap_read_folio_ctx *ctx) +struct iomap_read_folio_ctx *ctx) { -struct bio *bio = ctx->read_ctx; - bio->bi_end_io = ntfs_iomap_read_end_io; -submit_bio (bio); +iomap_bio_submit_read_endio (iter, ctx, ntfs_iomap_read_end_io); }static const struct iomap_read_ops ntfs_iomap_bio_read_ops = {
fs/ntfs3/inode.c +1 -4
@@ -609,10 +609,7 @@ static void ntfs_iomap_read_end_io(struct bio *bio)static void ntfs_iomap_bio_submit_read (const struct iomap_iter *iter,struct iomap_read_folio_ctx *ctx) { -struct bio *bio = ctx->read_ctx; - - bio->bi_end_io = ntfs_iomap_read_end_io; -submit_bio (bio); +iomap_bio_submit_read_endio (iter, ctx, ntfs_iomap_read_end_io); }static const struct iomap_read_ops ntfs_iomap_bio_read_ops = {
fs/xfs/xfs_aops.c +1 -2
@@ -764,8 +764,7 @@ xfs_bio_submit_read(/* defer read completions to the ioend workqueue */ iomap_init_ioend (iter->inode, bio, ctx->read_ctx_file_offset,0 ); - bio->bi_end_io = xfs_end_bio; -submit_bio (bio); +iomap_bio_submit_read_endio (iter, ctx, xfs_end_bio); }static const struct iomap_read_ops xfs_iomap_read_ops = {
include/linux/iomap.h +2 -0
@@ -622,6 +622,8 @@ extern struct bio_set iomap_ioend_bioset;#ifdef CONFIG_BLOCK int iomap_bio_read_folio_range (const struct iomap_iter *iter,struct iomap_read_folio_ctx *ctx,size_t plen); +void iomap_bio_submit_read_endio (const struct iomap_iter *iter, +struct iomap_read_folio_ctx *ctx,bio_end_io_t end_io);extern const struct iomap_read_ops iomap_bio_read_ops;
Signature · 1 line
2.53.0
Re: [PATCH 1/3] iomap: consolidate bio submission
Quoted 14 lines · Christoph Hellwig
Add a
iomap_bio_submit_read_endiohelper factored out ofiomap_bio_submit_readto that all ->submit_read implementations foriomap_read_opsthat useiomap_bio_read_folio_rangecan shared the logic.Right now that logic is mostly trivial, but already has a bug for XFS because the XFS version is too trivial: file system integrity validation needs a workqueue context and thus can't happen from the default iomap
bi_end_ioI/O handler. Unfortunately the iomap refactoring just before fs integrity landed moved code around here and the call go misplaced, meaning it never got called. The PI information still is verified by the block layer, but the offloading is less efficient (and the future userspace interface can't get at it).
Quoted 1 line
[...]
Applied to the vfs.fixes branch of the vfs/vfs.git tree. Patches in the vfs.fixes branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs.fixes
[1/3] iomap: consolidate bio submission
https://git.kernel.org/vfs/vfs/c/044472d5ee7d [2/3] fuse: call fuse_send_readpages explicitly from fuse_readahead https://git.kernel.org/vfs/vfs/c/3372eb0384b7 [3/3] iomap: submit read bio after each extent https://git.kernel.org/vfs/vfs/c/c1fb97d31782
Re: [PATCH 1/3] iomap: consolidate bio submission
Quoted 2 lines · Christian Brauner
Applied to the vfs.fixes branch of the vfs/vfs.git tree. Patches in the vfs.fixes branch should appear in linux-next soon.
Hmm, both this mail and the merge commit in git reference the first commit instead of the cower letter. Is there an issue with your automation that made it miss the cover letter?
Christian Brauner
maintainerRe: [PATCH 1/3] iomap: consolidate bio submission
Quoted 7 lines · Christoph Hellwig
Quoted 2 lines · Christian Brauner
Applied to the vfs.fixes branch of the vfs/vfs.git tree. Patches in the vfs.fixes branch should appear in linux-next soon.
Hmm, both this mail and the merge commit in git reference the first commit instead of the cower letter. Is there an issue with your automation that made it miss the cover letter?
Yes, your series aren't picked up by b4 correctly - I always take care that your cover letter is actually used but the tooling trips over it.
I thought about telling you but then I thought it might be easier to first try and fix the tooling. So a week ago or so I sent:
https://lore.kernel.org/tools/[email protected]
The issue basically is that b4 expects 0/N for the cover letter whereas you send "naked" cover letters.
Konstantin is on vacation though.
PATCH 2/3 fuse: call fuse_send_readpages explicitly from fuse_readahead
In reply to Christoph HellwigFrom: Joanne Koong <[email protected]>
Move the call to fuse_send_readpages from the iomap ->submit_read method to the fuse readahead implementation.
fuse_read_folio() does not need to call fuse_send_readpages() because it always does reads synchronously (the iomap->submit_read method for this was a no-op since data->ia is always NULL for fuse_read_folio()).
This prepares for an iomap fix that will call ->submit_read after each iomap.
--- fs/fuse/file.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)
fs/fuse/file.c +3 -11
@@ -981,19 +981,8 @@ static int fuse_iomap_read_folio_range_async(const struct iomap_iter *iter,return ret; } -static void fuse_iomap_submit_read (const struct iomap_iter *iter, -struct iomap_read_folio_ctx *ctx) -{ -struct fuse_fill_read_data *data = ctx->read_ctx; - -if (data->ia) -fuse_send_readpages (data->ia, data->file, data->nr_bytes, - data->fc->async_read); -} -static const struct iomap_read_ops fuse_iomap_read_ops = { .read_folio_range = fuse_iomap_read_folio_range_async, - .submit_read = fuse_iomap_submit_read, };static int fuse_read_folio (struct file *file,struct folio *folio)
@@ -1116,6 +1105,9 @@ static void fuse_readahead(struct readahead_control *rac)return ;iomap_readahead (&fuse_iomap_ops, &ctx,NULL ); +if (data.ia) +fuse_send_readpages (data.ia, data.file, data.nr_bytes, + fc->async_read); }static ssize_t fuse_cache_read_iter (struct kiocb *iocb,struct iov_iter *to)
Signature · 1 line
2.53.0
PATCH 3/3 iomap: submit read bio after each extent
In reply to Christoph HellwigCurrently the iomap buffered read path tries to build up read context (i.e. bios for the typical block based case) over multiple iomaps as long as the sector matches. This does not take into account files that can map to multiple different devices. While this could be fixed by a bdev check in iomap_bio_read_folio_range, the building up of I/O over iomaps actually was a problem for the not yet merged ext2 iomap port, as that does want to send out I/O at the end of an indirect block mapped range.
So instead of adding more checks move over to a model where a bio only spans a single iomap. Change ->submit_read to be called after each iteration so that the bio based users submit the bio after each iomap. Fuse is unchanged because the previous commit stopped using ->submit_read for it.
--- fs/iomap/bio.c | 2 ++ fs/iomap/buffered-io.c | 16 ++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-)
fs/iomap/bio.c +2 -0
@@ -87,6 +87,8 @@ void iomap_bio_submit_read_endio(const struct iomap_iter *iter,if (iter->iomap.flags &IOMAP_F_INTEGRITY )fs_bio_integrity_alloc (bio);submit_bio (bio); + + ctx->read_ctx =NULL ; }EXPORT_SYMBOL_GPL (iomap_bio_submit_read_endio);
fs/iomap/buffered-io.c +8 -8
@@ -642,12 +642,12 @@ void iomap_read_folio(const struct iomap_ops *ops,fsverity_readahead (ctx->vi, folio->index,folio_nr_pages (folio)); -while ((ret =iomap_iter (&iter, ops)) >0 ) +while ((ret =iomap_iter (&iter, ops)) >0 ) { iter.status =iomap_read_folio_iter (&iter, ctx, &bytes_submitted); - -if (ctx->read_ctx && ctx->ops->submit_read) - ctx->ops->submit_read (&iter, ctx); +if (ctx->read_ctx && ctx->ops->submit_read) + ctx->ops->submit_read (&iter, ctx); + }if (ctx->cur_folio)iomap_read_end (ctx->cur_folio, bytes_submitted);
@@ -718,12 +718,12 @@ void iomap_readahead(const struct iomap_ops *ops,fsverity_readahead (ctx->vi,readahead_index (rac),readahead_count (rac)); -while (iomap_iter (&iter, ops) >0 ) +while (iomap_iter (&iter, ops) >0 ) { iter.status =iomap_readahead_iter (&iter, ctx, &cur_bytes_submitted); - -if (ctx->read_ctx && ctx->ops->submit_read) - ctx->ops->submit_read (&iter, ctx); +if (ctx->read_ctx && ctx->ops->submit_read) + ctx->ops->submit_read (&iter, ctx); + }if (ctx->cur_folio)iomap_read_end (ctx->cur_folio, cur_bytes_submitted);
Signature · 1 line
2.53.0