From patchwork Mon Mar 28 06:29:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12793239 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CCB38C433F5 for ; Mon, 28 Mar 2022 06:29:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238453AbiC1GbM (ORCPT ); Mon, 28 Mar 2022 02:31:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238461AbiC1GbL (ORCPT ); Mon, 28 Mar 2022 02:31:11 -0400 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF8891164 for ; Sun, 27 Mar 2022 23:29:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1648448971; x=1679984971; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QKH/8wm+bXeq4ciczY4GMtSIhBOzRDlob2ZdPvhqb18=; b=TKRNIf/HV5XrKAUuGiqJ8W6xCi5kJyDgfFTaUDdqF1xkTqixUl7hJimk dqkgywsVFnmYQHJw3SVPNQyMZTooQ508ZpBg/svM1g7bGb0XrDHQkPhrz IbnugyQlj4DYOx665y2MviFYK4u+KXjI39Wfnm1rt/bqFMxNHogG4vYon YzPLNYBqTO/38oi5CMy1WYTVFtu+yGuVID5CfREFoEKmn/nFjPSpHt8Vt RkzgdUoCPy/3Hzqbcc4EIU6tDLqCDcLPUaQKc96UtJbqCkPmU3NZVaElb GseTICVi+Hk9CIUIKauVTk2Tj47LXP8UlCC/MTzJYrbIcsYY6VsVUc6u6 Q==; X-IronPort-AV: E=Sophos;i="5.90,216,1643644800"; d="scan'208";a="300566280" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 28 Mar 2022 14:29:31 +0800 IronPort-SDR: CgVUWher0AU0tcFxvA0XFeeAzNF2mMz/27O/KRcgB0Wm/gE4CnCAiaXelYqrYp9DwxLRqQLilf yX5HaIR0Q1QaiuEaKcxrOlok0+891O/jYGIztg875YrcT6ELYMFs41yE0tN6jIbVekQ8y8K/fi RuLITgRQJY69AE+WqEEZFwLbnCSLMV+Mi3m3sFQxYA58e5DlRkSDvDpOaGely5h2D/TMHcInpL 7a9IzCQvd818QLV6cotiOffWlFR4G8vSc6g4tOB/pkgDNZxIZTzLUaVGsNYMe2uhkheH6Y9Ehm KXv9y0aO9axmrSpZnrOFXr/P Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 27 Mar 2022 23:00:24 -0700 IronPort-SDR: gJJYoAUZYGnILQOJo4ovUSNu7eS5zPNyxicwdizEAUKpRSeXY7rD/SJw8Ap2psWE692o4dcug1 cBxCLNmooojHuNzKKxOnqGTVGepUM22eWCVdVk+J/RJiNHUUtf7nFuvm9aH5+vK50ljvuxnRUl mPTon85ovn4xCh4r15kVzR1UCs0YnSoM5uGhPLPXUT91CRSOkAK1c2BYeO8Gq0impl7v17bmVg WFioj6oVjMb35sTZdN3xqd7n6uKnmf7IDPctMI4UzHxkggS5u80gzoYa/P/YFltVC0Bj0ESGk/ ATs= WDCIronportException: Internal Received: from phd006511.ad.shared (HELO naota-xeon.wdc.com) ([10.225.52.242]) by uls-op-cesaip01.wdc.com with ESMTP; 27 Mar 2022 23:29:31 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: johannes.thumshirn@wdc.com, Naohiro Aota , Filipe Manana Subject: [PATCH v3 1/3] btrfs: mark resumed async balance as writing Date: Mon, 28 Mar 2022 15:29:20 +0900 Message-Id: <72503baa4f47792e9f7b6c3b5dc858e02e778fbf.1648448228.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org When btrfs balance is interrupted with umount, the background balance resumes on the next mount. There is a potential deadlock with FS freezing here like as described in commit 26559780b953 ("btrfs: zoned: mark relocation as writing"). Mark the process as sb_writing to avoid it. Reviewed-by: Filipe Manana Cc: stable@vger.kernel.org # 4.9+ Signed-off-by: Naohiro Aota --- fs/btrfs/volumes.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 3fd17e87815a..3471698fd831 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -4430,10 +4430,12 @@ static int balance_kthread(void *data) struct btrfs_fs_info *fs_info = data; int ret = 0; + sb_start_write(fs_info->sb); mutex_lock(&fs_info->balance_mutex); if (fs_info->balance_ctl) ret = btrfs_balance(fs_info, fs_info->balance_ctl, NULL); mutex_unlock(&fs_info->balance_mutex); + sb_end_write(fs_info->sb); return ret; } From patchwork Mon Mar 28 06:29:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12793240 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71FBCC433F5 for ; Mon, 28 Mar 2022 06:29:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238481AbiC1GbO (ORCPT ); Mon, 28 Mar 2022 02:31:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238472AbiC1GbM (ORCPT ); Mon, 28 Mar 2022 02:31:12 -0400 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32D061148 for ; Sun, 27 Mar 2022 23:29:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1648448973; x=1679984973; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AMYFyBdErjBYpbOwj42VFSS5eQqiRfGIhaZcEa/4+xo=; b=em4fZeNkBloLcayiCQNlU1jS3ovLS9BhImtEVGWm/BZ8k2uNWwgqnYMH hrqWl1xp9E9u+MQWWFr0TsgKWyMr3IuOHtGUZS1ktPvOyfufAB49Vaz6X RPH6znO/PQ1FE41PfP689awUsFf+fdP218RoWbvuy9dWna+INthYyeDfs 3LWneT6xtrXJ7mnYy2gFtEqaMvaTkTyCdlRWvFKQIBodxUxEYsVR+aAWO 2rRTgfaO4Ciao9r1yePAXJZiR0S8U2phB66C2tARxga+ATd6qHSspC3o8 AMofUITndMoHAR6z16ai619SJPFMtc6RPso2DmJLmt2aXDjU4R8qOOdSa A==; X-IronPort-AV: E=Sophos;i="5.90,216,1643644800"; d="scan'208";a="300566281" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 28 Mar 2022 14:29:32 +0800 IronPort-SDR: 3v0qT8HlSFDV00Vc0YT4qo/1OnSRlxxLPigotaEdIJ3IMRN+dQfe1eMPg/sVCp4IGRUo9GWSu+ 3BTdZqmXi+xv02wx3+KObwAuZHVy6C9NC5A4EBjGf+GGEARE7oEJOUGVZVP75l3F+HQhrYeRZF /5+iHrdwVP+rRcHeP8YxSZ6oRlZ2XfIqyLryLKnCRrIrCxhUfqcKqVq1+kCWqBspvtOyqhOmRE b/ewbLfYYPUkdAuRX6H/R5O7+Ef/W5THkYi7AQ6KGIkMFvmMYWLJ/DyLb+f+BCrzLoo0tD79PM yO1PV9YMskYBHTTmgupt60fh Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 27 Mar 2022 23:00:25 -0700 IronPort-SDR: tx97LU0y3k04xKL08O0GtYvdnL7tBxJrlz4ZIoDTedZVUXYE9UvC+PDiFFarzQQpdYjxEZpDzD zSZmyXWbGeMPXrm/xSBjA+elSFLKf51UBcZEt2p0NGlaybsjFt524RveYFaoAPqsHvxq7wywK5 nzwh170Ga+UMFfHfAVU0hNTLLVhCvU7xqEQcYhOg+7k7uvykQOQG2F6lMnhVPCM9O3RuvYsbbf SMmQ68YYyX/NYfiAxjN0TWf0999CLRj7B+y8Qq2U6inoUe8zi8WM36tycenL4mBhOGH9GjfUeQ /3U= WDCIronportException: Internal Received: from phd006511.ad.shared (HELO naota-xeon.wdc.com) ([10.225.52.242]) by uls-op-cesaip01.wdc.com with ESMTP; 27 Mar 2022 23:29:32 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: johannes.thumshirn@wdc.com, Naohiro Aota , Filipe Manana Subject: [PATCH v3 2/3] fs: add check functions for sb_start_{write,pagefault,intwrite} Date: Mon, 28 Mar 2022 15:29:21 +0900 Message-Id: <5a8a19efe9f19b3e11026f57835614731aeeb62d.1648448228.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Add a function sb_write_started() to return if sb_start_write() is properly called. It is used in the next commit. Reviewed-by: Filipe Manana Signed-off-by: Naohiro Aota --- include/linux/fs.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/linux/fs.h b/include/linux/fs.h index 27746a3da8fd..57fedc4af4a1 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1732,6 +1732,11 @@ static inline bool __sb_start_write_trylock(struct super_block *sb, int level) #define __sb_writers_release(sb, lev) \ percpu_rwsem_release(&(sb)->s_writers.rw_sem[(lev)-1], 1, _THIS_IP_) +static inline bool sb_write_started(struct super_block *sb) +{ + return lockdep_is_held_type(sb->s_writers.rw_sem + SB_FREEZE_WRITE - 1, 1); +} + /** * sb_end_write - drop write access to a superblock * @sb: the super we wrote to From patchwork Mon Mar 28 06:29:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12793241 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31C3EC433F5 for ; Mon, 28 Mar 2022 06:29:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238472AbiC1GbP (ORCPT ); Mon, 28 Mar 2022 02:31:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238478AbiC1GbN (ORCPT ); Mon, 28 Mar 2022 02:31:13 -0400 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E90211164 for ; Sun, 27 Mar 2022 23:29:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1648448973; x=1679984973; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qHrBn1YNCmuwXW6ORMDqdmjUIEQ2fsNF0+FgRscZpvE=; b=inaU4iMrPGgPClDPQ+Xo2Lu3xyqxJP4rztadSiUebD28u6FFNr+miIiz TAAcE6mOryjBLKZU/zwWnuykR7l1nkbnTxPTJXv6P/6KZ8beXi4FL/XIi AODfU5vfkagkZx6n7jB2nMQCJi8iEkwMU9xmuWTdOyzfdbufEgQrMQiib t0TvykBQfvKZcgLViCbCAN44uWsyKJlmk5soSlEA9dwOFrqFTWrwcQvrs OdYxQJfLx9M988jvI8WgeNWpL+5nfqJa9BtQ/ecBiQWugEEazA8aoXf1q an9d1C4mzfQWmftbz805gTdpapUogo7orK819uCN0vVATuqd3GjNYHBZP g==; X-IronPort-AV: E=Sophos;i="5.90,216,1643644800"; d="scan'208";a="300566282" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 28 Mar 2022 14:29:33 +0800 IronPort-SDR: pS9o2929oeo0o7uErnuWxyrrEX0KdOXmhWttCrY8rH9lZ1F4+4ZqBsCw53KT+kpJjwOmBWkxtl oxQizSqbQ5v6HRG0JZlUtNwW02gNUNWvkN0V89MD4sXJ4BP7G0X8mv5+lTSGw2/FxIHTayAYxi bAOZ6abf9DBquaWY0K6H1Iu0i+wqZoTqo+BIoPuEofoR0/Yw2rI5uI4ri9cRSylbvtdvLpYdd5 ZVVuF63d37MhM48uTEJWecXop4T3ZrS8BkGsyzVO/iNJBEEd0iLVvTqcPfXz7YHmeqEpTvyotw 5r9P0kTnd8sgMNAdh/nAtAUY Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 27 Mar 2022 23:00:26 -0700 IronPort-SDR: 3sl3qsOvfbPYooCMGdZP+wzt3rhl1lJXVT6IKw01rdQmMlUnoRT3aRiMyGEoQoTLwf2+Y1b082 FWYIwJYJTSB0qYdwaI5nfDJ99ijxKzCiqXCl4rKcVhfQi6kv7IGtZZC+GueE2QyaNxf2P+CEms CEIl8giBtAnaazNUfPeq7nOMhu0tAnX4rBJiaXOcmrjgxzb3k2iFutL1MXe5cH1hFLKfBL/ePh Nd66iF2/lhMONTVW76a6hRm2y8tWlB+6eqiIt5fQH550lBOWNSEr23FB46lY+GbWn11ZwzG5a3 yHo= WDCIronportException: Internal Received: from phd006511.ad.shared (HELO naota-xeon.wdc.com) ([10.225.52.242]) by uls-op-cesaip01.wdc.com with ESMTP; 27 Mar 2022 23:29:33 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: johannes.thumshirn@wdc.com, Naohiro Aota Subject: [PATCH v3 3/3] btrfs: assert that relocation is protected with sb_start_write() Date: Mon, 28 Mar 2022 15:29:22 +0900 Message-Id: <3c5403c65f3aacbba5f4e441b336233f2112f141.1648448228.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org btrfs_relocate_chunk() initiates new ordered extents. They can cause a hang when a process is trying to thaw the filesystem. We should have called sb_start_write(), so the filesystem is not being frozen. Add an ASSERT to check it is protected. Signed-off-by: Naohiro Aota --- fs/btrfs/relocation.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index fdc2c4b411f0..705799b2b207 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -3977,6 +3977,10 @@ int btrfs_relocate_block_group(struct btrfs_fs_info *fs_info, u64 group_start) if (!bg) return -ENOENT; + /* Assert we called sb_start_write(), not to race with FS freezing */ + if (bg->flags & BTRFS_BLOCK_GROUP_DATA) + ASSERT(sb_write_started(fs_info->sb)); + if (btrfs_pinned_by_swapfile(fs_info, bg)) { btrfs_put_block_group(bg); return -ETXTBSY;