From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796409636; b=fOplz/hAKcPRjFilQpdOBaodQAXoL49P4HAqCdwDYMFYDCNYj5ihFuNICVo9Xi/jR1ap beJKW7bxrlu0KV7SrF/aTNTnqOWtkr7eqeIgBD2ASh7/mJ9A4UL6+ROGHkjohrU76T+b5 ztRitOLDQi4E7pP5PqPH/MQ0l0yhJRnG1FaJfae/GaXtJsdXOEHx+xOljPSbwpmDWyooG GVwZ/G2U/45jUrtL+xiNu/XlZFIFtrhCLoda+y1aVZbvbtgx/ajl5FtdnICOjB+A0nIdb YLx8LOp+s8JcZwIbBEYx4o2CxFtVGujVdPNn9QWxvlu3Buy2KWNHiaRxhygR9LRULig== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796409636; h=Received:DKIM-Signature:Received:From:Subject:Date:Message-Id: MIME-Version:Content-Type:Content-Transfer-Encoding:X-B4-Tracking: X-Change-ID:To:Cc:X-Mailer:X-Developer-Signature:X-Developer-Key: X-Endpoint-Received:X-Original-From:Reply-To; bh=4a7spjp4c0s8MUsrOx5oPLvN8YJCIlQuQrRm9N4BP7I=; b=qI6VHJBVJ5QGNSWQir1QKp46Zasd/ilnj372frKoUaRwSKG4nfg5duV8W7FuIzhMEpxK eicGUYjDPZSzNTT0Chn8D7rI1VHG3gWMFTOb5YDMTQZJEYiXLcTEdhir/za9uOEZkroVP NSBxOBWCjPs7MDNYn12hkAXud7yQ9VgW/72vlLx6HcHc1Rc+W2jmAxdQSXLnnmlyhL9XS LvDKFlIsZGYTwgEJsbenItkUno+cVZ2fro8jGkbxpG0fU5eD5j6KQuXuHQgvOkJEgOfNw kkCk9prCDaxdmRI+pJmKrWSOubQOfK8lQJoEKKnxw2+nQyrAo+gRecBPRuldn6PWCBg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=MTLmIqPP; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5ABBA606A322; Fri, 4 Dec 2026 18:40:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=MTLmIqPP Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796409636; b=gsZItuNw32DeG6TBbW9bCvlvvBAKC66rxKJ4r/0dGdxSqpEz+8o/tLzaY1ero+CQWAYD xPm9pbo4vE+lYy+orFki5VutpjNE2J7utO/DIWhosfTTeyLoXDt2yBj31wfLoSIzO17by GIrz+JyIAp2ECXSX2aSElvpaC6PWa4ZAsBuEpoa/2bV6sENw+uB0C9nmOWrv4t4EVwr9O h3/6peEdNg2xDnPsbYZmwgvkw32pc/fJyMlDXWzJ8B2Qbhmkp6DcEkVvAA2/DFGJxAzP4 NCQxfM04ATl7auUPjzGXTNKAia6Wr5UQMip0rm+aIHCFKX5itmcakdlf8CyFVkcj6Cw== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796409636; h=DKIM-Signature:Received:From:Subject:Date:Message-Id:MIME-Version: Content-Type:Content-Transfer-Encoding:X-B4-Tracking:X-Change-ID:To: Cc:X-Mailer:X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To; bh=4a7spjp4c0s8MUsrOx5oPLvN8YJCIlQuQrRm9N4BP7I=; b=V6eSEa2UyB/dkZ0afJPi/RINicwkwF1S4QG8fITUtw6WHNN6BTq6Cj35F0v40L4gztj5 nCfGfPkB00lMmzC4bKZUxma70kctj48Db8MORdUrueC0H6V52jQOcD0NAeW+V5W8nHon6 KBq1QDV8rdzzWnyVhHA7GmTnvpNJb1CDZyvJApXjT1Me3GZ8mxGwKDtC1DSlsNVNuLWqh fENLnw+sLMDA1BGe4/slsyyrq4jzkx8cFpTEDttr8u9P3pvYMqHWvSfQneorNpZRzE+zj FrXp6iVEy/pHW38d+lazpHMsEC4WsjrXdrU8fYSBAIRscLm4S1EWLqObWHgurov1jfw== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id 3D1991F0093B; Fri, 4 Dec 2026 18:40:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796409636; bh=4a7spjp4c0s8MUsrOx5oPLvN8YJCIlQuQrRm9N4BP7I=; h=From:Subject:Date:To:Cc:Reply-To; b=MTLmIqPPF9Q88g8B4SN56v9WmYmFLItVoXb885qF0hk560Id2z1svhu1q2NlO5/Sr npcWAkU29KpZdBqJ6fNO9Ta6CDobFCnGjrZ11lWQiTL3M97sHcIbD4t8GvTRebCrqH XcYQCKovj6gie41Q8TjdQLPfR0cc9qiEV9hFlrdtA1SLENHJgkMs/+AKKPuyRwvNns Kd6NvaQWYxABgnBkM2Qb5OzU4Eunz08ZszgwarRsa5FsCeqsVwGzYWQassxAdhxmCl rqSVG3zvK4DTPo9IvAQz435Ae2vYQT9L9ScaZWMtUvLeYM1XEmPxkqoBSG7BEyOWX+ w9Z9xhKSdSRjA== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id AF29A4DC2E; Fri, 4 Dec 2026 18:40:34 +0000 (UTC) From: Ernest Borowski via B4 Relay Subject: [PATCH v5 00/13] ntfs: delayed allocation accounting and stale data fixes, part 1 Date: Fri, 04 Dec 2026 19:40:31 +0100 Message-Id: <20261204-b4-ntfs-delalloc-fixes-v5-0-1cd0267df2cd@proton.me> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-B4-Tracking: v=1; b=H4sIAAAAAAAC/4XOy07EIBQG4FeZsBblVpi68j2MCy4Hi6kwAWzGT PruQl3YaBqX/7l8+W+oQA5Q0OPphjIsoYQUWxjuTshOOr4CDq5lxAiTlDKGjcCx+oIdzHqek8U +XKHgwejRCRgVHzhqz5cM26L9Pr985/Jh3sDWrvULowtgk3W0Ux919GGTI1xrP5hCqSl/btUW2 qF/WywUE0wUk544C4Lwp0tONcX7d0C9xcL2jDhkWGM8H4U9EwL2L8N3DCeHDG/MWQnHhZaeevj NiB+GEXrIiMbA4Jz0ShEq9Z5Z1/ULtoeg3MQBAAA= X-Change-ID: 20261122-b4-ntfs-delalloc-fixes-5ba9d4e97353 To: Namjae Jeon , Hyunchul Lee , Baolin Liu Cc: Christian Brauner , Christoph Hellwig , "Darrick J. Wong" , ntfs@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, Zhan Xusheng , stable@vger.kernel.org, Ernest Borowski , Baolin Liu X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=9481; i=ernest.borowski.git@proton.me; s=default; h=from:subject:message-id; bh=qun4vzhArUZWwYH8TmSak/7bLlZk04fTamIChKrl320=; b=kA0DAAoWcwdpo3piFP8ByyZiAGsTCR+hKU68sr21wRdIT0UVywN9yGZM0M+T/AX9QBw6L1rVD Yh1BAAWCgAdFiEEiP/YVExU9vKmXiqOcwdpo3piFP8FAmsTCR8ACgkQcwdpo3piFP96dgEAk818 5MgAMonLTIwYUANtbzHllrSUV7fnXl6E3iUqAzMBAKrF2INaFAzJe0XdX4BiJn1Dg/dbpkKtJFj wtu4xuAYE X-Developer-Key: i=ernest.borowski.git@proton.me; a=openpgp; fpr=88FFD8544C54F6F2A65E2A8E730769A37A6214FF X-Endpoint-Received: by B4 Relay for ernest.borowski.git@proton.me/default with auth_id=1589 X-Original-From: Ernest Borowski Reply-To: ernest.borowski.git@proton.me ntfs did not give back its delayed allocation reservations (vol->dirty_clusters) on several paths. Under a write, truncate and punch-hole stress test on a 128 MiB volume, the free space statfs() reports fell from 79 MB to zero in 80 seconds, and writes then failed with ENOSPC, while $Bitmap stayed correct. The same paths let buffered writes into holes show old disk contents. What each patch does: 1 iomap: pass each run of clean blocks to ->punch() in one call, so ntfs can release a cluster smaller than a folio 2 iomap: add iomap_dirty_folio_range(), used by patch 10 3 release the reservations that truncate cuts off 4 do not consume reservations when fallocate(), direct I/O or page_mkwrite() fill a hole 5 keep the reservations when a cluster allocation fails 6 release the reservations of an evicted inode or removed stream 7 do not turn a delalloc run into real clusters when it is split 8 punch out the clusters a failed buffered write did not use 9 keep zeroing a new cluster's edges when writeback allocates it 10 zero the rest of a new cluster after a short copy 11 read, do not zero, blocks whose cluster a write fault or writeback allocated during the copy 12 zero a write fault's new cluster before the runlist shows it 13 at writeback, allocate only the clusters of dirty folios For XFS and ext4, patch 1 only means fewer ->punch() calls, and patch 2 changes nothing. All patches are Cc stable. Dependencies (an arrow points to the patch that needs it): 3 --> 6 --> 8 --> 9 --> 10 <-- 2 ^ | 1 +--> 11 4 --> 5 12 --> 13 7 The series applies to ntfs-next of git://git.kernel.org/pub/scm/linux/kernel/git/linkinjeon/ntfs.git at 94ebffe9b5d7, not to master or linux-next. To get it: git fetch https://github.com/xerrni/linux.git ntfs-delalloc-fixes-v5 git log --oneline 94ebffe9b5d7..FETCH_HEAD or, on that ntfs-next commit, "b4 shazam" with this message's Message-ID. Patch 10 uses ntfs_zero_range_unkillable() from Zhan Xusheng's short write fix [1], which is in ntfs-next. Part 2 follows with three patches: st_blocks of delalloc data and of named streams, and stale data from direct I/O into holes. Each bug has a reproducer that fails before its fix and passes after it: QEMU, a kernel with KASAN, lockdep and UBSAN, clusters from 512 B to 64 KiB, ntfsck -n after every case, Ubuntu 26.04 and Arch Linux. With this series all of them pass except the st_blocks check of delalloc_alloc_failure and the direct I/O case of hole_fill_stale, which part 2 fixes. Every test that passed before still passes. tests: https://github.com/xerrni/linux-ntfs ntfs-next: https://github.com/xerrni/linux-ntfs/actions/runs/47382059705 ntfs-next + this series: https://github.com/xerrni/linux-ntfs/actions/runs/47382064876 [1] https://lore.kernel.org/all/20261127031053.3695758-1-zhanxusheng1024@gmail.com/ [2] https://lore.kernel.org/all/20261203040352.1161120-2-liubaolin12138@163.com/ [3] https://github.com/xerrni/linux-ntfs/actions/runs/47389279532 (patch 13) https://github.com/xerrni/linux-ntfs/actions/runs/47389286024 ([2]) --- Changes in v5: - Patch 1: also leave the clean blocks at the end of the scanned part of a folio to the next punch. v4 split a clean 1 KiB cluster at EOF into two ->punch() calls, so a failed or short write next to EOF kept one cluster reserved. New reproducer: delalloc_leak_edges. - Patch 8: when a failed write's rollback keeps the allocation for a FALLOC_FL_KEEP_SIZE preallocation, also punch out the write's delalloc clusters past the new size. New reproducer: delalloc_leak_edges. - Patch 10: while the rest of the cluster is still delalloc, zero it instead of dirtying the cached folios as they are (Hyunchul). - New patches 12 and 13, moved here from part 2. They close the stale data window that patch 10 leaves when writeback or a write fault allocates a cluster during a short copy. New reproducer: killed_short_write_wb. - Patch 13 rather than Baolin Liu's "ntfs: limit writeback allocation to the dirty range" [2], which fixes the same bug: with 64 KiB clusters fsync() of 384 MiB takes 110-120 ms with patch 13 and 242-260 ms with [2], 3 runs each [3]. - Dropped Baolin Liu's Reviewed-by from patches 1, 8 and 10, whose code changed. - fstests on XFS and ext4 still give the same results with and without patches 1 and 2: https://github.com/xerrni/linux-ntfs/actions/runs/47041482649 https://github.com/xerrni/linux-ntfs/actions/runs/47041496050 - Rebased onto ntfs-next 94ebffe9b5d7. ntfs-next was rebased after v4, so v4's base is gone from it (Christoph). - Link to v4: https://patch.msgid.link/20261201-b4-ntfs-delalloc-fixes-v4-0-e5dd6f77016a@proton.me Changes in v4: - Patch 10: when zeroing the rest of the cluster fails, also record the error with mapping_set_error(), so that fsync() reports it (Baolin Liu). New reproducer: delalloc_tail_zero_failure. - Patch 10: use ntfs_zero_range_unkillable() from [1] instead of a second copy of it, with the lockdep check of the invalidate lock that the copy had. - Rebased onto ntfs-next 329758f9d73b, which adds [1], with no conflicts. - Link to v3: https://patch.msgid.link/20261130-b4-ntfs-delalloc-fixes-v3-0-874d34a6f1fe@proton.me Changes in v3: - Patch 1: split an overlong line by storing the punch start in a local variable (Christoph). - Patch 2: iomap_dirty_folio() now calls the same helper as iomap_dirty_folio_range() instead of duplicating its code; iomap_dirty_folio() still passes the mapping argument it receives, since ->dirty_folio can run without the folio lock (Christoph). - Rebased onto ntfs-next 0d9dc4ba9089, which is based on v7.4-rc4, with no conflicts. The new base includes 6fe08320c3 ("iomap: don't punch delalloc under a dirty EOF block"), which touches the same function as patch 1; that commit does not affect ntfs, since ntfs's ->punch() keeps every partly punched cluster. - The tests ran on ntfs-next 1975aab5bdb0, which differs from the new base only by f11d0178f3 ("ntfs: avoid lock inversion when stream base is the containing directory"). - fstests on XFS and ext4 (buffered_iomap) with 1k and 4k blocks give the same results with and without patches 1 and 2: XFS passes 156 (1k) and 158 (4k) tests, ext4 passes 97 (1k) and 99 (4k). The only failure is generic/223 on ext4 with both block sizes, which also fails without the patches. - [1] now points to v12 of Zhan Xusheng's short write fix. - Link to v2: https://patch.msgid.link/20261124-b4-ntfs-delalloc-fixes-v2-0-f394c800ec03@proton.me Changes in v2: - New patch 1 (iomap): one ->punch() call per run of clean blocks, so that 1 KiB and 2 KiB clusters of a dirty folio are released after a failed or short write (Hyunchul). - New patch 2 (iomap) and patch 10 (was 7): after a short copy, dirty only the rest of the cluster, so the clusters the write did not reach in the same folio are still released. - New patch 5, moved here from part 2: keep the reservations when a cluster allocation fails, instead of resetting every file's reservation or leaving a delalloc run with none (Hyunchul's question on v1 patch 1). - New patch 11: revalidate the delalloc mapping when a write fault or writeback allocated its clusters during the copy, instead of zeroing data written through a shared mapping (Hyunchul). - Patches 3-4 and 6-9 are v1 patches 1-6, unchanged. - Cc the iomap maintainers and lists for patches 1 and 2. - Link to v1: https://patch.msgid.link/20261122-b4-ntfs-delalloc-fixes-v1-0-0726f0dce403@proton.me --- Ernest Borowski (13): iomap: punch out a run of clean blocks in one call iomap: add a helper to mark a range of a folio dirty ntfs: release delalloc reservations cut off by truncate ntfs: do not consume delalloc reservations when filling holes ntfs: keep delalloc reservations when a cluster allocation fails ntfs: release the delalloc reservations of an evicted inode ntfs: do not shift the cluster number of a delalloc run on split ntfs: punch out the delalloc reservation of a failed buffered write ntfs: zero new delalloc clusters even when writeback allocates them ntfs: zero the rest of a new cluster after a short buffered write ntfs: revalidate a buffered write's mapping after its clusters were allocated ntfs: zero a write fault's new cluster before the runlist shows it ntfs: allocate delalloc clusters at writeback only for dirty folios fs/iomap/buffered-io.c | 114 ++++++----- fs/ntfs/attrib.c | 158 +++++++++++++++- fs/ntfs/attrib.h | 5 +- fs/ntfs/file.c | 34 +++- fs/ntfs/inode.c | 15 +- fs/ntfs/inode.h | 9 + fs/ntfs/iomap.c | 502 +++++++++++++++++++++++++++++++++++++++++-------- fs/ntfs/iomap.h | 1 + fs/ntfs/lcnalloc.c | 1 - fs/ntfs/runlist.c | 13 +- include/linux/iomap.h | 1 + 11 files changed, 715 insertions(+), 138 deletions(-) --- base-commit: 94ebffe9b5d71d008bff5ff3c202d4980a6f2a55 change-id: 20261122-b4-ntfs-delalloc-fixes-5ba9d4e97353 Best regards, -- Ernest Borowski