From patchwork Sun May 28 07:47:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 13257781 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 7C7E2C7EE2C for ; Sun, 28 May 2023 07:47:55 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1q3B84-0008GA-Jk; Sun, 28 May 2023 07:47:52 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1q3B7x-0008G3-3E for linux-f2fs-devel@lists.sourceforge.net; Sun, 28 May 2023 07:47:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=6N+7uTPZuTsIhxvm29IasATAb3tyhb4JyG678i7BiD8=; b=PzfOUHclyWtxyFSPa2o/PKlFx4 q1n+XQyxwwHU2DzBecvneR0gJYt/sUbzBp+y1xL/ye/oZm9hvnp3B6HJLSXaw/o3hdtu+3o0tnyQc Br2+MGDEKvXqPlJn2JxLwd3AOH+BynGNcxMQ6riAMu2LmeuUddecK/NL/PF+aYAT8SVQ=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject:Cc:To:From :Sender:Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=6N+7uTPZuTsIhxvm29IasATAb3tyhb4JyG678i7BiD8=; b=S +U4j+HvA+rncWb1RlViHCGz8GHrSH6tr55N7HbOiWIZ6hHErwPyKMBEFCgtOsIyY0GRbefcWKg4Pq bNro1iZ0aBrHaBmMDEwv1T8jFr3uKMvQ43jC6VrWOy3x0TQunvhVylJpbuM8jjHifEeK2tllm6pc/ wLW1wFQeCIWWqnxM=; 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 1q3B7o-0003hN-Ql for linux-f2fs-devel@lists.sourceforge.net; Sun, 28 May 2023 07:47:37 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9879F6157A for ; Sun, 28 May 2023 07:47:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D2343C433EF; Sun, 28 May 2023 07:47:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685260041; bh=ZpGoTX9qNRlEq5Lv9msG/vssYrKdybIlN/zFvyB6UuI=; h=From:To:Cc:Subject:Date:From; b=atEMSKqyr6WeZFg25oEMAjMSq7itWdfOb1eAFaxnqPwQEAU+b3Zh3KR21qtuIVRN6 uN862Glspb6p1NrG0mPZXuidGcOycI5KmN+Ieokw6dvY+9lbz0pwOG+14x+7XLpNxm T12poqoh9i15Wkvxl5OFFZfvvbVpvo16fKMJpthojQi657BuJ0UQOsTa6hgoQfBVg9 R7X8AXPjNUPuSxKxq/ID3srlFwt/+gezWH92UUrC0ke7H6tA0KPOQSHTNIdJX9wJPu HBQTFPbr+L/Celyg1FJjvn12FAY2GVQBt0FoAAIDPUT96W4atJyD57/c8zkDQi8SQP /li5PnUAEMrzA== From: Chao Yu To: jaegeuk@kernel.org Date: Sun, 28 May 2023 15:47:12 +0800 Message-Id: <20230528074713.1682062-1-chao@kernel.org> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Headers-End: 1q3B7o-0003hN-Ql Subject: [f2fs-dev] [PATCH 1/2] f2fs: fix to drop all dirty meta/node pages during umount() 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 Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net For cp error case, there will be dirty meta/node pages remained after f2fs_write_checkpoint() in f2fs_put_super(), drop them explicitly, and do sanity check on reference count of dirty pages and inflight IOs. Signed-off-by: Chao Yu --- fs/f2fs/super.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 7499ebabaf35..d1bce753f0d2 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -1573,6 +1573,7 @@ static void f2fs_put_super(struct super_block *sb) { struct f2fs_sb_info *sbi = F2FS_SB(sb); int i; + int err = 0; bool done; /* unregister procfs/sysfs entries in advance to avoid race case */ @@ -1599,7 +1600,7 @@ static void f2fs_put_super(struct super_block *sb) struct cp_control cpc = { .reason = CP_UMOUNT, }; - f2fs_write_checkpoint(sbi, &cpc); + err = f2fs_write_checkpoint(sbi, &cpc); } /* be sure to wait for any on-going discard commands */ @@ -1608,7 +1609,7 @@ static void f2fs_put_super(struct super_block *sb) struct cp_control cpc = { .reason = CP_UMOUNT | CP_TRIMMED, }; - f2fs_write_checkpoint(sbi, &cpc); + err = f2fs_write_checkpoint(sbi, &cpc); } /* @@ -1625,6 +1626,19 @@ static void f2fs_put_super(struct super_block *sb) f2fs_wait_on_all_pages(sbi, F2FS_WB_CP_DATA); + if (err) { + truncate_inode_pages_final(NODE_MAPPING(sbi)); + truncate_inode_pages_final(META_MAPPING(sbi)); + } + + for (i = 0; i < NR_COUNT_TYPE; i++) { + if (!get_pages(sbi, i)) + continue; + f2fs_err(sbi, "detect filesystem reference count leak during " + "umount, type: %d, count: %lld", i, get_pages(sbi, i)); + f2fs_bug_on(sbi, 1); + } + f2fs_bug_on(sbi, sbi->fsync_node_num); f2fs_destroy_compress_inode(sbi); From patchwork Sun May 28 07:47:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 13257780 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 B7379C77B7E for ; Sun, 28 May 2023 07:47:39 +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 1q3B7n-0001Zk-Ic; Sun, 28 May 2023 07:47:36 +0000 Received: from [172.30.20.202] (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 1q3B7l-0001Ze-Sj for linux-f2fs-devel@lists.sourceforge.net; Sun, 28 May 2023 07:47:34 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: 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=DSUaDLPQIfpwijO9Y3XrApi4nhDrR++yN0N7AA8HNy4=; b=II1z2T3Yqhv5zGNb0ah2LAVnwZ OSgCjV9XaLZFT3TKxAcCNiRnck0QGuxrLooVJsx38jxKX4T5HoF3OPtf1TccZtV+z6pvDJAXaCxW8 4EUtGgv5PH8A7nwNDZbE/gvRC4mYm9svNTY+y/IdWiKK/KHvMsdsrsDJRI5q5oyHqt0I=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: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=DSUaDLPQIfpwijO9Y3XrApi4nhDrR++yN0N7AA8HNy4=; b=a/lGVjJK7+gKYo7hSmmV1OlQhs 8FlamgSVQu5kWxO6pRZRCiqBlOGZol3hHjt0ndDjtU4rBA+TJ+rXwIsE2iudEzyyTErh/ESNYjerY hRx/MeRXcigMuSzngtQu8y+eCmj6hc5Q3k96a40/dGp7RB+pzq/A758mZbxxq7Hve8Ak=; Received: from dfw.source.kernel.org ([139.178.84.217]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1q3B7k-004s0z-MH for linux-f2fs-devel@lists.sourceforge.net; Sun, 28 May 2023 07:47:34 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4D9EF6171C for ; Sun, 28 May 2023 07:47:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87560C4339E; Sun, 28 May 2023 07:47:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685260042; bh=XJQ6lc7wdZU6+cv/rJ8sgqn00/BLJI7QVVP3DDSUxdM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CZb4me+ijOPGpu93KOF+bbjqG0ueMbvoiWT/BLJ48ZweazhNNh10Kds4Bmfy1+1Ii 6oQFi2eBfZ5U184vwHBLgmokAf1WXYmy9DY+svlSVWGAvb/iCjoHtvOG2yqAqYtv+T v0L6jPONsRP3hDL9Ou343jh5+zUk+sZf7CU8LWNNgc0ERHGQEBePSqNmn6+KSijP82 g0TdkxOCQKBeQ0c4ZhcmAeLzZ8F5LoJI85lZvDjqWsJCLDwTNKPkb7tWCb8X60tgeY xZ9KltNYFNPRm9JMJkqtkbNuMNA3KBdJET4WHWnCqGqzDJbw0nhonU2VHryHYrtzop 2iuiU7bJ3ztDA== From: Chao Yu To: jaegeuk@kernel.org Date: Sun, 28 May 2023 15:47:13 +0800 Message-Id: <20230528074713.1682062-2-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230528074713.1682062-1-chao@kernel.org> References: <20230528074713.1682062-1-chao@kernel.org> MIME-Version: 1.0 X-Headers-End: 1q3B7k-004s0z-MH Subject: [f2fs-dev] [PATCH 2/2] f2fs: avoid dead loop in f2fs_issue_checkpoint() 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 Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net generic/082 reports a bug as below: __schedule+0x332/0xf60 schedule+0x6f/0xf0 schedule_timeout+0x23b/0x2a0 wait_for_completion+0x8f/0x140 f2fs_issue_checkpoint+0xfe/0x1b0 f2fs_sync_fs+0x9d/0xb0 sync_filesystem+0x87/0xb0 dquot_load_quota_sb+0x41b/0x460 dquot_load_quota_inode+0xa5/0x130 dquot_quota_on+0x4b/0x60 f2fs_quota_on+0xe3/0x1b0 do_quotactl+0x483/0x700 __x64_sys_quotactl+0x15c/0x310 do_syscall_64+0x3f/0x90 entry_SYSCALL_64_after_hwframe+0x72/0xdc The root casue is race case as below: Thread A Kworker IRQ - write() : write data to quota.user file - writepages - f2fs_submit_page_write - __is_cp_guaranteed return false - inc_page_count(F2FS_WB_DATA) - submit_bio - quotactl(Q_QUOTAON) - f2fs_quota_on - dquot_quota_on - dquot_load_quota_inode - vfs_setup_quota_inode : inode->i_flags |= S_NOQUOTA - f2fs_write_end_io - __is_cp_guaranteed return true - dec_page_count(F2FS_WB_CP_DATA) - dquot_load_quota_sb - f2fs_sync_fs - f2fs_issue_checkpoint - do_checkpoint - f2fs_wait_on_all_pages(F2FS_WB_CP_DATA) : loop due to F2FS_WB_CP_DATA count is negative Calling filemap_fdatawrite() and filemap_fdatawait() to keep all data clean before quota file setup. Signed-off-by: Chao Yu --- fs/f2fs/super.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index d1bce753f0d2..0bfa98d053bd 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -2927,15 +2927,26 @@ static int f2fs_quota_on(struct super_block *sb, int type, int format_id, return -EBUSY; } + if (path->dentry->d_sb != sb) + return -EXDEV; + err = f2fs_quota_sync(sb, type); if (err) return err; - err = dquot_quota_on(sb, type, format_id, path); + inode = d_inode(path->dentry); + + err = filemap_fdatawrite(inode->i_mapping); if (err) return err; - inode = d_inode(path->dentry); + err = filemap_fdatawait(inode->i_mapping); + if (err) + return err; + + err = dquot_quota_on(sb, type, format_id, path); + if (err) + return err; inode_lock(inode); F2FS_I(inode)->i_flags |= F2FS_NOATIME_FL | F2FS_IMMUTABLE_FL;