linux/Documentation/filesystems
Paulo Alcantara 69bf14300b netfs: clear post-EOF pagecache when extending a file via write
Fix netfs to erase the contents of a hole created after the EOF by an
ordinary write if dirty data has been previously left there by writes
through an mmapped region.  Neither the buffered nor the unbuffered/DIO
write path clears that stale pagecache.

Zero the tail of the folio straddling the EOF before an extending
write.  That is the only folio that can hold data written past the EOF
through an mmap, as pages wholly beyond the EOF can't be faulted in.
The folio is zeroed rather than dropped so a concurrent extending write
can't lose data.

Both write paths downgrade the i_rwsem to shared, so extending writes
can run concurrently and the i_size read by the caller may be stale by
the time the folio is locked.  Re-read i_size under the folio lock and
clamp the zeroed range up to it, so a racing write that already put
data into the folio isn't clobbered.

Wait for any writeback on the folio to finish before zeroing it so that
the pagecache isn't modified while it may still be read by the transport
during transmission.  Honour IOCB_NOWAIT by returning -EAGAIN rather
than blocking on the folio lock, on writeback, or in folio_mkclean()'s
rmap walk when the folio is mapped.

truncate_pagecache() can't be used here: it must be called with the
i_rwsem held exclusively, but these write paths only hold it shared,
and it would block unconditionally, breaking IOCB_NOWAIT.

Callers that hold i_rwsem exclusively for the whole resize (truncate,
setattr, fallocate, clone) exclude any genuine concurrent buffered
writer, so staleness can instead be decided from the folio's dirty
state, as pagecache_isize_extended() already does for filesystems that
serialise writes against truncate/setattr via a single i_rwsem.
Export netfs_clear_stale_post_isize() helper to handle such case.

The helper is required by the CIFS client to fix generic/363.

