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=1796456664; b=R15jn8nkoVH5Rw7l1oW/ydB4Mi2BbEYM7nUvawv1EfIVMSoFE6zXrqIVk6xf7f4bQ7DS h796RtOt/+P/sGKj69yVHKi3dSWnlL0kHIFmXW0dcSQFZiZ5LLJ9LcUgoBJRVHyUMBs63 gD5XqFB2IbDyKMQMLKszEL+dLt21zCLm1pvbUnUwcynU8R8zQVYHpk+q0Y0V4+xRCkQcf 3qS93ODpfqlBwaCQtoUtxfLryG68NsJxzTkorjb+HGcW6+wBLrKSQ8WuMTut36rNAD2qp kLS6IWw2IubWh/M9NbeQLV6fWf9r+LNjmdBTL+ban/1kaOr6SWBZqrjcxsNkAYYPW+A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796456664; h=Received:DKIM-Signature:Message-ID:Date:MIME-Version:User-Agent:Cc: Subject:To:References:Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=V3ExJaIX79VUYltp/GvUuTRIBeN7pBv+f4JLYwJUP1w=; b=OSI5MmppQQdPXZwTlLEcQf8qHp8uZrkdq+hb165/MDqGWvJavkSDcNztCMqb27dOl1jF nlF7NkajNZih1QyhRdyscTyCF1AZGbQ/pOg058aQ29c0OjINEjfSBxW91+bYjnXotc0p6 hejmCxJkljpVOmc4BC2AdpfOYswRGcg/JvC8pJt4Cssh4pVP08WeGQFALqbLqWflB2FWY oC4NgPcPLOAU2Ik1nJMZGqrm3GxhXD8PdcVrM7MuPSBCWjC9jQZN9Yx9JoBkJmv+M0EZ9 PF7+O2Rdeyxb7AACT57G1IEIXP4fcL6Q6LqiKz6V9cWvWTKWWEmQBzQCvOYTa9aTqUw== 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=JUFZouXU; 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 C2837606A322; Sat, 5 Dec 2026 07:44:24 +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=JUFZouXU Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2471C1F0092B; Sat, 5 Dec 2026 07:44:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796456664; bh=V3ExJaIX79VUYltp/GvUuTRIBeN7pBv+f4JLYwJUP1w=; h=Date:Cc:Subject:To:References:From:In-Reply-To; b=JUFZouXUd8gQ1DUxPzCLd2TePBz+F2IQhjzz9ISnUgRCfzHoQXwOiGAOKg4xCqT5Y ws6R3rZ0iIt8UMxF6BjiKL+s+fdJmxYNwXJEw600emNrxjRdOitlJgknN+ugq7vxtf O84Cs4L1BS5X1Wm/nrruGZK+2jBMG7hSNGHr+/ltdlGqQRhxMLkTzB5P9BSf0OoWCZ qEBqATp1WKzNf91urLnwgTvmzF9Zt+5BuruLG5mFYXK7zy5gQVfqFfnb1ZL6VhVPbz hymJgpxR5A0J5tLDnbowa91jnNeJVmYRLhFAiUlHE5fQBClBcQoXXgoRNDUk5+E3zX UO7ckT4C4r2Uw== Message-ID: <64a8c25c-25be-42dc-85f0-1ff77b29ec85@kernel.org> Date: Sat, 5 Dec 2026 15:44:21 +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 User-Agent: Mozilla Thunderbird Cc: chao@kernel.org, jaegeuk@kernel.org, Daeho Jeong , linux-kernel@vger.kernel.org, stable@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Subject: Re: [f2fs-dev] [PATCH 4/6] f2fs: atomic: fix to keep committed data of atomic file in f2fs_write_failed() To: Daeho Jeong References: <20261201110842.1825797-7-chao@kernel.org> <20261201110842.1825797-10-chao@kernel.org> <54fce779-4920-4ece-b5fa-de97c7713689@kernel.org> Content-Language: en-US From: Chao Yu In-Reply-To: <54fce779-4920-4ece-b5fa-de97c7713689@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 12/5/26 15:43, Chao Yu wrote: > On 12/4/26 02:07, Daeho Jeong wrote: >> On Tue, Dec 1, 2026 at 3:10 AM Chao Yu via Linux-f2fs-devel >> wrote: >>> >>> From: Chao Yu >>> >>> With F2FS_IOC_START_ATOMIC_REPLACE, i_size of the original inode is set >>> to zero, and the old i_size is saved in fi->original_i_size. If a later >>> write past i_size fails in f2fs_write_begin(), f2fs_write_failed() will >>> truncate blocks of the original inode beyond i_size, i.e. committed data: >>> >>> f2fs_ioc_start_atomic_write(truncate=true) >>>   original_i_size = 512KB, i_size = 0 >>> pwrite(0, 100000) >>>   i_size = 100000, blocks are reserved in COW inode >>> pwrite(300000, 4096) >>>   f2fs_write_begin >>>    f2fs_filemap_get_folio                -ENOMEM >>>    f2fs_write_failed(inode, 304096) >>>     f2fs_truncate_blocks(inode, 100000)  frees committed blocks 25..127 >>> f2fs_ioc_abort_atomic_write >>>   i_size = original_i_size (512KB) >>> >>> Then, aborting the atomic write, or a crash before commit, leaves holes >>> in the original file, or loses the whole file if the failing write comes >>> first, while fsck.f2fs reports nothing. >>> >>> Reproducer (4KB blocks): >>>    write 512KB to a file, fsync >>>    ioctl(fd, F2FS_IOC_START_ATOMIC_REPLACE) >>>    pwrite(fd, buf, 100000, 0) >>>    pwrite(fd, buf, 4096, 300000)  -> -ENOMEM w/ FAULT_PAGE_GET injected >>>    ioctl(fd, F2FS_IOC_ABORT_ATOMIC_WRITE) >>> >>> Before: 103 of 128 blocks are zeroed, and freed on disk >>> After:  original data is intact >>> >>> Fix it by never truncating an atomic file below original_i_size in >>> f2fs_write_failed(), so that only blocks preallocated w/ >>> FALLOC_FL_KEEP_SIZE beyond it are freed, as for a regular file. >>> >>> Also round it up to the block size, otherwise truncate_partial_data_block() >>> zeroes and dirties the partial block via the original inode, while the >>> folio may hold uncommitted data and have lost its atomic flag after it >>> was written back to the COW inode, then the uncommitted data would be >>> written to the original inode. >>> >>> For non-replace atomic write, i_size never goes below original_i_size, >>> so only the round up applies. Regular files are not affected. >>> >>> Fixes: 41e8f85a75fc ("f2fs: introduce F2FS_IOC_START_ATOMIC_REPLACE") >>> Cc: stable@vger.kernel.org >>> Cc: Daeho Jeong >>> Signed-off-by: Chao Yu >>> --- >>>   fs/f2fs/data.c | 11 +++++++++++ >>>   1 file changed, 11 insertions(+) >>> >>> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c >>> index aecedd3a4298..5f6ad38c0de1 100644 >>> --- a/fs/f2fs/data.c >>> +++ b/fs/f2fs/data.c >>> @@ -5168,6 +5168,17 @@ void f2fs_write_failed(struct inode *inode, loff_t to) >>>                  filemap_invalidate_lock(inode->i_mapping); >>> >>>                  truncate_pagecache(inode, i_size); >>> +               /* >>> +                * The original inode of an atomic file holds committed data >>> +                * below original_i_size, don't truncate it, as i_size can be >>> +                * smaller in atomic replace mode. Round it up as well, so the >>> +                * partial block, which may hold uncommitted data, won't be >>> +                * dirtied via the original inode. >>> +                */ >>> +               if (f2fs_is_atomic_file(inode)) >>> +                       i_size = round_up(max_t(loff_t, i_size, >>> +                                       F2FS_I(inode)->original_i_size), >>> +                                       F2FS_BLKSIZE(F2FS_I_SB(inode))); >>>                  f2fs_truncate_blocks(inode, i_size, true); >>> >> >> Hi Chao, >> >> The analysis looks right to me, and the change covers both cases. > > Daeho, thanks for the review! > >> >> One thought. ->write_begin() of an atomic write reserves blocks only in the >> COW inode (prepare_atomic_write_begin() -> __reserve_data_block(cow_inode)), >> and w/ 5/6 f2fs_preallocate_blocks() doesn't touch the original inode >> either. So a failed atomic write leaves nothing for f2fs_truncate_blocks() >> to free in the original inode. The only thing it can still do there is to >> free the blocks preallocated w/ FALLOC_FL_KEEP_SIZE, and that is a change >> to the original inode which abort can't roll back, like the ones 5/6 and >> 6/6 remove. >> >> How about skipping f2fs_truncate_blocks() for an atomic file instead? Yes, I agreed. > > Actually, I kept extend truncation intentionally, as I investigated that SQLITE w/ > atomic write will do this during commit phase, I don't want to break this to cause > any regression. > > And previously, I noticed the post eof issue, and fixed in another 'post eof' patchset, > which was in my tree below, I have not yet had time to send them to mailing list, sorry. > > https://git.kernel.org/pub/scm/linux/kernel/git/chao/linux.git/commit/?h=bugfix/common&id=2ecf6804d6b58b01402260c140115a6a357ca6f5 > > Thanks, Sorry, please ignore this, my bad, reply to wrong email. :P Thanks, > >> >> Then it needs neither original_i_size nor the round up, as >> truncate_partial_data_block() is not called at all. It would be better >> to put 5/6 >> before this one in that case. >> >> Thanks, >> >>>                  filemap_invalidate_unlock(inode->i_mapping); >>> -- >>> 2.49.0 >>> >>> >>> >>> _______________________________________________ >>> Linux-f2fs-devel mailing list >>> Linux-f2fs-devel@lists.sourceforge.net >>> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel >