Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1052633ybl; Thu, 12 Dec 2019 08:57:33 -0800 (PST) X-Google-Smtp-Source: APXvYqz2MDsrFcvi6xX5wKUziHpVQ9Qzr3h+j/RP9yujtOUWLUzk8SirIEFH85mmdhr1D1tKL4TF X-Received: by 2002:a05:6830:591:: with SMTP id c17mr8729594oth.226.1576169853182; Thu, 12 Dec 2019 08:57:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576169853; cv=none; d=google.com; s=arc-20160816; b=JJL2a3EQ61dspTJ4hdZTf73WDhVGMyKs+D+H7+O2g7X272+SG9v8fSARwfYmh3gDq+ eEtHNSmC6QgEjyPtW+ysGCueYK6PhtXdhLlhCwDXHe95+P7EGJbbV6epy42dn8u1AxHY /LHvgbsX+RQbzyORtCrVQMZ1sbWXOKd3Dd1lECw2VUaNay4yCYJ0B1mzSy6k+9mlVIUK QP5Ei9ZO4AlDcUOf/rrKoAUwaBrxj55965bH4/QXpgMOZS9lQK9NlvnVkinoPpBJkLGn 1Tz8PWf19jrx78Sz6EPWOzMtmflO7m8TWo51FNxD2dOXIvl0eiLuNLjr3nMlE1yqxHS0 o4Rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Ocxvr01Fm2UWyx0UST9GpCzxDI9mhJkMLNwTUAjaBs4=; b=Uwh2zgJP7Te5zf/PBoSfSrPxXpCXYc/DnexW77DqdEV2Wk2X8zzzZ5uv3Ly6Z6qyfC EWi4DCw9FxLd00zhIDeat2P5tRSNYUO9LnECH4S5uA7KalesO53/hAe0W1O5h0zp3Hbv iz+TZpJW8etJ/ZTMss/9BXX6Z67d0wyUi3USKFd3vf5n/QCfV1GNr5hmfCNir/y3Cojh norBHMhAR7eyX0pjz4lS/ndrDm7aPBLWQ+pO5Mr0KomCDkZGHj3cQTLdtsjXFyWTP4qO Sg0Bu3j4kM1x28RuOI2MJtPjEEkA/JT5j9ZHk9ao+t01EwmP17+jmMHJva7C8BTG3WhD BgLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qtO+xA04; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p28si3623895oth.296.2019.12.12.08.57.20; Thu, 12 Dec 2019 08:57:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qtO+xA04; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730004AbfLLQzQ (ORCPT + 99 others); Thu, 12 Dec 2019 11:55:16 -0500 Received: from mail.kernel.org ([198.145.29.99]:46176 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729260AbfLLQzP (ORCPT ); Thu, 12 Dec 2019 11:55:15 -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 B98A8214AF; Thu, 12 Dec 2019 16:55:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576169713; bh=kBSKM05Y5UlxkAax2yGnAlFKO9UJ0g7IYs5IpgkDhpI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=qtO+xA04fkDFG7FSHB/vAS7LNo+5gecWiievUp2aAkDlgZpJPXcaDMx4cRqvtW9SF NjnDptZKR/G1TIjibF6HgL8Z2DtmVkAY6JqKs+BMJkgTq2WvzlywWO1jgCR77YG+37 BuhG7Bsr36M4cBqabjgMCvo2DD4lp3minkXPiFLA= Date: Thu, 12 Dec 2019 08:55:12 -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: <20191212165512.GA12419@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> <20191211012121.GA52962@jaegeuk-macbookpro.roam.corp.google.com> <00ced682-9522-236d-4078-4c8f2e348d39@huawei.com> <20191211013124.GB57416@jaegeuk-macbookpro.roam.corp.google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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/11, Chao Yu wrote: > On 2019/12/11 9:31, Jaegeuk Kim wrote: > > On 12/11, Chao Yu wrote: > >> On 2019/12/11 9:21, Jaegeuk Kim wrote: > >>> 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. > >> > >> Okay. > >> > >> Any comments on below question? > >> > >>> > >>>> > >>>>> + > >>>>> 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? > >> > >> Am I missing something? > > > > Not sure exactly tho, I suspect some races before/after unlock_new_inode(). > > Alright, I doubt some races on whiteout->i_state updating, as we set I_LINKABLE > w/o holding inode.i_lock. > > Could you have a try with holding i_lock? I don't see the warning with this patch, and jumped to another issue. I'd like to take a look at that later. Thanks, > > Thanks, > > > > >> > >> Thanks, > >> > >>>> > >>>> 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; > >>>>> } > >>>>> > >>>>> > >>> . > >>> > > . > >