Skip to content

ext4: Punch hole and DAX fixes

Jan Kara linux-ext4 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest9 patches 7 repliesIn review
  2. v39 patches 9 repliesSuperseded
  3. v29 patches 8 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v16 patches6 repliesSuperseded

Changes in v4 from the cover letter

* Fixed ext4_dax_mmap_get_block() to not return buffer_new buffer and thus avoid racy zeroing in generic dax code
* Fixed ext4_map_blocks() to zeroout blocks before inserting entry into extent status tree to avoid racy lookups of blocks.

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/9ext4: Fix races between page faults and hole punchingfs/ext4/ext4.h fs/ext4/extents.c fs/ext4/file.c +3 more+127 -420 replies
2/9ext4: Move unlocked dio protection from ext4_alloc_file_blocks()fs/ext4/extents.c+5 -100 replies
3/9ext4: Fix races between buffered IO and collapse / insert rangefs/ext4/extents.c+22 -282 replies
4/9ext4: Fix races of writeback with punch hole and zero rangefs/ext4/ext4.h fs/ext4/extents.c fs/ext4/inode.c+42 -10 replies
5/9ext4: Document lock orderingfs/ext4/super.c+30 -00 replies
6/9ext4: Get rid of EXT4_GET_BLOCKS_NO_LOCK flagfs/ext4/ext4.h fs/ext4/inode.c include/trace/events/ext4.h+22 -280 replies
7/9ext4: Provide ext4_issue_zeroout()fs/ext4/crypto.c fs/ext4/ext4.h fs/ext4/extents.c +1 more+23 -150 replies
8/9ext4: Implement allocation of pre-zeroed blocksfs/ext4/ext4.h fs/ext4/extents.c fs/ext4/inode.c +1 more+36 -40 replies
9/9ext4: Use pre-zeroed blocks for DAX page faultsfs/ext4/ext4.h fs/ext4/file.c fs/ext4/inode.c+74 -360 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v4 yet.

Read the v4 thread

Cover letter [PATCH 0/9 v4] ext4: Punch hole and DAX fixes

Hello,

Another version of my ext4 fixes. Since previous version I have fixed DAX block mapping to really avoid races for parallel page faults so that the test program by Brian passes. Note that you'll see ext4/001 failures - xfstests updates were submitted. Also note that testing with 1 KB blocksize on ramdisk is broken since brd has buggy discard implementation - Jens has a fix queued.

Change since v3:
* Fixed ext4_dax_mmap_get_block() to not return buffer_new buffer and thus avoid racy zeroing in generic dax code
* Fixed ext4_map_blocks() to zeroout blocks before inserting entry into extent status tree to avoid racy lookups of blocks.

Changes since v2:
* Fixed collaps range to truncate pagecache properly with blocksize < pagesize
* Fixed assertion in ext4_get_blocks_overwrite

Patch set description

This series fixes a long standing problem of racing punch hole and page fault resulting in possible filesystem corruption or stale data exposure. We fix the problem by using a new inode-private rw_semaphore i_mmap_sem to synchronize page faults with truncate and punch hole operations.

When having this exclusion, the only remaining problem with DAX implementation are races between two page faults zeroing out same block concurrently (where the data written after the first fault finishes are possibly overwritten by the second fault still doing zeroing).

Patch 1 introduces i_mmap_sem lock in ext4 inode and uses it to properly serialize extent manipulation operations and page faults.

Patch 2 is mostly a preparatory cleanup patch which also avoids double lock / unlock in unlocked DIO protections (currently harmless but nasty surprise).

Patches 3-4 fix further races of extent manipulation functions (such as zero range, collapse range, insert range) with buffered IO, page writeback

Patch 5 documents locking order of ext4 filesystem locks.

Patch 6 removes locking abuse of i_data_sem from the get_blocks() path when dioread_nolock is enabled since it is not needed anymore.

Patches 7-9 implement allocation of pre-zeroed blocks in ext4_map_blocks() callback and use such blocks for allocations from DAX page faults.

The patches survived xfstests run both in dax and non-dax mode.

Honza