mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ernest Borowski <ernest.borowski.git@proton.me>
To: Hyunchul Lee <hyc.lee@gmail.com>
Cc: ernest.borowski.git@proton.me,
	Namjae Jeon <linkinjeon@kernel.org>,
	Baolin Liu <liubaolin12138@163.com>,
	ntfs@lists.linux.dev, linux-kernel@vger.kernel.org,
	Zhan Xusheng <zhanxusheng1024@gmail.com>,
	stable@vger.kernel.org
Subject: Re: [PATCH 6/7] ntfs: zero new delalloc clusters even when writeback allocates them
Date: Tue, 24 Nov 2026 12:41:26 +0000	[thread overview]
Message-ID: <179552408028.2458487.7065441678711617197.b4-reply@b4> (raw)
In-Reply-To: <awPUQP3VxjqgW9Lf@hyunchul-PC02>

On Mon, Nov 23, 2026 at 02:50:56PM +0900, Hyunchul Lee wrote:
> Could the buffered-write iomap become stale after this unlock but before
> the data is copied?
>
> For example, suppose a buffered write obtains an IOMAP_DEALLOC mapping
> for a hole. After the unlock, a mmap write can allocate the cluster
> and write another byte in the same block. If that foilo is written back
> and reclaimed before the buffered write resumes, the buffered write
> still uses its old IOMAP_DEALLOC iomap. __iomap_write_begin() can zero
> the rest of the block instead of reading the mmap data from disk.

Yes, it can.  This is pre-existing: on ntfs-next, buffered writes take
no lock against page faults, and the ntfs_iomap_valid() removed by this
patch only guarded the zeroing in ->iomap_begin(), not the copy.

I wrote a reproducer for your sequence.  The copy blocks on a
userfaultfd page before the write's second folio.  While it is blocked,
the test stores a byte through a shared mapping into the block where the
write ends, runs sync_file_range() (which does not wait for the inode
lock), drops the page with POSIX_FADV_DONTNEED, and resumes the copy.
The byte reads back as zero on ntfs-next and with v1, and is kept with
the v2 fixes.  This holds in all 16 cases (512 B, 4 KiB, 16 KiB and
64 KiB clusters; files initialized to their end or not; Ubuntu 26.04
and Arch Linux):

  ntfs-next:                 https://github.com/xerrni/linux-ntfs/actions/runs/45292350658
  ntfs-next + v1:            https://github.com/xerrni/linux-ntfs/actions/runs/45292355094
  ntfs-next + v1 + v2 fixes: https://github.com/xerrni/linux-ntfs/actions/runs/45292359194

Reproducer: tests/stale_write_mapping.sh (with stale_write_mapping.c) in
https://github.com/xerrni/linux-ntfs.

v2 adds a ->iomap_valid() check for the delalloc mapping of a buffered
write.  ntfs_attr_map_cluster() bumps a per-inode sequence count when it
allocates clusters, and the mapping records that count.  If the count
has changed, the mapping is stale unless all of its clusters are still
delalloc.  A stale mapping is handled like a short write: ->iomap_end()
releases the clean delalloc clusters the write did not reach and, if
the cluster where it stopped is still delalloc, zeroes the rest of that
cluster where it is not cached and dirties it where it is, as for any
short copy.  The remaining range is then mapped again.  It is now
allocated, so __iomap_write_begin() reads the block.

Thanks,
Ernest


  reply	other threads:[~2026-11-24 12:41 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22 18:19 [PATCH 0/7] ntfs: delayed allocation accounting and stale data fixes, part 1 Ernest Borowski via B4 Relay
2026-11-22 18:19 ` [PATCH 1/7] ntfs: release delalloc reservations cut off by truncate Ernest Borowski via B4 Relay
2026-11-23  2:16   ` Hyunchul Lee
2026-11-24 12:38     ` Ernest Borowski
2026-11-22 18:19 ` [PATCH 2/7] ntfs: do not consume delalloc reservations when filling holes Ernest Borowski via B4 Relay
2026-11-22 18:19 ` [PATCH 3/7] ntfs: release the delalloc reservations of an evicted inode Ernest Borowski via B4 Relay
2026-11-22 18:19 ` [PATCH 4/7] ntfs: do not shift the cluster number of a delalloc run on split Ernest Borowski via B4 Relay
2026-11-22 18:19 ` [PATCH 5/7] ntfs: punch out the delalloc reservation of a failed buffered write Ernest Borowski via B4 Relay
2026-11-23  5:47   ` Hyunchul Lee
2026-11-24 12:40     ` Ernest Borowski
2026-11-22 18:19 ` [PATCH 6/7] ntfs: zero new delalloc clusters even when writeback allocates them Ernest Borowski via B4 Relay
2026-11-23  5:50   ` Hyunchul Lee
2026-11-24 12:41     ` Ernest Borowski [this message]
2026-11-22 18:19 ` [PATCH 7/7] ntfs: zero the rest of a new cluster after a short buffered write Ernest Borowski via B4 Relay

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179552408028.2458487.7065441678711617197.b4-reply@b4 \
    --to=ernest.borowski.git@proton.me \
    --cc=hyc.lee@gmail.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liubaolin12138@163.com \
    --cc=ntfs@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=zhanxusheng1024@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®