From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4F425C28B2F for ; Fri, 14 Mar 2025 22:22:02 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1ttDPk-0001Tp-Cd; Fri, 14 Mar 2025 22:22:00 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1ttDPj-0001Tj-6H for linux-f2fs-devel@lists.sourceforge.net; Fri, 14 Mar 2025 22:21:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=In-Reply-To:Content-Type:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=ivQn2WwHohzkMtNxCOJ0M6XkGvOtIV9+bdbVpzvMgEU=; b=MQBd1leD5oGASkBCKigf8rsUGb JW32BAOrf5dl+ilfP7yY002UQinynHGBGsgOiFPVzbDnpQLp0Z/SrUC5ATwZ9shyv5g4Jq+7YMnyh e0vm3P+YTRvihuLRX3gKMQSWgG+8fKznltl8l0n5Dhlf0XF5MMSEHQgOEo8PsHiTUj58=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To :From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=ivQn2WwHohzkMtNxCOJ0M6XkGvOtIV9+bdbVpzvMgEU=; b=LIxnno9p6cO8uc1RszccNMzU6E U5n15JN6tJbLIbbETiBG0XmnX8krkTr6Q2adFv0C5eZbMfsk/djpVpbu4vnOsruAajI1KELMR1Zwg uvpjyeMffC0HWkitvR7z0VBx3xAbHpu2u0I3x92la+ECZ87P5EX6jM0XSqF2/vc5dJyg=; Received: from dfw.source.kernel.org ([139.178.84.217]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1ttDPd-0007GU-U8 for linux-f2fs-devel@lists.sourceforge.net; Fri, 14 Mar 2025 22:21:59 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id B47425C55F4; Fri, 14 Mar 2025 22:19:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DDED3C4CEE3; Fri, 14 Mar 2025 22:21:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741990903; bh=yXi4VV69OQ5J9Ch0qeBs+FaNnX2iPv7Ofe2QeSUOJQc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=JPZyqGBdCCTlOuxqJOyOY/F0hpQQiyf/XDttYCvQLw/W9A2dB1OJBCexbEKyxnRhb V9Q5RpWD76b2LnGmJJMcyBdR6o9wxyND4oBSnPADxB5XokeViyyViTk4LgUVfteA2O tfi4zJdH4WZ1Bw/ZTnx7+ib2S8kxb8Roxgi7EMgKNg2mNQRhGQLUAdY6bXHyRbVyh0 C2IgJkvfxcERKbZNyr/Fwy5qVf+VUboQatcnUpHi97UDaI4dVoCQUytBLCYd/ZA6w8 rtvvHhEC/hICWn7/PsPG6AS2kj1XN9G0pfkLUer+mJKsBjFh/hWovJwyKAl5CH/mM/ YkP6WZZoYMKAQ== Date: Fri, 14 Mar 2025 22:21:41 +0000 To: Yeongjin Gil Message-ID: References: <20250314120651.443184-1-youngjin.gil@samsung.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Headers-End: 1ttDPd-0007GU-U8 Subject: Re: [f2fs-dev] [PATCH] f2fs: fix to avoid atomicity corruption of atomic file X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Jaegeuk Kim via Linux-f2fs-devel Reply-To: Jaegeuk Kim Cc: linux-f2fs-devel@lists.sourceforge.net, daehojeong@google.com, linux-kernel@vger.kernel.org, sj1557.seo@samsung.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net On 03/14, Jaegeuk Kim wrote: > On 03/14, Yeongjin Gil wrote: > > In the case of the following call stack for an atomic file, > > FI_DIRTY_INODE is set, but FI_ATOMIC_DIRTIED is not subsequently set. > > > > f2fs_file_write_iter > > f2fs_map_blocks > > f2fs_reserve_new_blocks > > inc_valid_block_count > > __mark_inode_dirty(dquot) > > f2fs_dirty_inode > > > > If FI_ATOMIC_DIRTIED is not set, atomic file can encounter corruption > > due to a mismatch between old file size and new data. > > > > To resolve this issue, I changed to set FI_ATOMIC_DIRTIED when > > FI_DIRTY_INODE is set. This ensures that FI_DIRTY_INODE, which was > > previously cleared by the Writeback thread during the commit atomic, is > > set and i_size is updated. > > > > Fixes: fccaa81de87e ("f2fs: prevent atomic file from being dirtied before commit") > > Reviewed-by: Sungjong Seo > > Reviewed-by: Sunmin Jeong > > Signed-off-by: Yeongjin Gil > > --- > > fs/f2fs/inode.c | 4 +--- > > fs/f2fs/super.c | 4 ++++ > > 2 files changed, 5 insertions(+), 3 deletions(-) > > > > diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c > > index aa2f41696a88..83f862578fc8 100644 > > --- a/fs/f2fs/inode.c > > +++ b/fs/f2fs/inode.c > > @@ -34,10 +34,8 @@ void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync) > > if (f2fs_inode_dirtied(inode, sync)) > > return; > > > > - if (f2fs_is_atomic_file(inode)) { > > - set_inode_flag(inode, FI_ATOMIC_DIRTIED); > > + if (f2fs_is_atomic_file(inode)) > > return; > > - } > > > > mark_inode_dirty_sync(inode); > > } > > diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c > > index 397df271885c..c08d52c6467a 100644 > > --- a/fs/f2fs/super.c > > +++ b/fs/f2fs/super.c > > @@ -1534,6 +1534,10 @@ int f2fs_inode_dirtied(struct inode *inode, bool sync) > > inc_page_count(sbi, F2FS_DIRTY_IMETA); > > } > > spin_unlock(&sbi->inode_lock[DIRTY_META]); > > + > > + if (!ret && f2fs_is_atomic_file(inode)) > > + set_inode_flag(inode, FI_ATOMIC_DIRTIED); > > + > > I'm not sure what's different here. > > Before and after this patch, set_inode_flag(inode, FI_ATOMIC_DIRTIED) is called > only if f2fs_inode_dirtied() returns zero and f2fs_is_atomic_file(inode). > > Note, f2fs_mark_inode_dirty_sync() looks the single caller of f2fs_inode_dirtied. Ok, I missed another caller, f2fs_dirty_inode, per discussion with Daeho. Let me apply this. > > > > return ret; > > } > > > > -- > > 2.34.1 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B723E1FECCE for ; Fri, 14 Mar 2025 22:21:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741990903; cv=none; b=bGtkYWrRczgI7GG3lH4t74KJemhQcIYDwAsOWycuvpvcEiZAzVhF1bJXPwJLHu+IqrHl75cTydodUmmEtk9EB6sZsIrrf++R+C4GIfg1+Ossl3tMBOhgTI3mw7otGoy7ylfqAZ5iLRnAwAyJhKu8jA/Ehtowl9Fc1Le1SpmyxPI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741990903; c=relaxed/simple; bh=yXi4VV69OQ5J9Ch0qeBs+FaNnX2iPv7Ofe2QeSUOJQc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=b2LW1a0GXVM2hiH6ZRgAgr1uZsbO3toqwcvg6TU7JVkjHhqkDP1l8NiG4CuUnJU4paAMHNJadrtFMss+GdbzZXmhkPDfcxwXuCp0c5iimUPk6bl9SJaI9v4/qCfyrhyjkmvjridfmdrhkrgHm51Zfx30wmkGB5vUtb/kLIoEQjk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JPZyqGBd; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JPZyqGBd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DDED3C4CEE3; Fri, 14 Mar 2025 22:21:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741990903; bh=yXi4VV69OQ5J9Ch0qeBs+FaNnX2iPv7Ofe2QeSUOJQc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=JPZyqGBdCCTlOuxqJOyOY/F0hpQQiyf/XDttYCvQLw/W9A2dB1OJBCexbEKyxnRhb V9Q5RpWD76b2LnGmJJMcyBdR6o9wxyND4oBSnPADxB5XokeViyyViTk4LgUVfteA2O tfi4zJdH4WZ1Bw/ZTnx7+ib2S8kxb8Roxgi7EMgKNg2mNQRhGQLUAdY6bXHyRbVyh0 C2IgJkvfxcERKbZNyr/Fwy5qVf+VUboQatcnUpHi97UDaI4dVoCQUytBLCYd/ZA6w8 rtvvHhEC/hICWn7/PsPG6AS2kj1XN9G0pfkLUer+mJKsBjFh/hWovJwyKAl5CH/mM/ YkP6WZZoYMKAQ== Date: Fri, 14 Mar 2025 22:21:41 +0000 From: Jaegeuk Kim To: Yeongjin Gil Cc: chao@kernel.org, daehojeong@google.com, linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, sj1557.seo@samsung.com, s_min.jeong@samsung.com Subject: Re: [PATCH] f2fs: fix to avoid atomicity corruption of atomic file Message-ID: References: <20250314120651.443184-1-youngjin.gil@samsung.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On 03/14, Jaegeuk Kim wrote: > On 03/14, Yeongjin Gil wrote: > > In the case of the following call stack for an atomic file, > > FI_DIRTY_INODE is set, but FI_ATOMIC_DIRTIED is not subsequently set. > > > > f2fs_file_write_iter > > f2fs_map_blocks > > f2fs_reserve_new_blocks > > inc_valid_block_count > > __mark_inode_dirty(dquot) > > f2fs_dirty_inode > > > > If FI_ATOMIC_DIRTIED is not set, atomic file can encounter corruption > > due to a mismatch between old file size and new data. > > > > To resolve this issue, I changed to set FI_ATOMIC_DIRTIED when > > FI_DIRTY_INODE is set. This ensures that FI_DIRTY_INODE, which was > > previously cleared by the Writeback thread during the commit atomic, is > > set and i_size is updated. > > > > Fixes: fccaa81de87e ("f2fs: prevent atomic file from being dirtied before commit") > > Reviewed-by: Sungjong Seo > > Reviewed-by: Sunmin Jeong > > Signed-off-by: Yeongjin Gil > > --- > > fs/f2fs/inode.c | 4 +--- > > fs/f2fs/super.c | 4 ++++ > > 2 files changed, 5 insertions(+), 3 deletions(-) > > > > diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c > > index aa2f41696a88..83f862578fc8 100644 > > --- a/fs/f2fs/inode.c > > +++ b/fs/f2fs/inode.c > > @@ -34,10 +34,8 @@ void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync) > > if (f2fs_inode_dirtied(inode, sync)) > > return; > > > > - if (f2fs_is_atomic_file(inode)) { > > - set_inode_flag(inode, FI_ATOMIC_DIRTIED); > > + if (f2fs_is_atomic_file(inode)) > > return; > > - } > > > > mark_inode_dirty_sync(inode); > > } > > diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c > > index 397df271885c..c08d52c6467a 100644 > > --- a/fs/f2fs/super.c > > +++ b/fs/f2fs/super.c > > @@ -1534,6 +1534,10 @@ int f2fs_inode_dirtied(struct inode *inode, bool sync) > > inc_page_count(sbi, F2FS_DIRTY_IMETA); > > } > > spin_unlock(&sbi->inode_lock[DIRTY_META]); > > + > > + if (!ret && f2fs_is_atomic_file(inode)) > > + set_inode_flag(inode, FI_ATOMIC_DIRTIED); > > + > > I'm not sure what's different here. > > Before and after this patch, set_inode_flag(inode, FI_ATOMIC_DIRTIED) is called > only if f2fs_inode_dirtied() returns zero and f2fs_is_atomic_file(inode). > > Note, f2fs_mark_inode_dirty_sync() looks the single caller of f2fs_inode_dirtied. Ok, I missed another caller, f2fs_dirty_inode, per discussion with Daeho. Let me apply this. > > > > return ret; > > } > > > > -- > > 2.34.1