Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp17939611ybl; Thu, 2 Jan 2020 15:12:22 -0800 (PST) X-Google-Smtp-Source: APXvYqxwEx/wThftbjxey/AXWDKtSBmT8thzHSsBDASjRQs9sfrO5jA7wzhLDWtpDlF8ruC+5vdf X-Received: by 2002:a05:6808:8d0:: with SMTP id k16mr3244574oij.68.1578006742825; Thu, 02 Jan 2020 15:12:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578006742; cv=none; d=google.com; s=arc-20160816; b=wgpFQut5uLrRijAzRxsjVWZF14Qel04pw3q4azKSfq2NBRcP2UpY0nBq2Mixlt4AOe S6kdjfIA1Eb106uFw0UuQJROqPOgV8ifEhO0MjfnsPU2OSJ86gbR/EwC70EdZKo1wVpb yDVLuSHvlqFqpjIKgGqWyE5d7A4NJEBtOJhfY47ReL1qplusG2719mRmnmWS0gwtq+sB iZ5oCtgXxkex2+qFkaHhnYjLIANVIpY3lJrvCaHSfay7YeEPewARDwv6xLhdwIXLfTy8 o7vm9yQhPUQvxkuYtjhDegeD6up1VRenU2pOOrCvN11e1SCLjSl4tlQCOcHDDI//vFFk QywQ== 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=gNzO3VL49W8bH1D4MPo/5WClF8kvi13mIaDmDC05AFo=; b=Gn74wUk2ANIy8tqSEEBAsg+fl/MnfUMEI3ToObFF2CTTXC4FESRKJzKc9q2aAZMoWl X20gQGRxW88/SFwJ4MHjxxQbyebVQO6pvcAP+4W3PrgUku4ja7BvgNqi374wbRlRqHUe GPbZEa1zLP5IfSjeWk8v5z6XygLMa8PNfEUxjSs6/UL2QqsN6QcRrDAlbL5dMBsWiOba aGUDMkX0Noq51tAVGMLM+HiDkLLRvD/g5SPedPBNTiJuqhWOo66Iw17nz6Dr6pI3HKZf 14i1TymOcCoP0USg9nTSH1pUab3UF1v4/dhKRdocyGkkzDCglteKkgelCvs9HQmj7Ui3 2dbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aUQ8TfKB; 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 f187si27669777oia.218.2020.01.02.15.12.11; Thu, 02 Jan 2020 15:12:22 -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=aUQ8TfKB; 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 S1730400AbgABWgh (ORCPT + 99 others); Thu, 2 Jan 2020 17:36:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:47510 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730940AbgABWgY (ORCPT ); Thu, 2 Jan 2020 17:36:24 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 163AE21D7D; Thu, 2 Jan 2020 22:36:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578004583; bh=kl004tIylIy2HeVOharYYJ5vMSraklAz5CHA3QF/Qis=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aUQ8TfKBAfEPidlHDPd/GxO/lGECgfvBaDWIuaV7C8f61VTcj5zQZG/Wh7lwQaejS SO0WpCdjkG6P/bDNLCUKCxByEsKp643zzqW62dzBhnnGlcfmJyLdQZ/EOlr8LBm830 xi7PPlNJK4OAKmyst7yGJzKOXfNuVgH78/52pQkE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josef Bacik , David Sterba , Sasha Levin Subject: [PATCH 4.4 068/137] btrfs: do not call synchronize_srcu() in inode_tree_del Date: Thu, 2 Jan 2020 23:07:21 +0100 Message-Id: <20200102220555.698776544@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102220546.618583146@linuxfoundation.org> References: <20200102220546.618583146@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Josef Bacik [ Upstream commit f72ff01df9cf5db25c76674cac16605992d15467 ] Testing with the new fsstress uncovered a pretty nasty deadlock with lookup and snapshot deletion. Process A unlink -> final iput -> inode_tree_del -> synchronize_srcu(subvol_srcu) Process B btrfs_lookup <- srcu_read_lock() acquired here -> btrfs_iget -> find inode that has I_FREEING set -> __wait_on_freeing_inode() We're holding the srcu_read_lock() while doing the iget in order to make sure our fs root doesn't go away, and then we are waiting for the inode to finish freeing. However because the free'ing process is doing a synchronize_srcu() we deadlock. Fix this by dropping the synchronize_srcu() in inode_tree_del(). We don't need people to stop accessing the fs root at this point, we're only adding our empty root to the dead roots list. A larger much more invasive fix is forthcoming to address how we deal with fs roots, but this fixes the immediate problem. Fixes: 76dda93c6ae2 ("Btrfs: add snapshot/subvolume destroy ioctl") CC: stable@vger.kernel.org # 4.4+ Signed-off-by: Josef Bacik Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/inode.c | 1 - 1 file changed, 1 deletion(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 383717ccecc7..548e9cd1a337 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -5506,7 +5506,6 @@ static void inode_tree_del(struct inode *inode) spin_unlock(&root->inode_lock); if (empty && btrfs_root_refs(&root->root_item) == 0) { - synchronize_srcu(&root->fs_info->subvol_srcu); spin_lock(&root->inode_lock); empty = RB_EMPTY_ROOT(&root->inode_tree); spin_unlock(&root->inode_lock); -- 2.20.1