From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AAC6B15B30B; Mon, 29 Jan 2024 17:16:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706548577; cv=none; b=nx7JYiZnrennR3YlU+9U0IqG48caEenb/zc+B5GUvyqbQTOM18oW78C333QkKz8tReoOkvNcibsW6QYuEQG+xtEDnChibSaQDnIq37UXmUWhC05ApVYd/W8oi9oS1YerO2TgcDPQNCkP9STp3er+xqy41Nmus7tHd4XDMvYAIPg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706548577; c=relaxed/simple; bh=QFx7fYET+7bKWz5GvU/ECdiWTP1YxjU4IqApbtIjHyQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ca55AiCYEdvnz1YNwfczFyFfcDt4mOHKsluZIB2L4IyxndeI35EWy926V8vH6DBg0mSd2ILPpGIYb8gpp5rJoNckRNBLnULsMIBfetUmIZFZrc7BKDBPFs7z2tvL6qK2Khu7Hwb06fMKsG9VHNaqz9QcTW7s+UcPZdvKe4dCFkg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=qMNPm/G7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="qMNPm/G7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73641C43390; Mon, 29 Jan 2024 17:16:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1706548577; bh=QFx7fYET+7bKWz5GvU/ECdiWTP1YxjU4IqApbtIjHyQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qMNPm/G7+ewwlyo/8468DdKhea7mSVWF6v/VQh9UKfj/ixQ14i5GOZr5wCmVQIETl MS1tte7ZgjaJu/ORC2Tx/6zcSkANA6DwmflLg47E1qk78Dwxvcpgvcfq/Z2bVWokLL PhqD4bW1mAg3hdBR/sUfRN/uGusURtJjFdR3U+t4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Naohiro Aota , David Sterba Subject: [PATCH 6.6 231/331] btrfs: zoned: fix lock ordering in btrfs_zone_activate() Date: Mon, 29 Jan 2024 09:04:55 -0800 Message-ID: <20240129170021.636912706@linuxfoundation.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240129170014.969142961@linuxfoundation.org> References: <20240129170014.969142961@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Naohiro Aota commit b18f3b60b35a8c01c9a2a0f0d6424c6d73971dc3 upstream. The btrfs CI reported a lockdep warning as follows by running generic generic/129. WARNING: possible circular locking dependency detected 6.7.0-rc5+ #1 Not tainted ------------------------------------------------------ kworker/u5:5/793427 is trying to acquire lock: ffff88813256d028 (&cache->lock){+.+.}-{2:2}, at: btrfs_zone_finish_one_bg+0x5e/0x130 but task is already holding lock: ffff88810a23a318 (&fs_info->zone_active_bgs_lock){+.+.}-{2:2}, at: btrfs_zone_finish_one_bg+0x34/0x130 which lock already depends on the new lock. the existing dependency chain (in reverse order) is: -> #1 (&fs_info->zone_active_bgs_lock){+.+.}-{2:2}: ... -> #0 (&cache->lock){+.+.}-{2:2}: ... This is because we take fs_info->zone_active_bgs_lock after a block_group's lock in btrfs_zone_activate() while doing the opposite in other places. Fix the issue by expanding the fs_info->zone_active_bgs_lock's critical section and taking it before a block_group's lock. Fixes: a7e1ac7bdc5a ("btrfs: zoned: reserve zones for an active metadata/system block group") CC: stable@vger.kernel.org # 6.6 Signed-off-by: Naohiro Aota Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/zoned.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1975,6 +1975,7 @@ bool btrfs_zone_activate(struct btrfs_bl map = block_group->physical_map; + spin_lock(&fs_info->zone_active_bgs_lock); spin_lock(&block_group->lock); if (test_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, &block_group->runtime_flags)) { ret = true; @@ -1987,7 +1988,6 @@ bool btrfs_zone_activate(struct btrfs_bl goto out_unlock; } - spin_lock(&fs_info->zone_active_bgs_lock); for (i = 0; i < map->num_stripes; i++) { struct btrfs_zoned_device_info *zinfo; int reserved = 0; @@ -2007,20 +2007,17 @@ bool btrfs_zone_activate(struct btrfs_bl */ if (atomic_read(&zinfo->active_zones_left) <= reserved) { ret = false; - spin_unlock(&fs_info->zone_active_bgs_lock); goto out_unlock; } if (!btrfs_dev_set_active_zone(device, physical)) { /* Cannot activate the zone */ ret = false; - spin_unlock(&fs_info->zone_active_bgs_lock); goto out_unlock; } if (!is_data) zinfo->reserved_active_zones--; } - spin_unlock(&fs_info->zone_active_bgs_lock); /* Successfully activated all the zones */ set_bit(BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE, &block_group->runtime_flags); @@ -2028,8 +2025,6 @@ bool btrfs_zone_activate(struct btrfs_bl /* For the active block group list */ btrfs_get_block_group(block_group); - - spin_lock(&fs_info->zone_active_bgs_lock); list_add_tail(&block_group->active_bg_list, &fs_info->zone_active_bgs); spin_unlock(&fs_info->zone_active_bgs_lock); @@ -2037,6 +2032,7 @@ bool btrfs_zone_activate(struct btrfs_bl out_unlock: spin_unlock(&block_group->lock); + spin_unlock(&fs_info->zone_active_bgs_lock); return ret; }