Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2759645imj; Mon, 11 Feb 2019 08:04:33 -0800 (PST) X-Google-Smtp-Source: AHgI3IbjryVEjhXtow6qr2V95HfRj/+Y/bexNvVTY7Ks3eVb7mXtbHx5sgn0iLHAInlNmKfrR+4I X-Received: by 2002:a17:902:b615:: with SMTP id b21mr32430158pls.338.1549901073064; Mon, 11 Feb 2019 08:04:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549901073; cv=none; d=google.com; s=arc-20160816; b=rg3VQy3X94beGxFCWrflHHia4EYxUJ/QhAIUjbBMqwg6iT/GvuREJdJBFiHb9ku0E3 96OWbbdq+huTT1utSxvx656ccDMSpCYATYmbO/N6zDAcXkn/WtdkAXICUrQlJlbZxJh8 kUkrU+Gh2bGcStoaiEgFOoLuRm/Yj195wqdkC5AggrtTEwVQmJ1rAQCm66FZpRWdgpfn dhSuaz1qr44ZUNw56uwiuDQlCUKOlrykWV1xGs67QLTLm0FFTah1/NrmiuiN6/eCLWxj S7UK8jE4CPYqkJtDo9mN9PMt13c3RIExr3XqkGtgppm/3bk86mD3/q02pbIpeQcvxK+5 kMBA== 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=t8l+S6MEXL5RlNwQJGEHg1GeVQdhOF+SGT2wEoeWGNU=; b=r2XReldlu6Eb/2YceEcvKC1FPuFkI8xF0EVU+SlWmZGODa/Xf77J9m0CQ5EbYZhCMz EkVNb75bVGoHyfmjOP2uyrqVK+gqYuUj0/x4jWjhInR/qVIZUtM9bYZv5FlNNFxvQKBo U5A/kuUfwQJxmLcL7NCZvw/N4I1WZO+q7i4qhMsve5C2aHuLj8DUWOujIImshNW856cD KldkZc5iS8KEeFbVP3praNWQkQD7DMfYpOt0GEV6MKWf0HN9JUz/ocv3nDW+0++cR3N9 x5ghv3CSgbeDLOl4DjQdCDld5nil6rY3wPrs21NKqCTvgV8qAWjHRbq9pVcgYG8JmUKF JhQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OAIAfuiR; 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 r27si9637447pgl.494.2019.02.11.08.04.09; Mon, 11 Feb 2019 08:04:33 -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=OAIAfuiR; 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 S1730259AbfBKQBf (ORCPT + 99 others); Mon, 11 Feb 2019 11:01:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:37674 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730225AbfBKObB (ORCPT ); Mon, 11 Feb 2019 09:31:01 -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 B080820675; Mon, 11 Feb 2019 14:31:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549895461; bh=KhA8XNN+0BZPSKKdkvs3lalVmwa4Yw8yhba1jyNHsAg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OAIAfuiRgS+TH31sd5svIRdeXvg4LTKS02+xWVouNrnL/Hqe4XQefdPve9Je//HZf LBHsiLd131SfBYs/D8y2uGVrNzYq6jADgPRKDTmQTKGFCSHUF1/cD10SPBnOIA8tn2 PCZMTVtY5L1UsGTtjqoPKvC9rtGinkxDPCSt5DlI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Sterba , Sasha Levin Subject: [PATCH 4.20 181/352] btrfs: reada: reorder dev-replace locks before radix tree preload Date: Mon, 11 Feb 2019 15:16:48 +0100 Message-Id: <20190211141858.608391723@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141846.543045703@linuxfoundation.org> References: <20190211141846.543045703@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. ------------------ [ Upstream commit ceb21a8db48559fd0809e03c4df9eb37743d9170 ] The device-replace read lock is going to use rw semaphore in followup commits. The semaphore might sleep which is not possible in the radix tree preload section. The lock nesting is now: * device replace * radix tree preload * readahead spinlock Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/reada.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/reada.c b/fs/btrfs/reada.c index dec14b739b10..6f81f3e88b6d 100644 --- a/fs/btrfs/reada.c +++ b/fs/btrfs/reada.c @@ -376,26 +376,28 @@ static struct reada_extent *reada_find_extent(struct btrfs_fs_info *fs_info, goto error; } + /* Insert extent in reada tree + all per-device trees, all or nothing */ + btrfs_dev_replace_read_lock(&fs_info->dev_replace); ret = radix_tree_preload(GFP_KERNEL); - if (ret) + if (ret) { + btrfs_dev_replace_read_unlock(&fs_info->dev_replace); goto error; + } - /* insert extent in reada_tree + all per-device trees, all or nothing */ - btrfs_dev_replace_read_lock(&fs_info->dev_replace); spin_lock(&fs_info->reada_lock); ret = radix_tree_insert(&fs_info->reada_tree, index, re); if (ret == -EEXIST) { re_exist = radix_tree_lookup(&fs_info->reada_tree, index); re_exist->refcnt++; spin_unlock(&fs_info->reada_lock); - btrfs_dev_replace_read_unlock(&fs_info->dev_replace); radix_tree_preload_end(); + btrfs_dev_replace_read_unlock(&fs_info->dev_replace); goto error; } if (ret) { spin_unlock(&fs_info->reada_lock); - btrfs_dev_replace_read_unlock(&fs_info->dev_replace); radix_tree_preload_end(); + btrfs_dev_replace_read_unlock(&fs_info->dev_replace); goto error; } radix_tree_preload_end(); -- 2.19.1