Linux filesystem development
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: Brian Foster <bfoster@redhat.com>
Cc: Joanne Koong <joannelkoong@gmail.com>,
	Christian Brauner <brauner@kernel.org>,
	hch@lst.de, linux-fsdevel@vger.kernel.org,
	changfengnan@bytedance.com, kbusch@kernel.org,
	Matthew Wilcox <willy@infradead.org>, Jan Kara <jack@suse.cz>,
	Jonathan Corbet <corbet@lwn.net>, David Sterba <dsterba@suse.com>,
	Gao Xiang <xiang@kernel.org>, Namjae Jeon <linkinjeon@kernel.org>,
	tytso@mit.edu, Jaegeuk Kim <jaegeuk@kernel.org>,
	Miklos Szeredi <miklos@szeredi.hu>,
	Andreas Gruenbacher <agruenba@redhat.com>,
	Mikulas Patocka <mikulas@artax.karlin.mff.cuni.cz>,
	Hyunchul Lee <hyc.lee@gmail.com>,
	Konstantin Komarov <almaz.alexandrovich@paragon-software.com>,
	Carlos Maiolino <cem@kernel.org>,
	Damien Le Moal <dlemoal@kernel.org>,
	libaokun@linux.alibaba.com, linux-ext4@vger.kernel.org,
	linux-xfs@vger.kernel.org
Subject: Re: [PATCH v4 01/21] iomap: split iomap_iter() logic into iomap_iter_next()
Date: Tue, 28 Jul 2026 08:55:08 -0700	[thread overview]
Message-ID: <20260728155508.GT2901224@frogsfrogsfrogs> (raw)
In-Reply-To: <amizdHj6ICgP2xFv@bfoster>

On Tue, Jul 28, 2026 at 09:49:40AM -0400, Brian Foster wrote:
> On Mon, Jul 27, 2026 at 02:17:38PM -0700, Joanne Koong wrote:
> > In preparation for changing iomap to use an in-iter (->iomap_next())
> > model, move the iomap_iter() logic out into the new iomap_iter_next()
> > helper function.
> > 
> > iomap_iter_next() is added as an inlined helper so it can be called
> > directly by ->iomap_next() implementations where the begin()/end()
> > callbacks can be direct calls.
> > 
> > The DEFINE_IOMAP_ITER_NEXT() and DEFINE_IOMAP_ITER_NEXT_END() macros are
> > also provided to generate the boilerplate ->iomap_next() wrapper
> > functions that simply forward to iomap_iter_next() with the appropriate
> > begin/end callbacks. DEFINE_IOMAP_ITER_NEXT() is for the common case
> > where there is no end() callback. DEFINE_IOMAP_ITER_NEXT_END() is for
> > the case where there is an explicit end() callback.
> > 
> > No functional change intended. The only code-level difference is that on
> > the iomap_end() error path (ret < 0 && !advanced), the old code returned
> > with iter.status left as the caller's last value whereas the new code
> > zeroes it, but this is not observable in practice as there are no in-tree
> > callers that read iter.status after the iteration loop.
> > 
> > Reviewed-by: Darrick J. Wong <djwong@kernel.org>
> > Reviewed-by: Fengnan Chang <changfengnan@bytedance.com>
> > Reviewed-by: Christoph Hellwig <hch@lst.de>
> > Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
> > ---
> >  fs/iomap/iter.c       | 123 +++++++++++++++++++++---------------------
> >  include/linux/iomap.h | 102 +++++++++++++++++++++++++++++------
> >  2 files changed, 147 insertions(+), 78 deletions(-)
> > 
> > diff --git a/fs/iomap/iter.c b/fs/iomap/iter.c
> > index e4a29829591a..66ccb87441ab 100644
> > --- a/fs/iomap/iter.c
> > +++ b/fs/iomap/iter.c
> > @@ -6,15 +6,6 @@
> >  #include <linux/iomap.h>
> >  #include "trace.h"
> >  
> > -static inline void iomap_iter_clean_fbatch(struct iomap_iter *iter)
> > -{
> > -	if (iter->iomap.flags & IOMAP_F_FOLIO_BATCH) {
> > -		folio_batch_release(iter->fbatch);
> > -		folio_batch_reinit(iter->fbatch);
> > -		iter->iomap.flags &= ~IOMAP_F_FOLIO_BATCH;
> > -	}
> > -}
> > -
> 
> So hch forwarded me a bit of Sashiko review feedback that called out a
> potential folio batch leak on error returns from iomap_begin() or
> iomap_end(). Note that I think the ->iomap_end() variant is currently
> not an issue because nothing returns error there, but it should be fixed
> regardless.
> 
> As such, I have the patch below as a fix based on current master. The
> idea here is to account for failures from either callback and also the
> fact that XFS may not necessarily transfer the iomap_flags on failure. I
> considered a couple other options here, like changing that behavior or
> using an iter flag, but I think this is the cleanest option.
> 
> However this obviously conflicts with this rework series. This isn't a
> major conflict IMO.. I'd probably just do the same thing and include the
> batch cleanup in the error/exit path of iomap_iter() (or maybe start
> passing ret into iomap_iter_done()), but I would need to reintroduce the
> helper above. Also after this series I think this could mean a duplicate
> call in the termination case where iomap_iter_continue() would have
> cleaned things up, but that is relatively harmless. Maybe there is
> something incrementally cleaner, but I'm still wrapping my head around
> the factoring here..
> 
> But anyways, the main thing I wanted to ask is how folks want to handle
> this particular bug..? This rework is invasive and looks mostly reviewed
> so I don't want to unnecessarily hold it up. I can rebase on top of this
> and leave the patch below for -stable, or avoid the helper churn and
> post the patch below on its own and rework it into this, or maybe just
> tweak this to leave the helper around and avoid some churn that way..
> thoughts?

