Root Cause Analysis
The warning in ifs_free() (fs/iomap/buffered-io.c:294-295):
WARN_ON_ONCE(ifs_is_fully_uptodate(folio, ifs) !=
folio_test_uptodate(folio));
enforces the invariant that whenever a struct iomap_folio_state (ifs) is attached to folio->private, the per-block uptodate bitmap (ifs->state[0 .. nr_blocks - 1]) is all-1s (ifs_is_fully_uptodate(folio, ifs)) if and only if the folio's PG_uptodate flag (folio_test_uptodate(folio)) is set.
Violating Paths in fs/ntfs3/
ntfs3 uses iomap folio state management on both regular and compressed file mappings (ntfs_aops and ntfs_aops_cmpr in fs/ntfs3/inode.c):
.dirty_folio = iomap_dirty_folio
.release_folio = iomap_release_folio
.invalidate_folio = iomap_invalidate_folio
In ntfs_init_from_boot() (fs/ntfs3/super.c:1244), sb_set_blocksize(sb, min_t(u32, sbi->cluster_size, PAGE_SIZE)) sets sb->s_blocksize_bits (inherited by inode->i_blkbits) to less than PAGE_SHIFT whenever the NTFS cluster size is smaller than PAGE_SIZE (e.g., 512, 1024, or 2048 bytes), and large folios also produce i_blocks_per_folio(inode, folio) > 1. Consequently, ifs_alloc() allocates and attaches an ifs structure to folio->private during iomap operations (__iomap_write_begin(), iomap_dirty_folio(), iomap_read_folio_iter(), etc.).
However, ntfs3 bypasses iomap_folio_mark_uptodate() (fs/iomap/buffered-io.c:110-114) and calls raw folio_mark_uptodate(folio) directly in several places:
-
ntfs_read_folio() in fs/ntfs3/inode.c:850-855 (primary trigger):
if (ni->i_valid <= vbo) {
folio_zero_range(folio, 0, folio_size(folio));
folio_mark_uptodate(folio);
folio_unlock(folio);
return 0;
}
When reading a folio at or beyond ni->i_valid, ntfs_read_folio() zeroes the folio and calls folio_mark_uptodate(folio) instead of iomap_folio_mark_uptodate(folio).
-
Additional occurrences in ntfs3 with the same pattern:
ni_read_folio_cmpr() in fs/ntfs3/frecord.c:1945: calls folio_mark_uptodate(folio) when vbo >= i_size_read(&ni->vfs_inode) on ntfs_aops_cmpr.
ntfs_compress_write() in fs/ntfs3/file.c:1175: calls folio_mark_uptodate(folio) on ntfs_aops_cmpr.
attr_make_nonresident() in fs/ntfs3/attrib.c:338: calls folio_mark_uptodate(folio) before folio_mark_dirty(folio) (which invokes iomap_dirty_folio()).
Trigger Sequence
- An NTFS filesystem with
sbi->cluster_size < PAGE_SIZE (or a large folio) gives i_blocks_per_folio(inode, folio) > 1.
- An iomap operation (
ntfs_file_write_iter() -> iomap_file_buffered_write() or ntfs_extend_initialized_size() -> iomap_zero_range()) invokes __iomap_write_begin() -> ifs_alloc(inode, folio, 0) on a folio at vbo >= ni->i_valid. Because !folio_test_uptodate(folio), ifs is attached to folio->private with all uptodate bits in ifs->state cleared (0).
- If that operation stops short or aborts before completing the whole folio (e.g., an EFAULT/short copy in
copy_folio_from_iter_atomic(), or a partial-folio write where __iomap_write_end() does not mark all blocks uptodate), the clean folio remains in the page cache with ifs attached, folio_test_uptodate(folio) == false, and ifs_is_fully_uptodate(folio, ifs) == false.
- A subsequent read on that folio enters
ntfs_read_folio(). Since ni->i_valid <= vbo, it executes folio_zero_range(folio, 0, folio_size(folio)) followed by folio_mark_uptodate(folio). This sets PG_uptodate on folio without updating ifs->state, leaving folio_test_uptodate(folio) == true while ifs_is_fully_uptodate(folio, ifs) == false.
- Later, during memory reclaim,
kswapd0 calls shrink_folio_list() -> iomap_release_folio() -> ifs_free() (fs/iomap/buffered-io.c:286-297), where ifs_is_fully_uptodate(folio, ifs) != folio_test_uptodate(folio) triggers the WARN_ON_ONCE at fs/iomap/buffered-io.c:294-295.
(Other filesystems using iomap_release_folio()—erofs, exfat, ext4, fuse, gfs2, xfs, and zonefs—as well as fs/iomap/buffered-io.c itself were audited and do not exhibit this desynchronization; e.g. fuse properly uses iomap_folio_mark_uptodate() and stores server blksize in fi->cached_i_blkbits rather than mutating inode->i_blkbits.)
Suggested Fix Direction
Replace direct folio_mark_uptodate(folio) calls on ntfs3 iomap-managed folios (at minimum ntfs_read_folio() in fs/ntfs3/inode.c:852, as well as fs/ntfs3/frecord.c:1945, fs/ntfs3/file.c:1175, and fs/ntfs3/attrib.c:338) with iomap_folio_mark_uptodate(folio) so ifs->state is updated consistently with PG_uptodate whenever ifs is attached.