Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2029758imu; Fri, 23 Nov 2018 03:46:56 -0800 (PST) X-Google-Smtp-Source: AFSGD/Vc1RsYana+QSqK63xOinE8jvJ9PmyKUoxLEdICHvFaVFOMDHL4KdEXYhquJP/aSrhXVbs0 X-Received: by 2002:a17:902:5066:: with SMTP id f35mr11303953plh.78.1542973616205; Fri, 23 Nov 2018 03:46:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542973616; cv=none; d=google.com; s=arc-20160816; b=ACXprltzxNbXecwLFk+kIrIVIpjHExGh5njRVjpZiEtVWu2gTQWiTR66V3YxbLcvBw mu1g7y3F/vUvtXkRKgQmrzfENNsH0DchTEBEXINx+t3ZMxc9nwgxUchrJQBrCuWaJjoI K1A+OPrwgLMXhIeIe9oFIAKNfZgwq3soozH5eD/kec+n/QSzUzTvOZg56KU6DoF0KtgK bonm74gDQVsj1W3TDAYhrkPuTQduaL+p8/SJXFWpppChmSP6FTwE03jR0Ss5HvYBs3em tfjfjiGGi4RWYRPXi105lruOhj7F8hQw2arXCWVc4y4BLwHR1wZqbbZDMYx4dQQ3Tqrb uPuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dmarc-filter:dkim-signature:dkim-signature; bh=YqhHBw+OcPAejnBqufIREL3HSJ8HtlfetX1q/eMGz8I=; b=fl9qIEFbN0eK1ITD56eHHX7/4h4jnA1MZRx8wh0bXX8HiBHFGbtwFKgCpKKqyff7cM Aux54G23hQX8fDf8zUp1PfGZQhCwham6G1KSwek/3TYO54DhgDiZeHtNNP108LylAkgC Ud3W/hW4qLLRv6UzHjA9vFHKejp/H+QNpzaVG9uFFKsm2WzmACRzaL3Ed+7aq3NiXxWj KvFHkegQQbsl9re7892G7hHb7wUCK/kNkBBzKCHR1zEOuZRk6oIHbMaYZfMwkZikSdBi GuEEwyxik+K12rLdv1U3mT0nuWJXAJtHNdPLCclJnbJb1CKqtpvHgaDIrFSlO/UP0dJ9 /rng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=l2iL7lLh; dkim=pass header.i=@codeaurora.org header.s=default header.b=d5iQcpYj; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i20si34111978pgh.187.2018.11.23.03.46.40; Fri, 23 Nov 2018 03:46:56 -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=@codeaurora.org header.s=default header.b=l2iL7lLh; dkim=pass header.i=@codeaurora.org header.s=default header.b=d5iQcpYj; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405422AbeKVVib (ORCPT + 99 others); Thu, 22 Nov 2018 16:38:31 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:51268 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405411AbeKVVia (ORCPT ); Thu, 22 Nov 2018 16:38:30 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id BA8BD601D1; Thu, 22 Nov 2018 10:59:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1542884376; bh=8z5ySr8rYwxZO/DhtzMDEWwz+t52kWpV7dd9bmEt/5I=; h=From:To:Cc:Subject:Date:From; b=l2iL7lLhwMSjMg9lQ5PbLN/V+acLSdXC5sfEqZB3pH8jktZ+Tz6+9UcBezhcDjyrC VPkLvRuexTnRfM+wWgdgthzQHGOdOmygFYTry4rNGBaGxybUJBxHiPUe9lGKsKlpZ4 b4BvYRVm97yB+CZhh6dTiZjI0PygY2NXoqVdZYUU= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_INVALID,DKIM_SIGNED autolearn=no autolearn_force=no version=3.4.0 Received: from codeaurora.org (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: stummala@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 492766035F; Thu, 22 Nov 2018 10:59:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1542884375; bh=8z5ySr8rYwxZO/DhtzMDEWwz+t52kWpV7dd9bmEt/5I=; h=From:To:Cc:Subject:Date:From; b=d5iQcpYjMC8m/4hPOl4qYdKFq3gujcOhvwN1WHYIP612yJiipjvctOVD5ppk26nWD i/BTH6WzqZkN7ZHLk6HQGGH5XKTr1ZHytfTbkOILBRmWxbh7tdEGMiz+twJSgLL8DY ytq21IL44AGUstjkqOkcR4ZfukKyczLxL5JBIPlM= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 492766035F Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=stummala@codeaurora.org From: Sahitya Tummala To: Jaegeuk Kim , Chao Yu , linux-f2fs-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org, Sahitya Tummala Subject: [PATCH 1/2] f2fs: fix sbi->extent_list corruption issue Date: Thu, 22 Nov 2018 16:29:19 +0530 Message-Id: <1542884360-19470-1-git-send-email-stummala@codeaurora.org> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When there is a failure in f2fs_fill_super() after/during the recovery of fsync'd nodes, it frees the current sbi and retries again. This time the mount is successful, but the files that got recovered before retry, still holds the extent tree, whose extent nodes list is corrupted since sbi and sbi->extent_list is freed up. The list_del corruption issue is observed when the file system is getting unmounted and when those recoverd files extent node is being freed up in the below context. list_del corruption. prev->next should be fffffff1e1ef5480, but was (null) <...> kernel BUG at kernel/msm-4.14/lib/list_debug.c:53! task: fffffff1f46f2280 task.stack: ffffff8008068000 lr : __list_del_entry_valid+0x94/0xb4 pc : __list_del_entry_valid+0x94/0xb4 <...> Call trace: __list_del_entry_valid+0x94/0xb4 __release_extent_node+0xb0/0x114 __free_extent_tree+0x58/0x7c f2fs_shrink_extent_tree+0xdc/0x3b0 f2fs_leave_shrinker+0x28/0x7c f2fs_put_super+0xfc/0x1e0 generic_shutdown_super+0x70/0xf4 kill_block_super+0x2c/0x5c kill_f2fs_super+0x44/0x50 deactivate_locked_super+0x60/0x8c deactivate_super+0x68/0x74 cleanup_mnt+0x40/0x78 __cleanup_mnt+0x1c/0x28 task_work_run+0x48/0xd0 do_notify_resume+0x678/0xe98 work_pending+0x8/0x14 Fix this by cleaning up the extent tree of those recovered files before freeing up sbi and before next retry. Signed-off-by: Sahitya Tummala --- fs/f2fs/extent_cache.c | 6 +++++- fs/f2fs/f2fs.h | 2 +- fs/f2fs/inode.c | 2 +- fs/f2fs/super.c | 10 ++++++++++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c index 1cb0fcc..763ba83 100644 --- a/fs/f2fs/extent_cache.c +++ b/fs/f2fs/extent_cache.c @@ -743,7 +743,7 @@ void f2fs_drop_extent_tree(struct inode *inode) f2fs_mark_inode_dirty_sync(inode, true); } -void f2fs_destroy_extent_tree(struct inode *inode) +void f2fs_destroy_extent_tree(struct inode *inode, bool force) { struct f2fs_sb_info *sbi = F2FS_I_SB(inode); struct extent_tree *et = F2FS_I(inode)->extent_tree; @@ -752,6 +752,9 @@ void f2fs_destroy_extent_tree(struct inode *inode) if (!et) return; + if (force) + goto destroy_et; + if (inode->i_nlink && !is_bad_inode(inode) && atomic_read(&et->node_cnt)) { mutex_lock(&sbi->extent_tree_lock); @@ -761,6 +764,7 @@ void f2fs_destroy_extent_tree(struct inode *inode) return; } +destroy_et: /* free all extent info belong to this extent tree */ node_cnt = f2fs_destroy_extent_node(inode); diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 1e03197..db8a919 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -3410,7 +3410,7 @@ bool f2fs_check_rb_tree_consistence(struct f2fs_sb_info *sbi, bool f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext); void f2fs_drop_extent_tree(struct inode *inode); unsigned int f2fs_destroy_extent_node(struct inode *inode); -void f2fs_destroy_extent_tree(struct inode *inode); +void f2fs_destroy_extent_tree(struct inode *inode, bool force); bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs, struct extent_info *ei); void f2fs_update_extent_cache(struct dnode_of_data *dn); diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c index 91ceee0..39e3ade3 100644 --- a/fs/f2fs/inode.c +++ b/fs/f2fs/inode.c @@ -649,7 +649,7 @@ void f2fs_evict_inode(struct inode *inode) f2fs_bug_on(sbi, get_dirty_pages(inode)); f2fs_remove_dirty_inode(inode); - f2fs_destroy_extent_tree(inode); + f2fs_destroy_extent_tree(inode, false); if (inode->i_nlink || is_bad_inode(inode)) goto no_delete; diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index af58b2c..f41ac43 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -3016,6 +3016,15 @@ static void f2fs_tuning_parameters(struct f2fs_sb_info *sbi) sbi->readdir_ra = 1; } +void f2fs_cleanup_extent_cache(struct f2fs_sb_info *sbi) +{ + struct super_block *sb = sbi->sb; + struct inode *inode, *next; + + list_for_each_entry_safe(inode, next, &sb->s_inodes, i_sb_list) + f2fs_destroy_extent_tree(inode, true); +} + static int f2fs_fill_super(struct super_block *sb, void *data, int silent) { struct f2fs_sb_info *sbi; @@ -3402,6 +3411,7 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) * falls into an infinite loop in f2fs_sync_meta_pages(). */ truncate_inode_pages_final(META_MAPPING(sbi)); + f2fs_cleanup_extent_cache(sbi); f2fs_unregister_sysfs(sbi); free_root_inode: dput(sb->s_root); -- Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.