From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E299C2D0D1 for ; Sun, 29 Dec 2019 18:18:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 745FD20748 for ; Sun, 29 Dec 2019 18:18:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577643510; bh=s5B3lJwV4LMC3f0kVupUoUXC08V/vbxtaHQo17eQX2I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=KZNre61+bkVcrlJj6dZ/EbbZlK0Amq40Sk3nOuDVHQmOAtCn9tVMPjny1Zxs5fvrO z/d079RV6rTtkA3DohbAsfdV3sJfX72teurOLMx+suHUx4BWTX0GCmMRoNfZahsMuq 7hpTaUKZAnDijPvJ8bOa6/6Nww2Iab1CZl9Dv2tA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726752AbfL2RVZ (ORCPT ); Sun, 29 Dec 2019 12:21:25 -0500 Received: from mail.kernel.org ([198.145.29.99]:36516 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726720AbfL2RVY (ORCPT ); Sun, 29 Dec 2019 12:21: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 8C866208E4; Sun, 29 Dec 2019 17:21:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577640084; bh=s5B3lJwV4LMC3f0kVupUoUXC08V/vbxtaHQo17eQX2I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c8gKmsQRRYFnmJRq/pME30Q0a6TdkVo7IU/R7DpScabXe5dL2MlsKbae9Yn7eA/A4 jRaiZW91Gc9iI0sTLpi+nepAKdTbY0kP4B2a3fkbQsFZbggHCC1R/CuiQsvc1y/lUM BrBWVW9x/brJk3DST2XzCPhU6Fez3LjjRlMnamBg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josef Bacik , David Sterba Subject: [PATCH 4.14 012/161] btrfs: do not call synchronize_srcu() in inode_tree_del Date: Sun, 29 Dec 2019 18:17:40 +0100 Message-Id: <20191229162359.542920188@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191229162355.500086350@linuxfoundation.org> References: <20191229162355.500086350@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Josef Bacik commit f72ff01df9cf5db25c76674cac16605992d15467 upstream. 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: Greg Kroah-Hartman --- fs/btrfs/inode.c | 2 -- 1 file changed, 2 deletions(-) --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -5729,7 +5729,6 @@ static void inode_tree_add(struct inode static void inode_tree_del(struct inode *inode) { - struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); struct btrfs_root *root = BTRFS_I(inode)->root; int empty = 0; @@ -5742,7 +5741,6 @@ static void inode_tree_del(struct inode spin_unlock(&root->inode_lock); if (empty && btrfs_root_refs(&root->root_item) == 0) { - synchronize_srcu(&fs_info->subvol_srcu); spin_lock(&root->inode_lock); empty = RB_EMPTY_ROOT(&root->inode_tree); spin_unlock(&root->inode_lock);