Closes: https://sashiko.dev/#/patchset/20260921230755.1133425-1-pc%40manguebit.org
Fixes: 938e13a73b ("netfs: Implement buffered write API")
Fixes: 153a9961b5 ("netfs: Implement unbuffered/DIO write support")
Reviewed-by: David Howells <dhowells@redhat.com>
Reviewed-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Paulo Alcantara <pc@manguebit.org>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Cc: Shyam Prasad N <sprasad@microsoft.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Bharath SM <bharathsm@microsoft.com>
Cc: stable@vger.kernel.org
2026-09-30 14:22:44 -03:00
..
caching cachefiles,netfs: sunset ondemand mode 2026-08-12 16:24:26 +02:00
ext4 Documentation: ext4: fix block_group layout when meta_bg is enabled 2026-07-22 11:45:36 -04:00
fuse docs: fuse: document io-uring buffer pool and zero-copy uapi 2026-08-17 17:02:37 +02:00
gfs2 Documentation: gfs2: Consolidate GFS2 docs into its own subdirectory 2025-10-31 21:00:43 +00:00
iomap docs: fix grammatical error in iomap docs 2026-08-12 09:17:07 +02:00
nfs NFSD: Sign filehandles 2026-03-29 21:25:09 -04:00
smb ksmbd: doc: update feature support status for durable handles and compression 2026-06-30 21:29:46 -05:00
spufs docs: spufs: fix ppc64 architecture line break 2026-01-06 15:21:26 -07:00
xfs xfs: new code for v6.19 2025-12-03 20:19:38 -08:00
9p.rst 9p: Add mount option for negative dentry cache retention 2026-06-21 05:22:56 +00:00
adding-new-filesystems.rst docs: add guidelines for submitting new filesystems 2026-05-21 13:39:34 +02:00
adfs.rst
affs.rst
afs.rst
api-summary.rst docs: filesystems: add fs/open.c to api-summary 2026-01-16 11:33:15 -07:00
autofs-mount-control.rst
autofs.rst
automount-support.rst
befs.rst
bfs.rst
btrfs.rst
buffer.rst
ceph.rst ceph: make nearfull sync writes opt-in 2026-08-26 19:57:28 +02:00
coda.rst
configfs.rst
cramfs.rst Documentation: filesystems: cramfs: correct stale hard-link and endianness claims 2026-05-03 09:12:23 -06:00
dax.rst doc: Remove misleading reference to brd in dax.rst 2025-06-25 12:49:29 -06:00
debugfs.rst docs: debugfs: do not recommend debugfs_remove_recursive 2025-04-30 19:11:04 +02:00
devpts.rst
directory-locking.rst
dlmfs.rst
dnotify.rst
ecryptfs.rst
efivarfs.rst
erofs.rst erofs: accept source file descriptor via fsconfig 2026-08-11 19:46:11 +08:00
ext2.rst doc : fix a broken link in ext2.rst 2025-12-19 15:01:27 +01:00
ext3.rst
f2fs.rst f2fs-for-7.3-rc1 2026-08-28 10:48:48 -07:00
failfs.rst Documentation: add failfs documentation 2026-07-27 17:18:00 +02:00
fiemap.rst
files.rst
fscrypt.rst mm.git review status for linus..mm-stable 2026-08-27 09:17:06 -07:00
fsverity.rst fs: add FS_XFLAG_VERITY for fs-verity files 2026-01-29 16:00:57 +01:00
hfs.rst
hfsplus.rst
hpfs.rst Documentation: Fix filesystems typos 2025-08-18 10:31:19 -06:00
idmappings.rst
index.rst Documentation: add failfs documentation 2026-07-27 17:18:00 +02:00
inotify.rst
isofs.rst docs: isofs: replace dead ECMA-119 FTP link 2026-04-27 12:58:07 +02:00
journalling.rst
locking.rst mm.git review status for linus..mm-stable 2026-08-27 09:17:06 -07:00
locks.rst
mmap_prepare.rst mm: add mmap_action_map_kernel_pages[_full]() 2026-04-05 13:53:45 -07:00
mount_api.rst fs: remove fsparam_path / fs_param_is_path 2026-02-19 14:34:26 +01:00
multigrain-ts.rst
netfs_library.rst netfs: clear post-EOF pagecache when extending a file via write 2026-09-30 14:22:44 -03:00
nilfs2.rst Documentation: fix grammar in description of nilfs2 recovery code 2026-07-27 17:52:42 -07:00
ntfs.rst docs/fs/ntfs: add mount options to support Windows native symbolic links 2026-06-15 19:39:45 +09:00
ntfs3.rst
ocfs2-online-filecheck.rst Documentation: ocfs2: Properly reindent filecheck operations list 2025-08-29 15:50:50 -06:00
ocfs2.rst
omfs.rst
orangefs.rst
overlayfs.rst It has been a not-too-busy cycle for docs; here's the highlights: 2026-08-20 10:31:50 -07:00
path-lookup.rst docs: path-lookup: fix unrenamed WALK_GET 2026-03-22 14:54:23 -06:00
path-lookup.txt
porting.rst vfs-7.3-rc1.misc 2026-08-17 12:56:12 -07:00
proc.rst mm.git review status for mm-hotfixes-stable..mm-stable 2026-08-20 18:17:08 -07:00
propagate_umount.txt docs: fix trailing whitespace error and remove repeated words in propagate_umount.txt 2025-08-21 12:49:01 -06:00
qnx6.rst
quota.rst
ramfs-rootfs-initramfs.rst fs: use nullfs unconditionally as the real rootfs 2026-01-14 11:23:39 +01:00
relay.rst docs: fix 're-use' -> 'reuse' in documentation 2026-02-02 09:54:15 -07:00
resctrl.rst fs/resctrl: Document tasks file behaviour for task id 0 and idle tasks 2026-05-08 12:27:00 +02:00
romfs.rst
seq_file.rst Documentation: seq_file: drop 2.6 reference 2026-04-10 08:39:08 -06:00
sharedsubtree.rst Documentation: sharedsubtree: Convert notes to note directive 2025-08-29 16:40:01 -06:00
splice.rst
squashfs.rst
sysfs.rst kernel.h: move VERIFY_OCTAL_PERMISSIONS() to sysfs.h 2026-01-31 16:16:05 -08:00
tmpfs.rst
ubifs-authentication.rst Documentation: treewide: Replace remaining spinics links with lore 2025-06-21 14:20:51 -06:00
ubifs.rst
udf.rst
vfat.rst
vfs.rst mm.git review status for linus..mm-stable 2026-08-27 09:17:06 -07:00
virtiofs.rst
zonefs.rst