Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5243880imu; Tue, 15 Jan 2019 13:58:07 -0800 (PST) X-Google-Smtp-Source: ALg8bN51U9WG11z0DYw6zgBgPktNEItU8S1FKUBAdOd3FauOcT8SmrGauNUVqMDAPyFDCIrqgl8T X-Received: by 2002:a17:902:2f03:: with SMTP id s3mr6186261plb.277.1547589487003; Tue, 15 Jan 2019 13:58:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547589486; cv=none; d=google.com; s=arc-20160816; b=YnQENJhtjoXBJlGvrv7qwwaXv3YhKejcYivaEyeDEYBfORLe5TvgRYe/IgyqRpep4K qTwwRJbwJiKZedLjQuG6M/MxSMCmBtm8vgFaV9QEDh1aEsk+wDh4grmIz/CEEh1SAreM gEeyAfg7gKB7ZynWEkjAGK8MHEbo/JmDxhD9jALD112k/xN4yS39zOE2ClC4/ofKmosc t7FSoCTQgt7loDJGWwPWFk1EoIPWmeHFJeYm6jz8JXcMX2IPZI3gF+2u8elltKEneccP OlZmV5uqhJgLvNIulC5borD+LpuX/bcC0ICXpqvePgBEsHfTjRu7BqtybAo3Wx0QKM91 6Srg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FAXiBzX5cu/5w+ejNfKJtIhYnxrKRIav+F+8v7VITds=; b=SoLJY1ovNXRrO4JchMyr3Dgx4pO6oMOk050GR7seeyC0EfcMxqU1G0+Zl8Tte3rAWy 0eVZTTgOTvOuBkiRK5rKSL7tKgwkxAytJWme1nJ7ZIMLSDaDjVQH790ZYNmRevEMHlz1 LS9dq1uFAFlu/sqTOILa1myAzCOyCHbHNHcG+3qLo5JPfWS8F+tiUvqgKo2B7HTdKB2r fMzteBeWAGn4A5C9+1yb3G93Csj/4YSETJeYOP3iuwBaYM/aosL5bGQgT+Lk0FdaJ1Iw EFX85nEv1dTlGxA+nV2msbdJ2ivziBCfJZbj/gBqLJKuDQz6qUA//K+Aan8oWU5bLLiN TInQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cGsgL5g9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e66si4532810plb.107.2019.01.15.13.57.50; Tue, 15 Jan 2019 13:58:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cGsgL5g9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387479AbfAOQoJ (ORCPT + 99 others); Tue, 15 Jan 2019 11:44:09 -0500 Received: from mail.kernel.org ([198.145.29.99]:33658 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387469AbfAOQoH (ORCPT ); Tue, 15 Jan 2019 11:44:07 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BF4CD2054F; Tue, 15 Jan 2019 16:44:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547570646; bh=jG+rAo61gvCU7PLL1KnFP9e45hwXCrfJK9LUonLqKfA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cGsgL5g9Qe/haLsG6hdtCL++NYf5oTyN68XuAuHaW4LKyUYR1Byx9253wyOj83RQ/ W/3GAaDElTtI/p6Kxj+W7/sAO8BY2ZNs4pxLBiUnjMxg9Re07rhjUDbAyVP8THfhGr KEqtoMTGj6exuRFkagPLipUWDJPb8ceKentxct00= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Filipe Manana , David Sterba Subject: [PATCH 4.20 02/57] Btrfs: fix deadlock when using free space tree due to block group creation Date: Tue, 15 Jan 2019 17:35:43 +0100 Message-Id: <20190115154910.863488970@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190115154910.734892368@linuxfoundation.org> References: <20190115154910.734892368@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Filipe Manana commit a6d8654d885d7d79a3fb82da64eaa489ca332a82 upstream. When modifying the free space tree we can end up COWing one of its extent buffers which in turn might result in allocating a new chunk, which in turn can result in flushing (finish creation) of pending block groups. If that happens we can deadlock because creating a pending block group needs to update the free space tree, and if any of the updates tries to modify the same extent buffer that we are COWing, we end up in a deadlock since we try to write lock twice the same extent buffer. So fix this by skipping pending block group creation if we are COWing an extent buffer from the free space tree. This is a case missed by commit 5ce555578e091 ("Btrfs: fix deadlock when writing out free space caches"). Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=202173 Fixes: 5ce555578e091 ("Btrfs: fix deadlock when writing out free space caches") CC: stable@vger.kernel.org # 4.18+ Signed-off-by: Filipe Manana Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/ctree.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -1015,19 +1015,21 @@ static noinline int __btrfs_cow_block(st parent_start = parent->start; /* - * If we are COWing a node/leaf from the extent, chunk or device trees, - * make sure that we do not finish block group creation of pending block - * groups. We do this to avoid a deadlock. + * If we are COWing a node/leaf from the extent, chunk, device or free + * space trees, make sure that we do not finish block group creation of + * pending block groups. We do this to avoid a deadlock. * COWing can result in allocation of a new chunk, and flushing pending * block groups (btrfs_create_pending_block_groups()) can be triggered * when finishing allocation of a new chunk. Creation of a pending block - * group modifies the extent, chunk and device trees, therefore we could - * deadlock with ourselves since we are holding a lock on an extent - * buffer that btrfs_create_pending_block_groups() may try to COW later. + * group modifies the extent, chunk, device and free space trees, + * therefore we could deadlock with ourselves since we are holding a + * lock on an extent buffer that btrfs_create_pending_block_groups() may + * try to COW later. */ if (root == fs_info->extent_root || root == fs_info->chunk_root || - root == fs_info->dev_root) + root == fs_info->dev_root || + root == fs_info->free_space_root) trans->can_flush_pending_bgs = false; cow = btrfs_alloc_tree_block(trans, root, parent_start,