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 227F1C282EC for ; Fri, 14 Mar 2025 21:50:48 +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 1ttCvW-00070d-U7; Fri, 14 Mar 2025 21:50:47 +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 1ttCvV-00070W-Iq for linux-f2fs-devel@lists.sourceforge.net; Fri, 14 Mar 2025 21:50:46 +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=GcZgsU2GtBFKXeDUFli8IPCMkoJfgdfjQKG7SDxCHUE=; b=AWoMX/4U6QlizNSW5pKWZuvHaM xjrfoEy5LXIJmy35z7wMQugSMgx7bJeY0/YidkgoqmpKrt0nrQmdDUiVvaeRgz49Kz1UWuHTKzuFK Rkx4qdgu2cHCXa4FzgYoMEVGmn2ak2LUIcLX/5kf6nsAHtCf9ENI56gYdUUkCUOboFeA=; 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=GcZgsU2GtBFKXeDUFli8IPCMkoJfgdfjQKG7SDxCHUE=; b=L5kzZ2GlZ7aSa7SMfHFHx4MbA8 gE+9jeuGJhxLIxC6FSsPnPD2OJ2s1OoE0oE/yufKKuA7mLMty6fWunZmsI0mpXl5Agsvw1ToKJqOg YB8K7qV62mSYzETy2y1gK+Vk1fx1zYGvb3YygiILzruI/KJuf+pjq5grhvn4ORK2qJj4=; Received: from nyc.source.kernel.org ([147.75.193.91]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1ttCvV-0005qY-Ca for linux-f2fs-devel@lists.sourceforge.net; Fri, 14 Mar 2025 21:50:45 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id DFF86A45424; Fri, 14 Mar 2025 21:45:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0BFC5C4CEE3; Fri, 14 Mar 2025 21:50:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741989034; bh=tmqCpcVXwWVsDWj4IBtSm1R/td472GxXq775uoQ0xnU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=qANbF8Cu1Xcn7oCvxwPNdeOT/ZHfCxCwgmoR8Isv7UjmWWWmWY/ErbzgOYy5fOemv qRr2yztxgzDYffVUcS4wsDOqLNyftZYFd6tMwmWjT1H3ADraeeEPrP7KFKePeEhP/E D4wsPS2ZVPpShC37DpcZPdzndtWzM32LVQ28lJNLxfDUSe8fXvPf+V05k75kDy841D UbjPn/xVLt81ObHsnjxmfbKMGwp5LCakvz1bt965CWDAqHAQjOVNKlvaRmBUXLmkC+ PPlhxF8p+9qZWKMJsin/C2ZOoUkD12sUmn3FwXN42iDTKvs3kd4AN2seNdMOuEQ2Wg EaYRGAttV5oiQ== Date: Fri, 14 Mar 2025 21:50:32 +0000 To: Yeongjin Gil Message-ID: References: <20250314120651.443184-1-youngjin.gil@samsung.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20250314120651.443184-1-youngjin.gil@samsung.com> X-Headers-End: 1ttCvV-0005qY-Ca 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, 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. > 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 E79D51C8631 for ; Fri, 14 Mar 2025 21:50:34 +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=1741989035; cv=none; b=Y7J9c/QkHaggNUcXdTPzqzifhExcN36Nbf3yhyTVceJJ3gOtMhOWsUwqKFisksUlTPT+N/0+hHJTmCsVEEhic/+c/S9dqif30GGI53bJdZJrNd25JPR2Zhh3PRlwWnWmDz0XfveMhu/ieNi6+Ul6g7xCoR3nBGEsGKs4Ztb4Wno= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741989035; c=relaxed/simple; bh=tmqCpcVXwWVsDWj4IBtSm1R/td472GxXq775uoQ0xnU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=eaxdozm70AMfChr04NaZXfGBqPweNz57DbvXqn1yy/KAjfSGxmujEJ+0rS9K+KT7TjhQ9FQf9YnZiF3jQisE4iBrSFkACl3HS3lVzt/5ZL5q43ipMPyQAIWxgpoUGkn715TIFX3X4xV4jQctUg7HP7g0Ur5HexpyyHUBpsRCRws= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qANbF8Cu; 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="qANbF8Cu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0BFC5C4CEE3; Fri, 14 Mar 2025 21:50:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741989034; bh=tmqCpcVXwWVsDWj4IBtSm1R/td472GxXq775uoQ0xnU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=qANbF8Cu1Xcn7oCvxwPNdeOT/ZHfCxCwgmoR8Isv7UjmWWWmWY/ErbzgOYy5fOemv qRr2yztxgzDYffVUcS4wsDOqLNyftZYFd6tMwmWjT1H3ADraeeEPrP7KFKePeEhP/E D4wsPS2ZVPpShC37DpcZPdzndtWzM32LVQ28lJNLxfDUSe8fXvPf+V05k75kDy841D UbjPn/xVLt81ObHsnjxmfbKMGwp5LCakvz1bt965CWDAqHAQjOVNKlvaRmBUXLmkC+ PPlhxF8p+9qZWKMJsin/C2ZOoUkD12sUmn3FwXN42iDTKvs3kd4AN2seNdMOuEQ2Wg EaYRGAttV5oiQ== Date: Fri, 14 Mar 2025 21:50:32 +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: <20250314120651.443184-1-youngjin.gil@samsung.com> 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. > return ret; > } > > -- > 2.34.1