Skip to contentSkip to conversation

iomap: zero range folio batch support

PATCH Applied Brian Foster 4 participants 14 messages Oct 3, 2025 – Dec 8, 2025

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v5 cover iomap: zero range folio batch support

Hi all,

Only minor changes in v5 to the XFS errortag patch. I've kept the R-b tags because the fundamental logic is the same, but the errortag mechanism has been reworked and so that one needed a rebase (which turns out much simpler). A second look certainly couldn't hurt, but otherwise the associated fstest still works as expected.

Note that the force zeroing fstests test has since been merged as xfs/131. Otherwise I still have some followup patches to this work re:
the ext4 on iomap work, but it would be nice to move this along before getting too far ahead with that.

Brian

--- Original cover letter ---

Hi all,

Here's a first real v1 of folio batch support for iomap. This initially only targets zero range, the use case being zeroing of dirty folios over unwritten mappings. There is potential to support other operations in the future: iomap seek data/hole has similar raciness issues as zero range, the prospect of using this for buffered write has been raised for granular locking purposes, etc.

The one major caveat with this zero range implementation is that it doesn't look at iomap_folio_state to determine whether to zero a sub-folio portion of the folio. Instead it just relies on whether the folio was dirty or not. This means that spurious zeroing of unwritten ranges is possible if a folio is dirty but the target range includes a subrange that is not.

The reasoning is that this is essentially a complexity tradeoff. The current use cases for iomap_zero_range() are limited mostly to partial block zeroing scenarios. It's relatively harmless to zero an unwritten block (i.e. not a correctness issue), and this is something that filesystems have done in the past without much notice or issue. The advantage is less code and this makes it a little easier to use a filemap lookup function for the batch rather than open coding more logic in iomap. That said, this can probably be enhanced to look at ifs in the future if the use case expands and/or other operations justify it.

WRT testing, I've tested with and without a local hack to redirect fallocate zero range calls to iomap_zero_range() in XFS. This helps test beyond the partial block/folio use case, i.e. to cover boundary conditions like full folio batch handling, etc. I recently added patch 7 in spirit of that, which turns this logic into an XFS errortag. Further comments on that are inline with patch 7.

Thoughts, reviews, flames appreciated.

Brian

v5:
- Rebased across XFS errortag mechanism rework.
v4: https://lore.kernel.org/linux-fsdevel/[email protected]/
- Update commit log description in patch 3.
- Added remaining R-b tags.
v3: https://lore.kernel.org/linux-fsdevel/[email protected]/
- Update commit log description in patch 2.
- Improve comments in patch 7.
v2: https://lore.kernel.org/linux-fsdevel/[email protected]/
- Move filemap patch to top. Add some comments and drop export.
- Drop unnecessary BUG_ON()s from iomap_write_begin() instead of moving.
- Added folio mapping check to batch codepath, improved comments.
v1: https://lore.kernel.org/linux-fsdevel/[email protected]/
- Dropped most prep patches from previous version (merged separately).
- Reworked dirty folio lookup to use find_get_entry() loop (new patch
for filemap helper).
- Misc. bug fixes, code cleanups, comments, etc.
- Added (RFC) prospective patch for wider zero range test coverage.
RFCv2: https://lore.kernel.org/linux-fsdevel/[email protected]/
- Port onto incremental advance, drop patch 1 from RFCv1.
- Moved batch into iomap_iter, dynamically allocate and drop flag.
- Tweak XFS patch to always trim zero range on EOF boundary.
RFCv1: https://lore.kernel.org/linux-fsdevel/[email protected]/

Brian Foster (7):
filemap: add helper to look up dirty folios in a range
iomap: remove pos+len BUG_ON() to after folio lookup
iomap: optional zero range dirty folio processing
xfs: always trim mapping to requested range for zero range
xfs: fill dirty folios on zero range of unwritten mappings
iomap: remove old partial eof zeroing optimization
xfs: error tag to force zeroing on debug kernels

 fs/iomap/buffered-io.c       | 117 +++++++++++++++++++++++++----------
 fs/iomap/iter.c              |   6 ++
 fs/xfs/libxfs/xfs_errortag.h |   6 +-
 fs/xfs/xfs_file.c            |  29 ++++++---
 fs/xfs/xfs_iomap.c           |  38 +++++++++---
 include/linux/iomap.h        |   4 ++
 include/linux/pagemap.h      |   2 +
 mm/filemap.c                 |  58 +++++++++++++++++
 8 files changed, 210 insertions(+), 50 deletions(-)
Signature · 1 line
2.51.0
#1 lore raw

PATCH v5 1/7 filemap: add helper to look up dirty folios in a range

Add a new filemap_get_folios_dirty() helper to look up existing dirty folios in a range and add them to a folio_batch. This is to support optimization of certain iomap operations that only care about dirty folios in a target range. For example, zero range only zeroes the subset of dirty pages over unwritten mappings, seek hole/data may use similar logic in the future, etc.

Note that the helper is intended for use under internal fs locks. Therefore it trylocks folios in order to filter out clean folios. This loosely follows the logic from filemap_range_has_writeback().

---
 include/linux/pagemap.h |  2 ++
 mm/filemap.c            | 58 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+)
include/linux/pagemap.h +2 -0
index 185644e288ea..0b471f0eb940 100644
@@ -977,6 +977,8 @@ unsigned filemap_get_folios_contig(struct address_space *mapping,
 		pgoff_t *start, pgoff_t end, struct folio_batch *fbatch);
 unsigned filemap_get_folios_tag(struct address_space *mapping, pgoff_t *start,
 		pgoff_t end, xa_mark_t tag, struct folio_batch *fbatch);
+unsigned filemap_get_folios_dirty(struct address_space *mapping,
+		pgoff_t *start, pgoff_t end, struct folio_batch *fbatch);
 
 struct folio *read_cache_folio(struct address_space *, pgoff_t index,
 		filler_t *filler, struct file *file);
mm/filemap.c +58 -0

64 lines not on this page · raw message

Signature · 1 line
2.51.0
#2 lore raw

PATCH v5 2/7 iomap: remove pos+len BUG_ON() to after folio lookup

In reply to Brian Foster

The bug checks at the top of iomap_write_begin() assume the pos/len reflect exactly the next range to process. This may no longer be the case once the get folio path is able to process a folio batch from the filesystem. On top of that, len is already trimmed to within the iomap/srcmap by iomap_length(), so these checks aren't terribly useful. Remove the unnecessary BUG_ON() checks.

---
 fs/iomap/buffered-io.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
