[PATCH v1 01/13] ntfs: limit writeback allocation to the dirty range

From: Baolin Liu

Date: Wed Dec 02 2026 - 23:06:36 EST


From: Baolin Liu <liubaolin@xxxxxxxxxx>

A buffered write into a hole reserves space before copying user data.
If the copy faults partway through, writeback can allocate the clean
remainder of the reservation because it maps up to allocated_size.
After fsync and cache eviction, reads can expose old disk contents
instead of zeros. A pwritev with an inaccessible second buffer
reproduces this with order-0 folios.

Limit writeback mappings to the dirty range supplied by iomap. Zero
unwritten edges of newly allocated clusters for writeback as for direct
writes and page_mkwrite, and keep reservation accounting independent
of that zeroing.

Fixes: b041ca562526 ("ntfs: update iomap and address space operations")
Signed-off-by: Baolin Liu <liubaolin@xxxxxxxxxx>
---
fs/ntfs/iomap.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/fs/ntfs/iomap.c b/fs/ntfs/iomap.c
index ce916707f69b..8970cadcd31e 100644
--- a/fs/ntfs/iomap.c
+++ b/fs/ntfs/iomap.c
@@ -620,7 +620,8 @@ static int ntfs_write_da_iomap_begin_non_resident(struct inode *inode,

if (balloc == true) {
if (flags & IOMAP_DIRECT ||
- ntfs_iomap_flags & NTFS_IOMAP_FLAGS_MKWRITE) {
+ ntfs_iomap_flags & (NTFS_IOMAP_FLAGS_MKWRITE |
+ NTFS_IOMAP_FLAGS_WRITEBACK)) {
loff_t end = offset + length;

if (vcn_ofs || ((vol->cluster_size > iomap->length) &&
@@ -636,7 +637,8 @@ static int ntfs_write_da_iomap_begin_non_resident(struct inode *inode,
(start_lcn + lcn_count - 1) <<
vol->cluster_size_bits,
vol->cluster_size);
- } else {
+ }
+ if (ntfs_iomap_flags & NTFS_IOMAP_FLAGS_WRITEBACK) {
if (lcn_count > ni->i_dealloc_clusters)
ni->i_dealloc_clusters = 0;
else
@@ -804,8 +806,8 @@ static ssize_t ntfs_writeback_range(struct iomap_writepage_ctx *wpc,
offset >= wpc->iomap.offset + wpc->iomap.length) {
int error;

- error = __ntfs_write_iomap_begin(wpc->inode, offset,
- NTFS_I(wpc->inode)->allocated_size - offset,
+ /* A short write may leave clean delalloc blocks after this range. */
+ error = __ntfs_write_iomap_begin(wpc->inode, offset, len,
IOMAP_WRITE, &wpc->iomap,
NTFS_IOMAP_FLAGS_WRITEBACK);
if (error)