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 X-Spam-Level: X-Spam-Status: No, score=-8.6 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC548C43603 for ; Wed, 11 Dec 2019 01:21:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 91C11206D5 for ; Wed, 11 Dec 2019 01:21:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576027284; bh=4s4oxL7XVcpXrJCAiCJ8CAjgQd6K4Rfti23V7t2oJfI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:List-ID:From; b=P5jFTwNYniFulfyoBABr+p+Dyx1AdtXLronuNK2J4tn0CQzY3lUTu4y/FsIpfshpq G2caOWua5P7D4QZ6khkjo7C+nFApg1VGTAjFODbcdzWYb6Lm7Gs77CSB5fkNDZI7sP jMm3s+ZGzpLDU9aWRjYa2gBauO+CzFBlTy40OxGQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727351AbfLKBVX (ORCPT ); Tue, 10 Dec 2019 20:21:23 -0500 Received: from mail.kernel.org ([198.145.29.99]:46440 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726362AbfLKBVX (ORCPT ); Tue, 10 Dec 2019 20:21:23 -0500 Received: from localhost (unknown [104.132.0.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 609562073B; Wed, 11 Dec 2019 01:21:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576027282; bh=4s4oxL7XVcpXrJCAiCJ8CAjgQd6K4Rfti23V7t2oJfI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=X81nwpqRdIxAA8X1PG8lS8in0dN1bDx5DbfkOLabOAUm0tRuRlbNR4FvCPCh5Ui12 m2SaTIPIrcTTwl2VdOuWZ6DpJlytsAUhGPud6elCiF+Ioe+8qMUB5DK2nJAORCXWeM bg2TUaRQHDoOpovqnDt9VUZp6xy12itwPGuGkAss= Date: Tue, 10 Dec 2019 17:21:21 -0800 From: Jaegeuk Kim To: Chao Yu Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Subject: Re: [f2fs-dev] [PATCH 6/6] f2fs: set I_LINKABLE early to avoid wrong access by vfs Message-ID: <20191211012121.GA52962@jaegeuk-macbookpro.roam.corp.google.com> References: <20191209222345.1078-1-jaegeuk@kernel.org> <20191209222345.1078-6-jaegeuk@kernel.org> <88dcbca9-3757-a440-ed73-9d99a56b816c@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <88dcbca9-3757-a440-ed73-9d99a56b816c@huawei.com> User-Agent: Mutt/1.8.2 (2017-04-18) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/10, Chao Yu wrote: > On 2019/12/10 6:23, Jaegeuk Kim wrote: > > This patch moves setting I_LINKABLE early in rename2(whiteout) to avoid the > > below warning. > > > > [ 3189.163385] WARNING: CPU: 3 PID: 59523 at fs/inode.c:358 inc_nlink+0x32/0x40 > > [ 3189.246979] Call Trace: > > [ 3189.248707] f2fs_init_inode_metadata+0x2d6/0x440 [f2fs] > > [ 3189.251399] f2fs_add_inline_entry+0x162/0x8c0 [f2fs] > > [ 3189.254010] f2fs_add_dentry+0x69/0xe0 [f2fs] > > [ 3189.256353] f2fs_do_add_link+0xc5/0x100 [f2fs] > > [ 3189.258774] f2fs_rename2+0xabf/0x1010 [f2fs] > > [ 3189.261079] vfs_rename+0x3f8/0xaa0 > > [ 3189.263056] ? tomoyo_path_rename+0x44/0x60 > > [ 3189.265283] ? do_renameat2+0x49b/0x550 > > [ 3189.267324] do_renameat2+0x49b/0x550 > > [ 3189.269316] __x64_sys_renameat2+0x20/0x30 > > [ 3189.271441] do_syscall_64+0x5a/0x230 > > [ 3189.273410] entry_SYSCALL_64_after_hwframe+0x49/0xbe > > [ 3189.275848] RIP: 0033:0x7f270b4d9a49 > > > > Signed-off-by: Jaegeuk Kim > > --- > > fs/f2fs/namei.c | 27 +++++++++++++-------------- > > 1 file changed, 13 insertions(+), 14 deletions(-) > > > > diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c > > index a1c507b0b4ac..5d9584281935 100644 > > --- a/fs/f2fs/namei.c > > +++ b/fs/f2fs/namei.c > > @@ -797,6 +797,7 @@ static int __f2fs_tmpfile(struct inode *dir, struct dentry *dentry, > > > > if (whiteout) { > > f2fs_i_links_write(inode, false); > > + inode->i_state |= I_LINKABLE; > > *whiteout = inode; > > } else { > > d_tmpfile(dentry, inode); > > @@ -867,6 +868,12 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, > > F2FS_I(old_dentry->d_inode)->i_projid))) > > return -EXDEV; > > > > + if (flags & RENAME_WHITEOUT) { > > + err = f2fs_create_whiteout(old_dir, &whiteout); > > + if (err) > > + return err; > > + } > > To record quota info correctly, we need to create whiteout inode after > dquot_initialize(old_dir)? __f2fs_tmpfile() will do it. > > > + > > err = dquot_initialize(old_dir); > > if (err) > > goto out; > > @@ -898,17 +905,11 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, > > } > > } > > > > - if (flags & RENAME_WHITEOUT) { > > - err = f2fs_create_whiteout(old_dir, &whiteout); > > - if (err) > > - goto out_dir; > > - } > > - > > if (new_inode) { > > > > err = -ENOTEMPTY; > > if (old_dir_entry && !f2fs_empty_dir(new_inode)) > > - goto out_whiteout; > > + goto out_dir; > > > > err = -ENOENT; > > new_entry = f2fs_find_entry(new_dir, &new_dentry->d_name, > > @@ -916,7 +917,7 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, > > if (!new_entry) { > > if (IS_ERR(new_page)) > > err = PTR_ERR(new_page); > > - goto out_whiteout; > > + goto out_dir; > > } > > > > f2fs_balance_fs(sbi, true); > > @@ -948,7 +949,7 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, > > err = f2fs_add_link(new_dentry, old_inode); > > if (err) { > > f2fs_unlock_op(sbi); > > - goto out_whiteout; > > + goto out_dir; > > } > > > > if (old_dir_entry) > > @@ -972,7 +973,7 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, > > if (IS_ERR(old_page)) > > err = PTR_ERR(old_page); > > f2fs_unlock_op(sbi); > > - goto out_whiteout; > > + goto out_dir; > > } > > } > > } > > @@ -991,7 +992,6 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, > > f2fs_delete_entry(old_entry, old_page, old_dir, NULL); > > > > if (whiteout) { > > - whiteout->i_state |= I_LINKABLE; > > set_inode_flag(whiteout, FI_INC_LINK); > > err = f2fs_add_link(old_dentry, whiteout); > > [ 3189.256353] f2fs_do_add_link+0xc5/0x100 [f2fs] > [ 3189.258774] f2fs_rename2+0xabf/0x1010 [f2fs] > > Does the call stack point here? if so, we have set I_LINKABLE before > f2fs_add_link(), why the warning still be triggered? > > Thanks, > > > if (err) > > @@ -1027,15 +1027,14 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, > > f2fs_unlock_op(sbi); > > if (new_page) > > f2fs_put_page(new_page, 0); > > -out_whiteout: > > - if (whiteout) > > - iput(whiteout); > > out_dir: > > if (old_dir_entry) > > f2fs_put_page(old_dir_page, 0); > > out_old: > > f2fs_put_page(old_page, 0); > > out: > > + if (whiteout) > > + iput(whiteout); > > return err; > > } > > > > 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 X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F3E9C43603 for ; Wed, 11 Dec 2019 01:21:36 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 5DBDE206D5; Wed, 11 Dec 2019 01:21:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sourceforge.net header.i=@sourceforge.net header.b="QbLkNy1X"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sf.net header.i=@sf.net header.b="Dy+X19sy"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="X81nwpqR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5DBDE206D5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-f2fs-devel-bounces@lists.sourceforge.net 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.90_1) (envelope-from ) id 1ieqh5-0002sj-TF; Wed, 11 Dec 2019 01:21:35 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ieqh0-0002s4-4P for linux-f2fs-devel@lists.sourceforge.net; Wed, 11 Dec 2019 01:21:30 +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=jHvMt49gtKkX5D3KBJ60LiD517OFyJrntPHMzIBjKTI=; b=QbLkNy1XiJuW2uhZLp7SL61Z5Q d9K2LnHfSS+gSXcvGTW2hBpKw6oxVwLHUBP3OhRuaV1cBwczIIpDvm4kGADdCoswduYOUseq5xfC+ ypdSWAVIJIvLCpP5yMH2VP4zDc4Bq/Bp5/j9K51UGrdRCmNtW8zyDnTGVlKOpeNH0+wE=; 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=jHvMt49gtKkX5D3KBJ60LiD517OFyJrntPHMzIBjKTI=; b=Dy+X19sy5VkbseMQ7KQmm6Psco eRM3JRSDDXcF+MUHc2INSfrHeQrqTcw5l9svApCGTvxkJr+BKu4TZpntnwptuYlxy30bnEZpM+RL3 8LvKdP6O5bujLXC0IInEUqZELAyGttzj92nv2Z/WEedfEjcC0CuAFrf0uyCc04btdp+Q=; Received: from mail.kernel.org ([198.145.29.99]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1ieqgy-0042uD-PT for linux-f2fs-devel@lists.sourceforge.net; Wed, 11 Dec 2019 01:21:30 +0000 Received: from localhost (unknown [104.132.0.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 609562073B; Wed, 11 Dec 2019 01:21:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576027282; bh=4s4oxL7XVcpXrJCAiCJ8CAjgQd6K4Rfti23V7t2oJfI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=X81nwpqRdIxAA8X1PG8lS8in0dN1bDx5DbfkOLabOAUm0tRuRlbNR4FvCPCh5Ui12 m2SaTIPIrcTTwl2VdOuWZ6DpJlytsAUhGPud6elCiF+Ioe+8qMUB5DK2nJAORCXWeM bg2TUaRQHDoOpovqnDt9VUZp6xy12itwPGuGkAss= Date: Tue, 10 Dec 2019 17:21:21 -0800 From: Jaegeuk Kim To: Chao Yu Message-ID: <20191211012121.GA52962@jaegeuk-macbookpro.roam.corp.google.com> References: <20191209222345.1078-1-jaegeuk@kernel.org> <20191209222345.1078-6-jaegeuk@kernel.org> <88dcbca9-3757-a440-ed73-9d99a56b816c@huawei.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <88dcbca9-3757-a440-ed73-9d99a56b816c@huawei.com> User-Agent: Mutt/1.8.2 (2017-04-18) X-Headers-End: 1ieqgy-0042uD-PT Subject: Re: [f2fs-dev] [PATCH 6/6] f2fs: set I_LINKABLE early to avoid wrong access by vfs 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: , Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net On 12/10, Chao Yu wrote: > On 2019/12/10 6:23, Jaegeuk Kim wrote: > > This patch moves setting I_LINKABLE early in rename2(whiteout) to avoid the > > below warning. > > > > [ 3189.163385] WARNING: CPU: 3 PID: 59523 at fs/inode.c:358 inc_nlink+0x32/0x40 > > [ 3189.246979] Call Trace: > > [ 3189.248707] f2fs_init_inode_metadata+0x2d6/0x440 [f2fs] > > [ 3189.251399] f2fs_add_inline_entry+0x162/0x8c0 [f2fs] > > [ 3189.254010] f2fs_add_dentry+0x69/0xe0 [f2fs] > > [ 3189.256353] f2fs_do_add_link+0xc5/0x100 [f2fs] > > [ 3189.258774] f2fs_rename2+0xabf/0x1010 [f2fs] > > [ 3189.261079] vfs_rename+0x3f8/0xaa0 > > [ 3189.263056] ? tomoyo_path_rename+0x44/0x60 > > [ 3189.265283] ? do_renameat2+0x49b/0x550 > > [ 3189.267324] do_renameat2+0x49b/0x550 > > [ 3189.269316] __x64_sys_renameat2+0x20/0x30 > > [ 3189.271441] do_syscall_64+0x5a/0x230 > > [ 3189.273410] entry_SYSCALL_64_after_hwframe+0x49/0xbe > > [ 3189.275848] RIP: 0033:0x7f270b4d9a49 > > > > Signed-off-by: Jaegeuk Kim > > --- > > fs/f2fs/namei.c | 27 +++++++++++++-------------- > > 1 file changed, 13 insertions(+), 14 deletions(-) > > > > diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c > > index a1c507b0b4ac..5d9584281935 100644 > > --- a/fs/f2fs/namei.c > > +++ b/fs/f2fs/namei.c > > @@ -797,6 +797,7 @@ static int __f2fs_tmpfile(struct inode *dir, struct dentry *dentry, > > > > if (whiteout) { > > f2fs_i_links_write(inode, false); > > + inode->i_state |= I_LINKABLE; > > *whiteout = inode; > > } else { > > d_tmpfile(dentry, inode); > > @@ -867,6 +868,12 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, > > F2FS_I(old_dentry->d_inode)->i_projid))) > > return -EXDEV; > > > > + if (flags & RENAME_WHITEOUT) { > > + err = f2fs_create_whiteout(old_dir, &whiteout); > > + if (err) > > + return err; > > + } > > To record quota info correctly, we need to create whiteout inode after > dquot_initialize(old_dir)? __f2fs_tmpfile() will do it. > > > + > > err = dquot_initialize(old_dir); > > if (err) > > goto out; > > @@ -898,17 +905,11 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, > > } > > } > > > > - if (flags & RENAME_WHITEOUT) { > > - err = f2fs_create_whiteout(old_dir, &whiteout); > > - if (err) > > - goto out_dir; > > - } > > - > > if (new_inode) { > > > > err = -ENOTEMPTY; > > if (old_dir_entry && !f2fs_empty_dir(new_inode)) > > - goto out_whiteout; > > + goto out_dir; > > > > err = -ENOENT; > > new_entry = f2fs_find_entry(new_dir, &new_dentry->d_name, > > @@ -916,7 +917,7 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, > > if (!new_entry) { > > if (IS_ERR(new_page)) > > err = PTR_ERR(new_page); > > - goto out_whiteout; > > + goto out_dir; > > } > > > > f2fs_balance_fs(sbi, true); > > @@ -948,7 +949,7 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, > > err = f2fs_add_link(new_dentry, old_inode); > > if (err) { > > f2fs_unlock_op(sbi); > > - goto out_whiteout; > > + goto out_dir; > > } > > > > if (old_dir_entry) > > @@ -972,7 +973,7 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, > > if (IS_ERR(old_page)) > > err = PTR_ERR(old_page); > > f2fs_unlock_op(sbi); > > - goto out_whiteout; > > + goto out_dir; > > } > > } > > } > > @@ -991,7 +992,6 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, > > f2fs_delete_entry(old_entry, old_page, old_dir, NULL); > > > > if (whiteout) { > > - whiteout->i_state |= I_LINKABLE; > > set_inode_flag(whiteout, FI_INC_LINK); > > err = f2fs_add_link(old_dentry, whiteout); > > [ 3189.256353] f2fs_do_add_link+0xc5/0x100 [f2fs] > [ 3189.258774] f2fs_rename2+0xabf/0x1010 [f2fs] > > Does the call stack point here? if so, we have set I_LINKABLE before > f2fs_add_link(), why the warning still be triggered? > > Thanks, > > > if (err) > > @@ -1027,15 +1027,14 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry, > > f2fs_unlock_op(sbi); > > if (new_page) > > f2fs_put_page(new_page, 0); > > -out_whiteout: > > - if (whiteout) > > - iput(whiteout); > > out_dir: > > if (old_dir_entry) > > f2fs_put_page(old_dir_page, 0); > > out_old: > > f2fs_put_page(old_page, 0); > > out: > > + if (whiteout) > > + iput(whiteout); > > return err; > > } > > > > _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel