Received: by 2002:a17:90a:9103:0:0:0:0 with SMTP id k3csp11802274pjo; Thu, 2 Jan 2020 14:32:16 -0800 (PST) X-Google-Smtp-Source: APXvYqxy10GA2nSI1HhbsBcz4s9B4b9wrD1/mOUksYX2/S0KJNcfLQ/C51XeBEAwyPLTAp7ICRnQ X-Received: by 2002:a05:6830:20cf:: with SMTP id z15mr94717745otq.277.1578004336054; Thu, 02 Jan 2020 14:32:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578004336; cv=none; d=google.com; s=arc-20160816; b=c5WCaalEOIuFZiYDyvvoSfoo0VQbZXZ+87AAguaefcXqzO1dpb8ALk6ojbk5S2zJ/K w2wnc507YhSy/dz8LTssMhb8qGRpZYzfLWPsYwLjwRfANAyb2Ttuhnqql7VCg5OjoBsB ykqV4ud3buCaG2mZ7MeHVLRkvz+40ly1eJlyxfVabX4vs4yKZEGEANXCHhG9TZ90k2gG ppld+S6EavWH2ssopcgRsAQQqucnm7O/v1d3g9g+4D/YjWS99YkrvZmBtsCo3CBzfXe9 N1WSSLzs40P1kOYdU9BX93FmzUDJezKeB0+GfQFXckP6vGf3dlDlR0iOmlxqqmSo2zV5 4REw== 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=NS74UmTAZ6Ci4RxgXW0XWIzfl1kheZDbouLulNyCGI8=; b=tl6U5dJIaDoBmJfu9OG25zgewISeKd9XUCQfjnYnGFEiRDOUDMfIOBkl1BImCyQEdW My8eFCDmv8syJcFseLcyTtHZ8do3Yiv+4TYQxRcC3D9u0QyLZUA3fNrYzctImFzB/kv/ jFJ1m1IxD0HklsQwWWYDQwc1NIp2eoCibsI0tU/EPnO0jszM9F2Poo/SU8j2Svr4naCB zCXUj3UtN5jhvHs2wn/zMWsIJq/URQA/gP37mILc/CKeQgs0lFk4wd0ONeMsSwqkyq7e w4ojWfbKBluXThAMgkIJtnu+CwHSBRPIf2F11SRUmkMQMAMfLbhXHGg0c4N6mpwpir2K K0wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2bQ3BXDR; 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 m4si29887825otn.281.2020.01.02.14.32.04; Thu, 02 Jan 2020 14:32:16 -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=2bQ3BXDR; 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 S1729743AbgABWa1 (ORCPT + 99 others); Thu, 2 Jan 2020 17:30:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:34168 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729899AbgABWaZ (ORCPT ); Thu, 2 Jan 2020 17:30:25 -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 E9EA220863; Thu, 2 Jan 2020 22:30:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578004224; bh=m5jp6toHKvY6DICKeFo4tapw/949r6gZ/yCWEKg4VJw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2bQ3BXDR4LWA2BFtmzyfuTqnhUDfBgVUjkMR9v9o6vMARSO2zWCakPA4mrFqx62NT SPjGtwlXbNF9Xk3eFyddst0kFe3zYO11usjSfyC0hpcaRHB8Wta/93ePuI9YGNMNfd i4w7UmakKt1WPqY8iBM9FnCxcMw1OuS/XMnHQ3J0= 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.9 089/171] btrfs: do not call synchronize_srcu() in inode_tree_del Date: Thu, 2 Jan 2020 23:07:00 +0100 Message-Id: <20200102220559.438935083@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102220546.960200039@linuxfoundation.org> References: <20200102220546.960200039@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 bb8863958ac0..250c8403ec67 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -5576,7 +5576,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