fs/iomap/buffered-io.c +1 -4
index 8b847a1e27f1..211644774bb8 100644
@@ -815,15 +815,12 @@ static int iomap_write_begin(struct iomap_iter *iter,
 		size_t *poffset, u64 *plen)
 {
 	const struct iomap *srcmap = iomap_iter_srcmap(iter);
-	loff_t pos = iter->pos;
+	loff_t pos;
 	u64 len = min_t(u64, SIZE_MAX, iomap_length(iter));
 	struct folio *folio;
 	int status = 0;
 
 	len = min_not_zero(len, *plen);
-	BUG_ON(pos + len > iter->iomap.offset + iter->iomap.length);
-	if (srcmap != &iter->iomap)
-		BUG_ON(pos + len > srcmap->offset + srcmap->length);
 
 	if (fatal_signal_pending(current))
 		return -EINTR;
Signature · 1 line
2.51.0
#3 lore raw

PATCH v5 3/7 iomap: optional zero range dirty folio processing

In reply to Brian Foster

The only way zero range can currently process unwritten mappings with dirty pagecache is to check whether the range is dirty before mapping lookup and then flush when at least one underlying mapping is unwritten. This ordering is required to prevent iomap lookup from racing with folio writeback and reclaim.

Since zero range can skip ranges of unwritten mappings that are clean in cache, this operation can be improved by allowing the filesystem to provide a set of dirty folios that require zeroing. In turn, rather than flush or iterate file offsets, zero range can iterate on folios in the batch and advance over clean or uncached ranges in between.

Add a folio_batch in struct iomap and provide a helper for filesystems to populate the batch at lookup time. Update the folio lookup path to return the next folio in the batch, if provided, and advance the iter if the folio starts beyond the current offset.

---
 fs/iomap/buffered-io.c | 89 +++++++++++++++++++++++++++++++++++++++---
 fs/iomap/iter.c        |  6 +++
 include/linux/iomap.h  |  4 ++
 3 files changed, 94 insertions(+), 5 deletions(-)
fs/iomap/buffered-io.c +84 -5
index 211644774bb8..a830ae5f5ac7 100644
@@ -761,6 +761,28 @@ static struct folio *__iomap_get_folio(struct iomap_iter *iter,
 	if (!mapping_large_folio_support(iter->inode->i_mapping))
 		len = min_t(size_t, len, PAGE_SIZE - offset_in_page(pos));
 
+	if (iter->fbatch) {
+		struct folio *folio = folio_batch_next(iter->fbatch);
+
+		if (!folio)
+			return NULL;
+
+		/*
+		 * The folio mapping generally shouldn't have changed based on
+		 * fs locks, but be consistent with filemap lookup and retry
+		 * the iter if it does.
+		 */
+		folio_lock(folio);
+		if (unlikely(folio->mapping != iter->inode->i_mapping)) {
+			iter->iomap.flags |= IOMAP_F_STALE;
+			folio_unlock(folio);
+			return NULL;
+		}
+
+		folio_get(folio);
+		return folio;
+	}
+
 	if (write_ops && write_ops->get_folio)
 		return write_ops->get_folio(iter, pos, len);
 	return iomap_get_folio(iter, pos, len);
@@ -821,6 +843,8 @@ static int iomap_write_begin(struct iomap_iter *iter,
 	int status = 0;
 
 	len = min_not_zero(len, *plen);
+	*foliop = NULL;
+	*plen = 0;
 
 	if (fatal_signal_pending(current))
 		return -EINTR;
@@ -829,6 +853,15 @@ static int iomap_write_begin(struct iomap_iter *iter,
 	if (IS_ERR(folio))
 		return PTR_ERR(folio);
 
+	/*
+	 * No folio means we're done with a batch. We still have range to
+	 * process so return and let the caller iterate and refill the batch.
+	 */
+	if (!folio) {
+		WARN_ON_ONCE(!iter->fbatch);
+		return 0;
+	}
+
 	/*
 	 * Now we have a locked folio, before we do anything with it we need to
 	 * check that the iomap we have cached is not stale. The inode extent
@@ -849,6 +882,21 @@ static int iomap_write_begin(struct iomap_iter *iter,
 		}
 	}
 
+	/*
+	 * The folios in a batch may not be contiguous. If we've skipped
+	 * forward, advance the iter to the pos of the current folio. If the
+	 * folio starts beyond the end of the mapping, it may have been trimmed
+	 * since the lookup for whatever reason. Return a NULL folio to
+	 * terminate the op.
+	 */
+	if (folio_pos(folio) > iter->pos) {
+		len = min_t(u64, folio_pos(folio) - iter->pos,
+				 iomap_length(iter));
+		status = iomap_iter_advance(iter, &len);
+		if (status || !len)
+			goto out_unlock;
+	}
+
 	pos = iomap_trim_folio_range(iter, folio, poffset, &len);
 
 	if (srcmap->type == IOMAP_INLINE)
@@ -1395,6 +1443,12 @@ static int iomap_zero_iter(struct iomap_iter *iter, bool *did_zero,
 		if (iter->iomap.flags & IOMAP_F_STALE)
 			break;
 
+		/* a NULL folio means we're done with a folio batch */
+		if (!folio) {
+			status = iomap_iter_advance_full(iter);
+			break;
+		}
+
 		/* warn about zeroing folios beyond eof that won't write back */
 		WARN_ON_ONCE(folio_pos(folio) > iter->inode->i_size);
 
@@ -1419,6 +1473,26 @@ static int iomap_zero_iter(struct iomap_iter *iter, bool *did_zero,
 	return status;
 }
 
+loff_t
+iomap_fill_dirty_folios(
+	struct iomap_iter	*iter,
+	loff_t			offset,
+	loff_t			length)
+{
+	struct address_space	*mapping = iter->inode->i_mapping;
+	pgoff_t			start = offset >> PAGE_SHIFT;
+	pgoff_t			end = (offset + length - 1) >> PAGE_SHIFT;
+
+	iter->fbatch = kmalloc(sizeof(struct folio_batch), GFP_KERNEL);
+	if (!iter->fbatch)
+		return offset + length;
+	folio_batch_init(iter->fbatch);
+
+	filemap_get_folios_dirty(mapping, &start, end, iter->fbatch);
+	return (start << PAGE_SHIFT);
+}
+EXPORT_SYMBOL_GPL(iomap_fill_dirty_folios);
+
 int
 iomap_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero,
 		const struct iomap_ops *ops,
@@ -1448,7 +1522,7 @@ iomap_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero,
 	 * flushing on partial eof zeroing, special case it to zero the
 	 * unaligned start portion if already dirty in pagecache.
 	 */
-	if (off &&
+	if (!iter.fbatch && off &&
 	    filemap_range_needs_writeback(mapping, pos, pos + plen - 1)) {
 		iter.len = plen;
 		while ((ret = iomap_iter(&iter, ops)) > 0)
@@ -1465,13 +1539,18 @@ iomap_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero,
 	 * if dirty and the fs returns a mapping that might convert on
 	 * writeback.
 	 */
-	range_dirty = filemap_range_needs_writeback(inode->i_mapping,
-					iter.pos, iter.pos + iter.len - 1);
+	range_dirty = filemap_range_needs_writeback(mapping, iter.pos,
+					iter.pos + iter.len - 1);
 	while ((ret = iomap_iter(&iter, ops)) > 0) {
 		const struct iomap *srcmap = iomap_iter_srcmap(&iter);
 
-		if (srcmap->type == IOMAP_HOLE ||
-		    srcmap->type == IOMAP_UNWRITTEN) {
+		if (WARN_ON_ONCE(iter.fbatch &&
+				 srcmap->type != IOMAP_UNWRITTEN))
+			return -EIO;
+
+		if (!iter.fbatch &&
+		    (srcmap->type == IOMAP_HOLE ||
+		     srcmap->type == IOMAP_UNWRITTEN)) {
 			s64 status;
 
 			if (range_dirty) {
fs/iomap/iter.c +6 -0
index cef77ca0c20b..66ca12aac57d 100644
@@ -8,6 +8,12 @@
 
 static inline void iomap_iter_reset_iomap(struct iomap_iter *iter)
 {
+	if (iter->fbatch) {
+		folio_batch_release(iter->fbatch);
+		kfree(iter->fbatch);
+		iter->fbatch = NULL;
+	}
+
 	iter->status = 0;
 	memset(&iter->iomap, 0, sizeof(iter->iomap));
 	memset(&iter->srcmap, 0, sizeof(iter->srcmap));
include/linux/iomap.h +4 -0
index 73dceabc21c8..cd0f573156d6 100644
@@ -9,6 +9,7 @@
 #include <linux/types.h>
 #include <linux/mm_types.h>
 #include <linux/blkdev.h>
+#include <linux/pagevec.h>
 
 struct address_space;
 struct fiemap_extent_info;
@@ -241,6 +242,7 @@ struct iomap_iter {
 	unsigned flags;
 	struct iomap iomap;
 	struct iomap srcmap;
+	struct folio_batch *fbatch;
 	void *private;
 };
 
@@ -349,6 +351,8 @@ bool iomap_dirty_folio(struct address_space *mapping, struct folio *folio);
 int iomap_file_unshare(struct inode *inode, loff_t pos, loff_t len,
 		const struct iomap_ops *ops,
 		const struct iomap_write_ops *write_ops);
+loff_t iomap_fill_dirty_folios(struct iomap_iter *iter, loff_t offset,
+		loff_t length);
 int iomap_zero_range(struct inode *inode, loff_t pos, loff_t len,
 		bool *did_zero, const struct iomap_ops *ops,
 		const struct iomap_write_ops *write_ops, void *private);
Signature · 1 line
2.51.0
#4 lore raw

PATCH v5 4/7 xfs: always trim mapping to requested range for zero range

In reply to Brian Foster

Refactor and tweak the IOMAP_ZERO logic in preparation to support filling the folio batch for unwritten mappings. Drop the superfluous imap offset check since the hole case has already been filtered out. Split the the delalloc case handling into a sub-branch, and always trim the imap to the requested offset/count so it can be more easily used to bound the range to lookup in pagecache.

---
 fs/xfs/xfs_iomap.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
fs/xfs/xfs_iomap.c +8 -9
index d3f6e3e42a11..6a05e04ad5ba 100644
@@ -1767,21 +1767,20 @@ xfs_buffered_write_iomap_begin(
 	}
 
 	/*
-	 * For zeroing, trim a delalloc extent that extends beyond the EOF
-	 * block.  If it starts beyond the EOF block, convert it to an
+	 * For zeroing, trim extents that extend beyond the EOF block. If a
+	 * delalloc extent starts beyond the EOF block, convert it to an
 	 * unwritten extent.
 	 */
-	if ((flags & IOMAP_ZERO) && imap.br_startoff <= offset_fsb &&
-	    isnullstartblock(imap.br_startblock)) {
+	if (flags & IOMAP_ZERO) {
 		xfs_fileoff_t eof_fsb = XFS_B_TO_FSB(mp, XFS_ISIZE(ip));
 
-		if (offset_fsb >= eof_fsb)
+		if (isnullstartblock(imap.br_startblock) &&
+		    offset_fsb >= eof_fsb)
 			goto convert_delay;
-		if (end_fsb > eof_fsb) {
+		if (offset_fsb < eof_fsb && end_fsb > eof_fsb)
 			end_fsb = eof_fsb;
-			xfs_trim_extent(&imap, offset_fsb,
-					end_fsb - offset_fsb);
-		}
+
+		xfs_trim_extent(&imap, offset_fsb, end_fsb - offset_fsb);
 	}
 
 	/*
Signature · 1 line
2.51.0
#5 lore raw

PATCH v5 5/7 xfs: fill dirty folios on zero range of unwritten mappings

In reply to Brian Foster

Use the iomap folio batch mechanism to select folios to zero on zero range of unwritten mappings. Trim the resulting mapping if the batch is filled (unlikely for current use cases) to distinguish between a range to skip and one that requires another iteration due to a full batch.

---
 fs/xfs/xfs_iomap.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
fs/xfs/xfs_iomap.c +23 -0
index 6a05e04ad5ba..535bf3b8705d 100644
@@ -1702,6 +1702,8 @@ xfs_buffered_write_iomap_begin(
 	struct iomap		*iomap,
 	struct iomap		*srcmap)
 {
+	struct iomap_iter	*iter = container_of(iomap, struct iomap_iter,
+						     iomap);
 	struct xfs_inode	*ip = XFS_I(inode);
 	struct xfs_mount	*mp = ip->i_mount;
 	xfs_fileoff_t		offset_fsb = XFS_B_TO_FSBT(mp, offset);
@@ -1773,6 +1775,7 @@ xfs_buffered_write_iomap_begin(
 	 */
 	if (flags & IOMAP_ZERO) {
 		xfs_fileoff_t eof_fsb = XFS_B_TO_FSB(mp, XFS_ISIZE(ip));
+		u64 end;
 
 		if (isnullstartblock(imap.br_startblock) &&
 		    offset_fsb >= eof_fsb)
@@ -1780,6 +1783,26 @@ xfs_buffered_write_iomap_begin(
 		if (offset_fsb < eof_fsb && end_fsb > eof_fsb)
 			end_fsb = eof_fsb;
 
+		/*
+		 * Look up dirty folios for unwritten mappings within EOF.
+		 * Providing this bypasses the flush iomap uses to trigger
+		 * extent conversion when unwritten mappings have dirty
+		 * pagecache in need of zeroing.
+		 *
+		 * Trim the mapping to the end pos of the lookup, which in turn
+		 * was trimmed to the end of the batch if it became full before
+		 * the end of the mapping.
+		 */
+		if (imap.br_state == XFS_EXT_UNWRITTEN &&
+		    offset_fsb < eof_fsb) {
+			loff_t len = min(count,
+					 XFS_FSB_TO_B(mp, imap.br_blockcount));
+
+			end = iomap_fill_dirty_folios(iter, offset, len);
+			end_fsb = min_t(xfs_fileoff_t, end_fsb,
+					XFS_B_TO_FSB(mp, end));
+		}
+
 		xfs_trim_extent(&imap, offset_fsb, end_fsb - offset_fsb);
 	}
 
Signature · 1 line
2.51.0
#6 lore raw

Re: [PATCH v5 5/7] xfs: fill dirty folios on zero range of unwritten mappings

Quoted 64 lines · Brian Foster

Use the iomap folio batch mechanism to select folios to zero on zero range of unwritten mappings. Trim the resulting mapping if the batch is filled (unlikely for current use cases) to distinguish between a range to skip and one that requires another iteration due to a full batch.

---
 fs/xfs/xfs_iomap.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
fs/xfs/xfs_iomap.c +23 -0
index 6a05e04ad5ba..535bf3b8705d 100644
@@ -1702,6 +1702,8 @@ xfs_buffered_write_iomap_begin(
 	struct iomap		*iomap,
 	struct iomap		*srcmap)
 {
+	struct iomap_iter	*iter = container_of(iomap, struct iomap_iter,
+						     iomap);
 	struct xfs_inode	*ip = XFS_I(inode);
 	struct xfs_mount	*mp = ip->i_mount;
 	xfs_fileoff_t		offset_fsb = XFS_B_TO_FSBT(mp, offset);
@@ -1773,6 +1775,7 @@ xfs_buffered_write_iomap_begin(
 	 */
 	if (flags & IOMAP_ZERO) {
 		xfs_fileoff_t eof_fsb = XFS_B_TO_FSB(mp, XFS_ISIZE(ip));
+		u64 end;
 
 		if (isnullstartblock(imap.br_startblock) &&
 		    offset_fsb >= eof_fsb)
@@ -1780,6 +1783,26 @@ xfs_buffered_write_iomap_begin(
 		if (offset_fsb < eof_fsb && end_fsb > eof_fsb)
 			end_fsb = eof_fsb;
 
+		/*
+		 * Look up dirty folios for unwritten mappings within EOF.
+		 * Providing this bypasses the flush iomap uses to trigger
+		 * extent conversion when unwritten mappings have dirty
+		 * pagecache in need of zeroing.
+		 *
+		 * Trim the mapping to the end pos of the lookup, which in turn
+		 * was trimmed to the end of the batch if it became full before
+		 * the end of the mapping.
+		 */
+		if (imap.br_state == XFS_EXT_UNWRITTEN &&
+		    offset_fsb < eof_fsb) {
+			loff_t len = min(count,
+					 XFS_FSB_TO_B(mp, imap.br_blockcount));
+
+			end = iomap_fill_dirty_folios(iter, offset, len);
+			end_fsb = min_t(xfs_fileoff_t, end_fsb,
+					XFS_B_TO_FSB(mp, end));
+		}
+
 		xfs_trim_extent(&imap, offset_fsb, end_fsb - offset_fsb);
 	}
 
Signature · 1 line
2.51.0

Hi Brian Foster,

Greetings!

I used Syzkaller and found that there is possible deadlock in xfs_ilock in linux-next next-20251203.

After bisection and the first bad commit is:
"
77c475692c5e xfs: fill dirty folios on zero range of unwritten mappings "

All detailed into can be found at:
https://github.com/laifryiee/syzkaller_logs/tree/main/251204_221645_xfs_ilock
Syzkaller repro code:
https://github.com/laifryiee/syzkaller_logs/tree/main/251204_221645_xfs_ilock/repro.c
Syzkaller repro syscall steps:
https://github.com/laifryiee/syzkaller_logs/tree/main/251204_221645_xfs_ilock/repro.prog
Syzkaller report:
https://github.com/laifryiee/syzkaller_logs/tree/main/251204_221645_xfs_ilock/repro.report
Kconfig(make olddefconfig):
https://github.com/laifryiee/syzkaller_logs/tree/main/251204_221645_xfs_ilock/kconfig_origin
Bisect info:
https://github.com/laifryiee/syzkaller_logs/tree/main/251204_221645_xfs_ilock/bisect_info.log
bzImage:
https://github.com/laifryiee/syzkaller_logs/raw/refs/heads/main/251204_221645_xfs_ilock/bzImage_b2c27842ba853508b0da00187a7508eb3a96c8f7
Issue dmesg:
https://github.com/laifryiee/syzkaller_logs/blob/main/251204_221645_xfs_ilock/b2c27842ba853508b0da00187a7508eb3a96c8f7_dmesg.log

"

[   21.088994] ======================================================
[   21.089362] WARNING: possible circular locking dependency detected
[   21.089726] 6.18.0-next-20251203-b2c27842ba85 #1 Not tainted
[   21.090060] ------------------------------------------------------
[   21.090417] kswapd0/58 is trying to acquire lock:
[   21.090697] ffff888028ff1f18 (&xfs_nondir_ilock_class){++++}-{4:4}, at: xfs_ilock+0x30f/0x390
[   21.091235]
[   21.091235] but task is already holding lock:
[   21.091575] ffffffff8784b580 (fs_reclaim){+.+.}-{0:0}, at: balance_pgdat+0xb7e/0x15c0
[   21.092058]
[   21.092058] which lock already depends on the new lock.
[   21.092058]
[   21.092524]
[   21.092524] the existing dependency chain (in reverse order) is:
[   21.092949]
[   21.092949] -> #1 (fs_reclaim){+.+.}-{0:0}:
[   21.093290]        fs_reclaim_acquire+0x116/0x160
[   21.093579]        __kmalloc_cache_noprof+0x53/0x7e0
[   21.093886]        iomap_fill_dirty_folios+0x118/0x2c0
[   21.094204]        xfs_buffered_write_iomap_begin+0xf18/0x2150
[   21.094552]        iomap_iter+0x551/0xf40
[   21.094798]        iomap_zero_range+0x20b/0xa90
[   21.095075]        xfs_zero_range+0xb5/0x100
[   21.095335]        xfs_reflink_remap_prep+0x3d3/0xa90
[   21.095643]        xfs_file_remap_range+0x23c/0xdc0
[   21.095944]        vfs_clone_file_range+0x2b1/0xda0
[   21.096243]        ioctl_file_clone+0x6e/0x110
[   21.096521]        do_vfs_ioctl+0xcab/0x14d0
[   21.096786]        __x64_sys_ioctl+0x127/0x220
[   21.097057]        x64_sys_call+0x1280/0x21b0
[   21.097331]        do_syscall_64+0x6d/0x1180
[   21.097607]        entry_SYSCALL_64_after_hwframe+0x76/0x7e
[   21.097936]
[   21.097936] -> #0 (&xfs_nondir_ilock_class){++++}-{4:4}:
[   21.098334]        __lock_acquire+0x14d1/0x2210
[   21.098615]        lock_acquire+0x170/0x2f0
[   21.098869]        down_write_nested+0x9a/0x210
[   21.099145]        xfs_ilock+0x30f/0x390
[   21.099385]        xfs_icwalk_ag+0xaec/0x1b60
[   21.099652]        xfs_icwalk+0x56/0xc0
[   21.099892]        xfs_reclaim_inodes_nr+0x1d3/0x2d0
[   21.100192]        xfs_fs_free_cached_objects+0x6a/0x90
[   21.100506]        super_cache_scan+0x415/0x570
[   21.100794]        do_shrink_slab+0x408/0x1030
[   21.101069]        shrink_slab+0x348/0x12f0
[   21.101329]        shrink_node+0xacc/0x2670
[   21.101587]        balance_pgdat+0xa2d/0x15c0
[   21.101860]        kswapd+0x5b9/0xab0
[   21.102093]        kthread+0x464/0x980
[   21.102329]        ret_from_fork+0x780/0x8f0
[   21.102596]        ret_from_fork_asm+0x1a/0x30
[   21.102873]
[   21.102873] other info that might help us debug this:
[   21.102873]
[   21.103335]  Possible unsafe locking scenario:
[   21.103335]
[   21.103683]        CPU0                    CPU1
[   21.103955]        ----                    ----
[   21.104225]   lock(fs_reclaim);
[   21.104428]                                lock(&xfs_nondir_ilock_class);
[   21.104823]                                lock(fs_reclaim);
[   21.105158]   lock(&xfs_nondir_ilock_class);
[   21.105416]
[   21.105416]  *** DEADLOCK ***
[   21.105416]
[   21.105762] 2 locks held by kswapd0/58:
[   21.105993]  #0: ffffffff8784b580 (fs_reclaim){+.+.}-{0:0}, at: balance_pgdat+0xb7e/0x15c0
[   21.106487]  #1: ffff88800fd580e0 (&type->s_umount_key#53){.+.+}-{4:4}, at: super_cache_scan+0x9f/0x570
[   21.107047]
[   21.107047] stack backtrace:
[   21.107307] CPU: 1 UID: 0 PID: 58 Comm: kswapd0 Not tainted 6.18.0-next-20251203-b2c27842ba85 #1 PREEMPT(volu
[   21.107319] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.0-0-gd239552ce722-prebuilt.q4
[   21.107326] Call Trace:
[   21.107335]  <TASK>
[   21.107338]  dump_stack_lvl+0xea/0x150
[   21.107352]  dump_stack+0x19/0x20
[   21.107359]  print_circular_bug+0x283/0x350
[   21.107370]  check_noncircular+0x12d/0x150
[   21.107383]  __lock_acquire+0x14d1/0x2210
[   21.107398]  lock_acquire+0x170/0x2f0
[   21.107407]  ? xfs_ilock+0x30f/0x390
[   21.107420]  ? __cond_resched+0x37/0x50
[   21.107434]  down_write_nested+0x9a/0x210
[   21.107445]  ? xfs_ilock+0x30f/0x390
[   21.107456]  ? __pfx_down_write_nested+0x10/0x10
[   21.107468]  ? xfs_icwalk_ag+0xadf/0x1b60
[   21.107482]  ? xfs_icwalk_ag+0xaec/0x1b60
[   21.107497]  ? xfs_icwalk_ag+0xaec/0x1b60
[   21.107510]  xfs_ilock+0x30f/0x390
[   21.107523]  xfs_icwalk_ag+0xaec/0x1b60
[   21.107542]  ? __pfx_xfs_icwalk_ag+0x10/0x10
[   21.107561]  ? __pfx_xa_find+0x10/0x10
[   21.107581]  ? xfs_group_grab_next_mark+0x26a/0x520
[   21.107605]  ? __this_cpu_preempt_check+0x21/0x30
[   21.107616]  ? lock_release+0x14f/0x2a0
[   21.107628]  ? xfs_group_grab_next_mark+0x274/0x520
[   21.107643]  ? __pfx_xfs_group_grab_next_mark+0x10/0x10
[   21.107662]  ? __pfx_try_to_wake_up+0x10/0x10
[   21.107678]  ? lock_release+0x14f/0x2a0
[   21.107689]  xfs_icwalk+0x56/0xc0
[   21.107704]  xfs_reclaim_inodes_nr+0x1d3/0x2d0
[   21.107718]  ? __pfx_xfs_reclaim_inodes_nr+0x10/0x10
[   21.107734]  ? __this_cpu_preempt_check+0x21/0x30
[   21.107744]  ? __pfx_prune_icache_sb+0x10/0x10
[   21.107762]  xfs_fs_free_cached_objects+0x6a/0x90
[   21.107777]  super_cache_scan+0x415/0x570
[   21.107794]  do_shrink_slab+0x408/0x1030
[   21.107813]  shrink_slab+0x348/0x12f0
[   21.107831]  ? shrink_slab+0x160/0x12f0
[   21.107845]  ? __pfx_shrink_slab+0x10/0x10
[   21.107866]  shrink_node+0xacc/0x2670
[   21.107888]  ? __pfx_shrink_node+0x10/0x10
[   21.107900]  ? preempt_schedule_common+0x49/0xd0
[   21.107913]  balance_pgdat+0xa2d/0x15c0
[   21.107929]  ? __pfx_balance_pgdat+0x10/0x10
[   21.107941]  ? rcu_watching_snap_stopped_since+0x20/0xf0
[   21.107975]  kswapd+0x5b9/0xab0
[   21.107990]  ? __pfx_kswapd+0x10/0x10
[   21.108002]  ? _raw_spin_unlock_irqrestore+0x35/0x70
[   21.108017]  ? trace_hardirqs_on+0x26/0x130
[   21.108040]  ? __pfx_autoremove_wake_function+0x10/0x10
[   21.108060]  ? __sanitizer_cov_trace_const_cmp1+0x1e/0x30
[   21.108080]  ? __kthread_parkme+0x1bc/0x260
[   21.108094]  ? __pfx_kswapd+0x10/0x10
[   21.108107]  ? __pfx_kswapd+0x10/0x10
[   21.108120]  kthread+0x464/0x980
[   21.108128]  ? __pfx_kthread+0x10/0x10
[   21.108135]  ? trace_hardirqs_on+0x26/0x130
[   21.108149]  ? _raw_spin_unlock_irq+0x3c/0x60
[   21.108158]  ? __pfx_kthread+0x10/0x10
[   21.108167]  ret_from_fork+0x780/0x8f0
[   21.108177]  ? __pfx_ret_from_fork+0x10/0x10
[   21.108186]  ? native_load_tls+0x16/0x50
[   21.108199]  ? __sanitizer_cov_trace_const_cmp8+0x1c/0x30
[   21.108213]  ? __switch_to+0x823/0x10b0
[   21.108232]  ? __pfx_kthread+0x10/0x10
[   21.108240]  ret_from_fork_asm+0x1a/0x30
[   21.108257]  </TASK>
[   21.592826] repro: page allocation failure: order:0, mode:0x10cc0(GFP_KERNEL|__GFP_NORETRY), nodemask=(null),0
[   21.593533] CPU: 1 UID: 0 PID: 727 Comm: repro Not tainted 6.18.0-next-20251203-b2c27842ba85 #1 PREEMPT(volun
[   21.593545] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.0-0-gd239552ce722-prebuilt.q4
[   21.593551] Call Trace:
[   21.593554]  <TASK>
[   21.593557]  dump_stack_lvl+0x121/0x150
[   21.593572]  dump_stack+0x19/0x20
[   21.593582]  warn_alloc+0x216/0x360
[   21.593595]  ? __pfx_warn_alloc+0x10/0x10
[   21.593607]  ? __pfx___alloc_pages_direct_compact+0x10/0x10
[   21.593618]  ? __drain_all_pages+0x27d/0x480
[   21.593628]  __alloc_pages_slowpath.constprop.0+0x1340/0x2230
[   21.593644]  ? __pfx___alloc_pages_slowpath.constprop.0+0x10/0x10
[   21.593657]  ? __might_sleep+0x108/0x160
[   21.593680]  __alloc_frozen_pages_noprof+0x47f/0x550
[   21.593690]  ? asm_sysvec_apic_timer_interrupt+0x1f/0x30
[   21.593702]  ? __pfx___alloc_frozen_pages_noprof+0x10/0x10
[   21.593716]  ? policy_nodemask+0xf9/0x450
[   21.593734]  alloc_pages_mpol+0x236/0x4c0
[   21.593746]  ? __pfx_alloc_pages_mpol+0x10/0x10
[   21.593758]  ? alloc_frozen_pages_noprof+0x48/0x180
[   21.593766]  ? alloc_frozen_pages_noprof+0x51/0x180
[   21.593775]  alloc_frozen_pages_noprof+0xa9/0x180
[   21.593783]  alloc_pages_noprof+0x27/0xa0
[   21.593791]  kimage_alloc_pages+0x78/0x240
[   21.593809]  kimage_alloc_control_pages+0x1ca/0xa60
[   21.593819]  ? __pfx_kimage_alloc_control_pages+0x10/0x10
[   21.593827]  ? __sanitizer_cov_trace_cmp8+0x1c/0x30
[   21.593844]  do_kexec_load+0x39b/0x8c0
[   21.593851]  ? __might_fault+0xf1/0x1b0
[   21.593868]  ? __pfx_do_kexec_load+0x10/0x10
[   21.593876]  ? __sanitizer_cov_trace_const_cmp8+0x1c/0x30
[   21.593887]  ? _copy_from_user+0x75/0xa0
[   21.593904]  __x64_sys_kexec_load+0x1cc/0x240
[   21.593913]  x64_sys_call+0x1c90/0x21b0
[   21.593922]  do_syscall_64+0x6d/0x1180
[   21.593930]  entry_SYSCALL_64_after_hwframe+0x76/0x7e
[   21.593938] RIP: 0033:0x7f347b83ee5d
[   21.593952] Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 88
[   21.593959] RSP: 002b:00007ffc6cb1d938 EFLAGS: 00000207 ORIG_RAX: 00000000000000f6
[   21.593972] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f347b83ee5d
[   21.593977] RDX: 0000200000000180 RSI: 0000000000000003 RDI: 0000000000000000
[   21.593982] RBP: 00007ffc6cb1d950 R08: 00007ffc6cb1d3c0 R09: 00007ffc6cb1d950
[   21.593986] R10: 0000000000000000 R11: 0000000000000207 R12: 00007ffc6cb1daa8
[   21.593991] R13: 00000000004030f5 R14: 000000000040ee08 R15: 00007f347bb26000
[   21.594000]  </TASK>

"

Hope this cound be insightful to you.

Regards,
Yi Lai

---

If you don't need the following environment to reproduce the problem or if you already have one reproduced environment, please ignore the following information.

How to reproduce:
git clone https://gitlab.com/xupengfe/repro_vm_env.git
cd repro_vm_env
tar -xvf repro_vm_env.tar.gz
cd repro_vm_env; ./start3.sh // it needs qemu-system-x86_64 and I used v7.1.0
// start3.sh will load bzImage_2241ab53cbb5cdb08a6b2d4688feb13971058f65 v6.2-rc5 kernel
// You could change the bzImage_xxx as you want
// Maybe you need to remove line "-drive if=pflash,format=raw,readonly=on,file=./OVMF_CODE.fd \" for different qemu version
You could use below command to log in, there is no password for root.
ssh -p 10023 root@localhost

After login vm(virtual machine) successfully, you could transfer reproduced binary to the vm by below way, and reproduce the problem in vm:
gcc -pthread -o repro repro.c
scp -P 10023 repro root@localhost:/root/

Get the bzImage for target kernel:
Please use target kconfig and copy it to kernel_src/.config make olddefconfig
make -jx bzImage //x should equal or less than cpu num your pc has

Fill the bzImage file into above start3.sh to load the target kernel in vm.

Tips:
If you already have qemu-system-x86_64, please ignore below info.
If you want to install qemu v7.1.0 version:
git clone https://github.com/qemu/qemu.git
cd qemu
git checkout -f v7.1.0
mkdir build
cd build
yum install -y ninja-build.x86_64
yum -y install libslirp-devel.x86_64
../configure --target-list=x86_64-softmmu --enable-kvm --enable-vnc --enable-gtk --enable-sdl --enable-usb-redir --enable-slirp make
make install

#7 lore raw

Re: [PATCH v5 5/7] xfs: fill dirty folios on zero range of unwritten mappings

Quoted 68 lines · Yi
Quoted 64 lines · Brian Foster

Use the iomap folio batch mechanism to select folios to zero on zero range of unwritten mappings. Trim the resulting mapping if the batch is filled (unlikely for current use cases) to distinguish between a range to skip and one that requires another iteration due to a full batch.

---
 fs/xfs/xfs_iomap.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
fs/xfs/xfs_iomap.c +23 -0
index 6a05e04ad5ba..535bf3b8705d 100644
@@ -1702,6 +1702,8 @@ xfs_buffered_write_iomap_begin(
 	struct iomap		*iomap,
 	struct iomap		*srcmap)
 {
+	struct iomap_iter	*iter = container_of(iomap, struct iomap_iter,
+						     iomap);
 	struct xfs_inode	*ip = XFS_I(inode);
 	struct xfs_mount	*mp = ip->i_mount;
 	xfs_fileoff_t		offset_fsb = XFS_B_TO_FSBT(mp, offset);
@@ -1773,6 +1775,7 @@ xfs_buffered_write_iomap_begin(
 	 */
 	if (flags & IOMAP_ZERO) {
 		xfs_fileoff_t eof_fsb = XFS_B_TO_FSB(mp, XFS_ISIZE(ip));
+		u64 end;
 
 		if (isnullstartblock(imap.br_startblock) &&
 		    offset_fsb >= eof_fsb)
@@ -1780,6 +1783,26 @@ xfs_buffered_write_iomap_begin(
 		if (offset_fsb < eof_fsb && end_fsb > eof_fsb)
 			end_fsb = eof_fsb;
 
+		/*
+		 * Look up dirty folios for unwritten mappings within EOF.
+		 * Providing this bypasses the flush iomap uses to trigger
+		 * extent conversion when unwritten mappings have dirty
+		 * pagecache in need of zeroing.
+		 *
+		 * Trim the mapping to the end pos of the lookup, which in turn
+		 * was trimmed to the end of the batch if it became full before
+		 * the end of the mapping.
+		 */
+		if (imap.br_state == XFS_EXT_UNWRITTEN &&
+		    offset_fsb < eof_fsb) {
+			loff_t len = min(count,
+					 XFS_FSB_TO_B(mp, imap.br_blockcount));
+
+			end = iomap_fill_dirty_folios(iter, offset, len);
+			end_fsb = min_t(xfs_fileoff_t, end_fsb,
+					XFS_B_TO_FSB(mp, end));
+		}
+
 		xfs_trim_extent(&imap, offset_fsb, end_fsb - offset_fsb);
 	}
 
Signature · 1 line
2.51.0

Hi Brian Foster,

Quoted 9 lines

Greetings!

I used Syzkaller and found that there is possible deadlock in xfs_ilock in linux-next next-20251203.

After bisection and the first bad commit is:
"
77c475692c5e xfs: fill dirty folios on zero range of unwritten mappings "

The referenced reproducer doesn't throw anything for me, but if you want to test the following:

https://lore.kernel.org/linux-fsdevel/[email protected]/

... that removes the allocation associated with this splat. Thanks.

Brian

Quoted 253 lines

All detailed into can be found at:
https://github.com/laifryiee/syzkaller_logs/tree/main/251204_221645_xfs_ilock
Syzkaller repro code:
https://github.com/laifryiee/syzkaller_logs/tree/main/251204_221645_xfs_ilock/repro.c
Syzkaller repro syscall steps:
https://github.com/laifryiee/syzkaller_logs/tree/main/251204_221645_xfs_ilock/repro.prog
Syzkaller report:
https://github.com/laifryiee/syzkaller_logs/tree/main/251204_221645_xfs_ilock/repro.report
Kconfig(make olddefconfig):
https://github.com/laifryiee/syzkaller_logs/tree/main/251204_221645_xfs_ilock/kconfig_origin
Bisect info:
https://github.com/laifryiee/syzkaller_logs/tree/main/251204_221645_xfs_ilock/bisect_info.log
bzImage:
https://github.com/laifryiee/syzkaller_logs/raw/refs/heads/main/251204_221645_xfs_ilock/bzImage_b2c27842ba853508b0da00187a7508eb3a96c8f7
Issue dmesg:
https://github.com/laifryiee/syzkaller_logs/blob/main/251204_221645_xfs_ilock/b2c27842ba853508b0da00187a7508eb3a96c8f7_dmesg.log

"

[   21.088994] ======================================================
[   21.089362] WARNING: possible circular locking dependency detected
[   21.089726] 6.18.0-next-20251203-b2c27842ba85 #1 Not tainted
[   21.090060] ------------------------------------------------------
[   21.090417] kswapd0/58 is trying to acquire lock:
[   21.090697] ffff888028ff1f18 (&xfs_nondir_ilock_class){++++}-{4:4}, at: xfs_ilock+0x30f/0x390
[   21.091235]
[   21.091235] but task is already holding lock:
[   21.091575] ffffffff8784b580 (fs_reclaim){+.+.}-{0:0}, at: balance_pgdat+0xb7e/0x15c0
[   21.092058]
[   21.092058] which lock already depends on the new lock.
[   21.092058]
[   21.092524]
[   21.092524] the existing dependency chain (in reverse order) is:
[   21.092949]
[   21.092949] -> #1 (fs_reclaim){+.+.}-{0:0}:
[   21.093290]        fs_reclaim_acquire+0x116/0x160
[   21.093579]        __kmalloc_cache_noprof+0x53/0x7e0
[   21.093886]        iomap_fill_dirty_folios+0x118/0x2c0
[   21.094204]        xfs_buffered_write_iomap_begin+0xf18/0x2150
[   21.094552]        iomap_iter+0x551/0xf40
[   21.094798]        iomap_zero_range+0x20b/0xa90
[   21.095075]        xfs_zero_range+0xb5/0x100
[   21.095335]        xfs_reflink_remap_prep+0x3d3/0xa90
[   21.095643]        xfs_file_remap_range+0x23c/0xdc0
[   21.095944]        vfs_clone_file_range+0x2b1/0xda0
[   21.096243]        ioctl_file_clone+0x6e/0x110
[   21.096521]        do_vfs_ioctl+0xcab/0x14d0
[   21.096786]        __x64_sys_ioctl+0x127/0x220
[   21.097057]        x64_sys_call+0x1280/0x21b0
[   21.097331]        do_syscall_64+0x6d/0x1180
[   21.097607]        entry_SYSCALL_64_after_hwframe+0x76/0x7e
[   21.097936]
[   21.097936] -> #0 (&xfs_nondir_ilock_class){++++}-{4:4}:
[   21.098334]        __lock_acquire+0x14d1/0x2210
[   21.098615]        lock_acquire+0x170/0x2f0
[   21.098869]        down_write_nested+0x9a/0x210
[   21.099145]        xfs_ilock+0x30f/0x390
[   21.099385]        xfs_icwalk_ag+0xaec/0x1b60
[   21.099652]        xfs_icwalk+0x56/0xc0
[   21.099892]        xfs_reclaim_inodes_nr+0x1d3/0x2d0
[   21.100192]        xfs_fs_free_cached_objects+0x6a/0x90
[   21.100506]        super_cache_scan+0x415/0x570
[   21.100794]        do_shrink_slab+0x408/0x1030
[   21.101069]        shrink_slab+0x348/0x12f0
[   21.101329]        shrink_node+0xacc/0x2670
[   21.101587]        balance_pgdat+0xa2d/0x15c0
[   21.101860]        kswapd+0x5b9/0xab0
[   21.102093]        kthread+0x464/0x980
[   21.102329]        ret_from_fork+0x780/0x8f0
[   21.102596]        ret_from_fork_asm+0x1a/0x30
[   21.102873]
[   21.102873] other info that might help us debug this:
[   21.102873]
[   21.103335]  Possible unsafe locking scenario:
[   21.103335]
[   21.103683]        CPU0                    CPU1
[   21.103955]        ----                    ----
[   21.104225]   lock(fs_reclaim);
[   21.104428]                                lock(&xfs_nondir_ilock_class);
[   21.104823]                                lock(fs_reclaim);
[   21.105158]   lock(&xfs_nondir_ilock_class);
[   21.105416]
[   21.105416]  *** DEADLOCK ***
[   21.105416]
[   21.105762] 2 locks held by kswapd0/58:
[   21.105993]  #0: ffffffff8784b580 (fs_reclaim){+.+.}-{0:0}, at: balance_pgdat+0xb7e/0x15c0
[   21.106487]  #1: ffff88800fd580e0 (&type->s_umount_key#53){.+.+}-{4:4}, at: super_cache_scan+0x9f/0x570
[   21.107047]
[   21.107047] stack backtrace:
[   21.107307] CPU: 1 UID: 0 PID: 58 Comm: kswapd0 Not tainted 6.18.0-next-20251203-b2c27842ba85 #1 PREEMPT(volu
[   21.107319] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.0-0-gd239552ce722-prebuilt.q4
[   21.107326] Call Trace:
[   21.107335]  <TASK>
[   21.107338]  dump_stack_lvl+0xea/0x150
[   21.107352]  dump_stack+0x19/0x20
[   21.107359]  print_circular_bug+0x283/0x350
[   21.107370]  check_noncircular+0x12d/0x150
[   21.107383]  __lock_acquire+0x14d1/0x2210
[   21.107398]  lock_acquire+0x170/0x2f0
[   21.107407]  ? xfs_ilock+0x30f/0x390
[   21.107420]  ? __cond_resched+0x37/0x50
[   21.107434]  down_write_nested+0x9a/0x210
[   21.107445]  ? xfs_ilock+0x30f/0x390
[   21.107456]  ? __pfx_down_write_nested+0x10/0x10
[   21.107468]  ? xfs_icwalk_ag+0xadf/0x1b60
[   21.107482]  ? xfs_icwalk_ag+0xaec/0x1b60
[   21.107497]  ? xfs_icwalk_ag+0xaec/0x1b60
[   21.107510]  xfs_ilock+0x30f/0x390
[   21.107523]  xfs_icwalk_ag+0xaec/0x1b60
[   21.107542]  ? __pfx_xfs_icwalk_ag+0x10/0x10
[   21.107561]  ? __pfx_xa_find+0x10/0x10
[   21.107581]  ? xfs_group_grab_next_mark+0x26a/0x520
[   21.107605]  ? __this_cpu_preempt_check+0x21/0x30
[   21.107616]  ? lock_release+0x14f/0x2a0
[   21.107628]  ? xfs_group_grab_next_mark+0x274/0x520
[   21.107643]  ? __pfx_xfs_group_grab_next_mark+0x10/0x10
[   21.107662]  ? __pfx_try_to_wake_up+0x10/0x10
[   21.107678]  ? lock_release+0x14f/0x2a0
[   21.107689]  xfs_icwalk+0x56/0xc0
[   21.107704]  xfs_reclaim_inodes_nr+0x1d3/0x2d0
[   21.107718]  ? __pfx_xfs_reclaim_inodes_nr+0x10/0x10
[   21.107734]  ? __this_cpu_preempt_check+0x21/0x30
[   21.107744]  ? __pfx_prune_icache_sb+0x10/0x10
[   21.107762]  xfs_fs_free_cached_objects+0x6a/0x90
[   21.107777]  super_cache_scan+0x415/0x570
[   21.107794]  do_shrink_slab+0x408/0x1030
[   21.107813]  shrink_slab+0x348/0x12f0
[   21.107831]  ? shrink_slab+0x160/0x12f0
[   21.107845]  ? __pfx_shrink_slab+0x10/0x10
[   21.107866]  shrink_node+0xacc/0x2670
[   21.107888]  ? __pfx_shrink_node+0x10/0x10
[   21.107900]  ? preempt_schedule_common+0x49/0xd0
[   21.107913]  balance_pgdat+0xa2d/0x15c0
[   21.107929]  ? __pfx_balance_pgdat+0x10/0x10
[   21.107941]  ? rcu_watching_snap_stopped_since+0x20/0xf0
[   21.107975]  kswapd+0x5b9/0xab0
[   21.107990]  ? __pfx_kswapd+0x10/0x10
[   21.108002]  ? _raw_spin_unlock_irqrestore+0x35/0x70
[   21.108017]  ? trace_hardirqs_on+0x26/0x130
[   21.108040]  ? __pfx_autoremove_wake_function+0x10/0x10
[   21.108060]  ? __sanitizer_cov_trace_const_cmp1+0x1e/0x30
[   21.108080]  ? __kthread_parkme+0x1bc/0x260
[   21.108094]  ? __pfx_kswapd+0x10/0x10
[   21.108107]  ? __pfx_kswapd+0x10/0x10
[   21.108120]  kthread+0x464/0x980
[   21.108128]  ? __pfx_kthread+0x10/0x10
[   21.108135]  ? trace_hardirqs_on+0x26/0x130
[   21.108149]  ? _raw_spin_unlock_irq+0x3c/0x60
[   21.108158]  ? __pfx_kthread+0x10/0x10
[   21.108167]  ret_from_fork+0x780/0x8f0
[   21.108177]  ? __pfx_ret_from_fork+0x10/0x10
[   21.108186]  ? native_load_tls+0x16/0x50
[   21.108199]  ? __sanitizer_cov_trace_const_cmp8+0x1c/0x30
[   21.108213]  ? __switch_to+0x823/0x10b0
[   21.108232]  ? __pfx_kthread+0x10/0x10
[   21.108240]  ret_from_fork_asm+0x1a/0x30
[   21.108257]  </TASK>
[   21.592826] repro: page allocation failure: order:0, mode:0x10cc0(GFP_KERNEL|__GFP_NORETRY), nodemask=(null),0
[   21.593533] CPU: 1 UID: 0 PID: 727 Comm: repro Not tainted 6.18.0-next-20251203-b2c27842ba85 #1 PREEMPT(volun
[   21.593545] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.0-0-gd239552ce722-prebuilt.q4
[   21.593551] Call Trace:
[   21.593554]  <TASK>
[   21.593557]  dump_stack_lvl+0x121/0x150
[   21.593572]  dump_stack+0x19/0x20
[   21.593582]  warn_alloc+0x216/0x360
[   21.593595]  ? __pfx_warn_alloc+0x10/0x10
[   21.593607]  ? __pfx___alloc_pages_direct_compact+0x10/0x10
[   21.593618]  ? __drain_all_pages+0x27d/0x480
[   21.593628]  __alloc_pages_slowpath.constprop.0+0x1340/0x2230
[   21.593644]  ? __pfx___alloc_pages_slowpath.constprop.0+0x10/0x10
[   21.593657]  ? __might_sleep+0x108/0x160
[   21.593680]  __alloc_frozen_pages_noprof+0x47f/0x550
[   21.593690]  ? asm_sysvec_apic_timer_interrupt+0x1f/0x30
[   21.593702]  ? __pfx___alloc_frozen_pages_noprof+0x10/0x10
[   21.593716]  ? policy_nodemask+0xf9/0x450
[   21.593734]  alloc_pages_mpol+0x236/0x4c0
[   21.593746]  ? __pfx_alloc_pages_mpol+0x10/0x10
[   21.593758]  ? alloc_frozen_pages_noprof+0x48/0x180
[   21.593766]  ? alloc_frozen_pages_noprof+0x51/0x180
[   21.593775]  alloc_frozen_pages_noprof+0xa9/0x180
[   21.593783]  alloc_pages_noprof+0x27/0xa0
[   21.593791]  kimage_alloc_pages+0x78/0x240
[   21.593809]  kimage_alloc_control_pages+0x1ca/0xa60
[   21.593819]  ? __pfx_kimage_alloc_control_pages+0x10/0x10
[   21.593827]  ? __sanitizer_cov_trace_cmp8+0x1c/0x30
[   21.593844]  do_kexec_load+0x39b/0x8c0
[   21.593851]  ? __might_fault+0xf1/0x1b0
[   21.593868]  ? __pfx_do_kexec_load+0x10/0x10
[   21.593876]  ? __sanitizer_cov_trace_const_cmp8+0x1c/0x30
[   21.593887]  ? _copy_from_user+0x75/0xa0
[   21.593904]  __x64_sys_kexec_load+0x1cc/0x240
[   21.593913]  x64_sys_call+0x1c90/0x21b0
[   21.593922]  do_syscall_64+0x6d/0x1180
[   21.593930]  entry_SYSCALL_64_after_hwframe+0x76/0x7e
[   21.593938] RIP: 0033:0x7f347b83ee5d
[   21.593952] Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 88
[   21.593959] RSP: 002b:00007ffc6cb1d938 EFLAGS: 00000207 ORIG_RAX: 00000000000000f6
[   21.593972] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f347b83ee5d
[   21.593977] RDX: 0000200000000180 RSI: 0000000000000003 RDI: 0000000000000000
[   21.593982] RBP: 00007ffc6cb1d950 R08: 00007ffc6cb1d3c0 R09: 00007ffc6cb1d950
[   21.593986] R10: 0000000000000000 R11: 0000000000000207 R12: 00007ffc6cb1daa8
[   21.593991] R13: 00000000004030f5 R14: 000000000040ee08 R15: 00007f347bb26000
[   21.594000]  </TASK>

"

Hope this cound be insightful to you.

Regards,
Yi Lai

---

If you don't need the following environment to reproduce the problem or if you already have one reproduced environment, please ignore the following information.

How to reproduce:
git clone https://gitlab.com/xupengfe/repro_vm_env.git
cd repro_vm_env
tar -xvf repro_vm_env.tar.gz
cd repro_vm_env; ./start3.sh // it needs qemu-system-x86_64 and I used v7.1.0
// start3.sh will load bzImage_2241ab53cbb5cdb08a6b2d4688feb13971058f65 v6.2-rc5 kernel
// You could change the bzImage_xxx as you want
// Maybe you need to remove line "-drive if=pflash,format=raw,readonly=on,file=./OVMF_CODE.fd \" for different qemu version
You could use below command to log in, there is no password for root.
ssh -p 10023 root@localhost

After login vm(virtual machine) successfully, you could transfer reproduced binary to the vm by below way, and reproduce the problem in vm:
gcc -pthread -o repro repro.c
scp -P 10023 repro root@localhost:/root/

Get the bzImage for target kernel:
Please use target kconfig and copy it to kernel_src/.config make olddefconfig
make -jx bzImage //x should equal or less than cpu num your pc has

Fill the bzImage file into above start3.sh to load the target kernel in vm.

Tips:
If you already have qemu-system-x86_64, please ignore below info.
If you want to install qemu v7.1.0 version:
git clone https://github.com/qemu/qemu.git
cd qemu
git checkout -f v7.1.0
mkdir build
cd build
yum install -y ninja-build.x86_64
yum -y install libslirp-devel.x86_64
../configure --target-list=x86_64-softmmu --enable-kvm --enable-vnc --enable-gtk --enable-sdl --enable-usb-redir --enable-slirp make
make install

#8 lore raw

Re: [PATCH v5 5/7] xfs: fill dirty folios on zero range of unwritten mappings

Quoted 79 lines · Brian Foster
Quoted 68 lines · Yi
Quoted 64 lines · Brian Foster

Use the iomap folio batch mechanism to select folios to zero on zero range of unwritten mappings. Trim the resulting mapping if the batch is filled (unlikely for current use cases) to distinguish between a range to skip and one that requires another iteration due to a full batch.

---
 fs/xfs/xfs_iomap.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
fs/xfs/xfs_iomap.c +23 -0
index 6a05e04ad5ba..535bf3b8705d 100644
@@ -1702,6 +1702,8 @@ xfs_buffered_write_iomap_begin(
 	struct iomap		*iomap,
 	struct iomap		*srcmap)
 {
+	struct iomap_iter	*iter = container_of(iomap, struct iomap_iter,
+						     iomap);
 	struct xfs_inode	*ip = XFS_I(inode);
 	struct xfs_mount	*mp = ip->i_mount;
 	xfs_fileoff_t		offset_fsb = XFS_B_TO_FSBT(mp, offset);
@@ -1773,6 +1775,7 @@ xfs_buffered_write_iomap_begin(
 	 */
 	if (flags & IOMAP_ZERO) {
 		xfs_fileoff_t eof_fsb = XFS_B_TO_FSB(mp, XFS_ISIZE(ip));
+		u64 end;
 
 		if (isnullstartblock(imap.br_startblock) &&
 		    offset_fsb >= eof_fsb)
@@ -1780,6 +1783,26 @@ xfs_buffered_write_iomap_begin(
 		if (offset_fsb < eof_fsb && end_fsb > eof_fsb)
 			end_fsb = eof_fsb;
 
+		/*
+		 * Look up dirty folios for unwritten mappings within EOF.
+		 * Providing this bypasses the flush iomap uses to trigger
+		 * extent conversion when unwritten mappings have dirty
+		 * pagecache in need of zeroing.
+		 *
+		 * Trim the mapping to the end pos of the lookup, which in turn
+		 * was trimmed to the end of the batch if it became full before
+		 * the end of the mapping.
+		 */
+		if (imap.br_state == XFS_EXT_UNWRITTEN &&
+		    offset_fsb < eof_fsb) {
+			loff_t len = min(count,
+					 XFS_FSB_TO_B(mp, imap.br_blockcount));
+
+			end = iomap_fill_dirty_folios(iter, offset, len);
+			end_fsb = min_t(xfs_fileoff_t, end_fsb,
+					XFS_B_TO_FSB(mp, end));
+		}
+
 		xfs_trim_extent(&imap, offset_fsb, end_fsb - offset_fsb);
 	}
 
Signature · 1 line
2.51.0

Hi Brian Foster,

Quoted 9 lines

Greetings!

I used Syzkaller and found that there is possible deadlock in xfs_ilock in linux-next next-20251203.

After bisection and the first bad commit is:
"
77c475692c5e xfs: fill dirty folios on zero range of unwritten mappings "

Quoted 9 lines

The referenced reproducer doesn't throw anything for me, but if you want to test the following:

https://lore.kernel.org/linux-fsdevel/[email protected]/

... that removes the allocation associated with this splat. Thanks.

Brian

After applying this patch, the possible deadlock issue cannot be reproduced.

Regards,
Yi Lai

Quoted 254 lines
Quoted 253 lines

All detailed into can be found at:
https://github.com/laifryiee/syzkaller_logs/tree/main/251204_221645_xfs_ilock
Syzkaller repro code:
https://github.com/laifryiee/syzkaller_logs/tree/main/251204_221645_xfs_ilock/repro.c
Syzkaller repro syscall steps:
https://github.com/laifryiee/syzkaller_logs/tree/main/251204_221645_xfs_ilock/repro.prog
Syzkaller report:
https://github.com/laifryiee/syzkaller_logs/tree/main/251204_221645_xfs_ilock/repro.report
Kconfig(make olddefconfig):
https://github.com/laifryiee/syzkaller_logs/tree/main/251204_221645_xfs_ilock/kconfig_origin
Bisect info:
https://github.com/laifryiee/syzkaller_logs/tree/main/251204_221645_xfs_ilock/bisect_info.log
bzImage:
https://github.com/laifryiee/syzkaller_logs/raw/refs/heads/main/251204_221645_xfs_ilock/bzImage_b2c27842ba853508b0da00187a7508eb3a96c8f7
Issue dmesg:
https://github.com/laifryiee/syzkaller_logs/blob/main/251204_221645_xfs_ilock/b2c27842ba853508b0da00187a7508eb3a96c8f7_dmesg.log

"

[   21.088994] ======================================================
[   21.089362] WARNING: possible circular locking dependency detected
[   21.089726] 6.18.0-next-20251203-b2c27842ba85 #1 Not tainted
[   21.090060] ------------------------------------------------------
[   21.090417] kswapd0/58 is trying to acquire lock:
[   21.090697] ffff888028ff1f18 (&xfs_nondir_ilock_class){++++}-{4:4}, at: xfs_ilock+0x30f/0x390
[   21.091235]
[   21.091235] but task is already holding lock:
[   21.091575] ffffffff8784b580 (fs_reclaim){+.+.}-{0:0}, at: balance_pgdat+0xb7e/0x15c0
[   21.092058]
[   21.092058] which lock already depends on the new lock.
[   21.092058]
[   21.092524]
[   21.092524] the existing dependency chain (in reverse order) is:
[   21.092949]
[   21.092949] -> #1 (fs_reclaim){+.+.}-{0:0}:
[   21.093290]        fs_reclaim_acquire+0x116/0x160
[   21.093579]        __kmalloc_cache_noprof+0x53/0x7e0
[   21.093886]        iomap_fill_dirty_folios+0x118/0x2c0
[   21.094204]        xfs_buffered_write_iomap_begin+0xf18/0x2150
[   21.094552]        iomap_iter+0x551/0xf40
[   21.094798]        iomap_zero_range+0x20b/0xa90
[   21.095075]        xfs_zero_range+0xb5/0x100
[   21.095335]        xfs_reflink_remap_prep+0x3d3/0xa90
[   21.095643]        xfs_file_remap_range+0x23c/0xdc0
[   21.095944]        vfs_clone_file_range+0x2b1/0xda0
[   21.096243]        ioctl_file_clone+0x6e/0x110
[   21.096521]        do_vfs_ioctl+0xcab/0x14d0
[   21.096786]        __x64_sys_ioctl+0x127/0x220
[   21.097057]        x64_sys_call+0x1280/0x21b0
[   21.097331]        do_syscall_64+0x6d/0x1180
[   21.097607]        entry_SYSCALL_64_after_hwframe+0x76/0x7e
[   21.097936]
[   21.097936] -> #0 (&xfs_nondir_ilock_class){++++}-{4:4}:
[   21.098334]        __lock_acquire+0x14d1/0x2210
[   21.098615]        lock_acquire+0x170/0x2f0
[   21.098869]        down_write_nested+0x9a/0x210
[   21.099145]        xfs_ilock+0x30f/0x390
[   21.099385]        xfs_icwalk_ag+0xaec/0x1b60
[   21.099652]        xfs_icwalk+0x56/0xc0
[   21.099892]        xfs_reclaim_inodes_nr+0x1d3/0x2d0
[   21.100192]        xfs_fs_free_cached_objects+0x6a/0x90
[   21.100506]        super_cache_scan+0x415/0x570
[   21.100794]        do_shrink_slab+0x408/0x1030
[   21.101069]        shrink_slab+0x348/0x12f0
[   21.101329]        shrink_node+0xacc/0x2670
[   21.101587]        balance_pgdat+0xa2d/0x15c0
[   21.101860]        kswapd+0x5b9/0xab0
[   21.102093]        kthread+0x464/0x980
[   21.102329]        ret_from_fork+0x780/0x8f0
[   21.102596]        ret_from_fork_asm+0x1a/0x30
[   21.102873]
[   21.102873] other info that might help us debug this:
[   21.102873]
[   21.103335]  Possible unsafe locking scenario:
[   21.103335]
[   21.103683]        CPU0                    CPU1
[   21.103955]        ----                    ----
[   21.104225]   lock(fs_reclaim);
[   21.104428]                                lock(&xfs_nondir_ilock_class);
[   21.104823]                                lock(fs_reclaim);
[   21.105158]   lock(&xfs_nondir_ilock_class);
[   21.105416]
[   21.105416]  *** DEADLOCK ***
[   21.105416]
[   21.105762] 2 locks held by kswapd0/58:
[   21.105993]  #0: ffffffff8784b580 (fs_reclaim){+.+.}-{0:0}, at: balance_pgdat+0xb7e/0x15c0
[   21.106487]  #1: ffff88800fd580e0 (&type->s_umount_key#53){.+.+}-{4:4}, at: super_cache_scan+0x9f/0x570
[   21.107047]
[   21.107047] stack backtrace:
[   21.107307] CPU: 1 UID: 0 PID: 58 Comm: kswapd0 Not tainted 6.18.0-next-20251203-b2c27842ba85 #1 PREEMPT(volu
[   21.107319] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.0-0-gd239552ce722-prebuilt.q4
[   21.107326] Call Trace:
[   21.107335]  <TASK>
[   21.107338]  dump_stack_lvl+0xea/0x150
[   21.107352]  dump_stack+0x19/0x20
[   21.107359]  print_circular_bug+0x283/0x350
[   21.107370]  check_noncircular+0x12d/0x150
[   21.107383]  __lock_acquire+0x14d1/0x2210
[   21.107398]  lock_acquire+0x170/0x2f0
[   21.107407]  ? xfs_ilock+0x30f/0x390
[   21.107420]  ? __cond_resched+0x37/0x50
[   21.107434]  down_write_nested+0x9a/0x210
[   21.107445]  ? xfs_ilock+0x30f/0x390
[   21.107456]  ? __pfx_down_write_nested+0x10/0x10
[   21.107468]  ? xfs_icwalk_ag+0xadf/0x1b60
[   21.107482]  ? xfs_icwalk_ag+0xaec/0x1b60
[   21.107497]  ? xfs_icwalk_ag+0xaec/0x1b60
[   21.107510]  xfs_ilock+0x30f/0x390
[   21.107523]  xfs_icwalk_ag+0xaec/0x1b60
[   21.107542]  ? __pfx_xfs_icwalk_ag+0x10/0x10
[   21.107561]  ? __pfx_xa_find+0x10/0x10
[   21.107581]  ? xfs_group_grab_next_mark+0x26a/0x520
[   21.107605]  ? __this_cpu_preempt_check+0x21/0x30
[   21.107616]  ? lock_release+0x14f/0x2a0
[   21.107628]  ? xfs_group_grab_next_mark+0x274/0x520
[   21.107643]  ? __pfx_xfs_group_grab_next_mark+0x10/0x10
[   21.107662]  ? __pfx_try_to_wake_up+0x10/0x10
[   21.107678]  ? lock_release+0x14f/0x2a0
[   21.107689]  xfs_icwalk+0x56/0xc0
[   21.107704]  xfs_reclaim_inodes_nr+0x1d3/0x2d0
[   21.107718]  ? __pfx_xfs_reclaim_inodes_nr+0x10/0x10
[   21.107734]  ? __this_cpu_preempt_check+0x21/0x30
[   21.107744]  ? __pfx_prune_icache_sb+0x10/0x10
[   21.107762]  xfs_fs_free_cached_objects+0x6a/0x90
[   21.107777]  super_cache_scan+0x415/0x570
[   21.107794]  do_shrink_slab+0x408/0x1030
[   21.107813]  shrink_slab+0x348/0x12f0
[   21.107831]  ? shrink_slab+0x160/0x12f0
[   21.107845]  ? __pfx_shrink_slab+0x10/0x10
[   21.107866]  shrink_node+0xacc/0x2670
[   21.107888]  ? __pfx_shrink_node+0x10/0x10
[   21.107900]  ? preempt_schedule_common+0x49/0xd0
[   21.107913]  balance_pgdat+0xa2d/0x15c0
[   21.107929]  ? __pfx_balance_pgdat+0x10/0x10
[   21.107941]  ? rcu_watching_snap_stopped_since+0x20/0xf0
[   21.107975]  kswapd+0x5b9/0xab0
[   21.107990]  ? __pfx_kswapd+0x10/0x10
[   21.108002]  ? _raw_spin_unlock_irqrestore+0x35/0x70
[   21.108017]  ? trace_hardirqs_on+0x26/0x130
[   21.108040]  ? __pfx_autoremove_wake_function+0x10/0x10
[   21.108060]  ? __sanitizer_cov_trace_const_cmp1+0x1e/0x30
[   21.108080]  ? __kthread_parkme+0x1bc/0x260
[   21.108094]  ? __pfx_kswapd+0x10/0x10
[   21.108107]  ? __pfx_kswapd+0x10/0x10
[   21.108120]  kthread+0x464/0x980
[   21.108128]  ? __pfx_kthread+0x10/0x10
[   21.108135]  ? trace_hardirqs_on+0x26/0x130
[   21.108149]  ? _raw_spin_unlock_irq+0x3c/0x60
[   21.108158]  ? __pfx_kthread+0x10/0x10
[   21.108167]  ret_from_fork+0x780/0x8f0
[   21.108177]  ? __pfx_ret_from_fork+0x10/0x10
[   21.108186]  ? native_load_tls+0x16/0x50
[   21.108199]  ? __sanitizer_cov_trace_const_cmp8+0x1c/0x30
[   21.108213]  ? __switch_to+0x823/0x10b0
[   21.108232]  ? __pfx_kthread+0x10/0x10
[   21.108240]  ret_from_fork_asm+0x1a/0x30
[   21.108257]  </TASK>
[   21.592826] repro: page allocation failure: order:0, mode:0x10cc0(GFP_KERNEL|__GFP_NORETRY), nodemask=(null),0
[   21.593533] CPU: 1 UID: 0 PID: 727 Comm: repro Not tainted 6.18.0-next-20251203-b2c27842ba85 #1 PREEMPT(volun
[   21.593545] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.0-0-gd239552ce722-prebuilt.q4
[   21.593551] Call Trace:
[   21.593554]  <TASK>
[   21.593557]  dump_stack_lvl+0x121/0x150
[   21.593572]  dump_stack+0x19/0x20
[   21.593582]  warn_alloc+0x216/0x360
[   21.593595]  ? __pfx_warn_alloc+0x10/0x10
[   21.593607]  ? __pfx___alloc_pages_direct_compact+0x10/0x10
[   21.593618]  ? __drain_all_pages+0x27d/0x480
[   21.593628]  __alloc_pages_slowpath.constprop.0+0x1340/0x2230
[   21.593644]  ? __pfx___alloc_pages_slowpath.constprop.0+0x10/0x10
[   21.593657]  ? __might_sleep+0x108/0x160
[   21.593680]  __alloc_frozen_pages_noprof+0x47f/0x550
[   21.593690]  ? asm_sysvec_apic_timer_interrupt+0x1f/0x30
[   21.593702]  ? __pfx___alloc_frozen_pages_noprof+0x10/0x10
[   21.593716]  ? policy_nodemask+0xf9/0x450
[   21.593734]  alloc_pages_mpol+0x236/0x4c0
[   21.593746]  ? __pfx_alloc_pages_mpol+0x10/0x10
[   21.593758]  ? alloc_frozen_pages_noprof+0x48/0x180
[   21.593766]  ? alloc_frozen_pages_noprof+0x51/0x180
[   21.593775]  alloc_frozen_pages_noprof+0xa9/0x180
[   21.593783]  alloc_pages_noprof+0x27/0xa0
[   21.593791]  kimage_alloc_pages+0x78/0x240
[   21.593809]  kimage_alloc_control_pages+0x1ca/0xa60
[   21.593819]  ? __pfx_kimage_alloc_control_pages+0x10/0x10
[   21.593827]  ? __sanitizer_cov_trace_cmp8+0x1c/0x30
[   21.593844]  do_kexec_load+0x39b/0x8c0
[   21.593851]  ? __might_fault+0xf1/0x1b0
[   21.593868]  ? __pfx_do_kexec_load+0x10/0x10
[   21.593876]  ? __sanitizer_cov_trace_const_cmp8+0x1c/0x30
[   21.593887]  ? _copy_from_user+0x75/0xa0
[   21.593904]  __x64_sys_kexec_load+0x1cc/0x240
[   21.593913]  x64_sys_call+0x1c90/0x21b0
[   21.593922]  do_syscall_64+0x6d/0x1180
[   21.593930]  entry_SYSCALL_64_after_hwframe+0x76/0x7e
[   21.593938] RIP: 0033:0x7f347b83ee5d
[   21.593952] Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 88
[   21.593959] RSP: 002b:00007ffc6cb1d938 EFLAGS: 00000207 ORIG_RAX: 00000000000000f6
[   21.593972] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f347b83ee5d
[   21.593977] RDX: 0000200000000180 RSI: 0000000000000003 RDI: 0000000000000000
[   21.593982] RBP: 00007ffc6cb1d950 R08: 00007ffc6cb1d3c0 R09: 00007ffc6cb1d950
[   21.593986] R10: 0000000000000000 R11: 0000000000000207 R12: 00007ffc6cb1daa8
[   21.593991] R13: 00000000004030f5 R14: 000000000040ee08 R15: 00007f347bb26000
[   21.594000]  </TASK>

"

Hope this cound be insightful to you.

Regards,
Yi Lai

---

If you don't need the following environment to reproduce the problem or if you already have one reproduced environment, please ignore the following information.

How to reproduce:
git clone https://gitlab.com/xupengfe/repro_vm_env.git
cd repro_vm_env
tar -xvf repro_vm_env.tar.gz
cd repro_vm_env; ./start3.sh // it needs qemu-system-x86_64 and I used v7.1.0
// start3.sh will load bzImage_2241ab53cbb5cdb08a6b2d4688feb13971058f65 v6.2-rc5 kernel
// You could change the bzImage_xxx as you want
// Maybe you need to remove line "-drive if=pflash,format=raw,readonly=on,file=./OVMF_CODE.fd \" for different qemu version
You could use below command to log in, there is no password for root.
ssh -p 10023 root@localhost

After login vm(virtual machine) successfully, you could transfer reproduced binary to the vm by below way, and reproduce the problem in vm:
gcc -pthread -o repro repro.c
scp -P 10023 repro root@localhost:/root/

Get the bzImage for target kernel:
Please use target kconfig and copy it to kernel_src/.config make olddefconfig
make -jx bzImage //x should equal or less than cpu num your pc has

Fill the bzImage file into above start3.sh to load the target kernel in vm.

Tips:
If you already have qemu-system-x86_64, please ignore below info.
If you want to install qemu v7.1.0 version:
git clone https://github.com/qemu/qemu.git
cd qemu
git checkout -f v7.1.0
mkdir build
cd build
yum install -y ninja-build.x86_64
yum -y install libslirp-devel.x86_64
../configure --target-list=x86_64-softmmu --enable-kvm --enable-vnc --enable-gtk --enable-sdl --enable-usb-redir --enable-slirp make
make install

#9 lore raw

PATCH v5 6/7 iomap: remove old partial eof zeroing optimization

In reply to Brian Foster

iomap_zero_range() optimizes the partial eof block zeroing use case by force zeroing if the mapping is dirty. This is to avoid frequent flushing on file extending workloads, which hurts performance.

Now that the folio batch mechanism provides a more generic solution and is used by the only real zero range user (XFS), this isolated optimization is no longer needed. Remove the unnecessary code and let callers use the folio batch or fall back to flushing by default.

---
 fs/iomap/buffered-io.c | 25 -------------------------
 1 file changed, 25 deletions(-)
fs/iomap/buffered-io.c +0 -25
index a830ae5f5ac7..51ecb6d48feb 100644
@@ -1506,34 +1506,9 @@ iomap_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero,
 		.private	= private,
 	};
 	struct address_space *mapping = inode->i_mapping;
-	unsigned int blocksize = i_blocksize(inode);
-	unsigned int off = pos & (blocksize - 1);
-	loff_t plen = min_t(loff_t, len, blocksize - off);
 	int ret;
 	bool range_dirty;
 
-	/*
-	 * Zero range can skip mappings that are zero on disk so long as
-	 * pagecache is clean. If pagecache was dirty prior to zero range, the
-	 * mapping converts on writeback completion and so must be zeroed.
-	 *
-	 * The simplest way to deal with this across a range is to flush
-	 * pagecache and process the updated mappings. To avoid excessive
-	 * flushing on partial eof zeroing, special case it to zero the
-	 * unaligned start portion if already dirty in pagecache.
-	 */
-	if (!iter.fbatch && off &&
-	    filemap_range_needs_writeback(mapping, pos, pos + plen - 1)) {
-		iter.len = plen;
-		while ((ret = iomap_iter(&iter, ops)) > 0)
-			iter.status = iomap_zero_iter(&iter, did_zero,
-					write_ops);
-
-		iter.len = len - (iter.pos - pos);
-		if (ret || !iter.len)
-			return ret;
-	}
-
 	/*
 	 * To avoid an unconditional flush, check pagecache state and only flush
 	 * if dirty and the fs returns a mapping that might convert on
Signature · 1 line
2.51.0
#10 lore raw

PATCH v5 7/7 xfs: error tag to force zeroing on debug kernels

In reply to Brian Foster

iomap_zero_range() has to cover various corner cases that are difficult to test on production kernels because it is used in fairly limited use cases. For example, it is currently only used by XFS and mostly only in partial block zeroing cases.

While it's possible to test most of these functional cases, we can provide more robust test coverage by co-opting fallocate zero range to invoke zeroing of the entire range instead of the more efficient block punch/allocate sequence. Add an errortag to occasionally invoke forced zeroing.

---
 fs/xfs/libxfs/xfs_errortag.h |  6 ++++--
 fs/xfs/xfs_file.c            | 29 ++++++++++++++++++++++-------
 2 files changed, 26 insertions(+), 9 deletions(-)
fs/xfs/libxfs/xfs_errortag.h +4 -2
index de840abc0bcd..57e47077c75a 100644
@@ -73,7 +73,8 @@
 #define XFS_ERRTAG_WRITE_DELAY_MS			43
 #define XFS_ERRTAG_EXCHMAPS_FINISH_ONE			44
 #define XFS_ERRTAG_METAFILE_RESV_CRITICAL		45
-#define XFS_ERRTAG_MAX					46
+#define XFS_ERRTAG_FORCE_ZERO_RANGE			46
+#define XFS_ERRTAG_MAX					47
 
 /*
  * Random factors for above tags, 1 means always, 2 means 1/2 time, etc.
@@ -133,7 +134,8 @@ XFS_ERRTAG(ATTR_LEAF_TO_NODE,	attr_leaf_to_node,	1) \
 XFS_ERRTAG(WB_DELAY_MS,		wb_delay_ms,		3000) \
 XFS_ERRTAG(WRITE_DELAY_MS,	write_delay_ms,		3000) \
 XFS_ERRTAG(EXCHMAPS_FINISH_ONE,	exchmaps_finish_one,	1) \
-XFS_ERRTAG(METAFILE_RESV_CRITICAL, metafile_resv_crit,	4)
+XFS_ERRTAG(METAFILE_RESV_CRITICAL, metafile_resv_crit,	4) \
+XFS_ERRTAG(FORCE_ZERO_RANGE,	force_zero_range,	4)
 #endif /* XFS_ERRTAG */
 
 #endif /* __XFS_ERRORTAG_H_ */
fs/xfs/xfs_file.c +22 -7
index 2702fef2c90c..5b9864c8582e 100644
@@ -27,6 +27,8 @@
 #include "xfs_file.h"
 #include "xfs_aops.h"
 #include "xfs_zone_alloc.h"
+#include "xfs_error.h"
+#include "xfs_errortag.h"
 
 #include <linux/dax.h>
 #include <linux/falloc.h>
@@ -1254,23 +1256,36 @@ xfs_falloc_zero_range(
 	struct xfs_zone_alloc_ctx *ac)
 {
 	struct inode		*inode = file_inode(file);
+	struct xfs_inode	*ip = XFS_I(inode);
 	unsigned int		blksize = i_blocksize(inode);
 	loff_t			new_size = 0;
 	int			error;
 
-	trace_xfs_zero_file_space(XFS_I(inode));
+	trace_xfs_zero_file_space(ip);
 
 	error = xfs_falloc_newsize(file, mode, offset, len, &new_size);
 	if (error)
 		return error;
 
-	error = xfs_free_file_space(XFS_I(inode), offset, len, ac);
-	if (error)
-		return error;
+	/*
+	 * Zero range implements a full zeroing mechanism but is only used in
+	 * limited situations. It is more efficient to allocate unwritten
+	 * extents than to perform zeroing here, so use an errortag to randomly
+	 * force zeroing on DEBUG kernels for added test coverage.
+	 */
+	if (XFS_TEST_ERROR(ip->i_mount,
+			   XFS_ERRTAG_FORCE_ZERO_RANGE)) {
+		error = xfs_zero_range(ip, offset, len, ac, NULL);
+	} else {
+		error = xfs_free_file_space(ip, offset, len, ac);
+		if (error)
+			return error;
 
-	len = round_up(offset + len, blksize) - round_down(offset, blksize);
-	offset = round_down(offset, blksize);
-	error = xfs_alloc_file_space(XFS_I(inode), offset, len);
+		len = round_up(offset + len, blksize) -
+			round_down(offset, blksize);
+		offset = round_down(offset, blksize);
+		error = xfs_alloc_file_space(ip, offset, len);
+	}
 	if (error)
 		return error;
 	return xfs_falloc_setsize(file, new_size);
Signature · 1 line
2.51.0
maintainer Applied
#11 lore raw
In reply to Brian Foster
Quoted 6 lines · Brian Foster

Only minor changes in v5 to the XFS errortag patch. I've kept the R-b tags because the fundamental logic is the same, but the errortag mechanism has been reworked and so that one needed a rebase (which turns out much simpler). A second look certainly couldn't hurt, but otherwise the associated fstest still works as expected.

Quoted 6 lines

Note that the force zeroing fstests test has since been merged as xfs/131. Otherwise I still have some followup patches to this work re:
the ext4 on iomap work, but it would be nice to move this along before getting too far ahead with that.

[...]

Applied to the vfs-6.19.iomap branch of the vfs/vfs.git tree. Patches in the vfs-6.19.iomap 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-6.19.iomap

[1/7] filemap: add helper to look up dirty folios in a range

      https://git.kernel.org/vfs/vfs/c/757f5ca76903
[2/7] iomap: remove pos+len BUG_ON() to after folio lookup
      https://git.kernel.org/vfs/vfs/c/e027b6ecb710
[3/7] iomap: optional zero range dirty folio processing
      https://git.kernel.org/vfs/vfs/c/5a9a21cb7706
[4/7] xfs: always trim mapping to requested range for zero range
      https://git.kernel.org/vfs/vfs/c/50dc360fa097
[5/7] xfs: fill dirty folios on zero range of unwritten mappings
      https://git.kernel.org/vfs/vfs/c/492258e4508a
[6/7] iomap: remove old partial eof zeroing optimization
      https://git.kernel.org/vfs/vfs/c/47520b756355
[7/7] xfs: error tag to force zeroing on debug kernels
      https://git.kernel.org/vfs/vfs/c/87a5ca9f6c56
#12 lore raw
Quoted 30 lines · Christian Brauner
Quoted 6 lines · Brian Foster

Only minor changes in v5 to the XFS errortag patch. I've kept the R-b tags because the fundamental logic is the same, but the errortag mechanism has been reworked and so that one needed a rebase (which turns out much simpler). A second look certainly couldn't hurt, but otherwise the associated fstest still works as expected.

Quoted 6 lines

Note that the force zeroing fstests test has since been merged as xfs/131. Otherwise I still have some followup patches to this work re:
the ext4 on iomap work, but it would be nice to move this along before getting too far ahead with that.

[...]

Applied to the vfs-6.19.iomap branch of the vfs/vfs.git tree. Patches in the vfs-6.19.iomap 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-6.19.iomap
Quoted 6 lines

[1/7] filemap: add helper to look up dirty folios in a range

      https://git.kernel.org/vfs/vfs/c/757f5ca76903
[2/7] iomap: remove pos+len BUG_ON() to after folio lookup
      https://git.kernel.org/vfs/vfs/c/e027b6ecb710
[3/7] iomap: optional zero range dirty folio processing
      https://git.kernel.org/vfs/vfs/c/5a9a21cb7706

Hi Christian,

Thanks for all your work with managing the vfs iomap branch. I noticed for vfs-6.19.iomap, this series was merged after a prior patch in the branch that had changed the iomap_iter_advance() interface [1]. As such for the merging ordering, I think this 3rd patch needs this minor patch-up to be compatible with the change made in [1], if you're able to fold this in:

fs/iomap/buffered-io.c +2 -1
index 72196e5021b1..36ee3290669a 100644
@@ -867,7 +867,8 @@ static int iomap_write_begin(struct iomap_iter *iter,
        if (folio_pos(folio) > iter->pos) {
                len = min_t(u64, folio_pos(folio) - iter->pos,
                                 iomap_length(iter));
-               status = iomap_iter_advance(iter, &len);
+               status = iomap_iter_advance(iter, len);
+               len = iomap_length(iter);
                if (status || !len)
                        goto out_unlock;
        }

Thanks,
Joanne

[1] https://lore.kernel.org/linux-fsdevel/CAJnrk1aJf1cgpzmDz0d+8K5gOFBpk5whqPRFsWtQ0M3dpOOJ2Q@mail.gmail.com/T/#u

Quoted 9 lines

[4/7] xfs: always trim mapping to requested range for zero range

      https://git.kernel.org/vfs/vfs/c/50dc360fa097
[5/7] xfs: fill dirty folios on zero range of unwritten mappings
      https://git.kernel.org/vfs/vfs/c/492258e4508a
[6/7] iomap: remove old partial eof zeroing optimization
      https://git.kernel.org/vfs/vfs/c/47520b756355
[7/7] xfs: error tag to force zeroing on debug kernels
      https://git.kernel.org/vfs/vfs/c/87a5ca9f6c56
#13 lore raw
Quoted 52 lines · Joanne Koong
Quoted 30 lines · Christian Brauner
Quoted 6 lines · Brian Foster

Only minor changes in v5 to the XFS errortag patch. I've kept the R-b tags because the fundamental logic is the same, but the errortag mechanism has been reworked and so that one needed a rebase (which turns out much simpler). A second look certainly couldn't hurt, but otherwise the associated fstest still works as expected.

Quoted 6 lines

Note that the force zeroing fstests test has since been merged as xfs/131. Otherwise I still have some followup patches to this work re:
the ext4 on iomap work, but it would be nice to move this along before getting too far ahead with that.

[...]

Applied to the vfs-6.19.iomap branch of the vfs/vfs.git tree. Patches in the vfs-6.19.iomap 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-6.19.iomap
Quoted 6 lines

[1/7] filemap: add helper to look up dirty folios in a range

      https://git.kernel.org/vfs/vfs/c/757f5ca76903
[2/7] iomap: remove pos+len BUG_ON() to after folio lookup
      https://git.kernel.org/vfs/vfs/c/e027b6ecb710
[3/7] iomap: optional zero range dirty folio processing
      https://git.kernel.org/vfs/vfs/c/5a9a21cb7706

Hi Christian,

Thanks for all your work with managing the vfs iomap branch. I noticed for vfs-6.19.iomap, this series was merged after a prior patch in the branch that had changed the iomap_iter_advance() interface [1]. As such for the merging ordering, I think this 3rd patch needs this minor patch-up to be compatible with the change made in [1], if you're able to fold this in:

fs/iomap/buffered-io.c +0 -0
index 72196e5021b1..36ee3290669a 100644

fs/iomap/buffered-io.c static int iomap_write_begin(struct iomap_iter *iter, · line 873

Quoted 8 lines
fs/iomap/buffered-io.c +2 -1
@@ -867,7 +867,8 @@ static int iomap_write_begin(struct iomap_iter *iter,
        if (folio_pos(folio) > iter->pos) {
                len = min_t(u64, folio_pos(folio) - iter->pos,
                                 iomap_length(iter));
-               status = iomap_iter_advance(iter, &len);
+               status = iomap_iter_advance(iter, len);
+               len = iomap_length(iter);
                if (status || !len)
                        goto out_unlock;

Thank you! Folded as requested!