Linux EXT4 FS development
 help / color / mirror / Atom feed
* [PATCH v4 0/9] ext4: fix unaligned edge handling in FALLOC_FL_WRITE_ZEROES
@ 2026-07-14  8:00 Zhang Yi
  2026-07-14  8:00 ` [PATCH v4 1/9] ext4: use FGP_WRITEBEGIN for tail block zeroing Zhang Yi
                   ` (8 more replies)
  0 siblings, 9 replies; 12+ messages in thread
From: Zhang Yi @ 2026-07-14  8:00 UTC (permalink / raw)
  To: linux-ext4
  Cc: linux-fsdevel, linux-kernel, tytso, adilger.kernel, libaokun,
	jack, ojaswin, ritesh.list, yi.zhang, yi.zhang, yizhang089,
	chengzhihao1, yangerkun, yukuai

From: Zhang Yi <yi.zhang@huawei.com>

Hi,

This is v4 of the series to fix unaligned edge handling in
FALLOC_FL_WRITE_ZEROES. No code changes have been made relative to v3.
This iteration solely adds a comment to document the race condition in
ext4_block_zero_eof() that prevents zeroing of inline inode's tail
block.

Changes since v3:
 - Collect RVB tags from Jan.
 - Add a comment clarifying the race between zeroing the EOF block and
   inline data conversion triggered by mmap write, which occurs without
   holding i_rwsem (Jan suggested).
Changes since v2:
 - Add patch 1 to use FGP_WRITEBEGIN in ext4_load_tail_bh(), fixing a
   pre-existing stable-writes bug exposed by patch 4's reordering.
 - Fold in two pre-existing fixes (now patches 2 and 3) that were
   originally going to be sent separately.
 - Rework patch 9 per Sashiko's review on the orphan list handling
   around the unwritten-to-written conversion.
Changes since v1:
 - Pick up Jan's Reviewed-by on patches 1, 3, and 5.
 - Expand patch 2 to also explain why a clean unwritten buffer returns
   NULL (a lookup-only get_block never sets BH_Mapped for unwritten
   extents), per Jan's review.
 - Drop the last cleanup patch "skip ext4_update_disksize_before_punch()
   in WRITE_ZEROES" because it's wrong.
 - Add a new patch to protect the WRITE_ZEROES crash window by adding
   the inode to the orphan list in the same handle that does the
   unwritten-to-written conversion, and removing it once i_disksize
   has caught up.

v3: https://lore.kernel.org/linux-ext4/20260708062049.1982410-1-yi.zhang@huaweicloud.com/
v2: https://lore.kernel.org/linux-ext4/20260707021338.1182268-1-yi.zhang@huawei.com/
v1: https://lore.kernel.org/linux-ext4/20260701142009.1510104-1-yizhang089@gmail.com/

Origin cover-letter
===================

The current FALLOC_FL_WRITE_ZEROES implementation in ext4 does not
correctly handle unaligned edge blocks. FALLOC_FL_WRITE_ZEROES is needed
to convert the requested range to written extents with zeroed content,
but the existing code only partially zero the edges and never guarantees
that:

  1) edges that are clean unwritten extents or holes get promoted to
     written extents, and
  2) edges that are dirty unwritten or delalloc get their underlying
     extents converted to written before the syscall returns.

Both cases leave the on-disk extent type unwritten, violating the
WRITE_ZEROES contract, and in these cases a subsequent sync buffered
overwrite would still observe pending metadata changes from the
conversion work that should have been completed by WRITE_ZEROES itself.

This series fixes the unaligned edge handling and cleans up a related
redundant i_disksize update. The first three patches are preparatory:
moving ext4_zero_partial_blocks() earlier in ext4_zero_range(),
documenting the return semantics of ext4_load_tail_bh(), and replacing
the single bool output of ext4_zero_partial_blocks() with a per-edge
bitmask (EXT4_PARTIAL_ZERO_START/END). The next two patches fix the two
scenarios above by expanding the aligned allocation range outward for
skipped (clean unwritten or hole) edges, and by writing back
partial-zeroed edges so the underlying extents are converted to written.
The final patch drops the now-redundant
ext4_update_disksize_before_punch() call on the WRITE_ZEROES path, since
WRITE_ZEROES is mutually exclusive with KEEP_SIZE and the i_disksize
update is already handled by ext4_alloc_file_blocks().

Thanks,
Yi.

Discussion Link:
  https://lore.kernel.org/linux-xfs/0b7f1a4f-da1c-4297-8099-98d738070ab7@huaweicloud.com/

Zhang Yi (9):
  ext4: use FGP_WRITEBEGIN for tail block zeroing
  ext4: skip tail block zeroing for inline data files
  ext4: check return value of ext4_get_block() in ext4_load_tail_bh()
  ext4: move partial block zeroing earlier in ext4_zero_range()
  ext4: clarify return semantics of ext4_load_tail_bh()
  ext4: track partial-zero outcome per edge in
    ext4_zero_partial_blocks()
  ext4: zero out whole block for clean edges in WRITE_ZEROES
  ext4: write back partial-zeroed edges in WRITE_ZEROES
  ext4: protect WRITE_ZEROES written extents with orphan list

 fs/ext4/ext4.h    |  5 ++-
 fs/ext4/extents.c | 84 +++++++++++++++++++++++++++++++++++++++--------
 fs/ext4/inode.c   | 61 +++++++++++++++++++++++++++++-----
 3 files changed, 127 insertions(+), 23 deletions(-)

-- 
2.52.0


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-07-22 17:07 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-14  8:00 [PATCH v4 0/9] ext4: fix unaligned edge handling in FALLOC_FL_WRITE_ZEROES Zhang Yi
2026-07-14  8:00 ` [PATCH v4 1/9] ext4: use FGP_WRITEBEGIN for tail block zeroing Zhang Yi
2026-07-14  8:00 ` [PATCH v4 2/9] ext4: skip tail block zeroing for inline data files Zhang Yi
2026-07-14 15:09   ` Jan Kara
2026-07-14  8:00 ` [PATCH v4 3/9] ext4: check return value of ext4_get_block() in ext4_load_tail_bh() Zhang Yi
2026-07-14  8:00 ` [PATCH v4 4/9] ext4: move partial block zeroing earlier in ext4_zero_range() Zhang Yi
2026-07-14  8:00 ` [PATCH v4 5/9] ext4: clarify return semantics of ext4_load_tail_bh() Zhang Yi
2026-07-14  8:00 ` [PATCH v4 6/9] ext4: track partial-zero outcome per edge in ext4_zero_partial_blocks() Zhang Yi
2026-07-14  8:00 ` [PATCH v4 7/9] ext4: zero out whole block for clean edges in WRITE_ZEROES Zhang Yi
2026-07-14  8:00 ` [PATCH v4 8/9] ext4: write back partial-zeroed " Zhang Yi
2026-07-14  8:00 ` [PATCH v4 9/9] ext4: protect WRITE_ZEROES written extents with orphan list Zhang Yi
     [not found]   ` <20260714084203.971381F000E9@smtp.kernel.org>
2026-07-22 17:07     ` Theodore Tso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox