Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.127.230.113 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796060384; b=oaV6f3qnBDlyyS3A3Z59UZpzAR5bStAA07hAR1I6RekAuifzIfvaayG991PO0HYr7H8T LZsP0BPelbzNDayhzjNH5qjozUee5BtVOroAq9k6d+guplSMUkrE2VTKZATYwAuiGZNpp Mvt3xPm8ir2is65lNuDw7g55MXlwtZZlO7o0iDi7ceMAw5ALdXEz4RzBIVSGevao1ZLgc 6XYwIWVpxKLj7NfgJQsAQ00RKDX0OGtlZ8pYyLzbx1JIqH7+UENLezCy6fqlEtzTT4eCE ynVPovvG4ZwBDmFs3Kr8csKvLhmFjKcBBL4dwuns63WrYLEN9Um1yR1nu/Azac/2HxA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796060384; h=DMARC-Filter:DKIM-Signature:Content-Type:X-Original-From:In-Reply-To: References:From:Message-Id:To:Date:Mime-Version:X-Lms-Return-Path: Content-Transfer-Encoding:Cc:Subject; bh=E0nSkfmJVqVyB7xbGONgRIBlZGitAr3qi4jBAVJU0dM=; b=qt02kzrEO7B5UxKLmayVVCmXu8v3RwsprM0Dk255XhFQL++FLK9qclDgcNV+SK/rUK3X o7qpeZlFhTTzkySrdVnhW0NvDSQPdFtlZ2WxsB+/ItnzbbIHLd859ISd6MW3fqeNmL1md JCqMux9ixoKkvN4fLzwZXNoIHU0di2jFz10AwKyNJDf9/P0uG41wzK02mSNLo7GjWKMcb MhgtUS/5a7/tp+STtruF3tMr6VfZAz3TK7ghI6DERTwmad6RE1SI6FYUYU7tmxGBYe8am x0ddGV64/Gq8cdfTFAqAua2abbdfqslTUhRZG8wFEWYik3ae6mDHS3NlKCrjFP2pOfw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass header.d=bytedance.com header.i=@bytedance.com header.a=rsa-sha256 header.s=2212171451 header.b=OKICJRmB; arc=none smtp.remote-ip=209.127.230.113 Received: from va-1-113.ptr.blmpb.com (va-1-113.ptr.blmpb.com [209.127.230.113]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A0BE8606A325 for ; Mon, 30 Nov 2026 17:39:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A0BE8606A325 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.a=rsa-sha256 header.s=2212171451 header.b=OKICJRmB DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1796060380; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=E0nSkfmJVqVyB7xbGONgRIBlZGitAr3qi4jBAVJU0dM=; b=OKICJRmBfmxV2Ldn4a+ySXVuS1Q1iTg3/97ROcaV4mC90eK1FYg8DsnEtyyGaA180BqB6E PPerK2Ik7c7bEUhSv6NoXkKOgAD8HbPPZvO0xw4TgQfqMwAkQSCMDWjaVetA7wZbcEIVCU YgABLz4uoTZogXEZbZqc4m7B0JQzWLl5Gbi/x5We7dJY/0asXBAt3s2beAwTWJwmHFTFCR 9f+nXtjb1tH3nP4PEUhn2T2s2QzGxZycbtfeguGUIuz8j5VWwOXejzrjnL9oQWht6Cc0q+ 0F1n9kNnkfuHing43yijTe67oiG8HLecm2BgwCLRf69BzvS3TDpkT2Di4BPRaQ== Content-Type: text/plain; charset=UTF-8 X-Original-From: Xing Ma In-Reply-To: <20261201013742.1563067-1-maxing.lan@bytedance.com> References: <20261201013742.1563067-1-maxing.lan@bytedance.com> From: "Xing Ma" Message-Id: <20261201013742.1563067-3-maxing.lan@bytedance.com> To: Date: Tue, 01 Dec 2026 01:37:44 +0800 X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 X-Lms-Return-Path: Content-Transfer-Encoding: 7bit Cc: "Theodore Ts'o" , "Andreas Dilger" , "Jan Kara" , "Baokun Li" , "Ojaswin Mujoo" , "Ritesh Harjani (IBM)" , "Zhang Yi" , "Harshad Shirwadkar" , Subject: [PATCH v2 2/2] ext4: track truncated block range in ext4_truncate() for fast commit Truncation range tracking (ext4_fc_track_range()) is currently only called in ext4_truncate_down(), which misses three cases where ext4_truncate() frees extents: 1. Same-size ftruncate(fd, oldsize) dropping FALLOC_FL_KEEP_SIZE preallocated blocks beyond EOF jumps straight to ext4_truncate() without calling ext4_fc_track_range(). 2. If a commit occurs between ext4_truncate_down() stopping its handle and ext4_truncate() starting a new handle in transaction T+1, ext4_fc_track_inode() resets i_fc_lblk_len to 0 and freed extents are not tracked. 3. If ext4_ext_remove_space() or ext4_ind_truncate() restarts the journal handle onto a new transaction, earlier tracking belonged to the previous transaction. In all three cases, a subsequent fast commit omits EXT4_FC_TAG_DEL_RANGE and resurrects freed extents (or emits an indirect-mapped inode without falling back to a full commit) after crash recovery. Case 1 reproduces deterministically on -O fast_commit: xfs_io -f -c "pwrite -S 0xaa 0 4k" -c "falloc -k 4k 64k" mnt/foo sync xfs_io -c "truncate 4k" -c "fsync" mnt/foo # crash (dm-flakey drop_writes) and remount: # stat -c %b mnt/foo returns 136 instead of 8 Call ext4_fc_track_range(handle, inode, start_lblk, EXT_MAX_BLOCKS - 1) in ext4_truncate() unconditionally (matching ext4_truncate_down()) after checking err and !ext4_handle_is_aborted(handle), so both extent-based and indirect-mapped inodes are tracked safely without dereferencing a NULL handle->h_transaction after a failed journal restart. Fixes: aa75f4d3daae ("ext4: main fast-commit commit path") Cc: stable@vger.kernel.org Signed-off-by: Xing Ma --- fs/ext4/inode.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 07a62d8569d31..22560318d2348 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5608,6 +5608,15 @@ int ext4_truncate(struct inode *inode) if (err) goto out_stop; + if (!ext4_handle_is_aborted(handle)) { + ext4_lblk_t start_lblk; + + start_lblk = inode->i_size > 0 ? + (inode->i_size - 1) >> inode->i_blkbits : 0; + ext4_fc_track_range(handle, inode, start_lblk, + EXT_MAX_BLOCKS - 1); + } + if (IS_SYNC(inode)) ext4_handle_sync(handle); -- 2.39.5