Skip to content

exfat: fix valid_size update races

Chi Zhiling exfat linux-fsdevel linux-xfs lkml 3 versions – Applied

Status from this message: Applied to the vfs-7.5.iomap branch of the vfs/vfs.git tree.

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest5 patches 3 repliesApplied
  2. v38 patches 1 replySuperseded
  3. v27 patches 7 repliesSuperseded

Changes in v4 from the cover letter

- Fold the series into five patches and rebase onto current exfat/dev.
- Add a patch that serialises file expansion with mmap write faults.
- Rework direct writes: prepare and write back the invalid range through the destination boundary folio, initialise the gap after the post-write invalidation, and keep pure overwrites asynchronous.
- Track initialised block tails in zeroed_size instead of IOMAP_F_ZERO_TAIL, record the on-disk length in i_size, and finish short direct reads with filemap_read().
- Pick up the Reviewed-by on the iomap patch.

Patches in v4 Applied

#Subject and filesSizeRepliesApplied
1/5iomap: export iomap_bio_read_folio_range_sync()fs/iomap/bio.c fs/iomap/internal.h include/linux/iomap.h+10 -121 reply
2/5exfat: increase VDL before unlocking initialized foliosfs/exfat/file.c fs/exfat/iomap.c fs/exfat/iomap.h+83 -520 replies
3/5exfat: zero invalid VDL tails in buffered and direct readsfs/exfat/exfat_fs.h fs/exfat/file.c fs/exfat/iomap.c+120 -770 replies
4/5exfat: serialize file expansion with mmap write faultsfs/exfat/file.c+12 -10 replies
5/5exfat: coordinate direct writes with mmap faultsfs/exfat/fatent.c fs/exfat/file.c fs/exfat/inode.c +2 more+385 -1240 replies

Reviews trailers per patch

1 of 5 patches has a Reviewed-by or Acked-by.

PatchChristoph HellwigNamjae Jeon
1/5R-b R-b
2/5
3/5
4/5
5/5

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCH v4 0/5] exfat: fix valid_size update races

From: Chi Zhiling <[email protected]>

exFAT uses valid_size (ValidDataLength) as the on-disk boundary of initialised data, but the current code advances it too late and without proper serialisation. Buffered writes can silently lose data reclaimed before valid_size covers it, file expansion and page faults can initialise the same range concurrently, and a failed or short direct write can still grow the file on disk.

This series advances valid_size under the folio lock, keeps zeroed_size in sync with the block tails that were actually initialised, and revalidates cached iomaps for buffered writes. File expansion holds invalidate_lock across allocation, EOF cleanup and the i_size update. Direct writes are prepared and written back through their destination boundary folio before submission, publish i_size and valid_size only from ->end_io(), and hold invalidate_lock across completion, post-write invalidation, gap initialisation and rollback so that mmap faults cannot interfere.

V4:
- Fold the series into five patches and rebase onto current exfat/dev.
- Add a patch that serialises file expansion with mmap write faults.
- Rework direct writes: prepare and write back the invalid range through the destination boundary folio, initialise the gap after the post-write invalidation, and keep pure overwrites asynchronous.
- Track initialised block tails in zeroed_size instead of IOMAP_F_ZERO_TAIL, record the on-disk length in i_size, and finish short direct reads with filemap_read().
- Pick up the Reviewed-by on the iomap patch.

V3: https://lore.kernel.org/exfat/[email protected]/
V2: https://lore.kernel.org/exfat/[email protected]/
V1: https://lore.kernel.org/exfat/[email protected]/

Chi Zhiling (3):
iomap: export iomap_bio_read_folio_range_sync()
exfat: increase VDL before unlocking initialized folios
exfat: zero invalid VDL tails in buffered and direct reads

Namjae Jeon (2):
exfat: serialize file expansion with mmap write faults
exfat: coordinate direct writes with mmap faults

 fs/exfat/exfat_fs.h   |   2 +-
 fs/exfat/fatent.c     |   6 +-
 fs/exfat/file.c       | 427 ++++++++++++++++++++++++++++++++----------
 fs/exfat/inode.c      |  19 +-
 fs/exfat/iomap.c      | 368 ++++++++++++++++++++++++------------
 fs/exfat/iomap.h      |  10 +-
 fs/iomap/bio.c        |   1 +
 fs/iomap/internal.h   |  12 --
 include/linux/iomap.h |   9 +
 9 files changed, 599 insertions(+), 255 deletions(-)
Signature · 1 line
2.53.0