From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796291069; b=l5FmerkuvgRb/Eeype7+Tp9RwlkPiomSiqXNAlX7UYnc13D09rEo+8ggTHFc7GC3bS0K HQDxb9OmZkJN2q4jiO6Cunlql4cqgf0Kjz/hUhFgacfV8xnYkE8vidiKrRlc6yd4xD0g8 u36kG9/aITqRECXhV9Hu3wja+38aRL+2LnXAxzsMBLd/BzMluq+lsBHr3XNzQCD1HOCT0 NhtWLjMGxTvOpo1l3DAwCVn+7MQzAszMEgQYDSvOvIa72/RFuP/UDJU8j2tlLvPXR1tp9 nWTek2XsqLZ+NU4DcDcsVtj9mQyh2XRMrNPWwrIMDb80xxvcjg6O9bHvLR8smPLekyQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796291069; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=fFCgYXtLCvzz6LasTL4frnLcqbCVOrexjsZBa2ZbSSw=; b=2cnBonF86is4O7Xuf4N589zOkt0kxuRLA0RI978X4X/M45LSbq2z0wZ0Ntizjo11RtVE QXgL6lldXr+OoBEkvoqqu29+3iN0L0ZSaIMPZY5Rz5We38nGWhrJkmOjXQU2oT3YQde88 mUcrKMPaBTsTpZjrpf5jAyJIqV3M9M8K9sB3vBmbEYqbj7Er+N7miBpLr2kwb/RCDuzxu CMxUet0GOyJLZrdTiyd9fzk6qFCg7nolp4DfEiJDYpruKXFSP9KvZdmzVZZlIhKAkim3F V0IbwChgPaLmFUCNZdS9+mvVSMoEo13nDtXbB8pIe+7ImnRvJ2iGXMTbGeujAMNMasQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=TMA9PCqz; arc=none 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 B4924606A334 for ; Thu, 3 Dec 2026 09:44:29 +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=TMA9PCqz Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7AE7D1F00899; Thu, 3 Dec 2026 09:44:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796291069; bh=fFCgYXtLCvzz6LasTL4frnLcqbCVOrexjsZBa2ZbSSw=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=TMA9PCqzmIbK5GqJ5IQCt8L4ByntzJT2E4zdlN7QVVshlR63hwtM3/XHHBy6rnAzv x0mozLhbat/1KrySXE1HiLCKDAxEtqCgJ5vOKkuooHwmOxQOkaWEbalWoLJXD3zx4d b8kTASJNVVcp0jGRW3TPFoU6MGaeleXov3ywyG5qjJi0Tyyf/IWbkn/l9BA9z7kiGA 3HkbQmQVgGze5PUasvfHF9c3RN2AmAXE7fc/kMT9Yoa78TSEPve+0Px6uHxObnCPcR ygtFAvaYt3a/i1xIY7JCwR3v+eNwAbIm9+2Kj1YfzKs9y4vB6VMSBriBekQ3A0D/wc xhldzmsMVChtw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] ext4: punch hole beyond i_size Reply-To: sashiko-reviews@lists.linux.dev To: "Ding Feng" Cc: linux-ext4@vger.kernel.org, tytso@mit.edu In-Reply-To: <20261203091435.73786-1-dingf3ng@gmail.com> References: <20261203091435.73786-1-dingf3ng@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 09:44:29 +0000 X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [High] ext4: exclusive end_lblk in ext4_fc_track_range() overflows on punch hole - [Low] ext4: Fixes trailer cites a4bb6b64e39a instead of 2be4751b21ae - [Low] ext4: ext4_punch_hole() zeroes past EOF when offset is in EOF block tail -- commit 6c7b0de4bc9b53afc710b59ac9a160251726fde0 Author: Ding Feng > ext4: punch hole beyond i_size > > ext4_punch_hole() returns early when the hole starts at or past i_size, > and otherwise ends it at the block that holds i_size. Blocks that > fallocate(FALLOC_FL_KEEP_SIZE) allocated past EOF can therefore never be > punched out; only a truncate frees them. XFS and tmpfs remove them. > fallocate(2) says that "within the specified range, partial filesystem > blocks are zeroed, and whole filesystem blocks are removed > from the file". > > A 4096-byte file with 1 MiB allocated by FALLOC_FL_KEEP_SIZE, then > PUNCH_HOLE|KEEP_SIZE over [4096, 1M), on v7.4-rc5 (x86_64, QEMU): > > ext4 st_blocks 2048 -> 2048 > xfs st_blocks 2048 -> 8 > tmpfs st_blocks 2048 -> 8 > > Hugh Dickins reported this in 2012 [1]. Allison Henderson's fix removed > the early return [2], and Lukas Czerner carried it in a later series, > but it was held back: the LSF 2012 discussion concluded to wait for range > locks rather than take i_mutex for a punch beyond i_size [3]. Today > ext4_punch_hole() always runs with the inode lock held. > > Remove extents up to the end of the range. Partial-block zeroing still > stops at the block that holds i_size, so nothing past EOF is written. > > [1] https://lists.openwall.net/linux-ext4/2012/01/12/3 > [2] https://lists.openwall.net/linux-ext4/2012/01/14/7 > [3] https://lists.openwall.net/linux-ext4/2012/05/16/3 > > Reported-by: Hugh Dickins > Fixes: a4bb6b64e39a ("ext4: enable "punch hole" functionality") > Signed-off-by: Ding Feng [Severity: Low] Commit a4bb6b64e39a ("ext4: enable "punch hole" functionality") did not check offset >=3D inode->i_size or clamp the hole end to i_size. Both were introduced in commit 2be4751b21ae ("ext4: fix 2nd xfstests 127 punch hole failure"). Should the Fixes tag be updated to: Fixes: 2be4751b21ae ("ext4: fix 2nd xfstests 127 punch hole failure") > diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c > index 07a62d8569d31..8031463792b15 100644 > --- a/fs/ext4/inode.c > +++ b/fs/ext4/inode.c [ ... ] > @@ -5371,19 +5372,16 @@ int ext4_punch_hole(struct file *file, loff_t off= set, loff_t length) > if (!ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) > max_end =3D EXT4_SB(sb)->s_bitmap_maxbytes - sb->s_blocksize; > =20 > - /* No need to punch hole beyond i_size */ > - if (offset >=3D inode->i_size || offset >=3D max_end) > + if (offset >=3D max_end) > return 0; > - > - /* > - * If the hole extends beyond i_size, set the hole to end after > - * the block that contains i_size to save pointless tail block zeroing. > - */ > - if (end >=3D inode->i_size) > - end =3D round_up(inode->i_size, sb->s_blocksize); > if (end > max_end) > end =3D max_end; > length =3D end - offset; [Severity: High] Can removing the i_size clamp cause ei->i_fc_lblk_len to overflow to 0 in fast commit tracking? With huge_file enabled, ext4_max_size() sets sb->s_maxbytes to 0xffffffffLL << blkbits. Without the i_size clamp, punching [0, sb->s_maxbytes) on a file of any size sets end_lblk to 0xffffffffU, which ext4_punch_hole() passes to an inclusive-end API: fs/ext4/inode.c:ext4_punch_hole() { ... start_lblk =3D EXT4_B_TO_LBLK(inode, offset); end_lblk =3D end >> inode->i_blkbits; ... ext4_fc_track_range(handle, inode, start_lblk, end_lblk); } In __track_range(), ei->i_fc_lblk_len is computed as __arg->end - __arg->start + 1 in 32-bit ext4_lblk_t arithmetic. When start_lblk is 0 and end_lblk is 0xffffffffU, ei->i_fc_lblk_len wraps to 0. On fsync(), ext4_fc_snapshot_inode_data() treats 0 as no modified ranges and succeeds without logging DEL_RANGE or prior ADD_RANGE records. Crash recovery then resurrects the punched extents (risking block cross-linking) and drops prior writes from the same transaction. For ordinary post-EOF punches, tracking exclusive end_lblk also includes an uncached block past the hole, hitting EXT4_FC_SNAP_ERR_ES_MISS and falling back to a full journal commit. On sub-block punches, calling it outside if (end_lblk > start_lblk) passes start_lblk >=3D end_lblk. Moving ext4_fc_track_range(handle, inode, start_lblk, end_lblk - 1) inside if (end_lblk > start_lblk) fixes both. > + /* > + * Blocks past i_size (from FALLOC_FL_KEEP_SIZE) are removed too, but > + * nothing after the block that contains i_size needs zeroing. > + */ > + zero_end =3D min_t(loff_t, end, round_up(inode->i_size, sb->s_blocksize= )); > =20 > ret =3D ext4_update_disksize_before_punch(inode, offset, length); > if (ret) > return ret; > =20 > @@ -5394,9 +5392,12 @@ int ext4_punch_hole(struct file *file, loff_t offs= et, loff_t length) > if (ret) > return ret; > =20 > - ret =3D ext4_zero_partial_blocks(inode, offset, length, &partial_zeroed= ); > - if (ret) > - return ret; > + if (offset < zero_end) { > + ret =3D ext4_zero_partial_blocks(inode, offset, zero_end - offset, > + &partial_zeroed); > + if (ret) > + return ret; > + } [Severity: Low] Will this still zero and dirty the EOF block when offset is at or past i_size? When i_size is not block-aligned and a punch starts in the EOF block tail (i_size <=3D offset < round_up(i_size, sb->s_blocksize)), offset < zero_end is true. ext4_zero_partial_blocks() then reads and dirties or journals the written EOF block, triggering writeback (synchronously under O_SYNC). Guarding the call with if (offset < inode->i_size) avoids writing past EOF while keeping zero_end for punches starting below i_size. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203091435.7378= 6-1-dingf3ng@gmail.com?part=3D1