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=1796146970; b=Y6go8WHV0AI0IJvE6vVeTnhTmZnkk6ug4BH0wAZBHZdV7z94BcFLlKhhHOZ33JSATAaO rXjH5ws/II3WGT4+7/DcIgLimhMyT86a0uWLFEueZp7s+Lsu5eiRkyuX59VAGaTlMMHHb DP2/pXyfM3g37apHpdvcuzMMfw8XYuVNHPsC+2RUUEA7pS3lrWW+85dVSv/vXLiVMm6jj vSnCYE5UIm6LpHHnDP7d75ICLf2AfH90038N47wHXAgQdLeOrFEbRTcjU7/BF7/LZhKQ4 bb54E4uFpq9cqMWWZDNf99zxrVhkRlFTq9gPCzGhj/SWwMLwtSmG2JdiKHwc+3CPQMA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796146970; 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=PN2ZkANBOvn8o//LBCZRIqxKxNNl7pZ53S2wLkbHYPY=; b=jp35SHzt9v6JP/8hA08wlmXIKs7POXTTKgQ6GVjqRRaqY7UwTdYgUnubcoxaf7Z9wMCD /lQFN/HnZFBeOEZWCj4E8qUYTGCEu6P8mvAiTnTcTnGUKUFrlIFfyAnsD/X+dv4aqGvPw Zp6QbWgcmkqMY5Us/KvnPIMCTZJJTMGr23ESrNMSzYPk12i1XNQWutaqO6db7gFSDO0H/ By3UA1IUvOO9qeVnwXuh606xX4IBhZ4f35Dx9zX01sQmv3wWMEqAShetTGQeKzHRuZfM6 us1ZwlAJ9qvtJ0oh/q5tG1PJEAjRpYU/C3CZUtQSBRzACRFbSUQYg71R8QlfrzbjskA== 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=ElOTqupJ; 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 B0DF2606A32D; Tue, 1 Dec 2026 17:42:50 +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=ElOTqupJ 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=1796146970; b=bmjz1ud9TK24onN5+7IgsSZuPsP9ldJbe4rq71mubKUO+0VstONPBejojhhAuTkuchQ4 0jczCa1QQ97qU29nnVO1gMXf0nQF4G7u22rV6xg8B/zn6evGu2w1mILoAVdG5RwuH9XyS p9NfDa8GcxOKnr6beYoDAfUbmzVSMiGJBYbsx6ky1Ej4qbfDMyIqo38nKWXb6lv13/Z9S riMOVltpbZiOnHB+cHTvJipTJ7lsWZ0XnKRhWdXgLDr14UtDtIN1pELQmm07JeKa0hbLE vGpwe5FWCSc/OEM+6/0KUW8CQZhI6fUw6+RlL2zr804R4PmgLSY8VcXrPaws2PSg6Sw== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796146970; 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=PN2ZkANBOvn8o//LBCZRIqxKxNNl7pZ53S2wLkbHYPY=; b=ILCSn5DKXi1RW/SkLcBFoHcpdJhPzURT3a3hsDr00z1HU7LEblaqk+0idgevrGsN7FyL CT2xIN38g+3zY8fOQFazllfa+s6vmjXvoGymkyMfv3yRvH5ldJc5XVGoYXmpAz0hHetcW UEuc0QqaWsdeoZBd4prKJEcuEOforELGQ5q6zdbwNXDEdfNVMxp7AaOLhyj4jHL/a9SM+ r+lBF9sKHpy2c3QTwoED00uoXBp63fCzHYLXDiKOfnVwSr99sEXE66aDMUqg5nbSrTb2Q BZl+YMXSbi5oae4uI7Z4icxeAOTLALFCQ8s0UBq8+jmO9b/aBoCzdqe/rKPvZBpt4Tw== 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 4137D1F00925; Tue, 1 Dec 2026 17:42:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796146970; bh=PN2ZkANBOvn8o//LBCZRIqxKxNNl7pZ53S2wLkbHYPY=; h=From:Subject:Date:To:Cc:Reply-To; b=ElOTqupJ3rJYpDQsaLCYU5yr6IUVZGIERjWau3eitRpmzU1asefEzKncK38WXpuYJ JsLtMBOevSYypKwwousywixXvxNgt/V8waHZIpaBJr9sBcNFMoeZdyYYqsR3SJ/y6a ZsPeaiGQiiKYrAUjmbpajCf9R38XuKrG7WrqLUrSq1zbVl9uLXNJBqOPu+6BnW1kvf r9+WHmwI6/HI1xuA2Rk7r+0d3D43KhnLhEdQU+vVvgxDBd+udOLvZIjHur9Rk21xF4 YV+rYAPpeVXPuyGMG9OGT8P4qfEQzmQTeg9k0+j+U/7rm1W0UnDfhUT0UTMTLIi2o3 LT1OcQwG9l4ZQ== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 422F54EF0F; Tue, 1 Dec 2026 17:42:38 +0000 (UTC) From: Ernest Borowski via B4 Relay Subject: [PATCH v4 00/11] ntfs: delayed allocation accounting and stale data fixes, part 1 Date: Tue, 01 Dec 2026 18:42:35 +0100 Message-Id: <20261201-b4-ntfs-delalloc-fixes-v4-0-e5dd6f77016a@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/4XOyW7CMBQF0F9BXveBJxLSVf8DsfDwTFylNrLdi Arl32uHTaQKdXnfcHQfJGPymMn77kESzj77GGqQbztiRhWuCN7WTDjlHWOcg5YQistgcVLTFA0 4f8cMR60GK3HoxVGQ+nxLuC7q7/nyzPlbf6IpTWsXWmUEnVQwYxs19LDKAe+lHYw+l5h+1moza 9C/LWYGFGjPO0etQUnFxy3FEsP+C0lrMfMtI18yvDJODNKcKEXzlxEbRtCXjKjMqZdWSNU55nD LLMvyCw2eryd9AQAA 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 X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=8346; i=ernest.borowski.git@proton.me; s=default; h=from:subject:message-id; bh=e3XzqE43lN49AZwjUH13SR9t442yixCBojXFvBjIoog=; b=owGbwMvMwCVWzJ65uCpJ5D/jabUkhmx+dm4lk7SbC6/t/dwRt2rf0wPzPq0+lqCwlevLw6Se7 4sjLrd96ChlYRDjYpAVU2Tp+H8jxCfk26dlcVp9MHNYmUCGMHBxCsBEzp5m+F9w1Fn0BKfT/N9H a4KFOR0P14Q8MVRxd3ZNbrlywL9OOIuR4ff1KHmTTw2Rt1gWWrrGvvKYu3HivKMCKhOffinj28z fwg8A 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 A write/truncate/punch-hole stress test on a 128 MiB volume showed the free space reported by statfs() falling from 79 MB to zero within 80 seconds, after which writes failed with ENOSPC or came back short, while $Bitmap stayed correct. The delalloc reservations in vol->dirty_clusters were not given back on several paths. The same paths also had buffered writes into holes that exposed old disk contents. The series has four groups: Patches 1-2 (iomap) are small prerequisites for patches 8 and 10. ntfs reserves delalloc space in whole clusters, and a cluster can be smaller than a folio (1 KiB or 2 KiB clusters with 512-byte blocks). Patch 1 passes each run of clean blocks to ->punch() in one call, so that ntfs sees a whole clean cluster and can release it. Patch 2 adds iomap_dirty_folio_range(), which patch 10 uses to dirty part of a folio. For XFS and ext4 the only effect of patch 1 is fewer ->punch() calls, and patch 2 changes nothing for them. Patches 3-6 fix reservations that were lost or dropped: on truncate (3), when fallocate(), direct I/O or page_mkwrite() fill a hole (4), when a cluster allocation fails (5), and when a named stream is removed or an inode is evicted (6). Patches 7-8 handle a buffered write that fails after ->iomap_begin() reserved its clusters, which left delalloc runs that no data covers. Patch 7 fixes the runlist split helpers, which turned such a run into real clusters when it was punched or collapsed, and so corrupted $Bitmap. Patch 8 turns the clusters the write did not use back into holes, so that no such run is left. Patches 9-11 fix buffered writes into holes that showed old disk contents or lost data written through a shared mapping: - patch 9: the zeroing of a new cluster's edges gave up as soon as writeback allocated the cluster; - patch 10: a copy that stopped inside a new cluster left the rest of the cluster unzeroed; - patch 11: when a write fault or writeback allocated the clusters during the copy, the write zeroed blocks instead of reading them, which overwrote data written through a shared mapping. All patches are Cc stable. Dependencies: - patches 1, 2, 3, 4 and 7 apply on their own; - 5 needs 4, 6 needs 3, and 8 needs 6; - 9 needs 8, 10 needs 9 and 2, and 11 needs 9; - 8 also needs 1 to release clusters smaller than a folio. 3 --> 6 --> 8 --> 9 --> 10 <-- 2 ^ | 1 +--> 11 4 --> 5 7 The series is based on ntfs-next, which now has Zhan Xusheng's "ntfs: trim the sizes after a short write" [1]. Patch 10 uses the helper that [1] added, which zeroes from a worker when the writer has a fatal signal pending (iomap_zero_range() refuses to run then). Part 2 follows with five more patches: st_blocks of delalloc data, and the remaining stale data windows of write faults, writeback and direct I/O into holes. Each bug fixed here has a reproducer that fails before and passes after its fix. The reproducers run in QEMU on a kernel with KASAN, lockdep and UBSAN, at 512 B, 1 KiB, 2 KiB, 4 KiB, 16 KiB and 64 KiB clusters, with ntfsck -n after every case, on Ubuntu 26.04 and Arch Linux. On ntfs-next 329758f9d73b the nine reproducers of these bugs (short_copy_stale, delalloc_accounting, delalloc_alloc_failure, delalloc_failed_write, delalloc_zero_race, stale_wb_race, delalloc_partial_fail, stale_write_mapping, delalloc_tail_zero_failure) pass with this series, except for the st_blocks check of delalloc_alloc_failure, 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/46674620717 ntfs-next + this series: https://github.com/xerrni/linux-ntfs/actions/runs/46674607930 [1] https://lore.kernel.org/all/20261127031053.3695758-1-zhanxusheng1024@gmail.com/ --- 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 (11): 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 fs/iomap/buffered-io.c | 45 +++++-- fs/ntfs/attrib.c | 130 +++++++++++++++++++- fs/ntfs/attrib.h | 2 + fs/ntfs/file.c | 5 +- fs/ntfs/inode.c | 13 +- fs/ntfs/inode.h | 3 + fs/ntfs/iomap.c | 321 +++++++++++++++++++++++++++++++++++++++---------- fs/ntfs/iomap.h | 1 + fs/ntfs/lcnalloc.c | 1 - fs/ntfs/runlist.c | 13 +- include/linux/iomap.h | 1 + 11 files changed, 452 insertions(+), 83 deletions(-) --- base-commit: 329758f9d73b0ec537302c23c0507bbb2d495263 change-id: 20261122-b4-ntfs-delalloc-fixes-5ba9d4e97353 Best regards, -- Ernest Borowski