Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp794714rwb; Mon, 26 Sep 2022 06:04:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7LdeH/uaIZ1MAUEchvieWP1nlhCjU3U4uu2MzsQkGi9P7y+mfONh6YDk84vW0howm1BRhc X-Received: by 2002:a17:906:cc46:b0:782:f40b:11db with SMTP id mm6-20020a170906cc4600b00782f40b11dbmr10053724ejb.32.1664197462707; Mon, 26 Sep 2022 06:04:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664197462; cv=none; d=google.com; s=arc-20160816; b=iMMfsjb6uamVwsV/S9aLqcapul/ze5UdsgcYzfHGYX8uabwYBCFUvTLovd/BH8xzhC ofhF+/vu2Juzj0LIY/C07Xw6dgabO4Gh++BzZUw6zBmztA7aKDlUI88s/nssc29MmG+t b4rnC6OFF6yqLhf+ksN+lRiYxxczd2L4fKEYd19LKwjJYGqTR+qgWFd8dk9DyO56aOR5 1bxCrcgEmI+OV42HGyyiweWC9p5dF0ua+KBpOxC9T7ofa5SEGQolcZvrc2fxtjzu0XcC EixrE1OV4pBjD8j6BAB+g5srbaNa4ldPEdDY8V3FsgfrllDgnyLfl16mbveDd7m/THtb 6Kgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/vc+yZXwfmeveUOrvcFlxo5BNYMKyIXrVAbyZUTB9PI=; b=Mb6Hs5aUIG+UC/FMBjgMkZvVQLRLDn8dMHCHX0dlnHiBpoR2KqIQgBom8XO4MQB0cz a5jhFkbbKFtMHKf2ntVGYFpMxsd1yKa427vmMs9z5nhGRAfoLi8PMkxIRHqFF64r+8iG 6X+W0C9e/cRS0aYEuQGfawNBcAEMXS7YnDp9cASGuz792IZ3rRpXcR31lxan3lSDlgnh lpi8n6h07QZ6htBiUkYU0YRVRrZtSMpeD16PwzQwuHXj2oAW3a4/QvkbdM4Qo9+xhXKk jqF1/+kgrtRblWl57IoiLCepI5KWl1no+5BAlqzWrnk0s1RwovM4IwaPPZtewTieSzr9 IdaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Z/zDM+9h"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qa34-20020a17090786a200b007417e9a2c71si16071126ejc.352.2022.09.26.06.03.46; Mon, 26 Sep 2022 06:04:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Z/zDM+9h"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238056AbiIZLfX (ORCPT + 99 others); Mon, 26 Sep 2022 07:35:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238146AbiIZLeM (ORCPT ); Mon, 26 Sep 2022 07:34:12 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B14866E2DE; Mon, 26 Sep 2022 03:43:22 -0700 (PDT) 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 415D060A52; Mon, 26 Sep 2022 10:43:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 56196C433C1; Mon, 26 Sep 2022 10:43:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664188998; bh=jLm3OD3DQ5HM9meF13VdBawooU2t/bfBfnoqYP3gKJA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z/zDM+9hdd+EwBtJQKXIOzT2aE0lyhtbKU6gJ6yrkgsL0FeZ2GCUxOon/w/ShJxZj SwJeDwwa7gr43EnKExB0fGGLYBAMtBho4ACJE2z2bDF/s+nlh+H8Ek5GYI5mveocLl c4G7Lequoi6xKzEcOBBPHliRvMpDuBtYvN4kHo1c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josef Bacik , Filipe Manana , David Sterba Subject: [PATCH 5.19 041/207] btrfs: fix hang during unmount when stopping block group reclaim worker Date: Mon, 26 Sep 2022 12:10:30 +0200 Message-Id: <20220926100808.459198084@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100806.522017616@linuxfoundation.org> References: <20220926100806.522017616@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Filipe Manana commit 8a1f1e3d1eecf9d2359a2709e276743a67e145db upstream. During early unmount, at close_ctree(), we try to stop the block group reclaim task with cancel_work_sync(), but that may hang if the block group reclaim task is currently at btrfs_relocate_block_group() waiting for the flag BTRFS_FS_UNFINISHED_DROPS to be cleared from fs_info->flags. During unmount we only clear that flag later, after trying to stop the block group reclaim task. Fix that by clearing BTRFS_FS_UNFINISHED_DROPS before trying to stop the block group reclaim task and after setting BTRFS_FS_CLOSING_START, so that if the reclaim task is waiting on that bit, it will stop immediately after being woken, because it sees the filesystem is closing (with a call to btrfs_fs_closing()), and then returns immediately with -EINTR. Fixes: 31e70e527806c5 ("btrfs: fix hang during unmount when block group reclaim task is running") CC: stable@vger.kernel.org # 5.15+ Reviewed-by: Josef Bacik Signed-off-by: Filipe Manana Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/disk-io.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -4587,6 +4587,17 @@ void __cold close_ctree(struct btrfs_fs_ set_bit(BTRFS_FS_CLOSING_START, &fs_info->flags); /* + * If we had UNFINISHED_DROPS we could still be processing them, so + * clear that bit and wake up relocation so it can stop. + * We must do this before stopping the block group reclaim task, because + * at btrfs_relocate_block_group() we wait for this bit, and after the + * wait we stop with -EINTR if btrfs_fs_closing() returns non-zero - we + * have just set BTRFS_FS_CLOSING_START, so btrfs_fs_closing() will + * return 1. + */ + btrfs_wake_unfinished_drop(fs_info); + + /* * We may have the reclaim task running and relocating a data block group, * in which case it may create delayed iputs. So stop it before we park * the cleaner kthread otherwise we can get new delayed iputs after @@ -4604,12 +4615,6 @@ void __cold close_ctree(struct btrfs_fs_ */ kthread_park(fs_info->cleaner_kthread); - /* - * If we had UNFINISHED_DROPS we could still be processing them, so - * clear that bit and wake up relocation so it can stop. - */ - btrfs_wake_unfinished_drop(fs_info); - /* wait for the qgroup rescan worker to stop */ btrfs_qgroup_wait_for_completion(fs_info, false);