From my 30000ft view I'd say push the folio leak fix to linus ASAP for
7.2 and work out the merge conflict resolution in for-next and send that
to broonie/linus for 7.3.  But I'm not sure if people are actually
hitting this and not realizing it; or if this is a fix for a theoretical
problem.

--D

> Brian
> 
> --- 8< ---
> 
> diff --git a/fs/iomap/iter.c b/fs/iomap/iter.c
> index e4a29829591a..63617ec48250 100644
> --- a/fs/iomap/iter.c
> +++ b/fs/iomap/iter.c
> @@ -6,12 +6,18 @@
>  #include <linux/iomap.h>
>  #include "trace.h"
>  
> +/*
> + * Release the iter folio batch. Note that the iomap flag is meant to control
> + * the I/O path for the mapping and may not be set in error situations.
> + */
>  static inline void iomap_iter_clean_fbatch(struct iomap_iter *iter)
>  {
> -	if (iter->iomap.flags & IOMAP_F_FOLIO_BATCH) {
> +	if (!iter->fbatch)
> +		return;
> +	iter->iomap.flags &= ~IOMAP_F_FOLIO_BATCH;
> +	if (folio_batch_count(iter->fbatch)) {
>  		folio_batch_release(iter->fbatch);
>  		folio_batch_reinit(iter->fbatch);
> -		iter->iomap.flags &= ~IOMAP_F_FOLIO_BATCH;
>  	}
>  }
>  
> @@ -79,7 +85,7 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops)
>  						  olen),
>  				advanced, iter->flags, &iter->iomap);
>  		if (ret < 0 && !advanced)
> -			return ret;
> +			goto error;
>  	}
>  
>  	/* detect old return semantics where this would advance */
> @@ -110,7 +116,11 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops)
>  	ret = ops->iomap_begin(iter->inode, iter->pos, iter->len, iter->flags,
>  			       &iter->iomap, &iter->srcmap);
>  	if (ret < 0)
> -		return ret;
> +		goto error;
>  	iomap_iter_done(iter);
>  	return 1;
> +
> +error:
> +	iomap_iter_clean_fbatch(iter);
> +	return ret;
>  }
> 
> 

  reply	other threads:[~2026-07-28 15:55 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-27 21:17 [PATCH v4 00/21] iomap: convert to in-iter iomap_next() model Joanne Koong
2026-07-27 21:17 ` [PATCH v4 01/21] iomap: split iomap_iter() logic into iomap_iter_next() Joanne Koong
2026-07-28 13:49   ` Brian Foster
2026-07-28 15:55     ` Darrick J. Wong [this message]
2026-07-28 18:23       ` Brian Foster
2026-07-27 21:17 ` [PATCH v4 02/21] iomap: decouple simple direct I/O reads from iomap_dio_rw Joanne Koong
2026-07-27 22:28   ` Darrick J. Wong
2026-07-28  3:03   ` changfengnan
2026-07-27 21:17 ` [PATCH v4 03/21] iomap: use GFP_NOWAIT when application for iomap_dio_simple allocations Joanne Koong
2026-07-28  3:04   ` changfengnan
2026-07-27 21:17 ` [PATCH v4 04/21] iomap: add ->iomap_next() Joanne Koong
2026-07-27 22:27   ` Darrick J. Wong
2026-07-27 21:17 ` [PATCH v4 05/21] xfs: convert iomap ops to ->iomap_next() Joanne Koong
2026-07-27 22:28   ` Darrick J. Wong
2026-07-27 21:17 ` [PATCH v4 06/21] btrfs: " Joanne Koong
2026-07-27 21:17 ` [PATCH v4 07/21] ntfs3: " Joanne Koong
2026-07-27 21:17 ` [PATCH v4 08/21] ntfs: " Joanne Koong
2026-07-27 21:17 ` [PATCH v4 09/21] ext4: " Joanne Koong
2026-07-27 21:17 ` [PATCH v4 10/21] erofs: " Joanne Koong
2026-07-27 21:17 ` [PATCH v4 11/21] zonefs: " Joanne Koong
2026-07-27 21:17 ` [PATCH v4 12/21] ext2: " Joanne Koong
2026-07-27 21:17 ` [PATCH v4 13/21] block: " Joanne Koong
2026-07-27 21:17 ` [PATCH v4 14/21] f2fs: " Joanne Koong
2026-07-27 21:17 ` [PATCH v4 15/21] gfs2: " Joanne Koong
2026-07-27 21:17 ` [PATCH v4 16/21] hpfs: " Joanne Koong
2026-07-27 21:17 ` [PATCH v4 17/21] fuse: " Joanne Koong
2026-07-27 21:17 ` [PATCH v4 18/21] exfat: " Joanne Koong
2026-07-27 21:17 ` [PATCH v4 19/21] iomap: remove ->iomap_begin()/->iomap_end() legacy path Joanne Koong
2026-07-27 21:17 ` [PATCH v4 20/21] iomap: pass iomap_iter_next_fn directly instead of struct iomap_ops Joanne Koong
2026-07-27 22:33   ` Darrick J. Wong
2026-07-27 21:17 ` [PATCH v4 21/21] Documentation: iomap: update docs to reflect iomap_iter_next model Joanne Koong
2026-07-27 22:39   ` Darrick J. Wong
2026-07-28  3:50 ` [PATCH v4 00/21] iomap: convert to in-iter iomap_next() model Christoph Hellwig

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=20260728155508.GT2901224@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=agruenba@redhat.com \
    --cc=almaz.alexandrovich@paragon-software.com \
    --cc=bfoster@redhat.com \
    --cc=brauner@kernel.org \
    --cc=cem@kernel.org \
    --cc=changfengnan@bytedance.com \
    --cc=corbet@lwn.net \
    --cc=dlemoal@kernel.org \
    --cc=dsterba@suse.com \
    --cc=hch@lst.de \
    --cc=hyc.lee@gmail.com \
    --cc=jack@suse.cz \
    --cc=jaegeuk@kernel.org \
    --cc=joannelkoong@gmail.com \
    --cc=kbusch@kernel.org \
    --cc=libaokun@linux.alibaba.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=mikulas@artax.karlin.mff.cuni.cz \
    --cc=tytso@mit.edu \
    --cc=willy@infradead.org \
    --cc=xiang@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox