Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp13477432ybl; Sun, 29 Dec 2019 12:51:20 -0800 (PST) X-Google-Smtp-Source: APXvYqwKtGJiom7XK0RqUIiJP+soSc5+Vj71g5xSe3FrGUY6FNZHalY8URrHtE9Q5/6yzIa1nrmB X-Received: by 2002:a9d:588d:: with SMTP id x13mr66638115otg.6.1577652680349; Sun, 29 Dec 2019 12:51:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577652680; cv=none; d=google.com; s=arc-20160816; b=BWSpjKg2nMz1I7ajQt2jJUuZhWLIfCKmFPSRd9keD4vvYmOC7kJo/t/V+bSCvm+9TG twN4GvMv2ZQfJE7y5gTluKNZZboCeR0CMQNaBqn4azIduBkjOWlVp2tJL9dMT8lAD5Tz u9BOx0wdVNSHFshumo31l4Cj7JZkrFeVXRNVcENV0j0wCNqOtWyyhvt9qXpLp6hszBlz IZ7TzoJvU8B2FXKmhjNF4Sea0/C8qRxz8lOukR4WWmmlQXGtnPLwwgX+DvAfl0zJqD1i gBDJWw5fyIkQ5B17mKpe6W5LYB8COv3UCzTu72C7jzlV5XY/293yniLX46XOmM1KWGqt aw+A== 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=6nkRfWAGbKskAHu+qdA6J90pg4XwYpeLOUcoPrvXMFk=; b=cjwLS+r61QqNpxGSiPexgtJKfS2m51HdmwN9Fc4SjbGGsDGKcFE6dHIueiZFh1jilj YWeZB5rAhTEktG5QMKwn8eNelqBH7U4jRhc3D5Gtox9jT6FGVFEebioukgrw/GGq9bPN LMZ/KLb+0R4FHYt1c9p4zRe8bKCgpAX8QXWBYwAs02sFkQZHfhtbjHhPVtfGwlAafNkd qcPTHLHCw3yDj5u0w8E/J3ku/GNgvzFU+MWuR2cTdY7NH3J3g2F0ujIBy0kOCxOe15Zk jxH77y9EXO/1q4D0Nzy7Okg7kjIqvoIK7Y+9nPCV/5buV6/hpRzCWEXREZRuVx3CdnHv TK0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="1T/7COL+"; 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 u5si15871225otg.99.2019.12.29.12.51.08; Sun, 29 Dec 2019 12:51:20 -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="1T/7COL+"; 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 S1732948AbfL2SMC (ORCPT + 99 others); Sun, 29 Dec 2019 13:12:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:48754 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730299AbfL2Rm2 (ORCPT ); Sun, 29 Dec 2019 12:42:28 -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 DAE9820718; Sun, 29 Dec 2019 17:42:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577641348; bh=lgjsUH1UaErPcRtHPJmQgEs/duTqCRqG4fyGowx74+Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1T/7COL+b9bHgAu3b8Cp7VRckaQIzTaA7ZodLK/G+XiZY7CeNgzCiBrLzZ0rZMSye zYC75BM6KRVTkHH8wOAg7J5qkyMIoSxQVH446v6U47hiezTYJa2/R0j87cMP+GcZqQ tWaITiej9Xsg5c2ATkoJwy8u9NfTNWnuKA8dyWW8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josef Bacik , David Sterba Subject: [PATCH 5.4 029/434] btrfs: do not call synchronize_srcu() in inode_tree_del Date: Sun, 29 Dec 2019 18:21:22 +0100 Message-Id: <20191229172703.983729188@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191229172702.393141737@linuxfoundation.org> References: <20191229172702.393141737@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 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 @@ -5697,7 +5697,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; @@ -5710,7 +5709,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);