From patchwork Tue Mar 29 06:55:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12794489 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 6F063C433F5 for ; Tue, 29 Mar 2022 06:56:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233193AbiC2G5y (ORCPT ); Tue, 29 Mar 2022 02:57:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233175AbiC2G5w (ORCPT ); Tue, 29 Mar 2022 02:57:52 -0400 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AB552DD69; Mon, 28 Mar 2022 23:56:07 -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=1648536969; x=1680072969; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QKH/8wm+bXeq4ciczY4GMtSIhBOzRDlob2ZdPvhqb18=; b=QJ1aJ+kyCGnPOnPGj2R3RAkZTrpR6NIYz4QXXrBLL/j7JdV6LwZBNT1Z DEOFHupVUi7D0SaJne+TkdXO7yhvZRa1CuHkcGZCo1EYAENhNKspNMiuv eoYCUoKzSgcmtxNxsXkR6/Nssd85eqYAxpjP+GRi00CvdK3aT7xXJDCNx CXSke7SqrIVmNr+nO7p0iLKICqUjfFMUFUpHB9h8MV6ufwb7D2KVs+/L8 KE82GBk+B6RhfhFt4OuMQS9y+eP9dXV/UHd+sDEVhoke0TnFW/HfBB7V5 ARpgBkPjv+BtkmrHnjzXXMdWG84RqXCQGHRqD4bKtyQ95+Go9ZyENrVYd w==; X-IronPort-AV: E=Sophos;i="5.90,219,1643644800"; d="scan'208";a="197429214" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 29 Mar 2022 14:56:07 +0800 IronPort-SDR: O6Xvw4Hqq/D3Kjog71QK5yQXsFSNC53i+wu5rt6YmUZA01nLICp0F+jK9Rtn/Vj4HpqsOpGSo7 2uBWET7uk6Tgz3q/ezLIW0gnOCLGnDlk6nhogcxGR8ZlNmNJ7YO77TDHDJ4SL9FnKXCQn4Wrpl cXvQUkeAJuYhjtS/VgTTb+vazs3XfVkqenbof9CojQ5qfspHxyJEl4T3sjf3JOgbEl3qG3rfUP muspi+p6I0WxnarkboAazjZZfqyF2lJxh85Gv0FHnxZL2g4tT42EZCq3IjsqIvSh5sMRmeS8hn BEHDMcrNqa/yhfVu03mP2I+X Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 28 Mar 2022 23:27:51 -0700 IronPort-SDR: 3BK7FG6rkbvLcD9T+0gxIeqTXfbUunRklBsG7fmu3Mw8K8+8sJwN086jlF7ZQkYtvDyRMXoeVE 9cneGMkRRUfrtGROrRWLBsz1jtR4dqNdFZpFwO2LAUyzrz5/bSqP3jlNGcHfuWqdn499awAls9 3wOk0P2ujkarI4mhx3eJM36g4F/dMWS3JhZalIg3oFQK5cV/Ry+BE3YkOVNhzVPZ/HhSnS2Tok W59PjmqQIFX8tVE91Ik6FY4v3ChxTirANyUL9wsZNrHRpJcZ0/UY44rqTk7xITLSvaFrSNnHHa 66s= WDCIronportException: Internal Received: from 2zx6353.ad.shared (HELO naota-xeon.wdc.com) ([10.225.48.64]) by uls-op-cesaip02.wdc.com with ESMTP; 28 Mar 2022 23:56:06 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: johannes.thumshirn@wdc.com, linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk, david@fromorbit.com, Naohiro Aota , Filipe Manana Subject: [PATCH v4 1/3] btrfs: mark resumed async balance as writing Date: Tue, 29 Mar 2022 15:55:58 +0900 Message-Id: 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 Tue Mar 29 06:55:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12794490 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 87F2CC433F5 for ; Tue, 29 Mar 2022 06:56:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233202AbiC2G5z (ORCPT ); Tue, 29 Mar 2022 02:57:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232317AbiC2G5w (ORCPT ); Tue, 29 Mar 2022 02:57:52 -0400 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDF422E093; Mon, 28 Mar 2022 23:56:08 -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=1648536969; x=1680072969; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6zGt4/7Bi6rVIM3CDrEKyuP24GWSiTE6w3IEXHN5j18=; b=Ho8efVm7o2X7ReeaeoBhBd6scPwTOkR95QgVGJPv3JHI7ez+FS86ej6p Sp64FGap9C/n8+lUJn4bNu//ZPf9NeXV5FjzA24L3QcI8+3fvyhL0bZFI 1smdJPotv5Ps9pdQ1vZodc4D2xyT98bs7VebvaeaCjU4A256iLk3cP/lt 64ku4OSA6JyPNkItHRD7f7R2xZ6o0IG+mFLZk5XbCVGmv6lcJ6xtk7F+R Fn5ri3mrk61THyrta6zNmOs7S/E7iBUOokOpjUsksmgIgaydlOaJshvD9 nWkg6tzwsfqlTAsDbe3oRBDiMVbPkvif8z/Xlc/0jKkvN8iNB57Y8cHtV g==; X-IronPort-AV: E=Sophos;i="5.90,219,1643644800"; d="scan'208";a="197429220" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 29 Mar 2022 14:56:08 +0800 IronPort-SDR: 2I/470t9N5Z7unptV6eP6d0zsYG5+qDmhh50Cqap8wEH+/U2rSPNsaT+5mEHnvx8w535wzpaIC iRMID2Sy3gGPer/3Ivj5r4P0Utoy1DLkINnBVEidd1NlwVJTzUpgpRHGnD1rcEQI+HbtH9vodo GcTIp5yMvHPxMxmbdngYXFYYM5/bR9ATcCG2oW30tZUAHsuSyL2l7jLKaBnJ+xsHwwhy9U00CA OefGkgok3ZHubacS0sh553HSH0ImsCKyU65nbw+pZmXUjNgosN30/19Tn7VY9y1ggzJ8h8E6h8 YL3ptQrvcr37rTOiDaHjTszC Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 28 Mar 2022 23:27:52 -0700 IronPort-SDR: 4hN00kNPKO2fkHyAezDcWBXq/WqkODj+0wNeRhhZrrd19y8IQGa9vc/xuelUMdhUlRvQCtYVV1 VBVTpi0OBn9W6o+CTGjinxj5zSQj0anWodWPy4s3KTWYOQZXqkIveIfQri8XLYeZF0934EIYCf uL3Km/3/KTcf5ItFyTK40dC7jpNHjrrte4IfRPWpTO4lRPXDQPTr1oum0nK/yM9x8nMg3DMO3L vakfxsU4xIH3fMxddr3LMmR4rmItiY0oixliGCRFRPUaPtQ6k+lei5TQNAOJ1L/Ny3F0gzTRLk kog= WDCIronportException: Internal Received: from 2zx6353.ad.shared (HELO naota-xeon.wdc.com) ([10.225.48.64]) by uls-op-cesaip02.wdc.com with ESMTP; 28 Mar 2022 23:56:07 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: johannes.thumshirn@wdc.com, linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk, david@fromorbit.com, Naohiro Aota , Filipe Manana Subject: [PATCH v4 2/3] fs: add a check function for sb_start_write() Date: Tue, 29 Mar 2022 15:55:59 +0900 Message-Id: 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..1f3df6e8a74d 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(const 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 Tue Mar 29 06:56:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12794491 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 F12D7C4332F for ; Tue, 29 Mar 2022 06:56:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233214AbiC2G56 (ORCPT ); Tue, 29 Mar 2022 02:57:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233191AbiC2G5y (ORCPT ); Tue, 29 Mar 2022 02:57:54 -0400 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 591A22E9ED; Mon, 28 Mar 2022 23:56:11 -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=1648536972; x=1680072972; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Cd0iTHAu9pZ35QJoZ2R6TCWqhJhsHQts6FYW7B5x2Uc=; b=frascRHxpNlZCTWZCotXN13MzLcs02LrD5FRFI3Ge9C5qeCTOaqK9ssi awRvo7YDd1aUOQyXWhutEmdfr2QhOOL2oS+kPI710q4STRdU9yh0rVAqh J93TNaVIWdyBYSGNIu9c7dXLKAVtetYF2UAMbQQGoxoriBM6Wm1LL1KYw y3LyE9S1XVRTjGzD2f24HmdpHT5RHfK27IlKn3cJ0EscadnfVBqMoiALQ zSOP8aYVEyq20t8QSLbMXx/oUo1IvcT0XkufQ+q6Jk5Gs5ffvyIpXb4DI H2jE4p9uREZwuVX97AX7usV7rkBmOIJmPnB0g9RTPwsItT6Y3CaKd35H2 A==; X-IronPort-AV: E=Sophos;i="5.90,219,1643644800"; d="scan'208";a="197429226" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 29 Mar 2022 14:56:09 +0800 IronPort-SDR: 59XS4lQMkN1w+H3gl56zHsMtYRBmOTDLTLnBhb0ENWShY700GKAAzldF8nRl2fWGhbILVqWqfs Kbhr/nxH/9mfQVsNQK1KC9eh1FNPo60SJyLg6WvL7jgKHCeLeBjEdEWiP85vDD1UgTQLzR7H6i iTPqNYUGypB/BGLO5679necolB016xuQLnmfw3T51BQV4I4VIpFNhIHn0rCICRgdBk+yCAf1wK 675dytWlL3+weoPFD90PNW/18ogOlbU+2+8SXCPnnMT0mW3Zus7XoVau7KiWoyZdFfmPyNwmP6 m6L/gw3R4PvEwQXNjH5LS9VK Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 28 Mar 2022 23:27:54 -0700 IronPort-SDR: kPAly7Qjv1lcmHzcVdNb5DbcEDrP+XFEGSu4UNV7LgsA7G4z4PZ4NSGJWZhf1T/FsyzkTjVLvK +2m6W9+FBQVQH8BSiOFaDpwozis8AN/gDewLTQcVv4ezft2ZxXA0c/ebKMh9lWujMlUHDmHvW5 4lKOECik6okuHE2b6+FhTM6W69nPgX89hhG4YaRIYkb6FOrlJN6z3w6hCz3Mqj+/civwb4QUV5 4VQrG6a0UruMVkRAmK/ixRV5CARBKsWd98j0QgiY/P8iZccExAG9eOJAnvV9dS4ctMmMVJHpnO ScY= WDCIronportException: Internal Received: from 2zx6353.ad.shared (HELO naota-xeon.wdc.com) ([10.225.48.64]) by uls-op-cesaip02.wdc.com with ESMTP; 28 Mar 2022 23:56:09 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: johannes.thumshirn@wdc.com, linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk, david@fromorbit.com, Naohiro Aota Subject: [PATCH v4 3/3] btrfs: assert that relocation is protected with sb_start_write() Date: Tue, 29 Mar 2022 15:56:00 +0900 Message-Id: <28e3e02ed14fe7c0859707e1a10a447fe4338c16.1648535838.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 Relocation of a data block group creates 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 Reviewed-by: Filipe Manana --- fs/btrfs/relocation.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index fdc2c4b411f0..5e52cd8d5f23 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -3977,6 +3977,16 @@ int btrfs_relocate_block_group(struct btrfs_fs_info *fs_info, u64 group_start) if (!bg) return -ENOENT; + /* + * Relocation of a data block group creates ordered extents. + * Without sb_start_write(), we can freeze the FS while unfinished + * ordered extents are left. Such ordered extents can cause a + * deadlock e.g, when syncfs() is trying to finish them because + * they never finish as the FS is already frozen. + */ + 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;